Submit
Path:
~
/
/
usr
/
share
/
grafana
/
public
/
app
/
plugins
/
datasource
/
loki
/
File Content:
responseUtils.ts
import { DataFrame, FieldType, isValidGoDuration, Labels } from '@grafana/data'; import { isBytesString, processLabels } from './languageUtils'; import { isLogLineJSON, isLogLineLogfmt, isLogLinePacked } from './lineParser'; import { LabelType } from './types'; export function dataFrameHasLokiError(frame: DataFrame): boolean { const labelSets: Labels[] = frame.fields.find((f) => f.name === 'labels')?.values ?? []; return labelSets.some((labels) => labels.__error__ !== undefined); } export function dataFrameHasLevelLabel(frame: DataFrame): boolean { const labelSets: Labels[] = frame.fields.find((f) => f.name === 'labels')?.values ?? []; return labelSets.some((labels) => labels.level !== undefined); } export function extractLogParserFromDataFrame(frame: DataFrame): { hasLogfmt: boolean; hasJSON: boolean; hasPack: boolean; } { const lineField = frame.fields.find((field) => field.type === FieldType.string); if (lineField == null) { return { hasJSON: false, hasLogfmt: false, hasPack: false }; } const logLines: string[] = lineField.values; let hasJSON = false; let hasLogfmt = false; let hasPack = false; logLines.forEach((line) => { if (isLogLineJSON(line)) { hasJSON = true; hasPack = isLogLinePacked(line); } if (isLogLineLogfmt(line)) { hasLogfmt = true; } }); return { hasLogfmt, hasJSON, hasPack }; } export function extractLabelKeysFromDataFrame(frame: DataFrame, type: LabelType = LabelType.Indexed): string[] { const labelsArray: Array<{ [key: string]: string }> | undefined = frame?.fields?.find((field) => field.name === 'labels')?.values ?? []; const labelTypeArray: Array<{ [key: string]: string }> | undefined = frame?.fields?.find((field) => field.name === 'labelTypes')?.values ?? []; if (!labelsArray?.length) { return []; } // if there are no label types and type is LabelType.Indexed return all label keys if (!labelTypeArray?.length) { if (type === LabelType.Indexed) { const { keys: labelKeys } = processLabels(labelsArray); return labelKeys; } return []; } // If we have label types, we can return only label keys that match type let labelsSet = new Set<string>(); for (let i = 0; i < labelsArray.length; i++) { const labels = labelsArray[i]; const labelsType = labelTypeArray[i]; const allLabelKeys = Object.keys(labels).filter((key) => labelsType[key] === type); labelsSet = new Set([...labelsSet, ...allLabelKeys]); } return Array.from(labelsSet); } export function extractUnwrapLabelKeysFromDataFrame(frame: DataFrame): string[] { const labelsArray: Array<{ [key: string]: string }> | undefined = frame?.fields?.find((field) => field.name === 'labels')?.values ?? []; if (!labelsArray?.length) { return []; } // We do this only for first label object, because we want to consider only labels that are present in all log lines // possibleUnwrapLabels are labels with 1. number value OR 2. value that is valid go duration OR 3. bytes string value const possibleUnwrapLabels = Object.keys(labelsArray[0]).filter((key) => { const value = labelsArray[0][key]; if (!value) { return false; } return !isNaN(Number(value)) || isValidGoDuration(value) || isBytesString(value); }); // Add only labels that are present in every line to unwrapLabels return possibleUnwrapLabels.filter((label) => labelsArray.every((obj) => obj[label])); } export function extractHasErrorLabelFromDataFrame(frame: DataFrame): boolean { const labelField = frame.fields.find((field) => field.name === 'labels' && field.type === FieldType.other); if (labelField == null) { return false; } const labels: Array<{ [key: string]: string }> = labelField.values; return labels.some((label) => label['__error__']); } export function extractLevelLikeLabelFromDataFrame(frame: DataFrame): string | null { const labelField = frame.fields.find((field) => field.name === 'labels' && field.type === FieldType.other); if (labelField == null) { return null; } // Depending on number of labels, this can be pretty heavy operation. // Let's just look at first 2 lines If needed, we can introduce more later. const labelsArray: Array<{ [key: string]: string }> = labelField.values.slice(0, 2); let levelLikeLabel: string | null = null; // Find first level-like label for (let labels of labelsArray) { const label = Object.keys(labels).find((label) => label === 'lvl' || label.includes('level')); if (label) { levelLikeLabel = label; break; } } return levelLikeLabel; }
Edit
Rename
Chmod
Delete
FILE
FOLDER
INFO
Name
Size
Permission
Action
__mocks__
---
0755
components
---
0755
configuration
---
0755
docs
---
0755
img
---
0755
migrations
---
0755
querybuilder
---
0755
LanguageProvider.test.ts
23374 bytes
0644
LanguageProvider.ts
13424 bytes
0644
LiveStreams.test.ts
7021 bytes
0644
LiveStreams.ts
2641 bytes
0644
LogContextProvider.test.ts
21477 bytes
0644
LogContextProvider.ts
14192 bytes
0644
LokiVariableSupport.test.ts
3307 bytes
0644
LokiVariableSupport.ts
984 bytes
0644
README.md
127 bytes
0644
backendResultTransformer.test.ts
5537 bytes
0644
backendResultTransformer.ts
5248 bytes
0644
dataquery.cue
1633 bytes
0644
dataquery.gen.ts
1269 bytes
0644
datasource.test.ts
67600 bytes
0644
datasource.ts
42882 bytes
0644
getDerivedFields.test.ts
6291 bytes
0644
getDerivedFields.ts
4351 bytes
0644
languageUtils.test.ts
4461 bytes
0644
languageUtils.ts
5123 bytes
0644
language_utils.test.ts
1463 bytes
0644
lineParser.test.ts
1846 bytes
0644
lineParser.ts
912 bytes
0644
liveStreamsResultTransformer.test.ts
3396 bytes
0644
liveStreamsResultTransformer.ts
2624 bytes
0644
logsTimeSplitting.test.ts
1463 bytes
0644
logsTimeSplitting.ts
1661 bytes
0644
makeTableFrames.test.ts
3834 bytes
0644
makeTableFrames.ts
2415 bytes
0644
metricTimeSplitting.test.ts
2925 bytes
0644
metricTimeSplitting.ts
1586 bytes
0644
modifyQuery.test.ts
27450 bytes
0644
modifyQuery.ts
20058 bytes
0644
module.test.ts
2975 bytes
0644
module.ts
809 bytes
0644
plugin.json
756 bytes
0644
queryHints.test.ts
7526 bytes
0644
queryHints.ts
4453 bytes
0644
querySplitting.test.ts
20808 bytes
0644
querySplitting.ts
9911 bytes
0644
queryUtils.test.ts
20063 bytes
0644
queryUtils.ts
11174 bytes
0644
responseUtils.test.ts
5757 bytes
0644
responseUtils.ts
4637 bytes
0644
sortDataFrame.test.ts
5184 bytes
0644
sortDataFrame.ts
2708 bytes
0644
streaming.test.ts
1264 bytes
0644
streaming.ts
2939 bytes
0644
syntax.test.ts
3545 bytes
0644
syntax.ts
7646 bytes
0644
tracking.test.ts
6407 bytes
0644
tracking.ts
8353 bytes
0644
types.ts
2568 bytes
0644
N4ST4R_ID | Naxtarrr