mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Grafana/Loki: Adds support for new Loki endpoints and metrics (#20158)
* Grafana/Loki: Adds support for new Loki endpoints and metrics * Adds `/loki/` prefix to new loki endpoints and updates response interfaces * Improved legacy support * Removed changes related to plugin.json and added Loki-specific hacks * Fixes live streaming for legacy loki datasources
This commit is contained in:
@@ -1,14 +1,90 @@
|
||||
import { Grammar } from 'prismjs';
|
||||
import { CompletionItem } from '@grafana/ui';
|
||||
|
||||
/* tslint:disable max-line-length */
|
||||
const AGGREGATION_OPERATORS: CompletionItem[] = [
|
||||
{
|
||||
label: 'sum',
|
||||
insertText: 'sum',
|
||||
documentation: 'Calculate sum over dimensions',
|
||||
},
|
||||
{
|
||||
label: 'min',
|
||||
insertText: 'min',
|
||||
documentation: 'Select minimum over dimensions',
|
||||
},
|
||||
{
|
||||
label: 'max',
|
||||
insertText: 'max',
|
||||
documentation: 'Select maximum over dimensions',
|
||||
},
|
||||
{
|
||||
label: 'avg',
|
||||
insertText: 'avg',
|
||||
documentation: 'Calculate the average 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: 'count',
|
||||
insertText: 'count',
|
||||
documentation: 'Count number of elements in the vector',
|
||||
},
|
||||
{
|
||||
label: 'bottomk',
|
||||
insertText: 'bottomk',
|
||||
documentation: 'Smallest k elements by sample value',
|
||||
},
|
||||
{
|
||||
label: 'topk',
|
||||
insertText: 'topk',
|
||||
documentation: 'Largest k elements by sample value',
|
||||
},
|
||||
];
|
||||
|
||||
export const RANGE_VEC_FUNCTIONS = [
|
||||
{
|
||||
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: 'rate',
|
||||
label: 'rate',
|
||||
detail: 'rate(v range-vector)',
|
||||
documentation:
|
||||
"Calculates the per-second average rate of increase of the time series in the range vector. Breaks in monotonicity (such as counter resets due to target restarts) are automatically adjusted for. Also, the calculation extrapolates to the ends of the time range, allowing for missed scrapes or imperfect alignment of scrape cycles with the range's time period.",
|
||||
},
|
||||
];
|
||||
|
||||
export const FUNCTIONS = [...AGGREGATION_OPERATORS, ...RANGE_VEC_FUNCTIONS];
|
||||
|
||||
const tokenizer: Grammar = {
|
||||
comment: {
|
||||
pattern: /(^|[^\n])#.*/,
|
||||
lookbehind: true,
|
||||
},
|
||||
'context-aggregation': {
|
||||
pattern: /((without|by)\s*)\([^)]*\)/, // by ()
|
||||
lookbehind: true,
|
||||
inside: {
|
||||
'label-key': {
|
||||
pattern: /[^(),\s][^,)]*[^),\s]*/,
|
||||
alias: 'attr-name',
|
||||
},
|
||||
punctuation: /[()]/,
|
||||
},
|
||||
},
|
||||
'context-labels': {
|
||||
pattern: /(^|\s)\{[^}]*(?=})/,
|
||||
pattern: /\{[^}]*(?=})/,
|
||||
lookbehind: true,
|
||||
inside: {
|
||||
'label-key': {
|
||||
@@ -23,9 +99,31 @@ const tokenizer: Grammar = {
|
||||
punctuation: /[{]/,
|
||||
},
|
||||
},
|
||||
// number: /\b-?\d+((\.\d*)?([eE][+-]?\d+)?)?\b/,
|
||||
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',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
number: /\b-?\d+((\.\d*)?([eE][+-]?\d+)?)?\b/,
|
||||
operator: new RegExp(`/&&?|\\|?\\||!=?|<(?:=>?|<|>)?|>[>=]?`, 'i'),
|
||||
punctuation: /[{}`,.]/,
|
||||
punctuation: /[{}()`,.]/,
|
||||
};
|
||||
|
||||
export default tokenizer;
|
||||
|
||||
Reference in New Issue
Block a user