-
Notifications
You must be signed in to change notification settings - Fork 461
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support metrics scrape #2344
base: master
Are you sure you want to change the base?
Conversation
We should add a way to scrape v3 metrics as well |
@jiuker is there a way we can create tests for this? since this is a new feature? like an integration test? Thanks. |
b38e1b6
to
982f5d4
Compare
Will take a look |
2c7c9e0
to
40012a7
Compare
40012a7
to
732b95c
Compare
@jiuker PTAL - pkg:golang/golang.org/x/[email protected] vulnerability |
pkg/controller/prometheus.go
Outdated
} | ||
} | ||
if !hasScrapeConfig { | ||
exceptedScrapeConfigs = append(exceptedScrapeConfigs, promCfg.ScrapeConfigs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only way to remove scrapeConfigs is to set prometheusOperator
to false, then re-initialize the array. This does not seem correct.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yesh. prometheusOperator: true
with this prometheusOperatorScrapeMetricsPath:[]
is means default /minio/v2/metrics/cluster
like before.
I think we should compatible that user don't set that before. Any advice ? @allanrogerr ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you mean expectedScrapeConfigs
instead of exceptedScrapeConfigs
? Or did you mean acceptedScapeConfigs
???
} | ||
|
||
for index, scrape := range t.Spec.PrometheusOperatorScrapeMetricsPath { | ||
promConfig.ScrapeConfigs = append(promConfig.ScrapeConfigs, ScrapeConfig{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider the following tenant yaml section; note that v3 cluster metrics is scraped using /minio/v3/metrics/cluster/
(see https://github.com/minio/minio/blob/master/docs/metrics/v3.md):
prometheusOperator: true
prometheusOperatorScrapeMetricsPath:
- /minio/v2/metrics/bucket
- /minio/v2/metrics/cluster
- /minio/v2/metrics/node
- /minio/v2/metrics/resource
- /minio/v3/metrics/cluster/
v3 metrics scraping is failing with server returned HTTP status 403 Forbidden
. Please try and check this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yesh. Should be like /minio/metrics/v3/*
, but that can be set with this strings slice field.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm no expert on Prometheus metrics and MinIO, but I think this code doesn't work correctly. Please make these changes to AIStor operator and implement proper integration tests.
pkg/apis/minio.min.io/v2/types.go
Outdated
// The name of the Prometheus instance to scrape metrics from. | ||
// | ||
// +optional | ||
PrometheusOperatorScrapeMetricsPath []string `json:"prometheusOperatorScrapeMetricsPath,omitempty"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you can specify multiple values, then this should probably be:
PrometheusOperatorScrapeMetricsPath []string `json:"prometheusOperatorScrapeMetricsPath,omitempty"` | |
PrometheusOperatorScrapeMetricsPaths []string `json:"prometheusOperatorScrapeMetricsPaths,omitempty"` |
@@ -278,6 +278,12 @@ type TenantSpec struct { | |||
PrometheusOperator bool `json:"prometheusOperator,omitempty"` | |||
// *Optional* + | |||
// | |||
// The name of the Prometheus instance to scrape metrics from. | |||
// | |||
// +optional |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add some information about the default (or fallback) value?
pkg/controller/prometheus.go
Outdated
} else { | ||
for i := range scrapeConfigs { | ||
if scrapeConfigs[i].JobName != exceptedScrapeConfigs[i].JobName || | ||
scrapeConfigs[i].MetricsPath != exceptedScrapeConfigs[i].MetricsPath || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add some comment that the generation of the scrape configuration always creates a new bearer token, so it shouldn't be included in this check, because it will always result in it being not equal.
How do we make sure the bearer token is updated when the tenant gets assigned other credentials (different access/secret key). This will result in another bearer token (but nothing else), so it will decide that the scape configuration hasn't changed, but Prometheus won't be able to access MinIO with the old token.
pkg/controller/prometheus.go
Outdated
@@ -161,20 +163,34 @@ func (c *Controller) checkAndCreatePrometheusAddlConfig(ctx context.Context, ten | |||
return err | |||
} | |||
} else { | |||
var scrapeConfigs []configmaps.ScrapeConfig | |||
var scrapeConfigs, exceptedScrapeConfigs []configmaps.ScrapeConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change line 146 to include the namespace/tenant that is getting the Prometheus scrape configuration?
pkg/controller/prometheus.go
Outdated
} | ||
} | ||
if !hasScrapeConfig { | ||
exceptedScrapeConfigs = append(exceptedScrapeConfigs, promCfg.ScrapeConfigs...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess you mean expectedScrapeConfigs
instead of exceptedScrapeConfigs
? Or did you mean acceptedScapeConfigs
???
pkg/apis/minio.min.io/v2/helper.go
Outdated
// GetAccessKeyFromBearerToken parses the BearerToken with secretKey to extract accessKey | ||
func GetAccessKeyFromBearerToken(bearerToken string, secretKey string) (string, error) { | ||
claims := &jwt.StandardClaims{} | ||
token, err := jwt.ParseWithClaims(bearerToken, claims, func(token *jwt.Token) (interface{}, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please address linter issue:
token, err := jwt.ParseWithClaims(bearerToken, claims, func(token *jwt.Token) (interface{}, error) { | |
token, err := jwt.ParseWithClaims(bearerToken, claims, func(_ *jwt.Token) (interface{}, error) { |
@@ -224,27 +247,20 @@ func (c *Controller) deletePrometheusAddlConfig(ctx context.Context, tenant *min | |||
return err | |||
} | |||
|
|||
var scrapeConfigs []configmaps.ScrapeConfig | |||
var scrapeConfigs, exceptedScrapeConfigs []configmaps.ScrapeConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a typo:
var scrapeConfigs, exceptedScrapeConfigs []configmaps.ScrapeConfig | |
var scrapeConfigs, expectedScrapeConfigs []configmaps.ScrapeConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be fine now
pkg/controller/prometheus.go
Outdated
} | ||
accKey, err := miniov2.GetAccessKeyFromBearerToken(scrapeConfigs[i].BearerToken, secretKey) | ||
if err != nil { | ||
klog.Errorf("Failed to get access key from bearer token: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When secretKey
is changed, then it will not be able to decrypt the existing bearer-token using the new secret key. The function will return an error. That shouldn't be logged, but is expected, but it should set updateScrapeConfig
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ignored it now
apply suggestion
feat: support metrics scrape
fix #2327
we just support
/minio/v2/metrics/cluster
beforenow we can do more type for this
like
default is
/minio/v2/metrics/cluster