mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Merge pull request #12876 from grafana/davkal/explore-rate-hinting
Explore: still show rate hint if query is complex
This commit is contained in:
commit
dc60848319
@ -110,10 +110,9 @@ export function determineQueryHints(series: any[], datasource?: any): any[] {
|
|||||||
|
|
||||||
// Check for monotony
|
// Check for monotony
|
||||||
const datapoints: [number, number][] = s.datapoints;
|
const datapoints: [number, number][] = s.datapoints;
|
||||||
const simpleMetric = query.trim().match(/^\w+$/);
|
if (datapoints.length > 1) {
|
||||||
if (simpleMetric && datapoints.length > 1) {
|
|
||||||
let increasing = false;
|
let increasing = false;
|
||||||
const monotonic = datapoints.every((dp, index) => {
|
const monotonic = datapoints.filter(dp => dp[0] !== null).every((dp, index) => {
|
||||||
if (index === 0) {
|
if (index === 0) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -122,18 +121,25 @@ export function determineQueryHints(series: any[], datasource?: any): any[] {
|
|||||||
return dp[0] >= datapoints[index - 1][0];
|
return dp[0] >= datapoints[index - 1][0];
|
||||||
});
|
});
|
||||||
if (increasing && monotonic) {
|
if (increasing && monotonic) {
|
||||||
const label = 'Time series is monotonously increasing.';
|
const simpleMetric = query.trim().match(/^\w+$/);
|
||||||
return {
|
let label = 'Time series is monotonously increasing.';
|
||||||
label,
|
let fix;
|
||||||
index,
|
if (simpleMetric) {
|
||||||
fix: {
|
fix = {
|
||||||
label: 'Fix by adding rate().',
|
label: 'Fix by adding rate().',
|
||||||
action: {
|
action: {
|
||||||
type: 'ADD_RATE',
|
type: 'ADD_RATE',
|
||||||
query,
|
query,
|
||||||
index,
|
index,
|
||||||
},
|
},
|
||||||
},
|
};
|
||||||
|
} else {
|
||||||
|
label = `${label} Try applying a rate() function.`;
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
label,
|
||||||
|
index,
|
||||||
|
fix,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -213,6 +213,30 @@ describe('PrometheusDatasource', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('returns a rate hint w/o action for a complex monotonously increasing series', () => {
|
||||||
|
const series = [{ datapoints: [[23, 1000], [24, 1001]], query: 'sum(metric)', responseIndex: 0 }];
|
||||||
|
const hints = determineQueryHints(series);
|
||||||
|
expect(hints.length).toBe(1);
|
||||||
|
expect(hints[0].label).toContain('rate()');
|
||||||
|
expect(hints[0].fix).toBeUndefined();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('returns a rate hint for a monotonously increasing series with missing data', () => {
|
||||||
|
const series = [{ datapoints: [[23, 1000], [null, 1001], [24, 1002]], query: 'metric', responseIndex: 0 }];
|
||||||
|
const hints = determineQueryHints(series);
|
||||||
|
expect(hints.length).toBe(1);
|
||||||
|
expect(hints[0]).toMatchObject({
|
||||||
|
label: 'Time series is monotonously increasing.',
|
||||||
|
index: 0,
|
||||||
|
fix: {
|
||||||
|
action: {
|
||||||
|
type: 'ADD_RATE',
|
||||||
|
query: 'metric',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
it('returns a histogram hint for a bucket series', () => {
|
it('returns a histogram hint for a bucket series', () => {
|
||||||
const series = [{ datapoints: [[23, 1000]], query: 'metric_bucket', responseIndex: 0 }];
|
const series = [{ datapoints: [[23, 1000]], query: 'metric_bucket', responseIndex: 0 }];
|
||||||
const hints = determineQueryHints(series);
|
const hints = determineQueryHints(series);
|
||||||
|
Loading…
Reference in New Issue
Block a user