@perses-dev/prometheus-plugin 0.0.0-snapshot-embed-import-errors-8906900 → 0.0.0-snapshot-test-internal-dep-dd238ac

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (91) hide show
  1. package/dist/cjs/components/PromQL.js +1 -1
  2. package/dist/cjs/components/index.js +1 -1
  3. package/dist/cjs/index.js +1 -1
  4. package/dist/cjs/model/api-types.js +1 -1
  5. package/dist/cjs/model/index.js +1 -2
  6. package/dist/cjs/model/parse-sample-values.js +1 -1
  7. package/dist/cjs/model/prometheus-client.js +4 -3
  8. package/dist/cjs/model/prometheus-selectors.js +1 -1
  9. package/dist/cjs/model/templating.js +2 -2
  10. package/dist/cjs/model/time.js +1 -1
  11. package/dist/cjs/plugins/MatcherEditor.js +1 -1
  12. package/dist/cjs/plugins/prometheus-datasource.js +10 -6
  13. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +3 -3
  14. package/dist/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +1 -1
  15. package/dist/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +9 -9
  16. package/dist/cjs/plugins/prometheus-time-series-query/index.js +1 -1
  17. package/dist/cjs/plugins/prometheus-time-series-query/query-editor-model.js +1 -1
  18. package/dist/cjs/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
  19. package/dist/cjs/plugins/prometheus-variables.js +10 -9
  20. package/dist/cjs/plugins/types.js +1 -1
  21. package/dist/cjs/plugins/variable.js +1 -1
  22. package/dist/cjs/test/setup-tests.js +1 -1
  23. package/dist/cjs/utils/index.js +28 -0
  24. package/dist/cjs/{model → utils}/utils.js +37 -2
  25. package/dist/components/PromQL.js +1 -1
  26. package/dist/components/PromQL.js.map +1 -1
  27. package/dist/components/index.js +1 -1
  28. package/dist/components/index.js.map +1 -1
  29. package/dist/index.js +1 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/model/api-types.js +1 -1
  32. package/dist/model/api-types.js.map +1 -1
  33. package/dist/model/index.d.ts +0 -1
  34. package/dist/model/index.d.ts.map +1 -1
  35. package/dist/model/index.js +1 -2
  36. package/dist/model/index.js.map +1 -1
  37. package/dist/model/parse-sample-values.js +1 -1
  38. package/dist/model/parse-sample-values.js.map +1 -1
  39. package/dist/model/prometheus-client.d.ts +3 -0
  40. package/dist/model/prometheus-client.d.ts.map +1 -1
  41. package/dist/model/prometheus-client.js +4 -3
  42. package/dist/model/prometheus-client.js.map +1 -1
  43. package/dist/model/prometheus-selectors.js +1 -1
  44. package/dist/model/prometheus-selectors.js.map +1 -1
  45. package/dist/model/templating.js +2 -2
  46. package/dist/model/templating.js.map +1 -1
  47. package/dist/model/time.js +1 -1
  48. package/dist/model/time.js.map +1 -1
  49. package/dist/plugins/MatcherEditor.js +1 -1
  50. package/dist/plugins/MatcherEditor.js.map +1 -1
  51. package/dist/plugins/prometheus-datasource.d.ts +2 -0
  52. package/dist/plugins/prometheus-datasource.d.ts.map +1 -1
  53. package/dist/plugins/prometheus-datasource.js +10 -6
  54. package/dist/plugins/prometheus-datasource.js.map +1 -1
  55. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +2 -2
  56. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
  57. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +1 -1
  58. package/dist/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
  59. package/dist/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
  60. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js +8 -8
  61. package/dist/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
  62. package/dist/plugins/prometheus-time-series-query/index.js +1 -1
  63. package/dist/plugins/prometheus-time-series-query/index.js.map +1 -1
  64. package/dist/plugins/prometheus-time-series-query/query-editor-model.js +1 -1
  65. package/dist/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
  66. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
  67. package/dist/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
  68. package/dist/plugins/prometheus-variables.d.ts.map +1 -1
  69. package/dist/plugins/prometheus-variables.js +3 -2
  70. package/dist/plugins/prometheus-variables.js.map +1 -1
  71. package/dist/plugins/types.js +1 -1
  72. package/dist/plugins/types.js.map +1 -1
  73. package/dist/plugins/variable.js +1 -1
  74. package/dist/plugins/variable.js.map +1 -1
  75. package/dist/test/setup-tests.js +1 -1
  76. package/dist/test/setup-tests.js.map +1 -1
  77. package/dist/utils/index.d.ts +2 -0
  78. package/dist/utils/index.d.ts.map +1 -0
  79. package/dist/utils/index.js +15 -0
  80. package/dist/utils/index.js.map +1 -0
  81. package/dist/{model → utils}/utils.d.ts +5 -0
  82. package/dist/{model → utils}/utils.d.ts.map +1 -1
  83. package/dist/{model → utils}/utils.js +37 -1
  84. package/dist/utils/utils.js.map +1 -0
  85. package/package.json +6 -5
  86. package/dist/cjs/model/utils.test.js +0 -126
  87. package/dist/model/utils.js.map +0 -1
  88. package/dist/model/utils.test.d.ts +0 -2
  89. package/dist/model/utils.test.d.ts.map +0 -1
  90. package/dist/model/utils.test.js +0 -124
  91. package/dist/model/utils.test.js.map +0 -1
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
package/dist/cjs/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -20,7 +20,6 @@ _exportStar(require("./prometheus-client"), exports);
20
20
  _exportStar(require("./prometheus-selectors"), exports);
