Submit
Path:
~
/
/
usr
/
share
/
grafana
/
public
/
app
/
plugins
/
datasource
/
loki
/
File Content:
syntax.ts
import { Grammar } from 'prismjs'; import { CompletionItem } from '@grafana/ui'; export const AGGREGATION_OPERATORS: CompletionItem[] = [ { label: 'avg', insertText: 'avg', documentation: 'Calculate the average over dimensions', }, { label: 'bottomk', insertText: 'bottomk', documentation: 'Smallest k elements by sample value', }, { label: 'count', insertText: 'count', documentation: 'Count number of elements in the vector', }, { label: 'max', insertText: 'max', documentation: 'Select maximum over dimensions', }, { label: 'min', insertText: 'min', documentation: 'Select minimum over dimensions', }, { label: 'stddev', insertText: 'stddev', documentation: 'Calculate population standard deviation over dimensions', }, { label: 'stdvar', insertText: 'stdvar', documentation: 'Calculate population standard variance over dimensions', }, { label: 'sum', insertText: 'sum', documentation: 'Calculate sum over dimensions', }, { label: 'topk', insertText: 'topk', documentation: 'Largest k elements by sample value', }, ]; export const PIPE_PARSERS: CompletionItem[] = [ { label: 'json', insertText: 'json', documentation: 'Extracting labels from the log line using json parser.', }, { label: 'regexp', insertText: 'regexp ""', documentation: 'Extracting labels from the log line using regexp parser.', move: -1, }, { label: 'logfmt', insertText: 'logfmt', documentation: 'Extracting labels from the log line using logfmt parser.', }, { label: 'pattern', insertText: 'pattern', documentation: 'Extracting labels from the log line using pattern parser. Only available in Loki 2.3+.', }, { label: 'unpack', insertText: 'unpack', detail: 'unpack identifier', documentation: 'Parses a JSON log line, unpacking all embedded labels in the pack stage. A special property "_entry" will also be used to replace the original log line. Only available in Loki 2.2+.', }, ]; export const PIPE_OPERATORS: CompletionItem[] = [ { label: 'unwrap', insertText: 'unwrap', detail: 'unwrap identifier', documentation: 'Take labels and use the values as sample data for metric aggregations.', }, { label: 'label_format', insertText: 'label_format', documentation: 'Use to rename, modify or add labels. For example, | label_format foo=bar .', }, { label: 'line_format', insertText: 'line_format', documentation: 'Rewrites log line content. For example, | line_format "{{.query}} {{.duration}}" .', }, ]; export const RANGE_VEC_FUNCTIONS = [ { insertText: 'avg_over_time', label: 'avg_over_time', detail: 'avg_over_time(range-vector)', documentation: 'The average of all values in the specified interval.', }, { insertText: 'bytes_over_time', label: 'bytes_over_time', detail: 'bytes_over_time(range-vector)', documentation: 'Counts the amount of bytes used by each log stream for a given range', }, { insertText: 'bytes_rate', label: 'bytes_rate', detail: 'bytes_rate(range-vector)', documentation: 'Calculates the number of bytes per second for each stream.', }, { insertText: 'first_over_time', label: 'first_over_time', detail: 'first_over_time(range-vector)', documentation: 'The first of all values in the specified interval. Only available in Loki 2.3+.', }, { insertText: 'last_over_time', label: 'last_over_time', detail: 'last_over_time(range-vector)', documentation: 'The last of all values in the specified interval. Only available in Loki 2.3+.', }, { insertText: 'sum_over_time', label: 'sum_over_time', detail: 'sum_over_time(range-vector)', documentation: 'The sum of all values in the specified interval.', }, { insertText: 'count_over_time', label: 'count_over_time', detail: 'count_over_time(range-vector)', documentation: 'The count of all values in the specified interval.', }, { insertText: 'max_over_time', label: 'max_over_time', detail: 'max_over_time(range-vector)', documentation: 'The maximum of all values in the specified interval.', }, { insertText: 'min_over_time', label: 'min_over_time', detail: 'min_over_time(range-vector)', documentation: 'The minimum of all values in the specified interval.', }, { insertText: 'quantile_over_time', label: 'quantile_over_time', detail: 'quantile_over_time(scalar, range-vector)', documentation: 'The φ-quantile (0 ≤ φ ≤ 1) of the values in the specified interval.', }, { insertText: 'rate', label: 'rate', detail: 'rate(v range-vector)', documentation: 'Calculates the number of entries per second.', }, { insertText: 'stddev_over_time', label: 'stddev_over_time', detail: 'stddev_over_time(range-vector)', documentation: 'The population standard deviation of the values in the specified interval.', }, { insertText: 'stdvar_over_time', label: 'stdvar_over_time', detail: 'stdvar_over_time(range-vector)', documentation: 'The population standard variance of the values in the specified interval.', }, ]; export const BUILT_IN_FUNCTIONS = [ { insertText: 'vector', label: 'vector', detail: 'vector(scalar)', documentation: 'Returns the scalar as a vector with no labels.', }, ]; export const FUNCTIONS = [...AGGREGATION_OPERATORS, ...RANGE_VEC_FUNCTIONS, ...BUILT_IN_FUNCTIONS]; // Loki grammar is used for query highlight in query previews outside of code editor export const lokiGrammar: Grammar = { comment: { pattern: /#.*/, }, 'context-aggregation': { pattern: /((without|by)\s*)\([^)]*\)/, // by () lookbehind: true, inside: { 'label-key': { pattern: /[^(),\s][^,)]*[^),\s]*/, alias: 'attr-name', }, punctuation: /[()]/, }, }, 'context-labels': { pattern: /\{[^}]*(?=}?)/, greedy: true, inside: { comment: { pattern: /#.*/, }, 'label-key': { pattern: /[a-zA-Z_]\w*(?=\s*(=|!=|=~|!~))/, alias: 'attr-name', greedy: true, }, 'label-value': { pattern: /"(?:\\.|[^\\"])*"/, greedy: true, alias: 'attr-value', }, punctuation: /[{]/, }, }, 'context-pipe': { pattern: /\s\|[^=~]\s?\w*/i, inside: { 'pipe-operator': { pattern: /\|/i, alias: 'operator', }, 'pipe-operations': { pattern: new RegExp(`${[...PIPE_PARSERS, ...PIPE_OPERATORS].map((f) => f.label).join('|')}`, 'i'), alias: 'keyword', }, }, }, function: new RegExp(`\\b(?:${FUNCTIONS.map((f) => f.label).join('|')})(?=\\s*\\()`, 'i'), 'context-range': [ { pattern: /\[[^\]]*(?=\])/, // [1m] inside: { 'range-duration': { pattern: /\b\d+[smhdwy]\b/i, alias: 'number', }, }, }, { pattern: /(offset\s+)\w+/, // offset 1m lookbehind: true, inside: { 'range-duration': { pattern: /\b\d+[smhdwy]\b/i, alias: 'number', }, }, }, ], quote: { pattern: /"(?:\\.|[^\\"])*"/, alias: 'string', greedy: true, }, backticks: { pattern: /`(?:\\.|[^\\`])*`/, alias: 'string', greedy: true, }, number: /\b-?\d+((\.\d*)?([eE][+-]?\d+)?)?\b/, operator: /\s?(\|[=~]?|!=?|<(?:=>?|<|>)?|>[>=]?)\s?/i, punctuation: /[{}(),.]/, }; export default lokiGrammar;
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