mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Handle invalid query type values (#50755)
* loki: more robust query-type handling * better comment Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com> Co-authored-by: Ivana Huckova <30407135+ivanahuckova@users.noreply.github.com>
This commit is contained in:
parent
7566f800e6
commit
a97f022612
@ -97,4 +97,16 @@ describe('getNormalizedLokiQuery', () => {
|
||||
it('handles new<>old conflict (new wins), instant', () => {
|
||||
expectNormalized({ instant: true, range: false, queryType: LokiQueryType.Instant }, LokiQueryType.Instant);
|
||||
});
|
||||
|
||||
it('handles invalid new, range', () => {
|
||||
expectNormalized({ queryType: 'invalid' }, LokiQueryType.Range);
|
||||
});
|
||||
|
||||
it('handles invalid new, when old-range exists, use old', () => {
|
||||
expectNormalized({ instant: false, range: true, queryType: 'invalid' }, LokiQueryType.Range);
|
||||
});
|
||||
|
||||
it('handles invalid new, when old-instant exists, use old', () => {
|
||||
expectNormalized({ instant: true, range: false, queryType: 'invalid' }, LokiQueryType.Instant);
|
||||
});
|
||||
});
|
||||
|
@ -80,8 +80,13 @@ export function addParsedLabelToQuery(expr: string, key: string, value: string |
|
||||
// - does not have `.instant`
|
||||
// - does not have `.range`
|
||||
export function getNormalizedLokiQuery(query: LokiQuery): LokiQuery {
|
||||
// if queryType field contains invalid data we behave as if the queryType is empty
|
||||
const { queryType } = query;
|
||||
const hasValidQueryType =
|
||||
queryType === LokiQueryType.Range || queryType === LokiQueryType.Instant || queryType === LokiQueryType.Stream;
|
||||
|
||||
// if queryType exists, it is respected
|
||||
if (query.queryType !== undefined) {
|
||||
if (hasValidQueryType) {
|
||||
const { instant, range, ...rest } = query;
|
||||
return rest;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user