Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ export const PROMQL_REQUIRED_PARAMS = PROMQL_PARAMS.filter(({ required }) => req
/* Matches "param=" or "param =" but not "endpoint=" for param "end". */
const PARAM_ASSIGNMENT_PATTERNS = PROMQL_PARAM_NAMES.map((param) => ({
param,
pattern: new RegExp(`\\b${param}\\s*=`, 'i'),
pattern: new RegExp(`${param}\\s*=`, 'i'),
}));

export function getPromqlParamDefinitions(): PromqlParamDefinition[] {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,54 @@ describe('PROMQL Validation', () => {
promqlExpectErrors('PROMQL step=5m start=?_tstart end=?_tend col0=(rate(x[5m]))', []);
});
});

describe('index validation', () => {
test('valid index', () => {
promqlExpectErrors(
'PROMQL index=timeseries_index step=5m start=?_tstart end=?_tend (rate(x[5m]))',
[]
);
});

test('unknown index', () => {
promqlExpectErrors(
'PROMQL index=unknown_xyz step=5m start=?_tstart end=?_tend (rate(x[5m]))',
['Unknown index "unknown_xyz"']
);
});

test('unknown index with missing query', () => {
promqlExpectErrors('PROMQL step="5m" index=hh', [
'Unknown index "hh"',
'[PROMQL] Missing query',
]);
});

test('multiple indexes - all valid', () => {
promqlExpectErrors(
'PROMQL index=timeseries_index,time_series_index step=5m start=?_tstart end=?_tend (rate(x[5m]))',
[]
);
});

test('multiple indexes - one invalid', () => {
promqlExpectErrors(
'PROMQL index=timeseries_index,unknown_xyz step=5m start=?_tstart end=?_tend (rate(x[5m]))',
['Unknown index "unknown_xyz"']
);
});

test('wildcard index', () => {
promqlExpectErrors(
'PROMQL index=timeseries_* step=5m start=?_tstart end=?_tend (rate(x[5m]))',
[]
);
});

test('invalid wildcard index', () => {
promqlExpectErrors('PROMQL index=unknown_* step=5m start=?_tstart end=?_tend (rate(x[5m]))', [
'Unknown index "unknown_*"',
]);
});
});
});
Loading
Loading