Setting up a vanilla prometheus-metrics-adapter is a time-consuming process. Happily, we have somewhat simplified it by defining a set of CRDs with different Scopes.

You can globally define a metric using the Cluster resource, while the Namespaced resource allows you to redefine it locally. All CRs have the same format.

Namespaced Custom resources

ServiceMetric

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

IngressMetric

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

PodMetric

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

DeploymentMetric

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

StatefulSetMetric

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

NamespaceMetric

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

DaemonSetMetric (not available to users)

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

Cluster Custom resources

ClusterServiceMetric (not available to users)

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

ClusterIngressMetric (not available to users)

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

ClusterPodMetric (not available to users)

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

ClusterDeploymentMetric (not available to users)

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

Example

ClusterStatefulSetMetric (not available to users)

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

Example

ClusterDaemonSetMetric (not available to users)

  • .metadata.name — the name of the metric (used in HPA).
  • .spec.query — a custom PromQL query that returns a unique value for your label set (you can use sum() by(), max() by(), etc., operators for grouping). The following keys must be used in the request:
    • <<.LabelMatchers>> — will be replaced with a set of {namespace="mynamespace",ingress="myingress"} labels. You can add your own comma-separated labels list (as in the example below).
    • <<.GroupBy>> — will be replaced with namespace,ingress labels for grouping (max() by(...), sum() by (...), etc.).

PrometheusRule

  • .metadata.namespace — is set to d8-monitoring in all cases;
  • .metadata.labels.prometheus — is set to main` in all cases;
  • .metadata.labels.component — is set to rules` in all cases;
  • `.spec.groups:
    • name — the name according to the recommended template (e.g., prometheus-metrics-adapter.mymetric);
    • rules:
      • record — the name of the metric;
      • expr — a request, the results of which will be passed to the final metric.