Skip to content
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

Merged

Conversation

ycabrer
Copy link
Contributor

@ycabrer ycabrer commented Dec 2, 2020

Metric Names are required to be unique in Scaled Objects

Checklist

Fixes #

@ycabrer
Copy link
Contributor Author

ycabrer commented Dec 2, 2020

@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?

Copy link
Member

@zroubalik zroubalik left a 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
Copy link
Member

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:

keda/controllers/hpa.go

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()
}

Copy link
Contributor Author

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

@zroubalik
Copy link
Member

@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).

The static check is strange, you can probably disable this specific one for the finalizers:

exclude-rules:

Also any tips on where to put the documentation update for the metric name validation?

We should probably add a new section unde KEDA Concepts, something like section Mutliple Scalers or Using Scalers ? @tomkerkhove WDYT?

@zroubalik
Copy link
Member

@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).

The static check is strange, you can probably disable this specific one for the finalizers:

exclude-rules:

Also any tips on where to put the documentation update for the metric name validation?

We should probably add a new section unde KEDA Concepts, something like section Mutliple Scalers or Using Scalers ? @tomkerkhove WDYT?

@ycabrer any update please? :)

@tomkerkhove
Copy link
Member

Also any tips on where to put the documentation update for the metric name validation?

We should probably add a new section unde KEDA Concepts, something like section Mutliple Scalers or Using Scalers ? @tomkerkhove WDYT?

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?

@zroubalik
Copy link
Member

@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!

@ycabrer
Copy link
Contributor Author

ycabrer commented Jan 14, 2021

@zroubalik Sorry for the delay. I've had a busy start to the new year! I'll go ahead and update the docs.

@ycabrer ycabrer force-pushed the feature/validate-metric-name-uniqueness branch from e6f2d6c to 5e5ddbb Compare January 14, 2021 19:44
@ycabrer
Copy link
Contributor Author

ycabrer commented Jan 14, 2021

@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).

The static check is strange, you can probably disable this specific one for the finalizers:

exclude-rules:

Also any tips on where to put the documentation update for the metric name validation?

We should probably add a new section unde KEDA Concepts, something like section Mutliple Scalers or Using Scalers ? @tomkerkhove WDYT?

@ycabrer any update please? :)

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?

@zroubalik
Copy link
Member

zroubalik commented Jan 14, 2021

@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).

The static check is strange, you can probably disable this specific one for the finalizers:

exclude-rules:

Also any tips on where to put the documentation update for the metric name validation?

We should probably add a new section unde KEDA Concepts, something like section Mutliple Scalers or Using Scalers ? @tomkerkhove WDYT?

@ycabrer any update please? :)

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 exclude-rules section in .golangci.yaml?

Something like this:

# Excluding interfacer for finalizers, reason: https://github.com/kedacore/keda/pull/1390
 - path: _finalizer.go
      linters:
        - interfacer

@ycabrer
Copy link
Contributor Author

ycabrer commented Jan 14, 2021

@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).

The static check is strange, you can probably disable this specific one for the finalizers:

exclude-rules:

Also any tips on where to put the documentation update for the metric name validation?

We should probably add a new section unde KEDA Concepts, something like section Mutliple Scalers or Using Scalers ? @tomkerkhove WDYT?

@ycabrer any update please? :)

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 exclude-rules section in .golangci.yaml?

Something like this:

# Excluding interfacer for finalizers, reason: https://github.com/kedacore/keda/pull/1390
 - path: _finalizer.go
      linters:
        - interfacer

That worked

@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).

The static check is strange, you can probably disable this specific one for the finalizers:

exclude-rules:

Also any tips on where to put the documentation update for the metric name validation?

We should probably add a new section unde KEDA Concepts, something like section Mutliple Scalers or Using Scalers ? @tomkerkhove WDYT?

@ycabrer any update please? :)

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 exclude-rules section in .golangci.yaml?

Something like this:

# Excluding interfacer for finalizers, reason: https://github.com/kedacore/keda/pull/1390
 - path: _finalizer.go
      linters:
        - interfacer

That did it! I had chosen the wrong linter.

@@ -56,6 +56,9 @@ issues:
- path: scale_handler.go
linters:
- gocyclo
- path: _finalizer.go
Copy link
Member

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?

Copy link
Contributor Author

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.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Require metricNames be unique in scaled objects.
- Require metricNames be unique in scaled objects ([#1390](https://github.com/kedacore/keda/pull/1390))

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just updated it

Copy link
Member

@zroubalik zroubalik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks @ycabrer!

@zroubalik zroubalik merged commit 05f015c into kedacore:main Jan 19, 2021
ycabrer added a commit to ycabrer/keda that referenced this pull request Mar 1, 2021
* add metricName uniqueness check

Signed-off-by: ycabrer <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants