Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions packages/grafana-prometheus/src/query_hints.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,13 +216,11 @@ describe('getQueryHints()', () => {
const datasource = mock as PrometheusDatasource;

let hints = getQueryHints('foo', series, datasource);
expect(hints!.length).toBe(6);
expect(hints!.length).toBe(3);
const hintsString = JSON.stringify(hints);
expect(hintsString).toContain('ADD_HISTOGRAM_AVG');
expect(hintsString).toContain('ADD_HISTOGRAM_COUNT');
expect(hintsString).toContain('ADD_HISTOGRAM_SUM');
expect(hintsString).toContain('ADD_HISTOGRAM_FRACTION');
expect(hintsString).toContain('ADD_HISTOGRAM_AVG');
expect(hintsString).toContain('ADD_HISTOGRAM_QUANTILE');
});

it('returns no hints for native histogram when there are native histogram functions in the query', () => {
Expand Down
55 changes: 10 additions & 45 deletions packages/grafana-prometheus/src/query_hints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,73 +50,38 @@ export function getQueryHints(query: string, series?: unknown[], datasource?: Pr

if (nativeHistogramNameMetric) {
// add hints:
// histogram_avg, histogram_count, histogram_sum, histogram_fraction, histogram_stddev, histogram_stdvar
// histogram_quantile, histogram_avg, histogram_count
const label = 'Selected metric is a native histogram.';
hints.push(
{
type: 'HISTOGRAM_AVG',
label,
fix: {
label: 'Consider calculating the arithmetic average of observed values by adding histogram_avg().',
action: {
type: 'ADD_HISTOGRAM_AVG',
query,
},
},
},
{
type: 'HISTOGRAM_COUNT',
label,
fix: {
label: 'Consider calculating the count of observations by adding histogram_count().',
action: {
type: 'ADD_HISTOGRAM_COUNT',
query,
},
},
},
{
type: 'HISTOGRAM_SUM',
label,
fix: {
label: 'Consider calculating the sum of observations by adding histogram_sum().',
action: {
type: 'ADD_HISTOGRAM_SUM',
query,
},
},
},
{
type: 'HISTOGRAM_FRACTION',
type: 'HISTOGRAM_QUANTILE',
label,
fix: {
label:
'Consider calculating the estimated fraction of observations between the provided lower and upper values by adding histogram_fraction().',
label: 'Consider calculating aggregated quantile by adding histogram_quantile().',
action: {
type: 'ADD_HISTOGRAM_FRACTION',
type: 'ADD_HISTOGRAM_QUANTILE',
query,
},
},
},
{
type: 'HISTOGRAM_STDDEV',
type: 'HISTOGRAM_AVG',
label,
fix: {
label:
'Consider calculating the estimated standard deviation of observations by adding histogram_stddev().',
label: 'Consider calculating the arithmetic average of observed values by adding histogram_avg().',
action: {
type: 'ADD_HISTOGRAM_STDDEV',
type: 'ADD_HISTOGRAM_AVG',
query,
},
},
},
{
type: 'HISTOGRAM_STDVAR',
type: 'HISTOGRAM_COUNT',
label,
fix: {
label: 'Consider calculating the estimated standard variance of observations by adding histogram_stdvar().',
label: 'Consider calculating the count of observations by adding histogram_count().',
action: {
type: 'ADD_HISTOGRAM_STDVAR',
type: 'ADD_HISTOGRAM_COUNT',
query,
},
},
Expand Down
Loading