-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…56369) * Loki: Fix unwrapped range operations with grouping * Update, fix tests * Fix modeller (cherry picked from commit 4469572) Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
- Loading branch information
1 parent
4d3408f
commit 5518641
Showing
7 changed files
with
428 additions
and
202 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
124 changes: 124 additions & 0 deletions
124
public/app/plugins/datasource/loki/querybuilder/operationUtils.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { createRangeOperation, createRangeOperationWithGrouping } from './operationUtils'; | ||
import { LokiVisualQueryOperationCategory } from './types'; | ||
|
||
describe('createRangeOperation', () => { | ||
it('should create basic range operation without possible grouping', () => { | ||
expect(createRangeOperation('test_range_operation')).toMatchObject({ | ||
id: 'test_range_operation', | ||
name: 'Test range operation', | ||
params: [{ name: 'Range', type: 'string' }], | ||
defaultParams: ['$__interval'], | ||
alternativesKey: 'range function', | ||
category: LokiVisualQueryOperationCategory.RangeFunctions, | ||
}); | ||
}); | ||
|
||
it('should create basic range operation with possible grouping', () => { | ||
expect(createRangeOperation('test_range_operation', true)).toMatchObject({ | ||
id: 'test_range_operation', | ||
name: 'Test range operation', | ||
params: [ | ||
{ name: 'Range', type: 'string' }, | ||
{ | ||
name: 'By label', | ||
type: 'string', | ||
restParam: true, | ||
optional: true, | ||
}, | ||
], | ||
defaultParams: ['$__interval'], | ||
alternativesKey: 'range function', | ||
category: LokiVisualQueryOperationCategory.RangeFunctions, | ||
}); | ||
}); | ||
|
||
it('should create range operation for quantile_over_time', () => { | ||
expect(createRangeOperation('quantile_over_time', true)).toMatchObject({ | ||
id: 'quantile_over_time', | ||
name: 'Quantile over time', | ||
params: [ | ||
{ name: 'Range', type: 'string' }, | ||
{ name: 'Quantile', type: 'number' }, | ||
{ name: 'By label', type: 'string', restParam: true, optional: true }, | ||
], | ||
defaultParams: ['$__interval', '0.95'], | ||
alternativesKey: 'range function', | ||
category: LokiVisualQueryOperationCategory.RangeFunctions, | ||
}); | ||
}); | ||
}); | ||
|
||
describe('createRangeOperationWithGrouping', () => { | ||
it('returns correct operation definitions with overrides and params', () => { | ||
const operations = createRangeOperationWithGrouping('quantile_over_time'); | ||
expect(operations).toHaveLength(3); | ||
expect(operations[0]).toMatchObject({ | ||
id: 'quantile_over_time', | ||
name: 'Quantile over time', | ||
params: [ | ||
{ name: 'Range', type: 'string' }, | ||
{ name: 'Quantile', type: 'number' }, | ||
{ name: 'By label', type: 'string', restParam: true, optional: true }, | ||
], | ||
defaultParams: ['$__interval', '0.95'], | ||
alternativesKey: 'range function', | ||
category: LokiVisualQueryOperationCategory.RangeFunctions, | ||
}); | ||
|
||
expect(operations[1]).toMatchObject({ | ||
id: '__quantile_over_time_by', | ||
name: 'Quantile over time by', | ||
params: [ | ||
{ name: 'Range', type: 'string' }, | ||
{ name: 'Quantile', type: 'number' }, | ||
{ name: 'Label', type: 'string', restParam: true, optional: true }, | ||
], | ||
defaultParams: ['$__interval', '0.95', ''], | ||
alternativesKey: 'range function with grouping', | ||
category: LokiVisualQueryOperationCategory.RangeFunctions, | ||
}); | ||
|
||
expect(operations[2]).toMatchObject({ | ||
id: '__quantile_over_time_without', | ||
name: 'Quantile over time without', | ||
params: [ | ||
{ name: 'Range', type: 'string' }, | ||
{ name: 'Quantile', type: 'number' }, | ||
{ name: 'Label', type: 'string', restParam: true, optional: true }, | ||
], | ||
defaultParams: ['$__interval', '0.95', ''], | ||
alternativesKey: 'range function with grouping', | ||
category: LokiVisualQueryOperationCategory.RangeFunctions, | ||
}); | ||
}); | ||
|
||
it('returns correct query string using range operation definitions for quantile_over_time with by grouping', () => { | ||
const operations = createRangeOperationWithGrouping('quantile_over_time'); | ||
const query = operations[1].renderer( | ||
{ id: '__quantile_over_time_by', params: ['[5m]', '0.95', 'source', 'place'] }, | ||
operations[1], | ||
'{job="grafana"}' | ||
); | ||
expect(query).toBe('quantile_over_time(0.95, {job="grafana"} [[5m]]) by (source, place)'); | ||
}); | ||
|
||
it('returns correct query string using range operation definitions for quantile_over_time with without grouping', () => { | ||
const operations = createRangeOperationWithGrouping('quantile_over_time'); | ||
const query = operations[2].renderer( | ||
{ id: '__quantile_over_time_without', params: ['[$__interval]', '0.91', 'source', 'place'] }, | ||
operations[2], | ||
'{job="grafana"}' | ||
); | ||
expect(query).toBe('quantile_over_time(0.91, {job="grafana"} [[$__interval]]) without (source, place)'); | ||
}); | ||
|
||
it('returns correct query string using range operation definitions for avg_over_time with without grouping', () => { | ||
const operations = createRangeOperationWithGrouping('avg_over_time'); | ||
const query = operations[2].renderer( | ||
{ id: '__avg_over_time_without', params: ['[$__interval]', 'source'] }, | ||
operations[2], | ||
'{job="grafana"}' | ||
); | ||
expect(query).toBe('avg_over_time({job="grafana"} [[$__interval]]) without (source)'); | ||
}); | ||
}); |
Oops, something went wrong.