Prometheus: bool bin op improvements (#47198)

* Change param order

* Align tooltip icon styling
This commit is contained in:
Andrej Ocenas 2022-04-01 17:51:50 +02:00 committed by GitHub
parent 07bb5b37a5
commit ba2332eb96
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 7 deletions

View File

@ -317,4 +317,19 @@ describe('PromQueryModeller', () => {
}) })
).toBe('metric_a / on(le, foo) metric_b'); ).toBe('metric_a / on(le, foo) metric_b');
}); });
it('can render bool in binary ops', () => {
expect(
modeller.renderQuery({
metric: 'cluster_namespace_slug_dialer_name',
labels: [],
operations: [
{
id: '__less_or_equal',
params: [2, true],
},
],
})
).toBe('cluster_namespace_slug_dialer_name <= bool 2');
});
}); });

View File

@ -77,12 +77,12 @@ export const binaryScalarOperations: QueryBuilderOperationDef[] = binaryScalarDe
const params: QueryBuilderOperationParamDef[] = [{ name: 'Value', type: 'number' }]; const params: QueryBuilderOperationParamDef[] = [{ name: 'Value', type: 'number' }];
const defaultParams: any[] = [2]; const defaultParams: any[] = [2];
if (opDef.comparison) { if (opDef.comparison) {
params.unshift({ params.push({
name: 'Bool', name: 'Bool',
type: 'boolean', type: 'boolean',
description: 'If checked comparison will return 0 or 1 for the value rather than filtering.', description: 'If checked comparison will return 0 or 1 for the value rather than filtering.',
}); });
defaultParams.unshift(false); defaultParams.push(false);
} }
return { return {
@ -102,8 +102,7 @@ function getSimpleBinaryRenderer(operator: string) {
let param = model.params[0]; let param = model.params[0];
let bool = ''; let bool = '';
if (model.params.length === 2) { if (model.params.length === 2) {
param = model.params[1]; bool = model.params[1] ? ' bool' : '';
bool = model.params[0] ? ' bool' : '';
} }
return `${innerExpr} ${operator}${bool} ${param}`; return `${innerExpr} ${operator}${bool} ${param}`;

View File

@ -422,7 +422,7 @@ describe('buildVisualQueryFromString', () => {
operations: [ operations: [
{ {
id: '__less_or_equal', id: '__less_or_equal',
params: [false, 2.5], params: [2.5, false],
}, },
], ],
}, },
@ -438,7 +438,7 @@ describe('buildVisualQueryFromString', () => {
operations: [ operations: [
{ {
id: '__less_or_equal', id: '__less_or_equal',
params: [true, 2], params: [2, true],
}, },
], ],
}, },

View File

@ -438,7 +438,7 @@ function makeBinOp(
) { ) {
const params: any[] = [parseFloat(getString(expr, numberNode))]; const params: any[] = [parseFloat(getString(expr, numberNode))];
if (opDef.comparison) { if (opDef.comparison) {
params.unshift(hasBool); params.push(hasBool);
} }
return { return {
id: opDef.id, id: opDef.id,

View File

@ -201,6 +201,10 @@ const getStyles = (theme: GrafanaTheme2) => {
}), }),
infoIcon: css({ infoIcon: css({
marginLeft: theme.spacing(0.5), marginLeft: theme.spacing(0.5),
color: theme.colors.text.secondary,
':hover': {
color: theme.colors.text.primary,
},
}), }),
body: css({ body: css({
margin: theme.spacing(1, 1, 0.5, 1), margin: theme.spacing(1, 1, 0.5, 1),