-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
158 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const REG_METACHARACTERS = /[*+?()|\\.\[\]{}^$]/g; | ||
|
||
export function unescapeLabelValue(labelValue: string): string { | ||
return labelValue.replace(/\\n/g, '\n').replace(/\\"/g, '"').replace(/\\\\/g, '\\'); | ||
} | ||
|
||
export function isRegexSelector(selector?: string) { | ||
return !!(selector && (selector.includes('=~') || selector.includes('!~'))); | ||
} | ||
|
||
function escapeMetaRegexp(value: string): string { | ||
return value.replace(REG_METACHARACTERS, '\\$&'); | ||
} | ||
|
||
export function escapeLabelValueInExactSelector(labelValue: string): string { | ||
return labelValue.replace(/\\/g, '\\\\').replace(/\n/g, '\\n').replace(/"/g, '\\"'); | ||
} | ||
|
||
export function escapeLabelValueInRegexSelector(labelValue: string): string { | ||
return escapeLabelValueInExactSelector(escapeMetaRegexp(labelValue)); | ||
} | ||
|
||
export function escapeLabelValueInSelector(labelValue: string, selector?: string): string { | ||
return isRegexSelector(selector) | ||
? escapeLabelValueInRegexSelector(labelValue) | ||
: escapeLabelValueInExactSelector(labelValue); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
export function queryHasFilter(query: string, key: string, value: string): boolean { | ||
return query.includes(`${key}:${value}`) | ||
} | ||
|
||
export const removeLabelFromQuery = (query: string, key: string, value: string): string => { | ||
const parts = query.split(' ') | ||
const index = parts.findIndex((part) => part.includes(`${key}:${value}`)) | ||
const newParts = removeAtIndexAndBefore(parts, index) | ||
return newParts.join(' ') | ||
} | ||
|
||
export const addLabelToQuery = (query: string, key: string, value: string, operator: string): string => { | ||
return `${query} ${operator} ${key}:${value}` | ||
} | ||
|
||
const removeAtIndexAndBefore = (arr: string[], index: number): string[] => { | ||
if (index < 0 || index >= arr.length) { | ||
return arr; | ||
} | ||
|
||
if (index === 0) { | ||
arr.splice(index, 1); | ||
} else { | ||
arr.splice(index - 1, 2); | ||
} | ||
|
||
return arr; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function handleQuotes(string: string) { | ||
if (string[0] === `"` && string[string.length - 1] === `"`) { | ||
return string | ||
.substring(1, string.length - 1) | ||
.replace(/\\"/g, '"') | ||
.replace(/\\\\/g, '\\'); | ||
} | ||
return string.replace(/`/g, ''); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
import { DataFrame, Labels } from "@grafana/data"; | ||
|
||
export function dataFrameHasLokiError(frame: DataFrame): boolean { | ||
export function dataFrameHasError(frame: DataFrame): boolean { | ||
const labelSets: Labels[] = frame.fields.find((f) => f.name === 'labels')?.values ?? []; | ||
return labelSets.some((labels) => labels.__error__ !== undefined); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters