Skip to content

Elasticsearch client: add support for label selectors #10

Open
@barkbay

Description

@barkbay

Within an HPA spec. a label selector can be used to describe a metric:

Many metrics pipelines allow you to describe metrics either by name or by a set of additional descriptors called labels. For all non-resource metric types (pod, object, and external, described below), you can specify an additional label selector which is passed to your metric pipeline. For instance, if you collect a metric http_requests with the verb label, you can specify the following metric block to scale only on GET requests:

type: Object
object:
  metric:
    name: http_requests
    selector: {matchLabels: {verb: GET}}

This selector uses the same syntax as the full Kubernetes label selectors. The monitoring pipeline determines how to collapse multiple series into a single value, if the name and selector match multiple series. The selector is additive, and cannot select metrics that describe objects that are not the target object (the target pods in the case of the Pods type, and the described object in the case of the Object type).

(see original documentation here)

For the moment metricSelector labels.Selector is not used to retrieve a metric:

// valueFor is a helper function to get just the value of a specific metric
func (mc *MetricsClient) valueFor(
ctx *context.Context,
info provider.CustomMetricInfo,
name types.NamespacedName,
originalSelector labels.Selector,
objects []string,
metricSelector labels.Selector,
) (timestampedMetric, error) {
and
// TODO: handle metricSelector
/*if !metricSelector.Matches(value.labels) {
return resource.Quantity{}, provider.NewMetricNotFoundForSelectorError(info.GroupResource, info.Metric, name.Name, metricSelector)
}*/

If we want to support this feature we need to understand what is a label in the context of a document stored in Elasticsearch.

Note that the same question can be raised in the context of External metrics, however they are not likely to be supported as part of a first release of the adapter:

func (mc *MetricsClient) GetExternalMetric(
_, _ string,
_ labels.Selector,
) (*external_metrics.ExternalMetricValueList, error) {
klog.Error("GetExternalMetric: external are not supported by Elasticsearch metrics client")
return nil, nil
}
func (mc *MetricsClient) ListExternalMetrics() (map[provider.ExternalMetricInfo]struct{}, error) {
klog.V(2).Infof("ListAllExternalMetrics: external are not supported by Elasticsearch metrics client")
return nil, nil
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions