mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Prometheus: Improvements to binary operations, nesting and parantheses handling (#45384)
* Prometheus: Improve query nesting ux * Prometheus: Add parentheses around nested queries with binary ops * removed unnessary typing change * Fixing ts issues * Improved paranthesis logic * Fixing unit test * Progress
This commit is contained in:
@@ -188,6 +188,76 @@ describe('PromQueryModeller', () => {
|
||||
).toBe('metric_a + metric_b + metric_c');
|
||||
});
|
||||
|
||||
it('Can render query with nested query with binary op', () => {
|
||||
expect(
|
||||
modeller.renderQuery({
|
||||
metric: 'metric_a',
|
||||
labels: [],
|
||||
operations: [],
|
||||
binaryQueries: [
|
||||
{
|
||||
operator: '/',
|
||||
query: {
|
||||
metric: 'metric_b',
|
||||
labels: [],
|
||||
operations: [{ id: PromOperationId.MultiplyBy, params: [1000] }],
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
).toBe('metric_a / (metric_b * 1000)');
|
||||
});
|
||||
|
||||
it('Can render query with nested binary query with parentheses', () => {
|
||||
expect(
|
||||
modeller.renderQuery({
|
||||
metric: 'metric_a',
|
||||
labels: [],
|
||||
operations: [],
|
||||
binaryQueries: [
|
||||
{
|
||||
operator: '/',
|
||||
query: {
|
||||
metric: 'metric_b',
|
||||
labels: [],
|
||||
operations: [],
|
||||
binaryQueries: [
|
||||
{
|
||||
operator: '*',
|
||||
query: {
|
||||
metric: 'metric_c',
|
||||
labels: [],
|
||||
operations: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
).toBe('metric_a / (metric_b * metric_c)');
|
||||
});
|
||||
|
||||
it('Should add parantheis around first query if it has binary op', () => {
|
||||
expect(
|
||||
modeller.renderQuery({
|
||||
metric: 'metric_a',
|
||||
labels: [],
|
||||
operations: [{ id: PromOperationId.MultiplyBy, params: [1000] }],
|
||||
binaryQueries: [
|
||||
{
|
||||
operator: '/',
|
||||
query: {
|
||||
metric: 'metric_b',
|
||||
labels: [],
|
||||
operations: [],
|
||||
},
|
||||
},
|
||||
],
|
||||
})
|
||||
).toBe('(metric_a * 1000) / metric_b');
|
||||
});
|
||||
|
||||
it('Can render with binary queries with vectorMatches expression', () => {
|
||||
expect(
|
||||
modeller.renderQuery({
|
||||
|
||||
Reference in New Issue
Block a user