21
21
  _exportStar(require("./templating"), exports);
22
22
  _exportStar(require("./time"), exports);
23
- _exportStar(require("./utils"), exports);
24
23
  function _exportStar(from, to) {
25
24
  Object.keys(from).forEach(function(k) {
26
25
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -53,12 +53,13 @@ function fetchWithGet(apiURI, params, queryOptions) {
53
53
  });
54
54
  }
55
55
  function fetchWithPost(apiURI, params, queryOptions) {
56
- const { datasourceUrl } = queryOptions;
56
+ const { datasourceUrl , headers } = queryOptions;
57
57
  const url = `${datasourceUrl}${apiURI}`;
58
58
  const init = {
59
59
  method: 'POST',
60
60
  headers: {
61
- 'Content-Type': 'application/x-www-form-urlencoded'
61
+ 'Content-Type': 'application/x-www-form-urlencoded',
62
+ ...headers
62
63
  },
63
64
  body: createSearchParams(params)
64
65
  };
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "useReplaceTemplateString", {
19
19
  get: ()=>useReplaceTemplateString
20
20
  });
21
21
  const _pluginSystem = require("@perses-dev/plugin-system");
22
- const _utils = require("./utils");
22
+ const _utils = require("../utils");
23
23
  function useReplaceTemplateString(templateString) {
24
24
  const templateVariablesInTemplate = (0, _utils.parseTemplateVariables)(templateString || '');
25
25
  const variables = (0, _pluginSystem.useTemplateVariableValues)(templateVariablesInTemplate);
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -22,7 +22,7 @@ const _model = require("../model");
22
22
  /**
23
23
  * Creates a PrometheusClient for a specific datasource spec.
24
24
  */ const createClient = (spec, options)=>{
25
- const { direct_url } = spec;
25
+ const { direct_url , headers } = spec;
26
26
  const { proxyUrl } = options;
27
27
  // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified
28
28
  const datasourceUrl = direct_url !== null && direct_url !== void 0 ? direct_url : proxyUrl;
@@ -35,16 +35,20 @@ const _model = require("../model");
35
35
  datasourceUrl
36
36
  },
37
37
  instantQuery: (params)=>(0, _model.instantQuery)(params, {
38
- datasourceUrl
38
+ datasourceUrl,
39
+ headers
39
40
  }),
40
41
  rangeQuery: (params)=>(0, _model.rangeQuery)(params, {
41
- datasourceUrl
42
+ datasourceUrl,
43
+ headers
42
44
  }),
43
45
  labelNames: (params)=>(0, _model.labelNames)(params, {
44
- datasourceUrl
46
+ datasourceUrl,
47
+ headers
45
48
  }),
46
49
  labelValues: (params)=>(0, _model.labelValues)(params, {
47
- datasourceUrl
50
+ datasourceUrl,
51
+ headers
48
52
  })
49
53
  };
50
54
  };
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "PrometheusTimeSeriesQuery", {
18
18
  enumerable: true,
19
19
  get: ()=>PrometheusTimeSeriesQuery
20
20
  });
21
- const _model = require("../../model");
21
+ const _utils = require("../../utils");
22
22
  const _getTimeSeriesData = require("./get-time-series-data");
23
23
  const _prometheusTimeSeriesQueryEditor = require("./PrometheusTimeSeriesQueryEditor");
24
24
  const PrometheusTimeSeriesQuery = {
@@ -30,7 +30,7 @@ const PrometheusTimeSeriesQuery = {
30
30
  }),
31
31
  dependsOn: (spec)=>{
32
32
  return {
33
- variables: (0, _model.parseTemplateVariables)(spec.query)
33
+ variables: (0, _utils.parseTemplateVariables)(spec.query)
34
34
  };
35
35
  }
36
36
  };
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -20,6 +20,7 @@ Object.defineProperty(exports, "getTimeSeriesData", {
20
20
  });
21
21
  const _dateFns = require("date-fns");
22
22
  const _model = require("../../model");
