mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Offer hint for metrics with labels (#45396)
* Prometheus: Offer hint for counter metric with labels * Update comment * Fix hinting for buckets with labe-values
This commit is contained in:
parent
39797e33ae
commit
d38f0e5d9e
@ -88,6 +88,21 @@ describe('getQueryHints()', () => {
|
||||
expect(hints).toEqual([]);
|
||||
});
|
||||
|
||||
it('returns a rate hint with action for a counter metric with labels', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[24, 1001],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('metric_total{job="grafana"}', series);
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0].label).toContain('Selected metric looks like a counter');
|
||||
expect(hints![0].fix).toBeDefined();
|
||||
});
|
||||
|
||||
it('returns a rate hint w/o action for a complex counter metric', () => {
|
||||
const series = [
|
||||
{
|
||||
@ -118,6 +133,21 @@ describe('getQueryHints()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a histogram hint with action for a bucket with labels', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[24, 1001],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('metric_bucket{job="grafana"}', series);
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0].label).toContain('Selected metric has buckets.');
|
||||
expect(hints![0].fix).toBeDefined();
|
||||
});
|
||||
|
||||
it('returns a sum hint when many time series results are returned for a simple metric', () => {
|
||||
const seriesCount = SUM_HINT_THRESHOLD_COUNT;
|
||||
const series = Array.from({ length: seriesCount }, (_) => ({
|
||||
|
@ -11,7 +11,7 @@ export function getQueryHints(query: string, series?: any[], datasource?: Promet
|
||||
const hints = [];
|
||||
|
||||
// ..._bucket metric needs a histogram_quantile()
|
||||
const histogramMetric = query.trim().match(/^\w+_bucket$/);
|
||||
const histogramMetric = query.trim().match(/^\w+_bucket$|^\w+_bucket{.*}$/);
|
||||
if (histogramMetric) {
|
||||
const label = 'Selected metric has buckets.';
|
||||
hints.push({
|
||||
@ -53,12 +53,13 @@ export function getQueryHints(query: string, series?: any[], datasource?: Promet
|
||||
}
|
||||
|
||||
if (counterNameMetric) {
|
||||
const simpleMetric = query.trim().match(/^\w+$/);
|
||||
// FixableQuery consists of metric name and optionally label-value pairs. We are not offering fix for complex queries yet.
|
||||
const fixableQuery = query.trim().match(/^\w+$|^\w+{.*}$/);
|
||||
const verb = certain ? 'is' : 'looks like';
|
||||
let label = `Selected metric ${verb} a counter.`;
|
||||
let fix: QueryFix | undefined;
|
||||
|
||||
if (simpleMetric) {
|
||||
if (fixableQuery) {
|
||||
fix = {
|
||||
label: 'Consider calculating rate of counter by adding rate().',
|
||||
action: {
|
||||
|
Loading…
Reference in New Issue
Block a user