mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Pyroscope: Fix normalize query function (#70836)
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { AbstractLabelOperator, DataSourceInstanceSettings, PluginMetaInfo, PluginType } from '@grafana/data';
|
||||
import { AbstractLabelOperator, CoreApp, DataSourceInstanceSettings, PluginMetaInfo, PluginType } from '@grafana/data';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
|
||||
import { defaultPhlareQueryType } from './dataquery.gen';
|
||||
import { PhlareDataSource } from './datasource';
|
||||
import { normalizeQuery, PhlareDataSource } from './datasource';
|
||||
import { Query } from './types';
|
||||
|
||||
describe('Phlare data source', () => {
|
||||
let ds: PhlareDataSource;
|
||||
@@ -79,6 +80,42 @@ describe('Phlare data source', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('normalizeQuery', () => {
|
||||
it('correctly normalizes the query', () => {
|
||||
// We need the type assertion here because the query types are inherently wrong in explore.
|
||||
let normalized = normalizeQuery({} as Query);
|
||||
expect(normalized).toMatchObject({
|
||||
labelSelector: '{}',
|
||||
groupBy: [],
|
||||
queryType: 'profile',
|
||||
});
|
||||
|
||||
normalized = normalizeQuery({
|
||||
labelSelector: '{app="myapp"}',
|
||||
groupBy: ['app'],
|
||||
queryType: 'metrics',
|
||||
profileTypeId: 'cpu',
|
||||
refId: '',
|
||||
});
|
||||
expect(normalized).toMatchObject({
|
||||
labelSelector: '{app="myapp"}',
|
||||
groupBy: ['app'],
|
||||
queryType: 'metrics',
|
||||
profileTypeId: 'cpu',
|
||||
});
|
||||
});
|
||||
|
||||
it('correctly normalizes the query when in explore', () => {
|
||||
// We need the type assertion here because the query types are inherently wrong in explore.
|
||||
const normalized = normalizeQuery({} as Query, CoreApp.Explore);
|
||||
expect(normalized).toMatchObject({
|
||||
labelSelector: '{}',
|
||||
groupBy: [],
|
||||
queryType: 'both',
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
const defaultQuery = (query: string) => {
|
||||
return {
|
||||
refId: 'x',
|
||||
|
||||
Reference in New Issue
Block a user