23
+ const _utils = require("../../utils");
23
24
  const getTimeSeriesData = async (spec, context)=>{
24
25
  var ref;
25
26
  if (spec.query === undefined || spec.query === null || spec.query === '') {
@@ -40,7 +41,7 @@ const getTimeSeriesData = async (spec, context)=>{
40
41
  end = alignedEnd;
41
42
  // Replace template variable placeholders in PromQL query
42
43
  let query = spec.query.replace('$__rate_interval', `15s`);
43
- query = (0, _model.replaceTemplateVariables)(query, context.variableState);
44
+ query = (0, _utils.replaceTemplateVariables)(query, context.variableState);
44
45
  var _datasource;
45
46
  // Get the datasource, using the default Prom Datasource if one isn't specified in the query
46
47
  const client = await context.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
@@ -62,17 +63,16 @@ const getTimeSeriesData = async (spec, context)=>{
62
63
  end: (0, _dateFns.fromUnixTime)(end)
63
64
  },
64
65
  stepMs: step * 1000,
65
- // TODO: Maybe do a proper Iterable implementation that defers some of this
66
- // processing until its needed
67
66
  series: result.map((value)=>{
68
67
  const { metric , values } = value;
69
- // Name the series after the metric labels or if no metric, just use the
70
- // overall query
71
- let name = Object.entries(metric).map(([labelName, labelValue])=>`${labelName}="${labelValue}"`).join(', ');
72
- if (name === '') name = query;
68
+ // Name the series after the metric labels or if no metric, use the query
69
+ let name = (0, _utils.getUniqueKeyForPrometheusResult)(metric);
70
+ if (name === '') {
71
+ name = query;
72
+ }
73
73
  // query editor allows you to define an optional series_name_format
74
74
  // property to customize legend and tooltip display
75
- const formattedName = spec.series_name_format ? (0, _model.formatSeriesName)(spec.series_name_format, metric) : name;
75
+ const formattedName = spec.series_name_format ? (0, _utils.formatSeriesName)(spec.series_name_format, metric) : name;
76
76
  return {
77
77
  name,
78
78
  values: values.map(_model.parseValueTuple),
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -28,6 +28,7 @@ _export(exports, {
28
28
  const _jsxRuntime = require("react/jsx-runtime");
29
29
  const _material = require("@mui/material");
30
30
  const _model = require("../model");
31
+ const _utils = require("../utils");
31
32
  const _matcherEditor = require("./MatcherEditor");
32
33
  function PrometheusLabelValuesVariableEditor(props) {
33
34
  var _matchers;
@@ -140,7 +141,7 @@ const PrometheusLabelNamesVariable = {
140
141
  getVariableOptions: async (spec, ctx)=>{
141
142
  var _datasource;
142
143
  const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
143
- const match = spec.matchers ? spec.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
144
+ const match = spec.matchers ? spec.matchers.map((m)=>(0, _utils.replaceTemplateVariables)(m, ctx.variables)) : undefined;
144
145
  const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
145
146
  const { data: options } = await client.labelNames({
146
147
  'match[]': match,
@@ -153,7 +154,7 @@ const PrometheusLabelNamesVariable = {
153
154
  dependsOn: (spec)=>{
154
155
  var ref;
155
156
  return {
156
- variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _model.parseTemplateVariables)(m)).flat()) || []
157
+ variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _utils.parseTemplateVariables)(m)).flat()) || []
157
158
  };
158
159
  },
159
160
  OptionsEditorComponent: PrometheusLabelNamesVariableEditor,
@@ -164,10 +165,10 @@ const PrometheusLabelValuesVariable = {
164
165
  const pluginDef = spec;
165
166
  var _datasource;
166
167
  const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
167
- const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _model.replaceTemplateVariables)(m, ctx.variables)) : undefined;
168
+ const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>(0, _utils.replaceTemplateVariables)(m, ctx.variables)) : undefined;
168
169
  const timeRange = (0, _model.getPrometheusTimeRange)(ctx.timeRange);
169
170
  const { data: options } = await client.labelValues({
170
- labelName: (0, _model.replaceTemplateVariables)(pluginDef.label_name, ctx.variables),
171
+ labelName: (0, _utils.replaceTemplateVariables)(pluginDef.label_name, ctx.variables),
171
172
  'match[]': match,
172
173
  ...timeRange
173
174
  });
@@ -178,7 +179,7 @@ const PrometheusLabelValuesVariable = {
178
179
  dependsOn: (spec)=>{
179
180
  var ref;
180
181
  return {
181
- variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _model.parseTemplateVariables)(m)).flat().concat((0, _model.parseTemplateVariables)(spec.label_name))) || []
182
+ variables: ((ref = spec.matchers) === null || ref === void 0 ? void 0 : ref.map((m)=>(0, _utils.parseTemplateVariables)(m)).flat().concat((0, _utils.parseTemplateVariables)(spec.label_name))) || []
182
183
  };
183
184
  },
184
185
  OptionsEditorComponent: PrometheusLabelValuesVariableEditor,
@@ -192,9 +193,9 @@ const PrometheusPromQLVariable = {
192
193
  const client = await ctx.datasourceStore.getDatasourceClient((_datasource = spec.datasource) !== null && _datasource !== void 0 ? _datasource : _model.DEFAULT_PROM);
193
194
  // TODO we may want to manage a range query as well.
194
195
  const { data: options } = await client.instantQuery({
195
- query: (0, _model.replaceTemplateVariables)(spec.expr, ctx.variables)
196
+ query: (0, _utils.replaceTemplateVariables)(spec.expr, ctx.variables)
196
197
  });
197
- const labelName = (0, _model.replaceTemplateVariables)(spec.label_name, ctx.variables);
198
+ const labelName = (0, _utils.replaceTemplateVariables)(spec.label_name, ctx.variables);
198
199
  let values = [];
199
200
  if ((options === null || options === void 0 ? void 0 : options.resultType) === 'matrix') {
200
201
  values = capturingMatrix(options, labelName);
@@ -207,7 +208,7 @@ const PrometheusPromQLVariable = {
207
208
  },
208
209
  dependsOn: (spec)=>{
209
210
  return {
210
- variables: (0, _model.parseTemplateVariables)(spec.expr).concat((0, _model.parseTemplateVariables)(spec.label_name))
211
+ variables: (0, _utils.parseTemplateVariables)(spec.expr).concat((0, _utils.parseTemplateVariables)(spec.label_name))
211
212
  };
212
213
  },
213
214
  OptionsEditorComponent: PrometheusPromQLVariableEditor,
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -0,0 +1,28 @@
1
+ // Copyright 2023 The Perses Authors
2
+ // Licensed under the Apache License, Version 2.0 (the "License");
3
+ // you may not use this file except in compliance with the License.
4
+ // You may obtain a copy of the License at
5
+ //
6
+ // http://www.apache.org/licenses/LICENSE-2.0
7
+ //
8
+ // Unless required by applicable law or agreed to in writing, software
9
+ // distributed under the License is distributed on an "AS IS" BASIS,
10
+ // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
+ // See the License for the specific language governing permissions and
12
+ // limitations under the License.
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ _exportStar(require("./utils"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -24,7 +24,8 @@ _export(exports, {
24
24
  replaceTemplateVariables: ()=>replaceTemplateVariables,
25
25
  replaceTemplateVariable: ()=>replaceTemplateVariable,
26
26
  parseTemplateVariables: ()=>parseTemplateVariables,
27
- formatSeriesName: ()=>formatSeriesName
27
+ formatSeriesName: ()=>formatSeriesName,
28
+ getUniqueKeyForPrometheusResult: ()=>getUniqueKeyForPrometheusResult
28
29
  });
29
30
  function replaceTemplateVariables(text, variableState) {
30
31
  const variables = parseTemplateVariables(text);
@@ -67,3 +68,37 @@ function formatSeriesName(inputFormat, seriesLabels) {
67
68
  const resolveLabelsRegex = /\{\{\s*(.+?)\s*\}\}/g;
68
69
  return inputFormat.replace(resolveLabelsRegex, (_, g)=>seriesLabels[g] ? seriesLabels[g] : g);
69
70
  }
71
+ /*
72
+ * Stringifies object of labels into valid PromQL for querying metric by label
73
+ */ function stringifyPrometheusMetricLabels(labels, removeExprWrap) {
74
+ const labelStrings = [];
75
+ Object.keys(labels).sort().forEach((labelName)=>{
76
+ const labelValue = labels[labelName];
77
+ if (labelValue !== undefined) {
78
+ if (removeExprWrap) {
79
+ labelStrings.push(`"${labelName}":"${labelValue}"`);
80
+ } else {
81
+ labelStrings.push(`${labelName}="${labelValue}"`);
82
+ }
83
+ }
84
+ });
85
+ return `{${labelStrings.join(',')}}`;
86
+ }
87
+ function getUniqueKeyForPrometheusResult(metricLabels, { removeExprWrap } = {}) {
88
+ const metricNameKey = '__name__';
89
+ if (metricLabels) {
90
+ if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {
91
+ const stringifiedLabels = stringifyPrometheusMetricLabels({
92
+ ...metricLabels,
93
+ [metricNameKey]: undefined
94
+ }, removeExprWrap);
95
+ if (removeExprWrap === true) {
96
+ return `${stringifiedLabels}`;
97
+ } else {
98
+ return `${metricLabels[metricNameKey]}${stringifiedLabels}`;
99
+ }
100
+ }
101
+ return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);
102
+ }
103
+ return '';
104
+ }
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/PromQL.tsx"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport CodeMirror, { ReactCodeMirrorProps } from '@uiw/react-codemirror';\nimport { PromQLExtension, CompleteConfiguration } from '@prometheus-io/codemirror-promql';\nimport { EditorView } from '@codemirror/view';\nimport { useTheme } from '@mui/material';\nimport { useMemo } from 'react';\n\nexport type PromQLEditorProps = { completeConfig: CompleteConfiguration } & Omit<\n ReactCodeMirrorProps,\n 'theme' | 'extensions'\n>;\n\nexport function PromQLEditor({ completeConfig, ...rest }: PromQLEditorProps) {\n const theme = useTheme();\n const isDarkMode = theme.palette.mode === 'dark';\n\n const promQLExtension = useMemo(() => {\n return new PromQLExtension().activateLinter(false).setComplete(completeConfig).asExtension();\n }, [completeConfig]);\n\n return (\n <CodeMirror\n {...rest}\n style={{ border: `1px solid ${theme.palette.divider}` }}\n theme={isDarkMode ? 'dark' : 'light'}\n basicSetup={{\n highlightActiveLine: false,\n highlightActiveLineGutter: false,\n foldGutter: false,\n }}\n extensions={[EditorView.lineWrapping, promQLExtension]}\n />\n );\n}\n"],"names":["CodeMirror","PromQLExtension","EditorView","useTheme","useMemo","PromQLEditor","completeConfig","rest","theme","isDarkMode","palette","mode","promQLExtension","activateLinter","setComplete","asExtension","style","border","divider","basicSetup","highlightActiveLine","highlightActiveLineGutter","foldGutter","extensions","lineWrapping"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,UAAU,MAAgC,uBAAuB,CAAC;AACzE,SAASC,eAAe,QAA+B,kCAAkC,CAAC;AAC1F,SAASC,UAAU,QAAQ,kBAAkB,CAAC;AAC9C,SAASC,QAAQ,QAAQ,eAAe,CAAC;AACzC,SAASC,OAAO,QAAQ,OAAO,CAAC;AAOhC,OAAO,SAASC,YAAY,CAAC,EAAEC,cAAc,CAAA,EAAE,GAAGC,IAAI,EAAqB,EAAE;IAC3E,MAAMC,KAAK,GAAGL,QAAQ,EAAE,AAAC;IACzB,MAAMM,UAAU,GAAGD,KAAK,CAACE,OAAO,CAACC,IAAI,KAAK,MAAM,AAAC;IAEjD,MAAMC,eAAe,GAAGR,OAAO,CAAC,IAAM;QACpC,OAAO,IAAIH,eAAe,EAAE,CAACY,cAAc,CAAC,KAAK,CAAC,CAACC,WAAW,CAACR,cAAc,CAAC,CAACS,WAAW,EAAE,CAAC;IAC/F,CAAC,EAAE;QAACT,cAAc;KAAC,CAAC,AAAC;IAErB,qBACE,KAACN,UAAU;QACR,GAAGO,IAAI;QACRS,KAAK,EAAE;YAAEC,MAAM,EAAE,CAAC,UAAU,EAAET,KAAK,CAACE,OAAO,CAACQ,OAAO,CAAC,CAAC;SAAE;QACvDV,KAAK,EAAEC,UAAU,GAAG,MAAM,GAAG,OAAO;QACpCU,UAAU,EAAE;YACVC,mBAAmB,EAAE,KAAK;YAC1BC,yBAAyB,EAAE,KAAK;YAChCC,UAAU,EAAE,KAAK;SAClB;QACDC,UAAU,EAAE;YAACrB,UAAU,CAACsB,YAAY;YAAEZ,eAAe;SAAC;MACtD,CACF;AACJ,CAAC"}
1
+ {"version":3,"sources":["../../src/components/PromQL.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport CodeMirror, { ReactCodeMirrorProps } from '@uiw/react-codemirror';\nimport { PromQLExtension, CompleteConfiguration } from '@prometheus-io/codemirror-promql';\nimport { EditorView } from '@codemirror/view';\nimport { useTheme } from '@mui/material';\nimport { useMemo } from 'react';\n\nexport type PromQLEditorProps = { completeConfig: CompleteConfiguration } & Omit<\n ReactCodeMirrorProps,\n 'theme' | 'extensions'\n>;\n\nexport function PromQLEditor({ completeConfig, ...rest }: PromQLEditorProps) {\n const theme = useTheme();\n const isDarkMode = theme.palette.mode === 'dark';\n\n const promQLExtension = useMemo(() => {\n return new PromQLExtension().activateLinter(false).setComplete(completeConfig).asExtension();\n }, [completeConfig]);\n\n return (\n <CodeMirror\n {...rest}\n style={{ border: `1px solid ${theme.palette.divider}` }}\n theme={isDarkMode ? 'dark' : 'light'}\n basicSetup={{\n highlightActiveLine: false,\n highlightActiveLineGutter: false,\n foldGutter: false,\n }}\n extensions={[EditorView.lineWrapping, promQLExtension]}\n />\n );\n}\n"],"names":["CodeMirror","PromQLExtension","EditorView","useTheme","useMemo","PromQLEditor","completeConfig","rest","theme","isDarkMode","palette","mode","promQLExtension","activateLinter","setComplete","asExtension","style","border","divider","basicSetup","highlightActiveLine","highlightActiveLineGutter","foldGutter","extensions","lineWrapping"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC;AAAA,OAAOA,UAAU,MAAgC,uBAAuB,CAAC;AACzE,SAASC,eAAe,QAA+B,kCAAkC,CAAC;AAC1F,SAASC,UAAU,QAAQ,kBAAkB,CAAC;AAC9C,SAASC,QAAQ,QAAQ,eAAe,CAAC;AACzC,SAASC,OAAO,QAAQ,OAAO,CAAC;AAOhC,OAAO,SAASC,YAAY,CAAC,EAAEC,cAAc,CAAA,EAAE,GAAGC,IAAI,EAAqB,EAAE;IAC3E,MAAMC,KAAK,GAAGL,QAAQ,EAAE,AAAC;IACzB,MAAMM,UAAU,GAAGD,KAAK,CAACE,OAAO,CAACC,IAAI,KAAK,MAAM,AAAC;IAEjD,MAAMC,eAAe,GAAGR,OAAO,CAAC,IAAM;QACpC,OAAO,IAAIH,eAAe,EAAE,CAACY,cAAc,CAAC,KAAK,CAAC,CAACC,WAAW,CAACR,cAAc,CAAC,CAACS,WAAW,EAAE,CAAC;IAC/F,CAAC,EAAE;QAACT,cAAc;KAAC,CAAC,AAAC;IAErB,qBACE,KAACN,UAAU;QACR,GAAGO,IAAI;QACRS,KAAK,EAAE;YAAEC,MAAM,EAAE,CAAC,UAAU,EAAET,KAAK,CAACE,OAAO,CAACQ,OAAO,CAAC,CAAC;SAAE;QACvDV,KAAK,EAAEC,UAAU,GAAG,MAAM,GAAG,OAAO;QACpCU,UAAU,EAAE;YACVC,mBAAmB,EAAE,KAAK;YAC1BC,yBAAyB,EAAE,KAAK;YAChCC,UAAU,EAAE,KAAK;SAClB;QACDC,UAAU,EAAE;YAACrB,UAAU,CAACsB,YAAY;YAAEZ,eAAe;SAAC;MACtD,CACF;AACJ,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/components/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './PromQL';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,UAAU,CAAC"}
1
+ {"version":3,"sources":["../../src/components/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './PromQL';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,UAAU,CAAC"}
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport {\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n} from './plugins/prometheus-variables';\nimport { PrometheusDatasource } from './plugins/prometheus-datasource';\n\n// Export plugins under the same name as the kinds they handle from the plugin.json\nexport {\n PrometheusTimeSeriesQuery,\n StaticListVariable,\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n PrometheusDatasource,\n};\n"],"names":["PrometheusTimeSeriesQuery","StaticListVariable","PrometheusLabelNamesVariable","PrometheusLabelValuesVariable","PrometheusPromQLVariable","PrometheusDatasource"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,yBAAyB,QAAQ,wCAAwC,CAAC;AACnF,+CAA+C;AAC/C,SAASC,kBAAkB,QAAQ,oBAAoB,CAAC;AACxD,SACEC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,QACnB,gCAAgC,CAAC;AACxC,SAASC,oBAAoB,QAAQ,iCAAiC,CAAC;AAEvE,mFAAmF;AACnF,SACEL,yBAAyB,EACzBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,EACxBC,oBAAoB,GACpB"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { PrometheusTimeSeriesQuery } from './plugins/prometheus-time-series-query';\n// @TODO: Move this to a more generic location;\nimport { StaticListVariable } from './plugins/variable';\nimport {\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n} from './plugins/prometheus-variables';\nimport { PrometheusDatasource } from './plugins/prometheus-datasource';\n\n// Export plugins under the same name as the kinds they handle from the plugin.json\nexport {\n PrometheusTimeSeriesQuery,\n StaticListVariable,\n PrometheusLabelNamesVariable,\n PrometheusLabelValuesVariable,\n PrometheusPromQLVariable,\n PrometheusDatasource,\n};\n"],"names":["PrometheusTimeSeriesQuery","StaticListVariable","PrometheusLabelNamesVariable","PrometheusLabelValuesVariable","PrometheusPromQLVariable","PrometheusDatasource"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,yBAAyB,QAAQ,wCAAwC,CAAC;AACnF,+CAA+C;AAC/C,SAASC,kBAAkB,QAAQ,oBAAoB,CAAC;AACxD,SACEC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,QACnB,gCAAgC,CAAC;AACxC,SAASC,oBAAoB,QAAQ,iCAAiC,CAAC;AAEvE,mFAAmF;AACnF,SACEL,yBAAyB,EACzBC,kBAAkB,EAClBC,4BAA4B,EAC5BC,6BAA6B,EAC7BC,wBAAwB,EACxBC,oBAAoB,GACpB"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/api-types.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\n\n// Just reuse dashboard model's type and re-export\nexport type { DurationString };\n\nexport interface SuccessResponse<T> {\n status: 'success';\n data: T;\n warnings?: string[];\n}\n\nexport interface ErrorResponse<T> {\n status: 'error';\n data?: T;\n errorType: string;\n error: string;\n}\n\nexport type ApiResponse<T> = SuccessResponse<T> | ErrorResponse<T>;\n\nexport type DurationSeconds = number;\n\nexport type UnixTimestampSeconds = number;\n\nexport type ValueTuple = [unixTimeSeconds: UnixTimestampSeconds, sampleValue: string];\n\nexport type Metric = Record<string, string>;\n\nexport interface VectorData {\n resultType: 'vector';\n result: Array<{\n metric: Metric;\n value: ValueTuple;\n }>;\n}\n\nexport interface MatrixData {\n resultType: 'matrix';\n result: Array<{\n metric: Metric;\n values: ValueTuple[];\n }>;\n}\n\nexport interface ScalarData {\n resultType: 'scalar';\n result: ValueTuple;\n}\n\nexport interface InstantQueryRequestParameters {\n query: string;\n time?: UnixTimestampSeconds;\n timeout?: DurationString;\n}\n\nexport type InstantQueryResponse = ApiResponse<MatrixData | VectorData | ScalarData>;\n\nexport interface RangeQueryRequestParameters {\n query: string;\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n step: DurationSeconds;\n timeout?: DurationString;\n}\n\nexport type RangeQueryResponse = ApiResponse<MatrixData>;\n\nexport interface SeriesRequestParameters {\n 'match[]': string[];\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n}\n\nexport type SeriesResponse = ApiResponse<Metric[]>;\n\nexport interface LabelNamesRequestParameters {\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelNamesResponse = ApiResponse<string[]>;\n\nexport interface LabelValuesRequestParameters {\n labelName: string;\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelValuesResponse = ApiResponse<string[]>;\n\nexport interface MetricMetadata {\n type: string;\n help: string;\n unit?: string;\n}\n\nexport interface MetricMetadataRequestParameters {\n limit?: number;\n metric?: string;\n}\n\nexport type MetricMetadataResponse = ApiResponse<Record<string, MetricMetadata[]>>;\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAuGmF"}
1
+ {"version":3,"sources":["../../src/model/api-types.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\n\n// Just reuse dashboard model's type and re-export\nexport type { DurationString };\n\nexport interface SuccessResponse<T> {\n status: 'success';\n data: T;\n warnings?: string[];\n}\n\nexport interface ErrorResponse<T> {\n status: 'error';\n data?: T;\n errorType: string;\n error: string;\n}\n\nexport type ApiResponse<T> = SuccessResponse<T> | ErrorResponse<T>;\n\nexport type DurationSeconds = number;\n\nexport type UnixTimestampSeconds = number;\n\nexport type ValueTuple = [unixTimeSeconds: UnixTimestampSeconds, sampleValue: string];\n\nexport type Metric = Record<string, string>;\n\nexport interface VectorData {\n resultType: 'vector';\n result: Array<{\n metric: Metric;\n value: ValueTuple;\n }>;\n}\n\nexport interface MatrixData {\n resultType: 'matrix';\n result: Array<{\n metric: Metric;\n values: ValueTuple[];\n }>;\n}\n\nexport interface ScalarData {\n resultType: 'scalar';\n result: ValueTuple;\n}\n\nexport interface InstantQueryRequestParameters {\n query: string;\n time?: UnixTimestampSeconds;\n timeout?: DurationString;\n}\n\nexport type InstantQueryResponse = ApiResponse<MatrixData | VectorData | ScalarData>;\n\nexport interface RangeQueryRequestParameters {\n query: string;\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n step: DurationSeconds;\n timeout?: DurationString;\n}\n\nexport type RangeQueryResponse = ApiResponse<MatrixData>;\n\nexport interface SeriesRequestParameters {\n 'match[]': string[];\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n}\n\nexport type SeriesResponse = ApiResponse<Metric[]>;\n\nexport interface LabelNamesRequestParameters {\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelNamesResponse = ApiResponse<string[]>;\n\nexport interface LabelValuesRequestParameters {\n labelName: string;\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n}\n\nexport type LabelValuesResponse = ApiResponse<string[]>;\n\nexport interface MetricMetadata {\n type: string;\n help: string;\n unit?: string;\n}\n\nexport interface MetricMetadataRequestParameters {\n limit?: number;\n metric?: string;\n}\n\nexport type MetricMetadataResponse = ApiResponse<Record<string, MetricMetadata[]>>;\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,WAuGmF"}
@@ -4,5 +4,4 @@ export * from './prometheus-client';
4
4
  export * from './prometheus-selectors';
5
5
  export * from './templating';
6
6
  export * from './time';
7
- export * from './utils';
8
7
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -16,6 +16,5 @@ export * from './prometheus-client';
16
16
  export * from './prometheus-selectors';
17
17
  export * from './templating';
18
18
  export * from './time';
19
- export * from './utils';
20
19
 
21
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './api-types';\nexport * from './parse-sample-values';\nexport * from './prometheus-client';\nexport * from './prometheus-selectors';\nexport * from './templating';\nexport * from './time';\nexport * from './utils';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"sources":["../../src/model/index.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './api-types';\nexport * from './parse-sample-values';\nexport * from './prometheus-client';\nexport * from './prometheus-selectors';\nexport * from './templating';\nexport * from './time';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,aAAa,CAAC;AAC5B,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,wBAAwB,CAAC;AACvC,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC"}
@@ -1,4 +1,4 @@
1
- // Copyright 2022 The Perses Authors
1
+ // Copyright 2023 The Perses Authors
2
2
  // Licensed under the Apache License, Version 2.0 (the "License");
3
3
  // you may not use this file except in compliance with the License.
4
4
  // You may obtain a copy of the License at
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/model/parse-sample-values.ts"],"sourcesContent":["// Copyright 2022 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ValueTuple } from './api-types';\n\n/**\n * ValueTuple from the Prom server, parsed into ms and floating point number\n */\nexport type ParsedValueTuple = [unixTimeMs: number, value: number];\n\n/**\n * Parse a ValueTuple from a PromServer response into the a millisecond-based\n * unix time and a numeric sample value.\n */\nexport function parseValueTuple(data: ValueTuple): ParsedValueTuple {\n const [unixTimeSeconds, sampleValue] = data;\n\n // Prom returns unix time in seconds, so convert to ms\n return [unixTimeSeconds * 1000, parseSampleValue(sampleValue)];\n}\n\n/**\n * Parses a string sample value from Prometheus, usually included as the\n * second member of a ValueTuple.\n */\nexport function parseSampleValue(sampleValue: ValueTuple[1]): number {\n // Account for Prometheus' representation of +/- infinity, otherwise just\n // parse the sample value as a float\n let value: number;\n switch (sampleValue) {\n case '+Inf':\n value = Number.POSITIVE_INFINITY;\n break;\n case '-Inf':\n value = Number.NEGATIVE_INFINITY;\n break;\n default:\n value = parseFloat(sampleValue);\n }\n return value;\n}\n"],"names":["parseValueTuple","data","unixTimeSeconds","sampleValue","parseSampleValue","value","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AASjC;;;CAGC,GACD,OAAO,SAASA,eAAe,CAACC,IAAgB,EAAoB;IAClE,MAAM,CAACC,eAAe,EAAEC,WAAW,CAAC,GAAGF,IAAI,AAAC;IAE5C,sDAAsD;IACtD,OAAO;QAACC,eAAe,GAAG,IAAI;QAAEE,gBAAgB,CAACD,WAAW,CAAC;KAAC,CAAC;AACjE,CAAC;AAED;;;CAGC,GACD,OAAO,SAASC,gBAAgB,CAACD,WAA0B,EAAU;IACnE,yEAAyE;IACzE,oCAAoC;IACpC,IAAIE,KAAK,AAAQ,AAAC;IAClB,OAAQF,WAAW;QACjB,KAAK,MAAM;YACTE,KAAK,GAAGC,MAAM,CAACC,iBAAiB,CAAC;YACjC,MAAM;QACR,KAAK,MAAM;YACTF,KAAK,GAAGC,MAAM,CAACE,iBAAiB,CAAC;YACjC,MAAM;QACR;YACEH,KAAK,GAAGI,UAAU,CAACN,WAAW,CAAC,CAAC;KACnC;IACD,OAAOE,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"sources":["../../src/model/parse-sample-values.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ValueTuple } from './api-types';\n\n/**\n * ValueTuple from the Prom server, parsed into ms and floating point number\n */\nexport type ParsedValueTuple = [unixTimeMs: number, value: number];\n\n/**\n * Parse a ValueTuple from a PromServer response into the a millisecond-based\n * unix time and a numeric sample value.\n */\nexport function parseValueTuple(data: ValueTuple): ParsedValueTuple {\n const [unixTimeSeconds, sampleValue] = data;\n\n // Prom returns unix time in seconds, so convert to ms\n return [unixTimeSeconds * 1000, parseSampleValue(sampleValue)];\n}\n\n/**\n * Parses a string sample value from Prometheus, usually included as the\n * second member of a ValueTuple.\n */\nexport function parseSampleValue(sampleValue: ValueTuple[1]): number {\n // Account for Prometheus' representation of +/- infinity, otherwise just\n // parse the sample value as a float\n let value: number;\n switch (sampleValue) {\n case '+Inf':\n value = Number.POSITIVE_INFINITY;\n break;\n case '-Inf':\n value = Number.NEGATIVE_INFINITY;\n break;\n default:\n value = parseFloat(sampleValue);\n }\n return value;\n}\n"],"names":["parseValueTuple","data","unixTimeSeconds","sampleValue","parseSampleValue","value","Number","POSITIVE_INFINITY","NEGATIVE_INFINITY","parseFloat"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AASjC;;;CAGC,GACD,OAAO,SAASA,eAAe,CAACC,IAAgB,EAAoB;IAClE,MAAM,CAACC,eAAe,EAAEC,WAAW,CAAC,GAAGF,IAAI,AAAC;IAE5C,sDAAsD;IACtD,OAAO;QAACC,eAAe,GAAG,IAAI;QAAEE,gBAAgB,CAACD,WAAW,CAAC;KAAC,CAAC;AACjE,CAAC;AAED;;;CAGC,GACD,OAAO,SAASC,gBAAgB,CAACD,WAA0B,EAAU;IACnE,yEAAyE;IACzE,oCAAoC;IACpC,IAAIE,KAAK,AAAQ,AAAC;IAClB,OAAQF,WAAW;QACjB,KAAK,MAAM;YACTE,KAAK,GAAGC,MAAM,CAACC,iBAAiB,CAAC;YACjC,MAAM;QACR,KAAK,MAAM;YACTF,KAAK,GAAGC,MAAM,CAACE,iBAAiB,CAAC;YACjC,MAAM;QACR;YACEH,KAAK,GAAGI,UAAU,CAACN,WAAW,CAAC,CAAC;KACnC;IACD,OAAOE,KAAK,CAAC;AACf,CAAC"}
@@ -1,6 +1,8 @@
1
+ import { RequestHeaders } from '@perses-dev/core';
1
2
  import { InstantQueryRequestParameters, InstantQueryResponse, LabelNamesRequestParameters, LabelNamesResponse, LabelValuesRequestParameters, LabelValuesResponse, RangeQueryRequestParameters, RangeQueryResponse } from './api-types';
2
3
  interface PrometheusClientOptions {
3
4
  datasourceUrl: string;
5
+ headers?: RequestHeaders;
4
6
  }
5
7
  export interface PrometheusClient {
6
8
  options: PrometheusClientOptions;
@@ -11,6 +13,7 @@ export interface PrometheusClient {
11
13
  }
12
14
  export interface QueryOptions {
13
15
  datasourceUrl: string;
16
+ headers?: RequestHeaders;
14
17
  }
15
18
  /**
16
19
  * Calls the `/api/v1/query` endpoint to get metrics data.
@@ -1 +1 @@
1
- {"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAcA,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAErB,UAAU,uBAAuB;IAC/B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,uBAAuB,CAAC;IACjC,YAAY,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnF,UAAU,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC7E,UAAU,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC7E,WAAW,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACjF;AAED,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,6BAA6B,EAAE,YAAY,EAAE,YAAY,iCAE7F;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,EAAE,YAAY,+BAEzF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,EAAE,YAAY,+BAEzF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,4BAA4B,EAAE,YAAY,EAAE,YAAY,gCAI3F"}
1
+ {"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAa,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAErB,UAAU,uBAAuB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,uBAAuB,CAAC;IACjC,YAAY,CAAC,MAAM,EAAE,6BAA6B,GAAG,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACnF,UAAU,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC7E,UAAU,CAAC,MAAM,EAAE,2BAA2B,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC7E,WAAW,CAAC,MAAM,EAAE,4BAA4B,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CACjF;AAED,MAAM,WAAW,YAAY;IAC3B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,6BAA6B,EAAE,YAAY,EAAE,YAAY,iCAE7F;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,EAAE,YAAY,+BAEzF;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,EAAE,YAAY,+BAEzF;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,4BAA4B,EAAE,YAAY,EAAE,YAAY,gCAI3F"}