From e7671bf9092811ecb053466e5b9c9913e2922fe1 Mon Sep 17 00:00:00 2001 From: Galen Kistler <109082771+gtk-grafana@users.noreply.github.com> Date: Mon, 24 Oct 2022 11:56:49 -0500 Subject: [PATCH] Revert "Prometheus: Provide label values match parameter API when supported prometheus instance is configured (#56510)" (#57551) This reverts commit 3cbbf706cf1685e572a607eda36d7658dc8c4f44. --- docs/sources/whatsnew/whats-new-in-v9-2.md | 7 ----- .../datasource/prometheus/datasource.tsx | 28 ------------------- .../prometheus/metric_find_query.ts | 19 ++++++++++--- 3 files changed, 15 insertions(+), 39 deletions(-) diff --git a/docs/sources/whatsnew/whats-new-in-v9-2.md b/docs/sources/whatsnew/whats-new-in-v9-2.md index df46a65e4f9..5ecf3788999 100644 --- a/docs/sources/whatsnew/whats-new-in-v9-2.md +++ b/docs/sources/whatsnew/whats-new-in-v9-2.md @@ -219,10 +219,3 @@ For more information, see the [SAML configuration documentation](https://grafana You can now map OAuth groups and roles to Server Admin for the GitLab, GitHub, AzureAD, Okta, and Generic OAuth integrations. To enable this functionality, set the `allow_assign_grafana_admin` configuration option to `true` in the desired OAuth integration section. For more information, see the [authentication configuration documentation](https://grafana.com/docs/grafana/latest/setup-grafana/configure-security/configure-authentication/) for each OAuth client. - -## Match parameter support in prometheus labels API - -Prometheus users running Prometheus v2.24 and higher can use the [labels endpoint](https://prometheus.io/docs/prometheus/latest/querying/api/#querying-label-values) instead of the [series endpoint](https://prometheus.io/docs/prometheus/latest/querying/api/#finding-series-by-label-matchers) for the [`label_values` function]({{< relref "../datasources/prometheus/#query-variable" >}}). -This decreases load times for templated high-cardinality Prometheus instances. - -If you want to benefit from this endpoint you must first configure the Prometheus type and version in any Prometheus data sources' [configuration]({{< relref "../datasources/prometheus/" >}}). diff --git a/public/app/plugins/datasource/prometheus/datasource.tsx b/public/app/plugins/datasource/prometheus/datasource.tsx index f739c898052..72593c513cd 100644 --- a/public/app/plugins/datasource/prometheus/datasource.tsx +++ b/public/app/plugins/datasource/prometheus/datasource.tsx @@ -3,7 +3,6 @@ import LRU from 'lru-cache'; import React from 'react'; import { forkJoin, lastValueFrom, merge, Observable, of, OperatorFunction, pipe, throwError } from 'rxjs'; import { catchError, filter, map, tap } from 'rxjs/operators'; -import semver from 'semver/preload'; import { AnnotationEvent, @@ -147,33 +146,6 @@ export class PrometheusDatasource return query.expr; } - hasLabelsMatchAPISupport(): boolean { - return ( - // https://github.com/prometheus/prometheus/releases/tag/v2.24.0 - this._isDatasourceVersionGreaterOrEqualTo('2.24.0', PromApplication.Prometheus) || - // All versions of Mimir support matchers for labels API - this._isDatasourceVersionGreaterOrEqualTo('2.0.0', PromApplication.Mimir) || - // https://github.com/cortexproject/cortex/discussions/4542 - this._isDatasourceVersionGreaterOrEqualTo('1.11.0', PromApplication.Cortex) || - // https://github.com/thanos-io/thanos/pull/3566 - //https://github.com/thanos-io/thanos/releases/tag/v0.18.0 - this._isDatasourceVersionGreaterOrEqualTo('0.18', PromApplication.Thanos) - ); - } - - _isDatasourceVersionGreaterOrEqualTo(targetVersion: string, targetFlavor: PromApplication): boolean { - // User hasn't configured flavor/version yet, default behavior is to not support features that require version configuration when not provided - if (!this.datasourceConfigurationPrometheusVersion || !this.datasourceConfigurationPrometheusFlavor) { - return false; - } - - if (targetFlavor !== this.datasourceConfigurationPrometheusFlavor) { - return false; - } - - return semver.gte(this.datasourceConfigurationPrometheusVersion, targetVersion); - } - _addTracingHeaders(httpOptions: PromQueryRequest, options: DataQueryRequest) { httpOptions.headers = {}; if (this.access === 'proxy') { diff --git a/public/app/plugins/datasource/prometheus/metric_find_query.ts b/public/app/plugins/datasource/prometheus/metric_find_query.ts index f3f678d1d2a..738982a7184 100644 --- a/public/app/plugins/datasource/prometheus/metric_find_query.ts +++ b/public/app/plugins/datasource/prometheus/metric_find_query.ts @@ -70,10 +70,16 @@ export default class PrometheusMetricFindQuery { labelValuesQuery(label: string, metric?: string) { const start = this.datasource.getPrometheusTime(this.range.from, false); const end = this.datasource.getPrometheusTime(this.range.to, true); - const params = { ...(metric && { 'match[]': metric }), start: start.toString(), end: end.toString() }; - if (!metric || this.datasource.hasLabelsMatchAPISupport()) { - const url = `/api/v1/label/${label}/values`; + let url: string; + + if (!metric) { + const params = { + start: start.toString(), + end: end.toString(), + }; + // return label values globally + url = `/api/v1/label/${label}/values`; return this.datasource.metadataRequest(url, params).then((result: any) => { return _map(result.data.data, (value) => { @@ -81,7 +87,12 @@ export default class PrometheusMetricFindQuery { }); }); } else { - const url = `/api/v1/series`; + const params = { + 'match[]': metric, + start: start.toString(), + end: end.toString(), + }; + url = `/api/v1/series`; return this.datasource.metadataRequest(url, params).then((result: any) => { const _labels = _map(result.data.data, (metric) => {