diff --git a/public/app/plugins/datasource/prometheus/query_hints.test.ts b/public/app/plugins/datasource/prometheus/query_hints.test.ts index 9f48bb3fa1b..7089ea3e2e1 100644 --- a/public/app/plugins/datasource/prometheus/query_hints.test.ts +++ b/public/app/plugins/datasource/prometheus/query_hints.test.ts @@ -171,4 +171,22 @@ describe('getQueryHints()', () => { }, }); }); + + it('should not return rate hint for a recorded query', () => { + const seriesCount = SUM_HINT_THRESHOLD_COUNT; + const series = Array.from({ length: seriesCount }, (_) => ({ + datapoints: [ + [0, 0], + [0, 0], + ], + })); + let hints = getQueryHints('node_namespace_pod_container:container_cpu_usage_seconds_total:sum_irate', series); + expect(hints!.length).toBe(0); + + hints = getQueryHints('node_namespace_pod_container:container_cpu_usage_seconds_total', series); + expect(hints!.length).toBe(0); + + hints = getQueryHints('container_cpu_usage_seconds_total:irate_total', series); + expect(hints!.length).toBe(0); + }); }); diff --git a/public/app/plugins/datasource/prometheus/query_hints.ts b/public/app/plugins/datasource/prometheus/query_hints.ts index aa08db4ae9d..05558235d87 100644 --- a/public/app/plugins/datasource/prometheus/query_hints.ts +++ b/public/app/plugins/datasource/prometheus/query_hints.ts @@ -32,7 +32,7 @@ export function getQueryHints(query: string, series?: any[], datasource?: Promet // Check for need of rate() 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/); + const nameMatch = query.match(/\b((?