Prometheus: Support new info function in code editor (#97850)

* first attempt to have info function

* unit test for query modeller

* enable info function in devenv

* fix unit test

* add unit test for info function

* throw error when trying to visualize the info function

* remove visual query support

* Update packages/grafana-prometheus/src/promql.ts

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>

* Update packages/grafana-prometheus/src/querybuilder/parsing.test.ts

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>

* update info function detail

---------

Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
pull/103456/head
ismail simsek 3 months ago committed by GitHub
parent 2c0255a72e
commit 1a988df143
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      devenv/docker/blocks/prometheus/Dockerfile
  2. 1
      devenv/docker/blocks/prometheus/docker-compose.yaml
  3. 1
      packages/grafana-prometheus/src/components/monaco-query-field/promql.ts
  4. 7
      packages/grafana-prometheus/src/promql.ts
  5. 51
      packages/grafana-prometheus/src/querybuilder/parsing.test.ts
  6. 9
      packages/grafana-prometheus/src/querybuilder/parsing.ts
  7. 1
      packages/grafana-prometheus/src/querybuilder/types.ts

@ -1,4 +1,4 @@
FROM prom/prometheus:v3.1.0
FROM prom/prometheus:v3.2.1
ADD prometheus.yml /etc/prometheus/
ADD recording.yml /etc/prometheus/
ADD alert.yml /etc/prometheus/

@ -6,6 +6,7 @@
- "host.docker.internal:host-gateway"
command: >
--enable-feature=remote-write-receiver
--enable-feature=promql-experimental-functions
--config.file=/etc/prometheus/prometheus.yml
--storage.tsdb.path=/prometheus
--web.console.libraries=/usr/share/prometheus/console_libraries

@ -97,6 +97,7 @@ const functions = [
'hour',
'idelta',
'increase',
'info',
'irate',
'label_join',
'label_replace',

@ -327,6 +327,13 @@ export const FUNCTIONS = [
documentation:
'Calculates the increase in the time series in the range vector. Breaks in monotonicity (such as counter resets due to target restarts) are automatically adjusted for. The increase is extrapolated to cover the full time range as specified in the range vector selector, so that it is possible to get a non-integer result even if a counter increases only by integer increments.',
},
{
insertText: 'info',
label: 'info',
detail: 'info(v instant-vector, [data-label-selector instant-vector])',
documentation:
'Returns latest details and metadata about a group of metrics, such as their labels and current values, without doing any calculations',
},
{
insertText: 'irate',
label: 'irate',

@ -3,6 +3,57 @@ import { buildVisualQueryFromString } from './parsing';
import { PromOperationId, PromVisualQuery } from './types';
describe('buildVisualQueryFromString', () => {
describe('info function support', () => {
// Currently, the visual query editor throws an error when parsing the 'info' function
// because this function is only supported in code mode.
// TODO: When visual query editor support for the 'info' function is implemented,
// this test should be updated to expect successful parsing instead of an error.
it('should throw error when trying to parse info function', () => {
expect(
buildVisualQueryFromString(
'sum by (cluster, sdk_language) ( info( rate(server_req_dur_sec_count{instance="the-instance"}[2m]), {sdk_language="go"} ) )'
)
).toEqual({
query: {
labels: [
{
label: 'instance',
op: '=',
value: 'the-instance',
},
{
label: 'sdk_language',
op: '=',
value: 'go',
},
],
metric: 'server_req_dur_sec_count',
operations: [
{
id: 'rate',
params: ['2m'],
},
{
id: 'info',
params: [],
},
{
id: '__sum_by',
params: ['cluster', 'sdk_language'],
},
],
},
errors: [
{
from: 33,
text: 'Query parsing is ambiguous.',
to: 121,
},
],
});
});
});
describe('utf8 support', () => {
it('supports uts-8 label names', () => {
expect(buildVisualQueryFromString('{"glück:🍀.dot"="luck"} == 11')).toEqual({

@ -256,6 +256,15 @@ function handleFunction(expr: string, node: SyntaxNode, context: Context) {
const nameNode = node.getChild(FunctionIdentifier);
const funcName = getString(expr, nameNode);
// Visual query builder doesn't support nested queries and so info function.
if (funcName === 'info') {
context.errors.push({
text: 'Query parsing is ambiguous.',
from: node.from,
to: node.to,
});
}
const body = node.getChild(FunctionCallBody);
const params = [];
let interval = '';

@ -77,6 +77,7 @@ export enum PromOperationId {
Hour = 'hour',
Idelta = 'idelta',
Increase = 'increase',
Info = 'info',
Irate = 'irate',
LabelJoin = 'label_join',
LabelReplace = 'label_replace',

Loading…
Cancel
Save