mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
Chore: Move Prometheus datasorce tests from specs folder and merge duplicated test files (#20755)
This commit is contained in:
parent
87d19787b4
commit
e68e93f595
@ -1,4 +1,4 @@
|
||||
import { addLabelToQuery, addLabelToSelector, keepSelectorFilters } from '../add_label_to_query';
|
||||
import { addLabelToQuery, addLabelToSelector, keepSelectorFilters } from './add_label_to_query';
|
||||
|
||||
describe('addLabelToQuery()', () => {
|
||||
it('should add label to simple query', () => {
|
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,4 @@
|
||||
import { expandRecordingRules, parseSelector } from '../language_utils';
|
||||
import { expandRecordingRules, parseSelector } from './language_utils';
|
||||
|
||||
describe('parseSelector()', () => {
|
||||
let parsed;
|
@ -1,7 +1,7 @@
|
||||
import { PrometheusDatasource } from '../datasource';
|
||||
import PrometheusMetricFindQuery from '../metric_find_query';
|
||||
import { PrometheusDatasource } from './datasource';
|
||||
import PrometheusMetricFindQuery from './metric_find_query';
|
||||
import { toUtc, DataSourceInstanceSettings } from '@grafana/data';
|
||||
import { PromOptions } from '../types';
|
||||
import { PromOptions } from './types';
|
||||
|
||||
import templateSrv from 'app/features/templating/template_srv';
|
||||
import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
@ -1,4 +1,4 @@
|
||||
import { plugin as PrometheusDatasourcePlugin } from '../module';
|
||||
import { plugin as PrometheusDatasourcePlugin } from './module';
|
||||
|
||||
describe('module', () => {
|
||||
it('should have metrics query field in panels and Explore', () => {
|
@ -1,6 +1,155 @@
|
||||
import { getQueryHints } from './query_hints';
|
||||
import { getQueryHints, SUM_HINT_THRESHOLD_COUNT } from './query_hints';
|
||||
//////
|
||||
describe('getQueryHints()', () => {
|
||||
it('returns no hints for no series', () => {
|
||||
expect(getQueryHints('', [])).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns no hints for empty series', () => {
|
||||
expect(getQueryHints('', [{ datapoints: [] }])).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns no hint for a monotonically decreasing series', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[22, 1001],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('metric', series);
|
||||
expect(hints).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns no hint for a flat series', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[null, 1000],
|
||||
[23, 1001],
|
||||
[null, 1002],
|
||||
[23, 1003],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('metric', series);
|
||||
expect(hints).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns a rate hint for a monotonically increasing series', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[24, 1001],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('metric', series);
|
||||
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0]).toMatchObject({
|
||||
label: 'Time series is monotonically increasing.',
|
||||
fix: {
|
||||
action: {
|
||||
type: 'ADD_RATE',
|
||||
query: 'metric',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns no rate hint for a monotonically increasing series that already has a rate', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[24, 1001],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('rate(metric[1m])', series);
|
||||
expect(hints).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns a rate hint w/o action for a complex monotonically increasing series', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[24, 1001],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('sum(metric)', series);
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0].label).toContain('rate()');
|
||||
expect(hints![0].fix).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns a rate hint for a monotonically increasing series with missing data', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[null, 1001],
|
||||
[24, 1002],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('metric', series);
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0]).toMatchObject({
|
||||
label: 'Time series is monotonically increasing.',
|
||||
fix: {
|
||||
action: {
|
||||
type: 'ADD_RATE',
|
||||
query: 'metric',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a histogram hint for a bucket series', () => {
|
||||
const series = [{ datapoints: [[23, 1000]] }];
|
||||
const hints = getQueryHints('metric_bucket', series);
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0]).toMatchObject({
|
||||
label: 'Time series has buckets, you probably wanted a histogram.',
|
||||
fix: {
|
||||
action: {
|
||||
type: 'ADD_HISTOGRAM_QUANTILE',
|
||||
query: 'metric_bucket',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
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 }, _ => ({
|
||||
datapoints: [
|
||||
[0, 0],
|
||||
[0, 0],
|
||||
],
|
||||
}));
|
||||
const hints = getQueryHints('metric', series);
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0]).toMatchObject({
|
||||
type: 'ADD_SUM',
|
||||
label: 'Many time series results returned.',
|
||||
fix: {
|
||||
label: 'Consider aggregating with sum().',
|
||||
action: {
|
||||
type: 'ADD_SUM',
|
||||
query: 'metric',
|
||||
preventSubmit: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
describe('getQueryHints', () => {
|
||||
describe('when called without datapoints in series', () => {
|
||||
it('then it should use rows instead and return correct hint', () => {
|
||||
const series = [
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { ResultTransformer } from '../result_transformer';
|
||||
import { ResultTransformer } from './result_transformer';
|
||||
import { DataQueryResponseData } from '@grafana/data';
|
||||
|
||||
describe('Prometheus Result Transformer', () => {
|
File diff suppressed because it is too large
Load Diff
@ -1,152 +0,0 @@
|
||||
import { getQueryHints, SUM_HINT_THRESHOLD_COUNT } from '../query_hints';
|
||||
|
||||
describe('getQueryHints()', () => {
|
||||
it('returns no hints for no series', () => {
|
||||
expect(getQueryHints('', [])).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns no hints for empty series', () => {
|
||||
expect(getQueryHints('', [{ datapoints: [] }])).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns no hint for a monotonically decreasing series', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[22, 1001],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('metric', series);
|
||||
expect(hints).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns no hint for a flat series', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[null, 1000],
|
||||
[23, 1001],
|
||||
[null, 1002],
|
||||
[23, 1003],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('metric', series);
|
||||
expect(hints).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns a rate hint for a monotonically increasing series', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[24, 1001],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('metric', series);
|
||||
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0]).toMatchObject({
|
||||
label: 'Time series is monotonically increasing.',
|
||||
fix: {
|
||||
action: {
|
||||
type: 'ADD_RATE',
|
||||
query: 'metric',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns no rate hint for a monotonically increasing series that already has a rate', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[24, 1001],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('rate(metric[1m])', series);
|
||||
expect(hints).toEqual(null);
|
||||
});
|
||||
|
||||
it('returns a rate hint w/o action for a complex monotonically increasing series', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[24, 1001],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('sum(metric)', series);
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0].label).toContain('rate()');
|
||||
expect(hints![0].fix).toBeUndefined();
|
||||
});
|
||||
|
||||
it('returns a rate hint for a monotonically increasing series with missing data', () => {
|
||||
const series = [
|
||||
{
|
||||
datapoints: [
|
||||
[23, 1000],
|
||||
[null, 1001],
|
||||
[24, 1002],
|
||||
],
|
||||
},
|
||||
];
|
||||
const hints = getQueryHints('metric', series);
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0]).toMatchObject({
|
||||
label: 'Time series is monotonically increasing.',
|
||||
fix: {
|
||||
action: {
|
||||
type: 'ADD_RATE',
|
||||
query: 'metric',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it('returns a histogram hint for a bucket series', () => {
|
||||
const series = [{ datapoints: [[23, 1000]] }];
|
||||
const hints = getQueryHints('metric_bucket', series);
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0]).toMatchObject({
|
||||
label: 'Time series has buckets, you probably wanted a histogram.',
|
||||
fix: {
|
||||
action: {
|
||||
type: 'ADD_HISTOGRAM_QUANTILE',
|
||||
query: 'metric_bucket',
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
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 }, _ => ({
|
||||
datapoints: [
|
||||
[0, 0],
|
||||
[0, 0],
|
||||
],
|
||||
}));
|
||||
const hints = getQueryHints('metric', series);
|
||||
expect(hints!.length).toBe(1);
|
||||
expect(hints![0]).toMatchObject({
|
||||
type: 'ADD_SUM',
|
||||
label: 'Many time series results returned.',
|
||||
fix: {
|
||||
label: 'Consider aggregating with sum().',
|
||||
action: {
|
||||
type: 'ADD_SUM',
|
||||
query: 'metric',
|
||||
preventSubmit: true,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user