From 3ae38c7417421ceebdc853926f76702bf90f4553 Mon Sep 17 00:00:00 2001 From: Carson Anderson Date: Fri, 5 Mar 2021 15:15:14 -0700 Subject: [PATCH 1/5] Allow metrics to be defined as namespaced: false When set to false, no namespace label will be set by the adapter based on the namespace portion of the url in the request path. This allows individual consumers to set namespace independent of the source kubernetes resource. --- Example: Given an adapter config like this: ``` externalRules: - seriesQuery: 'nsq_topic_depth' resources: namespaced: false ``` An HPA could target a different namespace by setting it in the selector: ``` - type: External external: metric: name: nsq_topic_depth selector: labelSelector: topic: my-topic namespace: nsq ``` This is useful for scaling on metrics from services that run in a differnt namespace than the source resource. --- pkg/config/config.go | 2 ++ pkg/naming/metric_namer.go | 12 ++++++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/pkg/config/config.go b/pkg/config/config.go index fee4e006..2536604d 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -58,6 +58,8 @@ type ResourceMapping struct { // Overrides specifies exceptions to the above template, mapping label names // to group-resources Overrides map[string]GroupResource `json:"overrides,omitempty" yaml:"overrides,omitempty"` + //Namespaced ignores the source namespace of the requester and requires one in the query + Namespaced *bool `json:"namespaced,omitempty" yaml:"namespaced,omitempty"` } // GroupResource represents a Kubernetes group-resource. diff --git a/pkg/naming/metric_namer.go b/pkg/naming/metric_namer.go index 54ac7183..7516a896 100644 --- a/pkg/naming/metric_namer.go +++ b/pkg/naming/metric_namer.go @@ -102,10 +102,15 @@ type metricNamer struct { nameMatches *regexp.Regexp nameAs string seriesMatchers []*ReMatcher + namespaced *bool ResourceConverter } +func (n *metricNamer) isNamespaced() bool { + return (n.namespaced != nil) && *n.namespaced +} + // queryTemplateArgs are the arguments for the metrics query template. func (n *metricNamer) FilterSeries(initialSeries []prom.Series) []prom.Series { if len(n.seriesMatchers) == 0 { @@ -131,8 +136,10 @@ func (n *metricNamer) QueryForSeries(series string, resource schema.GroupResourc } func (n *metricNamer) QueryForExternalSeries(series string, namespace string, metricSelector labels.Selector) (prom.Selector, error) { - //test := prom.Selector() - //return test, nil + if !n.isNamespaced() { + namespace = "" + } + return n.metricsQuery.BuildExternal(series, namespace, "", []string{}, metricSelector) } @@ -207,6 +214,7 @@ func NamersFromConfig(cfg []config.DiscoveryRule, mapper apimeta.RESTMapper) ([] nameMatches: nameMatches, nameAs: nameAs, seriesMatchers: seriesMatchers, + namespaced: rule.Resources.Namespaced, ResourceConverter: resConv, } From 510c3724ce0a21e8e47455211dc2331c5720d8c7 Mon Sep 17 00:00:00 2001 From: Carson Anderson Date: Thu, 8 Apr 2021 11:07:50 -0600 Subject: [PATCH 2/5] Add docs, tests, and move namespaced to metricsQuery --- docs/externalmetrics.md | 84 ++++++++++++++++++++++++++++++++ docs/sample-config.yaml | 13 +++++ pkg/config/config.go | 2 +- pkg/naming/metric_namer.go | 18 +++---- pkg/naming/metrics_query.go | 8 +-- pkg/naming/metrics_query_test.go | 48 +++++++++++++++++- pkg/resourceprovider/provider.go | 4 +- 7 files changed, 158 insertions(+), 19 deletions(-) create mode 100644 docs/externalmetrics.md diff --git a/docs/externalmetrics.md b/docs/externalmetrics.md new file mode 100644 index 00000000..080ecd13 --- /dev/null +++ b/docs/externalmetrics.md @@ -0,0 +1,84 @@ +External Metrics +=========== + +It's possible to configure [Autoscaling on metrics not related to Kubernetes objects](Autoscaling on metrics not related to Kubernetes objects) in Kubernetes. This is done with a special `External Metrics` system. Using external metrics in Kubernetes with the adapter requires you to configure special `external` rules in the configuration. + +The configuration for `external` metrics rules is almost identical to the normal `rules`: + +```yaml +external: +- seriesQuery: '{__name__="queue_consumer_lag",name!=""}' + metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (name) + resources: + overrides: { namespace: {resource: "namespace"} } +``` + +Namespacing +----------- + +All Kubernetes Horizontal Pod Autoscaler (HPA) resources are namespaced. And when you create an HPA that +references an external metric the adapter will automatically add a `namespace` label to the `seriesQuery` you have configured. + +This is done because the External Merics API Specification *requires* a namespace component in the URL: + +```shell +kubectl get --raw "/apis/external.metrics.k8s.io/v1beta1/namespaces/default/queue_consumer_lag" +``` + +Cross-Namespace or No Namespace Queries +--------------------------------------- + +A semi-common scenario is to have a `workload` in one namespace that needs to scale based on a metric from a different namespace. This is normally not +possible with `external` rules because the `namespace` label is set to match that of the source `workload`. + +However, you can explicitly disable the automatic add of the HPA namepace to the query, and instead opt to not set a namespace at all, or to target a different namespace. + +This is done by setting `namespaced: false` the `resources` section of the `external` rule: + +```yaml +# rules: ... + +external: +- seriesQuery: '{__name__="queue_depth",name!=""}' + metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (name) + resources: + namespaced: false +``` + +Given the `external` rules defined above any `External` metric query for `queue_depth` will simply ignore the source `namespace` of the HPA. This allows you to explicilty not put a namespace into an external query, or to set the namespace to one that might be different from that of the HPA. + +```yaml +apiVersion: autoscaling/v1 +kind: HorizontalPodAutoscaler +metadata: + name: external-queue-scaler + # the HPA and scaleTargetRef must exist in a namespace + namespace: default + annotations: + # The "External" metric below targets a metricName that has namespaced=false + # and this allows the metric to explicitly query a different + # namespace than that of the HPA and scaleTargetRef + autoscaling.alpha.kubernetes.io/metrics: | + [ + { + "type": "External", + "external": { + "metricName": "queue_depth", + "metricSelector": { + "matchLabels": { + "namespace": "queue", + "name": "my-sample-queue" + } + }, + "targetAverageValue": "50" + } + } + ] +spec: + maxReplicas: 5 + minReplicas: 1 + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: my-app +``` diff --git a/docs/sample-config.yaml b/docs/sample-config.yaml index 3aa5be6d..9d926a33 100644 --- a/docs/sample-config.yaml +++ b/docs/sample-config.yaml @@ -65,5 +65,18 @@ rules: brand: {group: "cheese.io", resource: "brand"} metricQuery: 'count(cheddar{sharp="true"})' +# external rules are not tied to a Kubernetes resource and can reference any metric +# https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-metrics-not-related-to-kubernetes-objects +external: +- seriesQuery: '{__name__="queue_consumer_lag",name!=""}' + metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (name) +- seriesQuery: '{__name__="queue_depth",topic!=""}' + metricsQuery: sum(<<.Series>>{<<.LabelMatchers>>}) by (name) + # Kubernetes metric queries include a namespace in the query by default + # but you can explicitly disable namespaces if needed with "namespaced: false" + # this is useful if you have an HPA with an external metric in namespace A + # but want to query for metrics from namespace B + namespaced: false + # TODO: should we be able to map to a constant instance of a resource # (e.g. `resources: {constant: [{resource: "namespace", name: "kube-system"}}]`)? diff --git a/pkg/config/config.go b/pkg/config/config.go index 2536604d..62c83cbe 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -58,7 +58,7 @@ type ResourceMapping struct { // Overrides specifies exceptions to the above template, mapping label names // to group-resources Overrides map[string]GroupResource `json:"overrides,omitempty" yaml:"overrides,omitempty"` - //Namespaced ignores the source namespace of the requester and requires one in the query + // Namespaced ignores the source namespace of the requester and requires one in the query Namespaced *bool `json:"namespaced,omitempty" yaml:"namespaced,omitempty"` } diff --git a/pkg/naming/metric_namer.go b/pkg/naming/metric_namer.go index 7516a896..32e96e36 100644 --- a/pkg/naming/metric_namer.go +++ b/pkg/naming/metric_namer.go @@ -102,15 +102,10 @@ type metricNamer struct { nameMatches *regexp.Regexp nameAs string seriesMatchers []*ReMatcher - namespaced *bool ResourceConverter } -func (n *metricNamer) isNamespaced() bool { - return (n.namespaced != nil) && *n.namespaced -} - // queryTemplateArgs are the arguments for the metrics query template. func (n *metricNamer) FilterSeries(initialSeries []prom.Series) []prom.Series { if len(n.seriesMatchers) == 0 { @@ -136,10 +131,6 @@ func (n *metricNamer) QueryForSeries(series string, resource schema.GroupResourc } func (n *metricNamer) QueryForExternalSeries(series string, namespace string, metricSelector labels.Selector) (prom.Selector, error) { - if !n.isNamespaced() { - namespace = "" - } - return n.metricsQuery.BuildExternal(series, namespace, "", []string{}, metricSelector) } @@ -162,7 +153,13 @@ func NamersFromConfig(cfg []config.DiscoveryRule, mapper apimeta.RESTMapper) ([] return nil, err } - metricsQuery, err := NewMetricsQuery(rule.MetricsQuery, resConv) + // queries are namespaced by default unless the rule specifically disables it + namespaced := true + if rule.Resources.Namespaced != nil { + namespaced = *rule.Resources.Namespaced + } + + metricsQuery, err := NewMetricsQuery(rule.MetricsQuery, resConv, namespaced) if err != nil { return nil, fmt.Errorf("unable to construct metrics query associated with series query %q: %v", rule.SeriesQuery, err) } @@ -214,7 +211,6 @@ func NamersFromConfig(cfg []config.DiscoveryRule, mapper apimeta.RESTMapper) ([] nameMatches: nameMatches, nameAs: nameAs, seriesMatchers: seriesMatchers, - namespaced: rule.Resources.Namespaced, ResourceConverter: resConv, } diff --git a/pkg/naming/metrics_query.go b/pkg/naming/metrics_query.go index 2f289262..b6666228 100644 --- a/pkg/naming/metrics_query.go +++ b/pkg/naming/metrics_query.go @@ -50,7 +50,7 @@ type MetricsQuery interface { // - LabelMatchersByName: the raw map-form of the above matchers // - GroupBy: the group-by clause to use for the resources in the query (stringified) // - GroupBySlice: the raw slice form of the above group-by clause -func NewMetricsQuery(queryTemplate string, resourceConverter ResourceConverter) (MetricsQuery, error) { +func NewMetricsQuery(queryTemplate string, resourceConverter ResourceConverter, namespaced bool) (MetricsQuery, error) { templ, err := template.New("metrics-query").Delims("<<", ">>").Parse(queryTemplate) if err != nil { return nil, fmt.Errorf("unable to parse metrics query template %q: %v", queryTemplate, err) @@ -59,6 +59,7 @@ func NewMetricsQuery(queryTemplate string, resourceConverter ResourceConverter) return &metricsQuery{ resConverter: resourceConverter, template: templ, + namespaced: namespaced, }, nil } @@ -68,6 +69,7 @@ func NewMetricsQuery(queryTemplate string, resourceConverter ResourceConverter) type metricsQuery struct { resConverter ResourceConverter template *template.Template + namespaced bool } // queryTemplateArgs contains the arguments for the template used in metricsQuery. @@ -88,7 +90,7 @@ type queryPart struct { func (q *metricsQuery) Build(series string, resource schema.GroupResource, namespace string, extraGroupBy []string, metricSelector labels.Selector, names ...string) (prom.Selector, error) { queryParts := q.createQueryPartsFromSelector(metricSelector) - if namespace != "" { + if q.namespaced && namespace != "" { namespaceLbl, err := q.resConverter.LabelForResource(NsGroupResource) if err != nil { return "", err @@ -150,7 +152,7 @@ func (q *metricsQuery) BuildExternal(seriesName string, namespace string, groupB // Build up the query parts from the selector. queryParts = append(queryParts, q.createQueryPartsFromSelector(metricSelector)...) - if namespace != "" { + if q.namespaced && namespace != "" { namespaceLbl, err := q.resConverter.LabelForResource(NsGroupResource) if err != nil { return "", err diff --git a/pkg/naming/metrics_query_test.go b/pkg/naming/metrics_query_test.go index 9661d15d..df4cc8de 100644 --- a/pkg/naming/metrics_query_test.go +++ b/pkg/naming/metrics_query_test.go @@ -76,7 +76,15 @@ func checks(cs ...checkFunc) checkFunc { func TestBuildSelector(t *testing.T) { mustNewQuery := func(queryTemplate string, namespaced bool) MetricsQuery { - mq, err := NewMetricsQuery(queryTemplate, &resourceConverterMock{namespaced}) + mq, err := NewMetricsQuery(queryTemplate, &resourceConverterMock{namespaced}, true) + if err != nil { + t.Fatal(err) + } + return mq + } + + mustNewNonNamespacedQuery := func(queryTemplate string, namespaced bool) MetricsQuery { + mq, err := NewMetricsQuery(queryTemplate, &resourceConverterMock{namespaced}, false) if err != nil { t.Fatal(err) } @@ -204,6 +212,21 @@ func TestBuildSelector(t *testing.T) { ), }, + { + name: "multiple LabelValuesByName values with namespace disabled", + + mq: mustNewNonNamespacedQuery(`<> <>`, true), + metricSelector: labels.NewSelector(), + resource: schema.GroupResource{Group: "group", Resource: "resource"}, + namespace: "default", + names: []string{"bar", "baz"}, + + check: checks( + hasError(nil), + hasSelector(" bar|baz"), + ), + }, + { name: "single GroupBy value", @@ -272,7 +295,15 @@ func TestBuildSelector(t *testing.T) { func TestBuildExternalSelector(t *testing.T) { mustNewQuery := func(queryTemplate string) MetricsQuery { - mq, err := NewMetricsQuery(queryTemplate, &resourceConverterMock{true}) + mq, err := NewMetricsQuery(queryTemplate, &resourceConverterMock{true}, true) + if err != nil { + t.Fatal(err) + } + return mq + } + + mustNewNonNamespacedQuery := func(queryTemplate string) MetricsQuery { + mq, err := NewMetricsQuery(queryTemplate, &resourceConverterMock{true}, false) if err != nil { t.Fatal(err) } @@ -348,6 +379,19 @@ func TestBuildExternalSelector(t *testing.T) { hasSelector("default [foo bar]"), ), }, + { + name: "multiple GroupBySlice values with namespace disabled", + + mq: mustNewNonNamespacedQuery(`<> <<.GroupBySlice>>`), + namespace: "default", + groupBySlice: []string{"foo", "bar"}, + metricSelector: labels.NewSelector(), + + check: checks( + hasError(nil), + hasSelector(" [foo bar]"), + ), + }, { name: "single LabelMatchers value", diff --git a/pkg/resourceprovider/provider.go b/pkg/resourceprovider/provider.go index 371eee0b..18376e69 100644 --- a/pkg/resourceprovider/provider.go +++ b/pkg/resourceprovider/provider.go @@ -54,11 +54,11 @@ func newResourceQuery(cfg config.ResourceRule, mapper apimeta.RESTMapper) (resou return resourceQuery{}, fmt.Errorf("unable to construct label-resource converter: %v", err) } - contQuery, err := naming.NewMetricsQuery(cfg.ContainerQuery, converter) + contQuery, err := naming.NewMetricsQuery(cfg.ContainerQuery, converter, true) if err != nil { return resourceQuery{}, fmt.Errorf("unable to construct container metrics query: %v", err) } - nodeQuery, err := naming.NewMetricsQuery(cfg.NodeQuery, converter) + nodeQuery, err := naming.NewMetricsQuery(cfg.NodeQuery, converter, true) if err != nil { return resourceQuery{}, fmt.Errorf("unable to construct node metrics query: %v", err) } From fa5f8cd74292e66c1dcbb8ab0c9ddfa95f8f91ee Mon Sep 17 00:00:00 2001 From: Carson Anderson Date: Fri, 23 Apr 2021 11:27:38 -0600 Subject: [PATCH 3/5] Add requested fixes --- docs/externalmetrics.md | 4 ++-- docs/sample-config.yaml | 3 ++- pkg/naming/metrics_query.go | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/docs/externalmetrics.md b/docs/externalmetrics.md index 080ecd13..461b8788 100644 --- a/docs/externalmetrics.md +++ b/docs/externalmetrics.md @@ -1,7 +1,7 @@ External Metrics =========== -It's possible to configure [Autoscaling on metrics not related to Kubernetes objects](Autoscaling on metrics not related to Kubernetes objects) in Kubernetes. This is done with a special `External Metrics` system. Using external metrics in Kubernetes with the adapter requires you to configure special `external` rules in the configuration. +It's possible to configure [Autoscaling on metrics not related to Kubernetes objects](https://kubernetes.io/docs/tasks/run-application/horizontal-pod-autoscale-walkthrough/#autoscaling-on-metrics-not-related-to-kubernetes-objects) in Kubernetes. This is done with a special `External Metrics` system. Using external metrics in Kubernetes with the adapter requires you to configure special `external` rules in the configuration. The configuration for `external` metrics rules is almost identical to the normal `rules`: @@ -33,7 +33,7 @@ possible with `external` rules because the `namespace` label is set to match tha However, you can explicitly disable the automatic add of the HPA namepace to the query, and instead opt to not set a namespace at all, or to target a different namespace. -This is done by setting `namespaced: false` the `resources` section of the `external` rule: +This is done by setting `namespaced: false` in the `resources` section of the `external` rule: ```yaml # rules: ... diff --git a/docs/sample-config.yaml b/docs/sample-config.yaml index 9d926a33..e36cefe5 100644 --- a/docs/sample-config.yaml +++ b/docs/sample-config.yaml @@ -76,7 +76,8 @@ external: # but you can explicitly disable namespaces if needed with "namespaced: false" # this is useful if you have an HPA with an external metric in namespace A # but want to query for metrics from namespace B - namespaced: false + resources: + namespaced: false # TODO: should we be able to map to a constant instance of a resource # (e.g. `resources: {constant: [{resource: "namespace", name: "kube-system"}}]`)? diff --git a/pkg/naming/metrics_query.go b/pkg/naming/metrics_query.go index b6666228..c7f5c156 100644 --- a/pkg/naming/metrics_query.go +++ b/pkg/naming/metrics_query.go @@ -90,7 +90,7 @@ type queryPart struct { func (q *metricsQuery) Build(series string, resource schema.GroupResource, namespace string, extraGroupBy []string, metricSelector labels.Selector, names ...string) (prom.Selector, error) { queryParts := q.createQueryPartsFromSelector(metricSelector) - if q.namespaced && namespace != "" { + if namespace != "" { namespaceLbl, err := q.resConverter.LabelForResource(NsGroupResource) if err != nil { return "", err From c0ae5d6dd4a451a1ab8687554075ba29d33987f2 Mon Sep 17 00:00:00 2001 From: Carson Anderson Date: Fri, 23 Apr 2021 11:39:47 -0600 Subject: [PATCH 4/5] fix tests --- pkg/naming/metrics_query_test.go | 23 ----------------------- 1 file changed, 23 deletions(-) diff --git a/pkg/naming/metrics_query_test.go b/pkg/naming/metrics_query_test.go index df4cc8de..36f0d110 100644 --- a/pkg/naming/metrics_query_test.go +++ b/pkg/naming/metrics_query_test.go @@ -83,14 +83,6 @@ func TestBuildSelector(t *testing.T) { return mq } - mustNewNonNamespacedQuery := func(queryTemplate string, namespaced bool) MetricsQuery { - mq, err := NewMetricsQuery(queryTemplate, &resourceConverterMock{namespaced}, false) - if err != nil { - t.Fatal(err) - } - return mq - } - mustNewLabelRequirement := func(key string, op selection.Operator, vals []string) *labels.Requirement { req, err := labels.NewRequirement(key, op, vals) if err != nil { @@ -212,21 +204,6 @@ func TestBuildSelector(t *testing.T) { ), }, - { - name: "multiple LabelValuesByName values with namespace disabled", - - mq: mustNewNonNamespacedQuery(`<> <>`, true), - metricSelector: labels.NewSelector(), - resource: schema.GroupResource{Group: "group", Resource: "resource"}, - namespace: "default", - names: []string{"bar", "baz"}, - - check: checks( - hasError(nil), - hasSelector(" bar|baz"), - ), - }, - { name: "single GroupBy value", From 6c1d85ccf9720b69430e4620354535badd6045ac Mon Sep 17 00:00:00 2001 From: Carson Anderson Date: Tue, 11 May 2021 14:49:11 -0600 Subject: [PATCH 5/5] Split ExternalMetricsQuery and MetricsQuery funcs --- pkg/naming/metric_namer.go | 2 +- pkg/naming/metrics_query.go | 22 +++++++++++++++++++++- pkg/naming/metrics_query_test.go | 6 +++--- pkg/resourceprovider/provider.go | 4 ++-- 4 files changed, 27 insertions(+), 7 deletions(-) diff --git a/pkg/naming/metric_namer.go b/pkg/naming/metric_namer.go index 32e96e36..b92c7610 100644 --- a/pkg/naming/metric_namer.go +++ b/pkg/naming/metric_namer.go @@ -159,7 +159,7 @@ func NamersFromConfig(cfg []config.DiscoveryRule, mapper apimeta.RESTMapper) ([] namespaced = *rule.Resources.Namespaced } - metricsQuery, err := NewMetricsQuery(rule.MetricsQuery, resConv, namespaced) + metricsQuery, err := NewExternalMetricsQuery(rule.MetricsQuery, resConv, namespaced) if err != nil { return nil, fmt.Errorf("unable to construct metrics query associated with series query %q: %v", rule.SeriesQuery, err) } diff --git a/pkg/naming/metrics_query.go b/pkg/naming/metrics_query.go index c7f5c156..0dbc13a5 100644 --- a/pkg/naming/metrics_query.go +++ b/pkg/naming/metrics_query.go @@ -50,7 +50,27 @@ type MetricsQuery interface { // - LabelMatchersByName: the raw map-form of the above matchers // - GroupBy: the group-by clause to use for the resources in the query (stringified) // - GroupBySlice: the raw slice form of the above group-by clause -func NewMetricsQuery(queryTemplate string, resourceConverter ResourceConverter, namespaced bool) (MetricsQuery, error) { +func NewMetricsQuery(queryTemplate string, resourceConverter ResourceConverter) (MetricsQuery, error) { + templ, err := template.New("metrics-query").Delims("<<", ">>").Parse(queryTemplate) + if err != nil { + return nil, fmt.Errorf("unable to parse metrics query template %q: %v", queryTemplate, err) + } + + return &metricsQuery{ + resConverter: resourceConverter, + template: templ, + namespaced: true, + }, nil +} + +// NewExternalMetricsQuery constructs a new MetricsQuery by compiling the given Go template. +// The delimiters on the template are `<<` and `>>`, and it may use the following fields: +// - Series: the series in question +// - LabelMatchers: a pre-stringified form of the label matchers for the resources in the query +// - LabelMatchersByName: the raw map-form of the above matchers +// - GroupBy: the group-by clause to use for the resources in the query (stringified) +// - GroupBySlice: the raw slice form of the above group-by clause +func NewExternalMetricsQuery(queryTemplate string, resourceConverter ResourceConverter, namespaced bool) (MetricsQuery, error) { templ, err := template.New("metrics-query").Delims("<<", ">>").Parse(queryTemplate) if err != nil { return nil, fmt.Errorf("unable to parse metrics query template %q: %v", queryTemplate, err) diff --git a/pkg/naming/metrics_query_test.go b/pkg/naming/metrics_query_test.go index 36f0d110..ebd23ce7 100644 --- a/pkg/naming/metrics_query_test.go +++ b/pkg/naming/metrics_query_test.go @@ -76,7 +76,7 @@ func checks(cs ...checkFunc) checkFunc { func TestBuildSelector(t *testing.T) { mustNewQuery := func(queryTemplate string, namespaced bool) MetricsQuery { - mq, err := NewMetricsQuery(queryTemplate, &resourceConverterMock{namespaced}, true) + mq, err := NewMetricsQuery(queryTemplate, &resourceConverterMock{namespaced}) if err != nil { t.Fatal(err) } @@ -272,7 +272,7 @@ func TestBuildSelector(t *testing.T) { func TestBuildExternalSelector(t *testing.T) { mustNewQuery := func(queryTemplate string) MetricsQuery { - mq, err := NewMetricsQuery(queryTemplate, &resourceConverterMock{true}, true) + mq, err := NewExternalMetricsQuery(queryTemplate, &resourceConverterMock{true}, true) if err != nil { t.Fatal(err) } @@ -280,7 +280,7 @@ func TestBuildExternalSelector(t *testing.T) { } mustNewNonNamespacedQuery := func(queryTemplate string) MetricsQuery { - mq, err := NewMetricsQuery(queryTemplate, &resourceConverterMock{true}, false) + mq, err := NewExternalMetricsQuery(queryTemplate, &resourceConverterMock{true}, false) if err != nil { t.Fatal(err) } diff --git a/pkg/resourceprovider/provider.go b/pkg/resourceprovider/provider.go index 18376e69..371eee0b 100644 --- a/pkg/resourceprovider/provider.go +++ b/pkg/resourceprovider/provider.go @@ -54,11 +54,11 @@ func newResourceQuery(cfg config.ResourceRule, mapper apimeta.RESTMapper) (resou return resourceQuery{}, fmt.Errorf("unable to construct label-resource converter: %v", err) } - contQuery, err := naming.NewMetricsQuery(cfg.ContainerQuery, converter, true) + contQuery, err := naming.NewMetricsQuery(cfg.ContainerQuery, converter) if err != nil { return resourceQuery{}, fmt.Errorf("unable to construct container metrics query: %v", err) } - nodeQuery, err := naming.NewMetricsQuery(cfg.NodeQuery, converter, true) + nodeQuery, err := naming.NewMetricsQuery(cfg.NodeQuery, converter) if err != nil { return resourceQuery{}, fmt.Errorf("unable to construct node metrics query: %v", err) }