-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
11 changed files
with
241 additions
and
2 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,99 @@ | ||
// Thanks to: https://github.com/prometheus-community/monaco-promql/blob/master/src/promql/promql.ts | ||
// As well as: https://kausal.co/blog/slate-prism-add-new-syntax-promql/ | ||
|
||
(function (Prism) { | ||
// PromQL Aggregation Operators | ||
// (https://prometheus.io/docs/prometheus/latest/querying/operators/#aggregation-operators) | ||
var aggregations = [ | ||
'sum', | ||
'min', | ||
'max', | ||
'avg', | ||
'group', | ||
'stddev', | ||
'stdvar', | ||
'count', | ||
'count_values', | ||
'bottomk', | ||
'topk', | ||
'quantile' | ||
]; | ||
|
||
// PromQL vector matching + the by and without clauses | ||
// (https://prometheus.io/docs/prometheus/latest/querying/operators/#vector-matching) | ||
var vectorMatching = [ | ||
'on', | ||
'ignoring', | ||
'group_right', | ||
'group_left', | ||
'by', | ||
'without', | ||
]; | ||
|
||
// PromQL offset modifier | ||
// (https://prometheus.io/docs/prometheus/latest/querying/basics/#offset-modifier) | ||
var offsetModifier = ['offset']; | ||
|
||
var keywords = aggregations.concat(vectorMatching, offsetModifier); | ||
|
||
Prism.languages.promql = { | ||
'comment': { | ||
pattern: /(^[ \t]*)#.*/m, | ||
lookbehind: true | ||
}, | ||
'vector-match': { | ||
// Match the comma-separated label lists inside vector matching: | ||
pattern: new RegExp('((?:' + vectorMatching.join('|') + ')\\s*)\\([^)]*\\)'), | ||
lookbehind: true, | ||
inside: { | ||
'label-key': { | ||
pattern: /\b[^,]*\b/, | ||
alias: 'attr-name', | ||
}, | ||
'punctuation': /[(),]/ | ||
}, | ||
}, | ||
'context-labels': { | ||
pattern: /\{[^{}]*\}/, | ||
inside: { | ||
'label-key': { | ||
pattern: /\b[a-z_]\w*(?=\s*(?:=~?|![=~]))/, | ||
alias: 'attr-name', | ||
}, | ||
'label-value': { | ||
pattern: /(["'`])(?:\\[\s\S]|(?!\1)[^\\])*\1/, | ||
greedy: true, | ||
alias: 'attr-value', | ||
}, | ||
'punctuation': /\{|\}|=~?|![=~]|,/, | ||
}, | ||
}, | ||
'context-range': [ | ||
{ | ||
pattern: /\[[\w\s:]+\]/, // [1m] | ||
inside: { | ||
'punctuation': /\[|\]|:/, | ||
'range-duration': { | ||
pattern: /\b(?:\d+(?:[smhdwy]|ms))+\b/i, | ||
alias: 'number', | ||
}, | ||
}, | ||
}, | ||
{ | ||
pattern: /(\boffset\s+)\w+/, // offset 1m | ||
lookbehind: true, | ||
inside: { | ||
'range-duration': { | ||
pattern: /\b(?:\d+(?:[smhdwy]|ms))+\b/i, | ||
alias: 'number', | ||
}, | ||
}, | ||
}, | ||
], | ||
'keyword': new RegExp('\\b(?:' + keywords.join('|') + ')\\b', 'i'), | ||
'function': /\b[a-zA-Z_]\w*(?=\s*\()/i, | ||
'number': /[-+]?(?:(?:\b\d+(?:\.\d+)?|\B\.\d+)(?:e[-+]?\d+)?\b|\b(?:0x[0-9a-f]+|nan|inf)\b)/i, | ||
'operator': /[\^*/%+-]|==|!=|<=|<|>=|>|\b(?:and|unless|or)\b/i, | ||
'punctuation': /[{};()`,.[\]]/, | ||
}; | ||
})(Prism); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,17 @@ | ||
<h2>Examples</h2> | ||
<pre><code># These examples are taken from: https://prometheus.io/docs/prometheus/latest/querying/examples/ | ||
|
||
http_requests_total{job="apiserver", handler="/api/comments"}[5m] | ||
|
||
http_requests_total{job=~".*server"} | ||
|
||
max_over_time(deriv(rate(distance_covered_total[5s])[30s:5s])[10m:]) | ||
|
||
sum by (job) ( | ||
rate(http_requests_total[5m]) | ||
) | ||
|
||
sum by (app, proc) ( | ||
instance_memory_limit_bytes - instance_memory_usage_bytes | ||
) / 1024 / 1024 | ||
</code></pre> |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,30 @@ | ||
sum by (job) ( | ||
rate(http_requests_total[5m]) | ||
) | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["keyword", "sum"], | ||
["keyword", "by"], | ||
["vector-match", [ | ||
["punctuation", "("], | ||
["label-key", "job"], | ||
["punctuation", ")"] | ||
]], | ||
["punctuation", "("], | ||
["function", "rate"], | ||
["punctuation", "("], | ||
"http_requests_total", | ||
["context-range", [ | ||
["punctuation", "["], | ||
["range-duration", "5m"], | ||
["punctuation", "]"] | ||
]], | ||
["punctuation", ")"], | ||
["punctuation", ")"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks aggregate query. |
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,11 @@ | ||
# These examples are taken from ... | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["comment", "# These examples are taken from ..."] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks for comments. |
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,38 @@ | ||
max_over_time(deriv(rate(distance_covered_total[5s])[30s:5s])[10m:]) | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
["function", "max_over_time"], | ||
["punctuation", "("], | ||
["function", "deriv"], | ||
["punctuation", "("], | ||
["function", "rate"], | ||
["punctuation", "("], | ||
"distance_covered_total", | ||
["context-range", [ | ||
["punctuation", "["], | ||
["range-duration", "5s"], | ||
["punctuation", "]"] | ||
]], | ||
["punctuation", ")"], | ||
["context-range", [ | ||
["punctuation", "["], | ||
["range-duration", "30s"], | ||
["punctuation", ":"], | ||
["range-duration", "5s"], | ||
["punctuation", "]"] | ||
]], | ||
["punctuation", ")"], | ||
["context-range", [ | ||
["punctuation", "["], | ||
["range-duration", "10m"], | ||
["punctuation", ":"], | ||
["punctuation", "]"] | ||
]], | ||
["punctuation", ")"] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks subquery. |
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,38 @@ | ||
http_requests_total{job="apiserver", handler="/api/comments"}[5m] | ||
|
||
http_requests_total{job=~".*server"} | ||
|
||
---------------------------------------------------- | ||
|
||
[ | ||
"http_requests_total", | ||
["context-labels", [ | ||
["punctuation", "{"], | ||
["label-key", "job"], | ||
["punctuation", "="], | ||
["label-value", "\"apiserver\""], | ||
["punctuation", ","], | ||
["label-key", "handler"], | ||
["punctuation", "="], | ||
["label-value", "\"/api/comments\""], | ||
["punctuation", "}"] | ||
]], | ||
["context-range", [ | ||
["punctuation", "["], | ||
["range-duration", "5m"], | ||
["punctuation", "]"] | ||
]], | ||
|
||
"\r\n\r\nhttp_requests_total", | ||
["context-labels", [ | ||
["punctuation", "{"], | ||
["label-key", "job"], | ||
["punctuation", "=~"], | ||
["label-value", "\".*server\""], | ||
["punctuation", "}"] | ||
]] | ||
] | ||
|
||
---------------------------------------------------- | ||
|
||
Checks simple time series queries. |