mirror of https://github.com/grafana/grafana
Prometheus: Library fixes for using in external vendor DS (#82115)
* fix stateSlice type errors for build, do not export stateSlice in the future * fix exports for consistency * fix package.json for rollup, update licence, keep private * rollup as devdependencies * try a different version of @testing-library/dom to try to fix the aria-query issue in drone * remove testUtils export * change @testing-library/dom version back * remove icon bundling, grafana-ui handles this * remove unused dependencies * components folder: avoid nested barrel files and use named exports * configuration folder: avoid nested barrel files and use named exports * querybuilder folder: avoid nested barrel files and use named exports * general files: use named exports * fix loader issue with promql for external ds * default to support labels match api * export things necessary for custom config auth * remove changes to core datasource.test.ts * Update packages/grafana-prometheus/package.json Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com> * remove icons script, not needed * update readme, remove references to grafana/ui * remove private property * check tests * remove private property in package.json * update changelog * update npm drone script for file checks * debug why updating test in script broke another library that had never been tested before * fix npm test for checking licenses * fix npm test for checking licenses * fix npm test for checking licenses * fix npm test for checking licenses * update license file for npm drone test * fix bash script --------- Co-authored-by: Jack Westbrook <jack.westbrook@gmail.com>pull/82918/head^2
parent
0a9389c8f7
commit
c6f8462a06
@ -1,3 +1,3 @@ |
||||
# (2023-06-11) |
||||
# (2024-02-16) |
||||
|
||||
First public release |
||||
First public release. This release provides Prometheus exports in Grafana. Please be aware this is in the alpha state and there is likely to be breaking changes. |
||||
|
@ -0,0 +1,38 @@ |
||||
import image from '@rollup/plugin-image'; |
||||
import resolve from '@rollup/plugin-node-resolve'; |
||||
import path from 'path'; |
||||
import dts from 'rollup-plugin-dts'; |
||||
import esbuild from 'rollup-plugin-esbuild'; |
||||
import { externals } from 'rollup-plugin-node-externals'; |
||||
|
||||
const pkg = require('./package.json'); |
||||
|
||||
export default [ |
||||
{ |
||||
input: 'src/index.ts', |
||||
plugins: [externals({ deps: true, packagePath: './package.json' }), resolve(), esbuild(), image()], |
||||
output: [ |
||||
{ |
||||
format: 'cjs', |
||||
sourcemap: true, |
||||
dir: path.dirname(pkg.publishConfig.main), |
||||
}, |
||||
{ |
||||
format: 'esm', |
||||
sourcemap: true, |
||||
dir: path.dirname(pkg.publishConfig.module), |
||||
preserveModules: true, |
||||
// @ts-expect-error (TS cannot assure that `process.env.PROJECT_CWD` is a string)
|
||||
preserveModulesRoot: path.join(process.env.PROJECT_CWD, `packages/grafana-prometheus/src`), |
||||
}, |
||||
], |
||||
}, |
||||
{ |
||||
input: './compiled/index.d.ts', |
||||
plugins: [dts()], |
||||
output: { |
||||
file: pkg.publishConfig.types, |
||||
format: 'es', |
||||
}, |
||||
}, |
||||
]; |
@ -1,10 +0,0 @@ |
||||
export * from './AnnotationQueryEditor'; |
||||
export * from './PromCheatSheet'; |
||||
export * from './PrometheusMetricsBrowser'; |
||||
export * from './PromExemplarField'; |
||||
export * from './PromExploreExtraField'; |
||||
export * from './PromQueryEditorByApp'; |
||||
export * from './PromQueryEditorForAlerting'; |
||||
export * from './PromQueryField'; |
||||
export * from './types'; |
||||
export * from './VariableQueryEditor'; |
@ -0,0 +1,247 @@ |
||||
// The MIT License (MIT)
|
||||
//
|
||||
// Copyright (c) Celian Garcia and Augustin Husson @ Amadeus IT Group
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
'use strict'; |
||||
// import { languages } from "monaco-editor";
|
||||
// noinspection JSUnusedGlobalSymbols
|
||||
export const languageConfiguration = { |
||||
// the default separators except `@$`
|
||||
wordPattern: /(-?\d*\.\d\w*)|([^`~!#%^&*()\-=+\[{\]}\\|;:'",.<>\/?\s]+)/g, |
||||
// Not possible to make comments in PromQL syntax
|
||||
comments: { |
||||
lineComment: '#', |
||||
}, |
||||
brackets: [ |
||||
['{', '}'], |
||||
['[', ']'], |
||||
['(', ')'], |
||||
], |
||||
autoClosingPairs: [ |
||||
{ open: '{', close: '}' }, |
||||
{ open: '[', close: ']' }, |
||||
{ open: '(', close: ')' }, |
||||
{ open: '"', close: '"' }, |
||||
{ open: "'", close: "'" }, |
||||
], |
||||
surroundingPairs: [ |
||||
{ open: '{', close: '}' }, |
||||
{ open: '[', close: ']' }, |
||||
{ open: '(', close: ')' }, |
||||
{ open: '"', close: '"' }, |
||||
{ open: "'", close: "'" }, |
||||
{ open: '<', close: '>' }, |
||||
], |
||||
folding: {}, |
||||
}; |
||||
// PromQL Aggregation Operators
|
||||
// (https://prometheus.io/docs/prometheus/latest/querying/operators/#aggregation-operators)
|
||||
const aggregations = [ |
||||
'sum', |
||||
'min', |
||||
'max', |
||||
'avg', |
||||
'group', |
||||
'stddev', |
||||
'stdvar', |
||||
'count', |
||||
'count_values', |
||||
'bottomk', |
||||
'topk', |
||||
'quantile', |
||||
]; |
||||
// PromQL functions
|
||||
// (https://prometheus.io/docs/prometheus/latest/querying/functions/)
|
||||
const functions = [ |
||||
'abs', |
||||
'absent', |
||||
'ceil', |
||||
'changes', |
||||
'clamp_max', |
||||
'clamp_min', |
||||
'day_of_month', |
||||
'day_of_week', |
||||
'days_in_month', |
||||
'delta', |
||||
'deriv', |
||||
'exp', |
||||
'floor', |
||||
'histogram_quantile', |
||||
'holt_winters', |
||||
'hour', |
||||
'idelta', |
||||
'increase', |
||||
'irate', |
||||
'label_join', |
||||
'label_replace', |
||||
'ln', |
||||
'log2', |
||||
'log10', |
||||
'minute', |
||||
'month', |
||||
'predict_linear', |
||||
'rate', |
||||
'resets', |
||||
'round', |
||||
'scalar', |
||||
'sort', |
||||
'sort_desc', |
||||
'sqrt', |
||||
'time', |
||||
'timestamp', |
||||
'vector', |
||||
'year', |
||||
]; |
||||
// PromQL specific functions: Aggregations over time
|
||||
// (https://prometheus.io/docs/prometheus/latest/querying/functions/#aggregation_over_time)
|
||||
const aggregationsOverTime = []; |
||||
for (let _i = 0, aggregations_1 = aggregations; _i < aggregations_1.length; _i++) { |
||||
let agg = aggregations_1[_i]; |
||||
aggregationsOverTime.push(agg + '_over_time'); |
||||
} |
||||
// PromQL vector matching + the by and without clauses
|
||||
// (https://prometheus.io/docs/prometheus/latest/querying/operators/#vector-matching)
|
||||
const vectorMatching = ['on', 'ignoring', 'group_right', 'group_left', 'by', 'without']; |
||||
// Produce a regex matching elements : (elt1|elt2|...)
|
||||
const vectorMatchingRegex = |
||||
'(' + |
||||
vectorMatching.reduce(function (prev, curr) { |
||||
return prev + '|' + curr; |
||||
}) + |
||||
')'; |
||||
// PromQL Operators
|
||||
// (https://prometheus.io/docs/prometheus/latest/querying/operators/)
|
||||
const operators = ['+', '-', '*', '/', '%', '^', '==', '!=', '>', '<', '>=', '<=', 'and', 'or', 'unless']; |
||||
// PromQL offset modifier
|
||||
// (https://prometheus.io/docs/prometheus/latest/querying/basics/#offset-modifier)
|
||||
const offsetModifier = ['offset']; |
||||
// Merging all the keywords in one list
|
||||
const keywords = aggregations |
||||
.concat(functions) |
||||
.concat(aggregationsOverTime) |
||||
.concat(vectorMatching) |
||||
.concat(offsetModifier); |
||||
// noinspection JSUnusedGlobalSymbols
|
||||
export const language = { |
||||
ignoreCase: false, |
||||
defaultToken: '', |
||||
tokenPostfix: '.promql', |
||||
keywords: keywords, |
||||
operators: operators, |
||||
vectorMatching: vectorMatchingRegex, |
||||
// we include these common regular expressions
|
||||
symbols: /[=><!~?:&|+\-*\/^%]+/, |
||||
escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/, |
||||
digits: /\d+(_+\d+)*/, |
||||
octaldigits: /[0-7]+(_+[0-7]+)*/, |
||||
binarydigits: /[0-1]+(_+[0-1]+)*/, |
||||
hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/, |
||||
integersuffix: /(ll|LL|u|U|l|L)?(ll|LL|u|U|l|L)?/, |
||||
floatsuffix: /[fFlL]?/, |
||||
// The main tokenizer for our languages
|
||||
tokenizer: { |
||||
root: [ |
||||
// 'by', 'without' and vector matching
|
||||
[/@vectorMatching\s*(?=\()/, 'type', '@clauses'], |
||||
// labels
|
||||
[/[a-z_]\w*(?=\s*(=|!=|=~|!~))/, 'tag'], |
||||
// comments
|
||||
[/(^#.*$)/, 'comment'], |
||||
// all keywords have the same color
|
||||
[ |
||||
/[a-zA-Z_]\w*/, |
||||
{ |
||||
cases: { |
||||
'@keywords': 'type', |
||||
'@default': 'identifier', |
||||
}, |
||||
}, |
||||
], |
||||
// strings
|
||||
[/"([^"\\]|\\.)*$/, 'string.invalid'], |
||||
[/'([^'\\]|\\.)*$/, 'string.invalid'], |
||||
[/"/, 'string', '@string_double'], |
||||
[/'/, 'string', '@string_single'], |
||||
[/`/, 'string', '@string_backtick'], |
||||
// whitespace
|
||||
{ include: '@whitespace' }, |
||||
// delimiters and operators
|
||||
[/[{}()\[\]]/, '@brackets'], |
||||
[/[<>](?!@symbols)/, '@brackets'], |
||||
[ |
||||
/@symbols/, |
||||
{ |
||||
cases: { |
||||
'@operators': 'delimiter', |
||||
'@default': '', |
||||
}, |
||||
}, |
||||
], |
||||
// numbers
|
||||
[/\d+[smhdwy]/, 'number'], |
||||
[/\d*\d+[eE]([\-+]?\d+)?(@floatsuffix)/, 'number.float'], |
||||
[/\d*\.\d+([eE][\-+]?\d+)?(@floatsuffix)/, 'number.float'], |
||||
[/0[xX][0-9a-fA-F']*[0-9a-fA-F](@integersuffix)/, 'number.hex'], |
||||
[/0[0-7']*[0-7](@integersuffix)/, 'number.octal'], |
||||
[/0[bB][0-1']*[0-1](@integersuffix)/, 'number.binary'], |
||||
[/\d[\d']*\d(@integersuffix)/, 'number'], |
||||
[/\d(@integersuffix)/, 'number'], |
||||
], |
||||
string_double: [ |
||||
[/[^\\"]+/, 'string'], |
||||
[/@escapes/, 'string.escape'], |
||||
[/\\./, 'string.escape.invalid'], |
||||
[/"/, 'string', '@pop'], |
||||
], |
||||
string_single: [ |
||||
[/[^\\']+/, 'string'], |
||||
[/@escapes/, 'string.escape'], |
||||
[/\\./, 'string.escape.invalid'], |
||||
[/'/, 'string', '@pop'], |
||||
], |
||||
string_backtick: [ |
||||
[/[^\\`$]+/, 'string'], |
||||
[/@escapes/, 'string.escape'], |
||||
[/\\./, 'string.escape.invalid'], |
||||
[/`/, 'string', '@pop'], |
||||
], |
||||
clauses: [ |
||||
[/[^(,)]/, 'tag'], |
||||
[/\)/, 'identifier', '@pop'], |
||||
], |
||||
whitespace: [[/[ \t\r\n]+/, 'white']], |
||||
}, |
||||
}; |
||||
// noinspection JSUnusedGlobalSymbols
|
||||
// export const completionItemProvider = {
|
||||
// provideCompletionItems: function () {
|
||||
// // To simplify, we made the choice to never create automatically the parenthesis behind keywords
|
||||
// // It is because in PromQL, some keywords need parenthesis behind, some don't, some can have but it's optional.
|
||||
// const suggestions = keywords.map(function (value) {
|
||||
// return {
|
||||
// label: value,
|
||||
// kind: languages.CompletionItemKind.Keyword,
|
||||
// insertText: value,
|
||||
// insertTextRules: languages.CompletionItemInsertTextRule.InsertAsSnippet
|
||||
// };
|
||||
// });
|
||||
// return { suggestions: suggestions };
|
||||
// }
|
||||
// };
|
@ -1,7 +0,0 @@ |
||||
export * from './AlertingSettingsOverhaul'; |
||||
export * from './ConfigEditor'; |
||||
export * from './DataSourceHttpSettingsOverhaul'; |
||||
export * from './ExemplarSetting'; |
||||
export * from './ExemplarsSettings'; |
||||
export * from './PromFlavorVersions'; |
||||
export * from './PromSettings'; |
@ -1,16 +1,87 @@ |
||||
export * from './components'; |
||||
export * from './configuration'; |
||||
export * from './querybuilder'; |
||||
// The Grafana Prometheus library exports a number of components.
|
||||
// There are main components that can be imported directly into your plugin module.ts file.
|
||||
// There are also more granular components that can be used to build components, for example, the config section can be built with granular parts to allow for custom auths.
|
||||
|
||||
export * from './add_label_to_query'; |
||||
export * from './dataquery.gen'; |
||||
export * from './datasource'; |
||||
export * from './language_provider'; |
||||
export * from './language_utils'; |
||||
export * from './metric_find_query'; |
||||
export * from './promql'; |
||||
export * from './query_hints'; |
||||
export * from './result_transformer'; |
||||
export * from './tracking'; |
||||
export * from './types'; |
||||
export * from './variables'; |
||||
// COMPONENTS/
|
||||
// Main export
|
||||
export { PromQueryEditorByApp } from './components/PromQueryEditorByApp'; |
||||
// The parts
|
||||
export { MonacoQueryFieldLazy } from './components/monaco-query-field/MonacoQueryFieldLazy'; |
||||
export { AnnotationQueryEditor } from './components/AnnotationQueryEditor'; |
||||
export { PromCheatSheet } from './components/PromCheatSheet'; |
||||
export { PrometheusMetricsBrowser } from './components/PrometheusMetricsBrowser'; |
||||
export { PromExemplarField } from './components/PromExemplarField'; |
||||
export { PromExploreExtraField } from './components/PromExploreExtraField'; |
||||
export { PromQueryEditorForAlerting } from './components/PromQueryEditorForAlerting'; |
||||
export { PromQueryField } from './components/PromQueryField'; |
||||
export { PromVariableQueryEditor } from './components/VariableQueryEditor'; |
||||
|
||||
// CONFIGURATION/
|
||||
// Main export
|
||||
export { |
||||
ConfigEditor, |
||||
docsTip, |
||||
overhaulStyles, |
||||
validateInput, |
||||
PROM_CONFIG_LABEL_WIDTH, |
||||
} from './configuration/ConfigEditor'; |
||||
// The parts
|
||||
export { AlertingSettingsOverhaul } from './configuration/AlertingSettingsOverhaul'; |
||||
export { DataSourceHttpSettingsOverhaul } from './configuration/DataSourceHttpSettingsOverhaul'; |
||||
export { ExemplarSetting } from './configuration/ExemplarSetting'; |
||||
export { ExemplarsSettings } from './configuration/ExemplarsSettings'; |
||||
export { PromFlavorVersions } from './configuration/PromFlavorVersions'; |
||||
export { PromSettings } from './configuration/PromSettings'; |
||||
|
||||
// QUERYBUILDER/
|
||||
// The parts (The query builder is imported into PromQueryEditorByApp)
|
||||
export { QueryPattern } from './querybuilder/QueryPattern'; |
||||
export { QueryPatternsModal } from './querybuilder/QueryPatternsModal'; |
||||
|
||||
// QUERYBUILDER/COMPONENTS/
|
||||
export { LabelFilterItem } from './querybuilder/components/LabelFilterItem'; |
||||
export { LabelFilters } from './querybuilder/components/LabelFilters'; |
||||
export { LabelParamEditor } from './querybuilder/components/LabelParamEditor'; |
||||
export { MetricSelect } from './querybuilder/components/MetricSelect'; |
||||
export { MetricsLabelsSection } from './querybuilder/components/MetricsLabelsSection'; |
||||
export { NestedQuery } from './querybuilder/components/NestedQuery'; |
||||
export { NestedQueryList } from './querybuilder/components/NestedQueryList'; |
||||
export { PromQueryBuilder } from './querybuilder/components/PromQueryBuilder'; |
||||
export { PromQueryBuilderContainer } from './querybuilder/components/PromQueryBuilderContainer'; |
||||
export { PromQueryBuilderExplained } from './querybuilder/components/PromQueryBuilderExplained'; |
||||
export { PromQueryBuilderOptions } from './querybuilder/components/PromQueryBuilderOptions'; |
||||
export { PromQueryCodeEditor } from './querybuilder/components/PromQueryCodeEditor'; |
||||
export { PromQueryEditorSelector } from './querybuilder/components/PromQueryEditorSelector'; |
||||
export { PromQueryLegendEditor } from './querybuilder/components/PromQueryLegendEditor'; |
||||
export { QueryPreview } from './querybuilder/components/QueryPreview'; |
||||
export { MetricsModal } from './querybuilder/components/metrics-modal/MetricsModal'; |
||||
export { PromQail } from './querybuilder/components/promQail/PromQail'; |
||||
|
||||
// SRC/
|
||||
// Main export
|
||||
export { PrometheusDatasource } from './datasource'; |
||||
// The parts
|
||||
export { addLabelToQuery } from './add_label_to_query'; |
||||
export { type QueryEditorMode, type PromQueryFormat, type Prometheus } from './dataquery.gen'; |
||||
export { PrometheusMetricFindQuery } from './metric_find_query'; |
||||
export { promqlGrammar } from './promql'; |
||||
export { getQueryHints, getInitHints } from './query_hints'; |
||||
export { transformV2, transformDFToTable } from './result_transformer'; |
||||
export { |
||||
type PromQuery, |
||||
type PrometheusCacheLevel, |
||||
type PromApplication, |
||||
type PromOptions, |
||||
type ExemplarTraceIdDestination, |
||||
type PromQueryRequest, |
||||
type PromMetricsMetadataItem, |
||||
type PromMetricsMetadata, |
||||
type PromValue, |
||||
type PromMetric, |
||||
type PromBuildInfoResponse, |
||||
type LegendFormatMode, |
||||
type PromVariableQueryType, |
||||
type PromVariableQuery, |
||||
type StandardPromVariableQuery, |
||||
} from './types'; |
||||
export { PrometheusVariableSupport } from './variables'; |
||||
|
@ -1,17 +0,0 @@ |
||||
export * from './LabelFilterItem'; |
||||
export * from './LabelFilters'; |
||||
export * from './LabelParamEditor'; |
||||
export * from './MetricSelect'; |
||||
export * from './MetricsLabelsSection'; |
||||
export * from './NestedQuery'; |
||||
export * from './NestedQueryList'; |
||||
export * from './PromQueryBuilder'; |
||||
export * from './PromQueryBuilderContainer'; |
||||
export * from './PromQueryBuilderExplained'; |
||||
export * from './PromQueryBuilderOptions'; |
||||
export * from './PromQueryCodeEditor'; |
||||
export * from './PromQueryEditorSelector'; |
||||
export * from './PromQueryLegendEditor'; |
||||
export * from './QueryPreview'; |
||||
export * from './metrics-modal'; |
||||
export * from './promQail'; |
@ -1,13 +0,0 @@ |
||||
export * from './aggregations'; |
||||
export * from './binaryScalarOperations'; |
||||
export * from './operations'; |
||||
export * from './operationUtils'; |
||||
export * from './parsing'; |
||||
export * from './parsingUtils'; |
||||
export * from './PromQueryModeller'; |
||||
export * from './QueryPattern'; |
||||
export * from './QueryPatternsModal'; |
||||
export * from './state'; |
||||
export * from './testUtils'; |
||||
export * from './types'; |
||||
export * from './components'; |
Loading…
Reference in new issue