-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Feature/validate metric name uniqueness #1390
Feature/validate metric name uniqueness #1390
Conversation
@zroubalik I'm not sure why the static check is failing. It seems to be referencing code in the object finilizers. I didn't modify them (I think). Also any tips on where to put the documentation update for the metric name validation? |
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.
Looking good so far, we should add a check though
observedMetricNames := make(map[string]struct{}) | ||
for _, scaler := range scalers { | ||
for _, metric := range scaler.GetMetricSpecForScaling() { | ||
metricName := metric.External.Metric.Name |
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.
We should check whether the scaler contains External metrics (if != nil
), becasue if Resource based Metrics are used, External Metrics are not set.
See:
Lines 135 to 162 in af2b36f
func (r *ScaledObjectReconciler) getScaledObjectMetricSpecs(logger logr.Logger, scaledObject *kedav1alpha1.ScaledObject) ([]autoscalingv2beta2.MetricSpec, error) { | |
var scaledObjectMetricSpecs []autoscalingv2beta2.MetricSpec | |
var externalMetricNames []string | |
var resourceMetricNames []string | |
scalers, err := r.scaleHandler.GetScalers(scaledObject) | |
if err != nil { | |
logger.Error(err, "Error getting scalers") | |
return nil, err | |
} | |
for _, scaler := range scalers { | |
metricSpecs := scaler.GetMetricSpecForScaling() | |
for _, metricSpec := range metricSpecs { | |
if metricSpec.Resource != nil { | |
resourceMetricNames = append(resourceMetricNames, string(metricSpec.Resource.Name)) | |
} | |
if metricSpec.External != nil { | |
// add the scaledObjectName label. This is how the MetricsAdapter will know which scaledobject a metric is for when the HPA queries it. | |
metricSpec.External.Metric.Selector = &metav1.LabelSelector{MatchLabels: make(map[string]string)} | |
metricSpec.External.Metric.Selector.MatchLabels["scaledObjectName"] = scaledObject.Name | |
externalMetricNames = append(externalMetricNames, metricSpec.External.Metric.Name) | |
} | |
} | |
scaledObjectMetricSpecs = append(scaledObjectMetricSpecs, metricSpecs...) | |
scaler.Close() | |
} |
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.
That's a great point! I went ahead and added a continue when external metrics is nil
The static check is strange, you can probably disable this specific one for the finalizers: Line 50 in af2b36f
We should probably add a new section unde KEDA Concepts, something like section |
@ycabrer any update please? :) |
Missed this one, sorry @zroubalik, but I agree to have a section on multiple scalers and what to expect of them. Not sure though if this should include technical details such as metric name validation but more how the decision making will happen maybe? |
@ycabrer are you able to update this please? It is completely OK, if you don't have a time to do so. But please let us know, so we can manage this. Thanks! |
@zroubalik Sorry for the delay. I've had a busy start to the new year! I'll go ahead and update the docs. |
Signed-off-by: ycabrer <[email protected]>
Signed-off-by: ycabrer <[email protected]>
Signed-off-by: ycabrer <[email protected]>
Signed-off-by: ycabrer <[email protected]>
Signed-off-by: ycabrer <[email protected]>
Signed-off-by: ycabrer <[email protected]>
Signed-off-by: ycabrer <[email protected]>
e6f2d6c
to
5e5ddbb
Compare
I rebased my branch against kedacore/main. It seems like the static checks are still failing for me on the finalizers. I took a look at the golang ci config file and can't seem to ignore the failures. Any advice? |
Have you tried adding a new section to the Something like this: # Excluding interfacer for finalizers, reason: https://github.com/kedacore/keda/pull/1390
- path: _finalizer.go
linters:
- interfacer |
Signed-off-by: ycabrer <[email protected]>
That worked
That did it! I had chosen the wrong linter. |
@@ -56,6 +56,9 @@ issues: | |||
- path: scale_handler.go | |||
linters: | |||
- gocyclo | |||
- path: _finalizer.go |
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.
Could you please add a comment with a description why are we adding this exception, eg. with a link to this PR?
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.
Sure thing! I missed that you had already given an example
CHANGELOG.md
Outdated
@@ -40,6 +40,7 @@ | |||
- Improve error reporting in prometheus scaler ([PR #1497](https://github.com/kedacore/keda/pull/1497)) | |||
|
|||
### Breaking Changes | |||
- Require metricNames be unique in scaled objects. |
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.
- Require metricNames be unique in scaled objects. | |
- Require metricNames be unique in scaled objects ([#1390](https://github.com/kedacore/keda/pull/1390)) |
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 just updated it
Signed-off-by: ycabrer <[email protected]>
Signed-off-by: ycabrer <[email protected]>
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.
LGTM, thanks @ycabrer!
* add metricName uniqueness check Signed-off-by: ycabrer <[email protected]>
Metric Names are required to be unique in Scaled Objects
Checklist
Fixes #