Prometheus: Do not show rate hint when increase function is applied (#21955)

This commit is contained in:
Huan Wang 2020-02-06 04:56:53 -07:00 committed by GitHub
parent 89d1ab37de
commit 8b632ac029
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -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 = [
{

View File

@ -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] : '';