Chore: Update native histogram hints in prometheus data source (#96270)

* [Prometheus] Update native histogram hints

* update unit tests
This commit is contained in:
Mohammad Iskandarany 2024-11-15 19:12:01 +03:00 committed by GitHub
parent 11f1a6b034
commit 4e3e50bf91
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 51 deletions

View File

@ -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', () => {

View File

@ -50,9 +50,20 @@ 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_QUANTILE',
label,
fix: {
label: 'Consider calculating aggregated quantile by adding histogram_quantile().',
action: {
type: 'ADD_HISTOGRAM_QUANTILE',
query,
},
},
},
{
type: 'HISTOGRAM_AVG',
label,
@ -74,52 +85,6 @@ export function getQueryHints(query: string, series?: unknown[], datasource?: Pr
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',
label,
fix: {
label:
'Consider calculating the estimated fraction of observations between the provided lower and upper values by adding histogram_fraction().',
action: {
type: 'ADD_HISTOGRAM_FRACTION',
query,
},
},
},
{
type: 'HISTOGRAM_STDDEV',
label,
fix: {
label:
'Consider calculating the estimated standard deviation of observations by adding histogram_stddev().',
action: {
type: 'ADD_HISTOGRAM_STDDEV',
query,
},
},
},
{
type: 'HISTOGRAM_STDVAR',
label,
fix: {
label: 'Consider calculating the estimated standard variance of observations by adding histogram_stdvar().',
action: {
type: 'ADD_HISTOGRAM_STDVAR',
query,
},
},
}
);
}