From 8b632ac0290cb58c6193330016f1161bd2f1fcb2 Mon Sep 17 00:00:00 2001 From: Huan Wang Date: Thu, 6 Feb 2020 04:56:53 -0700 Subject: [PATCH] Prometheus: Do not show rate hint when increase function is applied (#21955) --- .../datasource/prometheus/query_hints.test.ts | 13 +++++++++++++ .../plugins/datasource/prometheus/query_hints.ts | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/public/app/plugins/datasource/prometheus/query_hints.test.ts b/public/app/plugins/datasource/prometheus/query_hints.test.ts index 9345a5f4083..6f5f9ce460e 100644 --- a/public/app/plugins/datasource/prometheus/query_hints.test.ts +++ b/public/app/plugins/datasource/prometheus/query_hints.test.ts @@ -75,6 +75,19 @@ describe('getQueryHints()', () => { expect(hints).toEqual(null); }); + it('returns no rate hint for a counter metric that already has an increase', () => { + const series = [ + { + datapoints: [ + [23, 1000], + [24, 1001], + ], + }, + ]; + const hints = getQueryHints('increase(metric_total[1m])', series); + expect(hints).toEqual(null); + }); + it('returns a rate hint w/o action for a complex counter metric', () => { const series = [ { diff --git a/public/app/plugins/datasource/prometheus/query_hints.ts b/public/app/plugins/datasource/prometheus/query_hints.ts index 946ae5e0f1a..69de51443dc 100644 --- a/public/app/plugins/datasource/prometheus/query_hints.ts +++ b/public/app/plugins/datasource/prometheus/query_hints.ts @@ -28,7 +28,7 @@ export function getQueryHints(query: string, series?: any[], datasource?: Promet } // Check for need of rate() - if (query.indexOf('rate(') === -1) { + if (query.indexOf('rate(') === -1 && query.indexOf('increase(') === -1) { // Use metric metadata for exact types const nameMatch = query.match(/\b(\w+_(total|sum|count))\b/); let counterNameMetric = nameMatch ? nameMatch[1] : '';