@perses-dev/prometheus-plugin 0.45.0 → 0.46.0-rc1

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.
@@ -172,7 +172,7 @@ function PrometheusDatasourceEditor(props) {
172
172
  spacing: 2,
173
173
  mb: 2,
174
174
  children: [
175
- ((_value_proxy = value.proxy) === null || _value_proxy === void 0 ? void 0 : _value_proxy.spec.allowedEndpoints) && ((_value_proxy1 = value.proxy) === null || _value_proxy1 === void 0 ? void 0 : _value_proxy1.spec.allowedEndpoints.length) != 0 ? value.proxy.spec.allowedEndpoints.map(({ endpointPattern, method }, i)=>{
175
+ ((_value_proxy = value.proxy) === null || _value_proxy === void 0 ? void 0 : _value_proxy.spec.allowedEndpoints) && ((_value_proxy1 = value.proxy) === null || _value_proxy1 === void 0 ? void 0 : _value_proxy1.spec.allowedEndpoints.length) !== 0 ? value.proxy.spec.allowedEndpoints.map(({ endpointPattern, method }, i)=>{
176
176
  return /*#__PURE__*/ (0, _jsxruntime.jsxs)(_react.Fragment, {
177
177
  children: [
178
178
  /*#__PURE__*/ (0, _jsxruntime.jsx)(_material.Grid, {
@@ -513,8 +513,8 @@ function PrometheusDatasourceEditor(props) {
513
513
  ];
514
514
  // Use of findIndex instead of providing hardcoded values to avoid desynchronisatio or
515
515
  // bug in case the tabs get eventually swapped in the future.
516
- const directModeId = tabs.findIndex((tab)=>tab.label == strDirect);
517
- const proxyModeId = tabs.findIndex((tab)=>tab.label == strProxy);
516
+ const directModeId = tabs.findIndex((tab)=>tab.label === strDirect);
517
+ const proxyModeId = tabs.findIndex((tab)=>tab.label === strProxy);
518
518
  // In "update datasource" case, set defaultTab to the mode that this datasource is currently relying on.
519
519
  // Otherwise (create datasource), set defaultTab to Direct access.
520
520
  const defaultTab = value.proxy ? proxyModeId : directModeId;
@@ -563,10 +563,10 @@ function PrometheusDatasourceEditor(props) {
563
563
  // When changing mode, remove previous mode's config + append default values for the new mode.
564
564
  const handleModeChange = (v)=>{
565
565
  var _tabs_v, _tabs_v1;
566
- if (((_tabs_v = tabs[v]) === null || _tabs_v === void 0 ? void 0 : _tabs_v.label) == strDirect) {
566
+ if (((_tabs_v = tabs[v]) === null || _tabs_v === void 0 ? void 0 : _tabs_v.label) === strDirect) {
567
567
  setPreviousSpecProxy(value);
568
568
  onChange(previousSpecDirect);
569
- } else if (((_tabs_v1 = tabs[v]) === null || _tabs_v1 === void 0 ? void 0 : _tabs_v1.label) == strProxy) {
569
+ } else if (((_tabs_v1 = tabs[v]) === null || _tabs_v1 === void 0 ? void 0 : _tabs_v1.label) === strProxy) {
570
570
  setPreviousSpecDirect(value);
571
571
  onChange(previousSpecProxy);
572
572
  }
@@ -27,7 +27,6 @@ const _model = require("../../model");
27
27
  const _utils = require("../../utils");
28
28
  const _types = require("../types");
29
29
  const getTimeSeriesData = async (spec, context)=>{
30
- var _response_data;
31
30
  if (spec.query === undefined || spec.query === null || spec.query === '') {
32
31
  // Do not make a request to the backend, instead return an empty TimeSeriesData
33
32
  return {
@@ -72,15 +71,26 @@ const getTimeSeriesData = async (spec, context)=>{
72
71
  // Get the datasource, using the default Prom Datasource if one isn't specified in the query
73
72
  const client = await context.datasourceStore.getDatasourceClient((_spec_datasource1 = spec.datasource) !== null && _spec_datasource1 !== void 0 ? _spec_datasource1 : _model.DEFAULT_PROM);
74
73
  // Make the request to Prom
75
- const response = await client.rangeQuery({
76
- query,
77
- start,
78
- end,
79
- step
80
- });
81
- var _response_data_result;
74
+ let response;
75
+ switch(context.mode){
76
+ case 'instant':
77
+ response = await client.instantQuery({
78
+ query,
79
+ time: end
80
+ });
81
+ break;
82
+ case 'range':
83
+ default:
84
+ response = await client.rangeQuery({
85
+ query,
86
+ start,
87
+ end,
88
+ step
89
+ });
90
+ break;
91
+ }
82
92
  // TODO: What about error responses from Prom that have a response body?
83
- const result = (_response_data_result = (_response_data = response.data) === null || _response_data === void 0 ? void 0 : _response_data.result) !== null && _response_data_result !== void 0 ? _response_data_result : [];
93
+ const result = response.data;
84
94
  // Custom display for response header warnings, configurable error responses display coming next
85
95
  const notices = [];
86
96
  if (response.status === 'success') {
@@ -103,17 +113,7 @@ const getTimeSeriesData = async (spec, context)=>{
103
113
  end: (0, _datefns.fromUnixTime)(end)
104
114
  },
105
115
  stepMs: step * 1000,
106
- series: result.map((value)=>{
107
- const { metric, values } = value;
108
- // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.
109
- const { name, formattedName } = (0, _utils.getFormattedPrometheusSeriesName)(query, metric, seriesNameFormat);
110
- return {
111
- name,
112
- values: values.map(_model.parseValueTuple),
113
- formattedName,
114
- labels: metric
115
- };
116
- }),
116
+ series: buildTimeSeries(result, query, seriesNameFormat),
117
117
  metadata: {
118
118
  notices,
119
119
  executedQueryString: query
@@ -121,3 +121,60 @@ const getTimeSeriesData = async (spec, context)=>{
121
121
  };
122
122
  return chartData;
123
123
  };
124
+ function buildVectorData(data, query, seriesNameFormat) {
125
+ return data.result.map((res)=>{
126
+ const { metric, value } = res;
127
+ // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.
128
+ const { name, formattedName } = (0, _utils.getFormattedPrometheusSeriesName)(query, metric, seriesNameFormat);
129
+ return {
130
+ name,
131
+ values: [
132
+ (0, _model.parseValueTuple)(value)
133
+ ],
134
+ formattedName,
135
+ labels: metric
136
+ };
137
+ });
138
+ }
139
+ function buildMatrixData(data, query, seriesNameFormat) {
140
+ return data.result.map((res)=>{
141
+ const { metric, values } = res;
142
+ // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.
143
+ const { name, formattedName } = (0, _utils.getFormattedPrometheusSeriesName)(query, metric, seriesNameFormat);
144
+ return {
145
+ name,
146
+ values: values.map(_model.parseValueTuple),
147
+ formattedName,
148
+ labels: metric
149
+ };
150
+ });
151
+ }
152
+ function buildScalarData(data, query, seriesNameFormat) {
153
+ const { name, formattedName } = (0, _utils.getFormattedPrometheusSeriesName)(query, {}, seriesNameFormat);
154
+ return [
155
+ {
156
+ name,
157
+ values: [
158
+ (0, _model.parseValueTuple)(data.result)
159
+ ],
160
+ formattedName
161
+ }
162
+ ];
163
+ }
164
+ function buildTimeSeries(data, query, seriesNameFormat) {
165
+ if (!data) {
166
+ return [];
167
+ }
168
+ const resultType = data.resultType;
169
+ switch(resultType){
170
+ case 'vector':
171
+ return buildVectorData(data, query, seriesNameFormat);
172
+ case 'matrix':
173
+ return buildMatrixData(data, query, seriesNameFormat);
174
+ case 'scalar':
175
+ return buildScalarData(data, query, seriesNameFormat);
176
+ default:
177
+ console.warn('Unknown result type', resultType, data);
178
+ return [];
179
+ }
180
+ }
@@ -31,7 +31,6 @@ _export(exports, {
31
31
  return getUniqueKeyForPrometheusResult;
32
32
  }
33
33
  });
34
- const _core = require("@perses-dev/core");
35
34
  function formatSeriesName(inputFormat, seriesLabels) {
36
35
  const resolveLabelsRegex = /\{\{\s*(.+?)\s*\}\}/g;
37
36
  return inputFormat.replace(resolveLabelsRegex, (_match, token)=>{
@@ -58,29 +57,22 @@ function formatSeriesName(inputFormat, seriesLabels) {
58
57
  }
59
58
  function getUniqueKeyForPrometheusResult(metricLabels, { removeExprWrap } = {}) {
60
59
  const metricNameKey = '__name__';
61
- if (metricLabels) {
62
- if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {
63
- const stringifiedLabels = stringifyPrometheusMetricLabels({
64
- ...metricLabels,
65
- [metricNameKey]: undefined
66
- }, removeExprWrap);
67
- if (removeExprWrap === true) {
68
- return `${stringifiedLabels}`;
69
- } else {
70
- return `${metricLabels[metricNameKey]}${stringifiedLabels}`;
71
- }
60
+ if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {
61
+ const stringifiedLabels = stringifyPrometheusMetricLabels({
62
+ ...metricLabels,
63
+ [metricNameKey]: undefined
64
+ }, removeExprWrap);
65
+ if (removeExprWrap) {
66
+ return `${stringifiedLabels}`;
67
+ } else {
68
+ return `${metricLabels[metricNameKey]}${stringifiedLabels}`;
72
69
  }
73
- return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);
74
70
  }
75
- return '';
71
+ return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);
76
72
  }
77
73
  function getFormattedPrometheusSeriesName(query, metric, formatter) {
78
74
  // Name the series after the metric labels by default.
79
- // Use the query if no metric or metric labels are empty.
80
- let name = getUniqueKeyForPrometheusResult(metric);
81
- if (name === '' || (0, _core.isEmptyObject)(metric)) {
82
- name = query;
83
- }
75
+ const name = getUniqueKeyForPrometheusResult(metric);
84
76
  // Query editor allows you to define an optional seriesNameFormat property.
85
77
  // This controls the regex used to customize legend and tooltip display.
86
78
  const formattedName = formatter ? formatSeriesName(formatter, metric) : name;
@@ -116,7 +116,7 @@ export function PrometheusDatasourceEditor(props) {
116
116
  spacing: 2,
117
117
  mb: 2,
118
118
  children: [
119
- ((_value_proxy = value.proxy) === null || _value_proxy === void 0 ? void 0 : _value_proxy.spec.allowedEndpoints) && ((_value_proxy1 = value.proxy) === null || _value_proxy1 === void 0 ? void 0 : _value_proxy1.spec.allowedEndpoints.length) != 0 ? value.proxy.spec.allowedEndpoints.map(({ endpointPattern, method }, i)=>{
119
+ ((_value_proxy = value.proxy) === null || _value_proxy === void 0 ? void 0 : _value_proxy.spec.allowedEndpoints) && ((_value_proxy1 = value.proxy) === null || _value_proxy1 === void 0 ? void 0 : _value_proxy1.spec.allowedEndpoints.length) !== 0 ? value.proxy.spec.allowedEndpoints.map(({ endpointPattern, method }, i)=>{
120
120
  return /*#__PURE__*/ _jsxs(Fragment, {
121
121
  children: [
122
122
  /*#__PURE__*/ _jsx(Grid, {
@@ -457,8 +457,8 @@ export function PrometheusDatasourceEditor(props) {
457
457
  ];
458
458
  // Use of findIndex instead of providing hardcoded values to avoid desynchronisatio or
459
459
  // bug in case the tabs get eventually swapped in the future.
460
- const directModeId = tabs.findIndex((tab)=>tab.label == strDirect);
461
- const proxyModeId = tabs.findIndex((tab)=>tab.label == strProxy);
460
+ const directModeId = tabs.findIndex((tab)=>tab.label === strDirect);
461
+ const proxyModeId = tabs.findIndex((tab)=>tab.label === strProxy);
462
462
  // In "update datasource" case, set defaultTab to the mode that this datasource is currently relying on.
463
463
  // Otherwise (create datasource), set defaultTab to Direct access.
464
464
  const defaultTab = value.proxy ? proxyModeId : directModeId;
@@ -507,10 +507,10 @@ export function PrometheusDatasourceEditor(props) {
507
507
  // When changing mode, remove previous mode's config + append default values for the new mode.
508
508
  const handleModeChange = (v)=>{
509
509
  var _tabs_v, _tabs_v1;
510
- if (((_tabs_v = tabs[v]) === null || _tabs_v === void 0 ? void 0 : _tabs_v.label) == strDirect) {
510
+ if (((_tabs_v = tabs[v]) === null || _tabs_v === void 0 ? void 0 : _tabs_v.label) === strDirect) {
511
511
  setPreviousSpecProxy(value);
512
512
  onChange(previousSpecDirect);
513
- } else if (((_tabs_v1 = tabs[v]) === null || _tabs_v1 === void 0 ? void 0 : _tabs_v1.label) == strProxy) {
513
+ } else if (((_tabs_v1 = tabs[v]) === null || _tabs_v1 === void 0 ? void 0 : _tabs_v1.label) === strProxy) {
514
514
  setPreviousSpecDirect(value);
515
515
  onChange(previousSpecProxy);
516
516
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/plugins/PrometheusDatasourceEditor.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 { DurationString, RequestHeaders } from '@perses-dev/core';\nimport { OptionsEditorRadios } from '@perses-dev/plugin-system';\nimport { Grid, IconButton, MenuItem, TextField, Typography } from '@mui/material';\nimport React, { Fragment, useState } from 'react';\nimport { produce } from 'immer';\nimport { Controller } from 'react-hook-form';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from './types';\n\nexport interface PrometheusDatasourceEditorProps {\n value: PrometheusDatasourceSpec;\n onChange: (next: PrometheusDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function PrometheusDatasourceEditor(props: PrometheusDatasourceEditorProps) {\n const { value, onChange, isReadonly } = props;\n const strDirect = 'Direct access';\n const strProxy = 'Proxy';\n\n // utilitary function used for headers when renaming a property\n // -> TODO it would be cleaner to manipulate headers as an intermediary list instead, to avoid doing this.\n const buildNewHeaders = (oldHeaders: RequestHeaders | undefined, oldName: string, newName: string) => {\n if (oldHeaders === undefined) return oldHeaders;\n const keys = Object.keys(oldHeaders);\n const newHeaders = keys.reduce<Record<string, string>>((acc, val) => {\n if (val === oldName) {\n acc[newName] = oldHeaders[oldName] || '';\n } else {\n acc[val] = oldHeaders[val] || '';\n }\n return acc;\n }, {});\n\n return { ...newHeaders };\n };\n\n const tabs = [\n {\n label: strDirect,\n content: (\n <Controller\n name=\"URL\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"URL\"\n value={value.directUrl || ''}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n draft.directUrl = e.target.value;\n })\n );\n }}\n />\n )}\n />\n ),\n },\n {\n label: strProxy,\n content: (\n <>\n <Controller\n name=\"URL\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"URL\"\n value={value.proxy?.spec.url || ''}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.url = e.target.value;\n }\n })\n );\n }}\n sx={{ mb: 2 }}\n />\n )}\n />\n <Typography variant=\"h4\" mb={2}>\n Allowed endpoints\n </Typography>\n <Grid container spacing={2} mb={2}>\n {value.proxy?.spec.allowedEndpoints && value.proxy?.spec.allowedEndpoints.length != 0 ? (\n value.proxy.spec.allowedEndpoints.map(({ endpointPattern, method }, i) => {\n return (\n <Fragment key={i}>\n <Grid item xs={8}>\n <Controller\n name={`Endpoint pattern ${i}`}\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Endpoint pattern\"\n value={endpointPattern}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = draft.proxy.spec.allowedEndpoints?.map(\n (item, itemIndex) => {\n if (i === itemIndex) {\n return {\n endpointPattern: e.target.value,\n method: item.method,\n };\n } else {\n return item;\n }\n }\n );\n }\n })\n );\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={3}>\n <Controller\n name={`Method ${i}`}\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n select\n fullWidth\n label=\"Method\"\n value={method}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = draft.proxy.spec.allowedEndpoints?.map(\n (item, itemIndex) => {\n if (i === itemIndex) {\n return {\n endpointPattern: item.endpointPattern,\n method: e.target.value,\n };\n } else {\n return item;\n }\n }\n );\n }\n })\n );\n }}\n >\n <MenuItem value=\"GET\">GET</MenuItem>\n <MenuItem value=\"POST\">POST</MenuItem>\n <MenuItem value=\"PUT\">PUT</MenuItem>\n <MenuItem value=\"PATCH\">PATCH</MenuItem>\n <MenuItem value=\"DELETE\">DELETE</MenuItem>\n </TextField>\n )}\n />\n </Grid>\n <Grid item xs={1}>\n <Controller\n name={`Remove Endpoint ${i}`}\n render={({ field }) => (\n <IconButton\n {...field}\n disabled={isReadonly}\n // Remove the given allowed endpoint from the list\n onClick={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = [\n ...(draft.proxy.spec.allowedEndpoints?.filter((item, itemIndex) => {\n return itemIndex !== i;\n }) || []),\n ];\n }\n })\n );\n }}\n >\n <MinusIcon />\n </IconButton>\n )}\n />\n </Grid>\n </Fragment>\n );\n })\n ) : (\n <Grid item xs={4}>\n <Typography sx={{ fontStyle: 'italic' }}>None</Typography>\n </Grid>\n )}\n <Grid item xs={12} sx={{ paddingTop: '0px !important', paddingLeft: '5px !important' }}>\n <IconButton\n disabled={isReadonly}\n // Add a new (empty) allowed endpoint to the list\n onClick={() =>\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = [\n ...(draft.proxy.spec.allowedEndpoints ?? []),\n { endpointPattern: '', method: '' },\n ];\n }\n })\n )\n }\n >\n <PlusIcon />\n </IconButton>\n </Grid>\n </Grid>\n <Typography variant=\"h4\" mb={2}>\n Request Headers\n </Typography>\n <Grid container spacing={2} mb={2}>\n {value.proxy?.spec.headers &&\n Object.keys(value.proxy.spec.headers).map((headerName, i) => {\n return (\n <Fragment key={i}>\n <Grid item xs={4}>\n <Controller\n name={`Header name ${i}`}\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Header name\"\n value={headerName}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = buildNewHeaders(\n draft.proxy.spec.headers,\n headerName,\n e.target.value\n );\n }\n })\n );\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={7}>\n <Controller\n name={`Header value ${i}`}\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Header value\"\n value={value.proxy?.spec.headers?.[headerName]}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = {\n ...draft.proxy.spec.headers,\n [headerName]: e.target.value,\n };\n }\n })\n );\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={1}>\n <Controller\n name={`Remove Header ${i}`}\n render={({ field }) => (\n <IconButton\n {...field}\n disabled={isReadonly}\n // Remove the given header from the list\n onClick={(e) => {\n field.onChange(e);\n const newHeaders = { ...value.proxy?.spec.headers };\n delete newHeaders[headerName];\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = newHeaders;\n }\n })\n );\n }}\n >\n <MinusIcon />\n </IconButton>\n )}\n />\n </Grid>\n </Fragment>\n );\n })}\n <Grid item xs={12} sx={{ paddingTop: '0px !important', paddingLeft: '5px !important' }}>\n <IconButton\n disabled={isReadonly}\n // Add a new (empty) header to the list\n onClick={() =>\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = { ...draft.proxy.spec.headers, '': '' };\n }\n })\n )\n }\n >\n <PlusIcon />\n </IconButton>\n </Grid>\n </Grid>\n\n <Controller\n name=\"Secret\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Secret\"\n value={value.proxy?.spec.secret || ''}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.secret = e.target.value;\n }\n })\n );\n }}\n />\n )}\n />\n </>\n ),\n },\n ];\n\n // Use of findIndex instead of providing hardcoded values to avoid desynchronisatio or\n // bug in case the tabs get eventually swapped in the future.\n const directModeId = tabs.findIndex((tab) => tab.label == strDirect);\n const proxyModeId = tabs.findIndex((tab) => tab.label == strProxy);\n\n // In \"update datasource\" case, set defaultTab to the mode that this datasource is currently relying on.\n // Otherwise (create datasource), set defaultTab to Direct access.\n const defaultTab = value.proxy ? proxyModeId : directModeId;\n\n const initialSpecDirect: PrometheusDatasourceSpec = {\n directUrl: '',\n };\n\n const initialSpecProxy: PrometheusDatasourceSpec = {\n proxy: {\n kind: 'HTTPProxy',\n spec: {\n allowedEndpoints: [\n // list of standard endpoints suggested by default\n {\n endpointPattern: '/api/v1/labels',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/series',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/metadata',\n method: 'GET',\n },\n {\n endpointPattern: '/api/v1/query',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/query_range',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',\n method: 'GET',\n },\n ],\n url: '',\n },\n },\n };\n\n // For better user experience, save previous states in mind for both mode.\n // This avoids losing everything when the user changes their mind back.\n const [previousSpecDirect, setPreviousSpecDirect] = useState(initialSpecDirect);\n const [previousSpecProxy, setPreviousSpecProxy] = useState(initialSpecProxy);\n\n // When changing mode, remove previous mode's config + append default values for the new mode.\n const handleModeChange = (v: number) => {\n if (tabs[v]?.label == strDirect) {\n setPreviousSpecProxy(value);\n onChange(previousSpecDirect);\n } else if (tabs[v]?.label == strProxy) {\n setPreviousSpecDirect(value);\n onChange(previousSpecProxy);\n }\n };\n\n return (\n <>\n <Typography variant=\"h4\" mb={2}>\n General Settings\n </Typography>\n <TextField\n fullWidth\n label=\"Scrape Interval\"\n value={value.scrapeInterval || ''}\n placeholder={`Default: ${DEFAULT_SCRAPE_INTERVAL}`}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => onChange({ ...value, scrapeInterval: e.target.value as DurationString })}\n />\n <Typography variant=\"h4\" mt={2}>\n HTTP Settings\n </Typography>\n <OptionsEditorRadios\n isReadonly={isReadonly}\n tabs={tabs}\n defaultTab={defaultTab}\n onModeChange={handleModeChange}\n />\n </>\n );\n}\n"],"names":["OptionsEditorRadios","Grid","IconButton","MenuItem","TextField","Typography","React","Fragment","useState","produce","Controller","MinusIcon","PlusIcon","DEFAULT_SCRAPE_INTERVAL","PrometheusDatasourceEditor","props","value","onChange","isReadonly","strDirect","strProxy","buildNewHeaders","oldHeaders","oldName","newName","undefined","keys","Object","newHeaders","reduce","acc","val","tabs","label","content","name","render","field","fieldState","fullWidth","directUrl","error","helperText","message","InputProps","readOnly","InputLabelProps","shrink","e","draft","target","proxy","spec","url","sx","mb","variant","container","spacing","allowedEndpoints","length","map","endpointPattern","method","i","item","xs","itemIndex","select","disabled","onClick","filter","fontStyle","paddingTop","paddingLeft","headers","headerName","secret","directModeId","findIndex","tab","proxyModeId","defaultTab","initialSpecDirect","initialSpecProxy","kind","previousSpecDirect","setPreviousSpecDirect","previousSpecProxy","setPreviousSpecProxy","handleModeChange","v","scrapeInterval","placeholder","mt","onModeChange"],"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;;AAGjC,SAASA,mBAAmB,QAAQ,4BAA4B;AAChE,SA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/BC,aAAa,CAAC,SAAS,EAAEhF,wBAAwB,CAAC;gBAClD+B,YAAY;oBACVC,UAAU3B;gBACZ;gBACA4B,iBAAiB;oBAAEC,QAAQ7B,aAAa,OAAOO;gBAAU;gBACzDR,UAAU,CAAC+B,IAAM/B,SAAS;wBAAE,GAAGD,KAAK;wBAAE4E,gBAAgB5C,EAAEE,MAAM,CAAClC,KAAK;oBAAmB;;0BAEzF,KAACX;gBAAWmD,SAAQ;gBAAKsC,IAAI;0BAAG;;0BAGhC,KAAC9F;gBACCkB,YAAYA;gBACZc,MAAMA;gBACNkD,YAAYA;gBACZa,cAAcL;;;;AAItB"}
1
+ {"version":3,"sources":["../../src/plugins/PrometheusDatasourceEditor.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 { DurationString, RequestHeaders } from '@perses-dev/core';\nimport { OptionsEditorRadios } from '@perses-dev/plugin-system';\nimport { Grid, IconButton, MenuItem, TextField, Typography } from '@mui/material';\nimport React, { Fragment, useState } from 'react';\nimport { produce } from 'immer';\nimport { Controller } from 'react-hook-form';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from './types';\n\nexport interface PrometheusDatasourceEditorProps {\n value: PrometheusDatasourceSpec;\n onChange: (next: PrometheusDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function PrometheusDatasourceEditor(props: PrometheusDatasourceEditorProps) {\n const { value, onChange, isReadonly } = props;\n const strDirect = 'Direct access';\n const strProxy = 'Proxy';\n\n // utilitary function used for headers when renaming a property\n // -> TODO it would be cleaner to manipulate headers as an intermediary list instead, to avoid doing this.\n const buildNewHeaders = (oldHeaders: RequestHeaders | undefined, oldName: string, newName: string) => {\n if (oldHeaders === undefined) return oldHeaders;\n const keys = Object.keys(oldHeaders);\n const newHeaders = keys.reduce<Record<string, string>>((acc, val) => {\n if (val === oldName) {\n acc[newName] = oldHeaders[oldName] || '';\n } else {\n acc[val] = oldHeaders[val] || '';\n }\n return acc;\n }, {});\n\n return { ...newHeaders };\n };\n\n const tabs = [\n {\n label: strDirect,\n content: (\n <Controller\n name=\"URL\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"URL\"\n value={value.directUrl || ''}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n draft.directUrl = e.target.value;\n })\n );\n }}\n />\n )}\n />\n ),\n },\n {\n label: strProxy,\n content: (\n <>\n <Controller\n name=\"URL\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"URL\"\n value={value.proxy?.spec.url || ''}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.url = e.target.value;\n }\n })\n );\n }}\n sx={{ mb: 2 }}\n />\n )}\n />\n <Typography variant=\"h4\" mb={2}>\n Allowed endpoints\n </Typography>\n <Grid container spacing={2} mb={2}>\n {value.proxy?.spec.allowedEndpoints && value.proxy?.spec.allowedEndpoints.length !== 0 ? (\n value.proxy.spec.allowedEndpoints.map(({ endpointPattern, method }, i) => {\n return (\n <Fragment key={i}>\n <Grid item xs={8}>\n <Controller\n name={`Endpoint pattern ${i}`}\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Endpoint pattern\"\n value={endpointPattern}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = draft.proxy.spec.allowedEndpoints?.map(\n (item, itemIndex) => {\n if (i === itemIndex) {\n return {\n endpointPattern: e.target.value,\n method: item.method,\n };\n } else {\n return item;\n }\n }\n );\n }\n })\n );\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={3}>\n <Controller\n name={`Method ${i}`}\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n select\n fullWidth\n label=\"Method\"\n value={method}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = draft.proxy.spec.allowedEndpoints?.map(\n (item, itemIndex) => {\n if (i === itemIndex) {\n return {\n endpointPattern: item.endpointPattern,\n method: e.target.value,\n };\n } else {\n return item;\n }\n }\n );\n }\n })\n );\n }}\n >\n <MenuItem value=\"GET\">GET</MenuItem>\n <MenuItem value=\"POST\">POST</MenuItem>\n <MenuItem value=\"PUT\">PUT</MenuItem>\n <MenuItem value=\"PATCH\">PATCH</MenuItem>\n <MenuItem value=\"DELETE\">DELETE</MenuItem>\n </TextField>\n )}\n />\n </Grid>\n <Grid item xs={1}>\n <Controller\n name={`Remove Endpoint ${i}`}\n render={({ field }) => (\n <IconButton\n {...field}\n disabled={isReadonly}\n // Remove the given allowed endpoint from the list\n onClick={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = [\n ...(draft.proxy.spec.allowedEndpoints?.filter((item, itemIndex) => {\n return itemIndex !== i;\n }) || []),\n ];\n }\n })\n );\n }}\n >\n <MinusIcon />\n </IconButton>\n )}\n />\n </Grid>\n </Fragment>\n );\n })\n ) : (\n <Grid item xs={4}>\n <Typography sx={{ fontStyle: 'italic' }}>None</Typography>\n </Grid>\n )}\n <Grid item xs={12} sx={{ paddingTop: '0px !important', paddingLeft: '5px !important' }}>\n <IconButton\n disabled={isReadonly}\n // Add a new (empty) allowed endpoint to the list\n onClick={() =>\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.allowedEndpoints = [\n ...(draft.proxy.spec.allowedEndpoints ?? []),\n { endpointPattern: '', method: '' },\n ];\n }\n })\n )\n }\n >\n <PlusIcon />\n </IconButton>\n </Grid>\n </Grid>\n <Typography variant=\"h4\" mb={2}>\n Request Headers\n </Typography>\n <Grid container spacing={2} mb={2}>\n {value.proxy?.spec.headers &&\n Object.keys(value.proxy.spec.headers).map((headerName, i) => {\n return (\n <Fragment key={i}>\n <Grid item xs={4}>\n <Controller\n name={`Header name ${i}`}\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Header name\"\n value={headerName}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = buildNewHeaders(\n draft.proxy.spec.headers,\n headerName,\n e.target.value\n );\n }\n })\n );\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={7}>\n <Controller\n name={`Header value ${i}`}\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Header value\"\n value={value.proxy?.spec.headers?.[headerName]}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = {\n ...draft.proxy.spec.headers,\n [headerName]: e.target.value,\n };\n }\n })\n );\n }}\n />\n )}\n />\n </Grid>\n <Grid item xs={1}>\n <Controller\n name={`Remove Header ${i}`}\n render={({ field }) => (\n <IconButton\n {...field}\n disabled={isReadonly}\n // Remove the given header from the list\n onClick={(e) => {\n field.onChange(e);\n const newHeaders = { ...value.proxy?.spec.headers };\n delete newHeaders[headerName];\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = newHeaders;\n }\n })\n );\n }}\n >\n <MinusIcon />\n </IconButton>\n )}\n />\n </Grid>\n </Fragment>\n );\n })}\n <Grid item xs={12} sx={{ paddingTop: '0px !important', paddingLeft: '5px !important' }}>\n <IconButton\n disabled={isReadonly}\n // Add a new (empty) header to the list\n onClick={() =>\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.headers = { ...draft.proxy.spec.headers, '': '' };\n }\n })\n )\n }\n >\n <PlusIcon />\n </IconButton>\n </Grid>\n </Grid>\n\n <Controller\n name=\"Secret\"\n render={({ field, fieldState }) => (\n <TextField\n {...field}\n fullWidth\n label=\"Secret\"\n value={value.proxy?.spec.secret || ''}\n error={!!fieldState.error}\n helperText={fieldState.error?.message}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => {\n field.onChange(e);\n onChange(\n produce(value, (draft) => {\n if (draft.proxy !== undefined) {\n draft.proxy.spec.secret = e.target.value;\n }\n })\n );\n }}\n />\n )}\n />\n </>\n ),\n },\n ];\n\n // Use of findIndex instead of providing hardcoded values to avoid desynchronisatio or\n // bug in case the tabs get eventually swapped in the future.\n const directModeId = tabs.findIndex((tab) => tab.label === strDirect);\n const proxyModeId = tabs.findIndex((tab) => tab.label === strProxy);\n\n // In \"update datasource\" case, set defaultTab to the mode that this datasource is currently relying on.\n // Otherwise (create datasource), set defaultTab to Direct access.\n const defaultTab = value.proxy ? proxyModeId : directModeId;\n\n const initialSpecDirect: PrometheusDatasourceSpec = {\n directUrl: '',\n };\n\n const initialSpecProxy: PrometheusDatasourceSpec = {\n proxy: {\n kind: 'HTTPProxy',\n spec: {\n allowedEndpoints: [\n // list of standard endpoints suggested by default\n {\n endpointPattern: '/api/v1/labels',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/series',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/metadata',\n method: 'GET',\n },\n {\n endpointPattern: '/api/v1/query',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/query_range',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',\n method: 'GET',\n },\n ],\n url: '',\n },\n },\n };\n\n // For better user experience, save previous states in mind for both mode.\n // This avoids losing everything when the user changes their mind back.\n const [previousSpecDirect, setPreviousSpecDirect] = useState(initialSpecDirect);\n const [previousSpecProxy, setPreviousSpecProxy] = useState(initialSpecProxy);\n\n // When changing mode, remove previous mode's config + append default values for the new mode.\n const handleModeChange = (v: number) => {\n if (tabs[v]?.label === strDirect) {\n setPreviousSpecProxy(value);\n onChange(previousSpecDirect);\n } else if (tabs[v]?.label === strProxy) {\n setPreviousSpecDirect(value);\n onChange(previousSpecProxy);\n }\n };\n\n return (\n <>\n <Typography variant=\"h4\" mb={2}>\n General Settings\n </Typography>\n <TextField\n fullWidth\n label=\"Scrape Interval\"\n value={value.scrapeInterval || ''}\n placeholder={`Default: ${DEFAULT_SCRAPE_INTERVAL}`}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => onChange({ ...value, scrapeInterval: e.target.value as DurationString })}\n />\n <Typography variant=\"h4\" mt={2}>\n HTTP Settings\n </Typography>\n <OptionsEditorRadios\n isReadonly={isReadonly}\n tabs={tabs}\n defaultTab={defaultTab}\n onModeChange={handleModeChange}\n />\n </>\n );\n}\n"],"names":["OptionsEditorRadios","Grid","IconButton","MenuItem","TextField","Typography","React","Fragment","useState","produce","Controller","MinusIcon","PlusIcon","DEFAULT_SCRAPE_INTERVAL","PrometheusDatasourceEditor","props","value","onChange","isReadonly","strDirect","strProxy","buildNewHeaders","oldHeaders","oldName","newName","undefined","keys","Object","newHeaders","reduce","acc","val","tabs","label","content","name","render","field","fieldState","fullWidth","directUrl","error","helperText","message","InputProps","readOnly","InputLabelProps","shrink","e","draft","target","proxy","spec","url","sx","mb","variant","container","spacing","allowedEndpoints","length","map","endpointPattern","method","i","item","xs","itemIndex","select","disabled","onClick","filter","fontStyle","paddingTop","paddingLeft","headers","headerName","secret","directModeId","findIndex","tab","proxyModeId","defaultTab","initialSpecDirect","initialSpecProxy","kind","previousSpecDirect","setPreviousSpecDirect","previousSpecProxy","setPreviousSpecProxy","handleModeChange","v","scrapeInterval","placeholder","mt","onModeChange"],"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;;AAGjC,SAASA,mBAAmB,QAAQ,4BAA4B;AAChE,SAASC,IAAI,EAAEC,UAAU,EAAEC,QAAQ,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAgB;AAClF,OAAOC,SAASC,QAAQ,EAAEC,QAAQ,QAAQ,QAAQ;AAClD,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAASC,UAAU,QAAQ,kBAAkB;AAC7C,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,cAAc,uBAAuB;AAC5C,SAASC,uBAAuB,QAAkC,UAAU;AAQ5E,OAAO,SAASC,2BAA2BC,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9F;gBACCkB,YAAYA;gBACZc,MAAMA;gBACNkD,YAAYA;gBACZa,cAAcL;;;;AAItB"}
@@ -1 +1 @@
1
- {"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAsBA,OAAO,EAAE,qBAAqB,EAAqD,MAAM,2BAA2B,CAAC;AAYrH,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CA0GvG,CAAC"}
1
+ {"version":3,"file":"get-time-series-data.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"names":[],"mappings":"AAuBA,OAAO,EAAE,qBAAqB,EAAqD,MAAM,2BAA2B,CAAC;AAerH,OAAO,EAAE,6BAA6B,EAAE,MAAM,2BAA2B,CAAC;AAE1E,eAAO,MAAM,iBAAiB,EAAE,qBAAqB,CAAC,6BAA6B,CAAC,CAAC,mBAAmB,CA0GvG,CAAC"}
@@ -17,7 +17,6 @@ import { parseValueTuple, getDurationStringSeconds, getPrometheusTimeRange, getR
17
17
  import { getFormattedPrometheusSeriesName } from '../../utils';
18
18
  import { DEFAULT_SCRAPE_INTERVAL } from '../types';
19
19
  export const getTimeSeriesData = async (spec, context)=>{
20
- var _response_data;
21
20
  if (spec.query === undefined || spec.query === null || spec.query === '') {
22
21
  // Do not make a request to the backend, instead return an empty TimeSeriesData
23
22
  return {
@@ -62,15 +61,26 @@ export const getTimeSeriesData = async (spec, context)=>{
62
61
  // Get the datasource, using the default Prom Datasource if one isn't specified in the query
63
62
  const client = await context.datasourceStore.getDatasourceClient((_spec_datasource1 = spec.datasource) !== null && _spec_datasource1 !== void 0 ? _spec_datasource1 : DEFAULT_PROM);
64
63
  // Make the request to Prom
65
- const response = await client.rangeQuery({
66
- query,
67
- start,
68
- end,
69
- step
70
- });
71
- var _response_data_result;
64
+ let response;
65
+ switch(context.mode){
66
+ case 'instant':
67
+ response = await client.instantQuery({
68
+ query,
69
+ time: end
70
+ });
71
+ break;
72
+ case 'range':
73
+ default:
74
+ response = await client.rangeQuery({
75
+ query,
76
+ start,
77
+ end,
78
+ step
79
+ });
80
+ break;
81
+ }
72
82
  // TODO: What about error responses from Prom that have a response body?
73
- const result = (_response_data_result = (_response_data = response.data) === null || _response_data === void 0 ? void 0 : _response_data.result) !== null && _response_data_result !== void 0 ? _response_data_result : [];
83
+ const result = response.data;
74
84
  // Custom display for response header warnings, configurable error responses display coming next
75
85
  const notices = [];
76
86
  if (response.status === 'success') {
@@ -93,17 +103,7 @@ export const getTimeSeriesData = async (spec, context)=>{
93
103
  end: fromUnixTime(end)
94
104
  },
95
105
  stepMs: step * 1000,
96
- series: result.map((value)=>{
97
- const { metric, values } = value;
98
- // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.
99
- const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);
100
- return {
101
- name,
102
- values: values.map(parseValueTuple),
103
- formattedName,
104
- labels: metric
105
- };
106
- }),
106
+ series: buildTimeSeries(result, query, seriesNameFormat),
107
107
  metadata: {
108
108
  notices,
109
109
  executedQueryString: query
@@ -111,5 +111,62 @@ export const getTimeSeriesData = async (spec, context)=>{
111
111
  };
112
112
  return chartData;
113
113
  };
114
+ function buildVectorData(data, query, seriesNameFormat) {
115
+ return data.result.map((res)=>{
116
+ const { metric, value } = res;
117
+ // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.
118
+ const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);
119
+ return {
120
+ name,
121
+ values: [
122
+ parseValueTuple(value)
123
+ ],
124
+ formattedName,
125
+ labels: metric
126
+ };
127
+ });
128
+ }
129
+ function buildMatrixData(data, query, seriesNameFormat) {
130
+ return data.result.map((res)=>{
131
+ const { metric, values } = res;
132
+ // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.
133
+ const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);
134
+ return {
135
+ name,
136
+ values: values.map(parseValueTuple),
137
+ formattedName,
138
+ labels: metric
139
+ };
140
+ });
141
+ }
142
+ function buildScalarData(data, query, seriesNameFormat) {
143
+ const { name, formattedName } = getFormattedPrometheusSeriesName(query, {}, seriesNameFormat);
144
+ return [
145
+ {
146
+ name,
147
+ values: [
148
+ parseValueTuple(data.result)
149
+ ],
150
+ formattedName
151
+ }
152
+ ];
153
+ }
154
+ function buildTimeSeries(data, query, seriesNameFormat) {
155
+ if (!data) {
156
+ return [];
157
+ }
158
+ const resultType = data.resultType;
159
+ switch(resultType){
160
+ case 'vector':
161
+ return buildVectorData(data, query, seriesNameFormat);
162
+ case 'matrix':
163
+ return buildMatrixData(data, query, seriesNameFormat);
164
+ case 'scalar':
165
+ return buildScalarData(data, query, seriesNameFormat);
166
+ default:
167
+ console.warn('Unknown result type', resultType, data);
168
+ return [];
169
+ }
170
+ }
114
171
 
115
172
  //# sourceMappingURL=get-time-series-data.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.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 {\n DatasourceSpec,\n DurationString,\n formatDuration,\n msToPrometheusDuration,\n Notice,\n parseDurationString,\n TimeSeriesData,\n} from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceTemplateVariables, replaceTemplateVariable } from '@perses-dev/plugin-system';\nimport { fromUnixTime, milliseconds } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const datasource = (await context.datasourceStore.getDatasource(\n spec.datasource ?? DEFAULT_PROM\n )) as DatasourceSpec<PrometheusDatasourceSpec>;\n const datasourceScrapeInterval = Math.trunc(\n milliseconds(parseDurationString(datasource.plugin.spec.scrapeInterval ?? DEFAULT_SCRAPE_INTERVAL)) / 1000\n );\n\n const minStep =\n getDurationStringSeconds(\n // resolve any variable that may have been provided\n // TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here\n replaceTemplateVariables(spec.minStep as string, context.variableState) as DurationString\n ) ?? datasourceScrapeInterval;\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n // Replace template variable placeholders in PromQL query\n const intervalMs = context.suggestedStepMs ?? step * 1000; // Step is in seconds\n let query = replaceTemplateVariable(spec.query, '__interval_ms', intervalMs.toString());\n query = replaceTemplateVariable(spec.query, '__interval', formatDuration(msToPrometheusDuration(intervalMs)));\n\n const scrapeIntervalMs = minStep * 1000;\n // The $__rate_interval variable is meant to be used in the rate function.\n // It is defined as max($__interval + Scrape interval, 4 * Scrape interval), where Scrape interval is the Min step setting (a setting per PromQL query),\n // if any is set, and otherwise the Scrape interval as set in the Prometheus datasource\n const rateIntervalMs = Math.max(intervalMs + scrapeIntervalMs, 4 * scrapeIntervalMs);\n query = replaceTemplateVariable(query, '__rate_interval', formatDuration(msToPrometheusDuration(rateIntervalMs)));\n query = replaceTemplateVariables(query, context.variableState);\n\n let seriesNameFormat = spec.seriesNameFormat;\n // if series name format is defined, replace template variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceTemplateVariables(seriesNameFormat, context.variableState);\n }\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n\n // Make the request to Prom\n const response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data?.result ?? [];\n\n // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n series: result.map((value) => {\n const { metric, values } = value;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n labels: metric,\n };\n }),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n"],"names":["formatDuration","msToPrometheusDuration","parseDurationString","replaceTemplateVariables","replaceTemplateVariable","fromUnixTime","milliseconds","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getFormattedPrometheusSeriesName","DEFAULT_SCRAPE_INTERVAL","getTimeSeriesData","spec","context","response","query","undefined","series","datasource","datasourceStore","getDatasource","datasourceScrapeInterval","Math","trunc","plugin","scrapeInterval","minStep","variableState","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","floor","alignedStart","intervalMs","toString","scrapeIntervalMs","rateIntervalMs","max","seriesNameFormat","client","getDatasourceClient","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","map","value","metric","values","name","formattedName","labels","metadata","executedQueryString"],"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,SAGEA,cAAc,EACdC,sBAAsB,EAEtBC,mBAAmB,QAEd,mBAAmB;AAC1B,SAAgCC,wBAAwB,EAAEC,uBAAuB,QAAQ,4BAA4B;AACrH,SAASC,YAAY,EAAEC,YAAY,QAAQ,WAAW;AACtD,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,QACP,cAAc;AACrB,SAASC,gCAAgC,QAAQ,cAAc;AAC/D,SAASC,uBAAuB,QAAkC,WAAW;AAG7E,OAAO,MAAMC,oBAA+F,OAC1GC,MACAC;QA+DeC;IA7Df,IAAIF,KAAKG,KAAK,KAAKC,aAAaJ,KAAKG,KAAK,KAAK,QAAQH,KAAKG,KAAK,KAAK,IAAI;QACxE,+EAA+E;QAC/E,OAAO;YAAEE,QAAQ,EAAE;QAAC;IACtB;QAGEL;IADF,MAAMM,aAAc,MAAML,QAAQM,eAAe,CAACC,aAAa,CAC7DR,CAAAA,mBAAAA,KAAKM,UAAU,cAAfN,8BAAAA,mBA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AAGvD,iCAAiCM,OAAO8C,QAAQjB;YAEhF,OAAO;gBACLmB;gBACAD,QAAQA,OAAOH,GAAG,CAACvD;gBACnB4D;gBACAC,QAAQJ;YACV;QACF;QACAK,UAAU;YACRhB;YACAiB,qBAAqBpD;QACvB;IACF;IAEA,OAAO0C;AACT,EAAE"}
1
+ {"version":3,"sources":["../../../src/plugins/prometheus-time-series-query/get-time-series-data.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 {\n DatasourceSpec,\n DurationString,\n formatDuration,\n msToPrometheusDuration,\n Notice,\n parseDurationString,\n TimeSeries,\n TimeSeriesData,\n} from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceTemplateVariables, replaceTemplateVariable } from '@perses-dev/plugin-system';\nimport { fromUnixTime, milliseconds } from 'date-fns';\nimport {\n parseValueTuple,\n PrometheusClient,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n DEFAULT_PROM,\n MatrixData,\n VectorData,\n ScalarData,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (spec.query === undefined || spec.query === null || spec.query === '') {\n // Do not make a request to the backend, instead return an empty TimeSeriesData\n return { series: [] };\n }\n\n const datasource = (await context.datasourceStore.getDatasource(\n spec.datasource ?? DEFAULT_PROM\n )) as DatasourceSpec<PrometheusDatasourceSpec>;\n const datasourceScrapeInterval = Math.trunc(\n milliseconds(parseDurationString(datasource.plugin.spec.scrapeInterval ?? DEFAULT_SCRAPE_INTERVAL)) / 1000\n );\n\n const minStep =\n getDurationStringSeconds(\n // resolve any variable that may have been provided\n // TODO add a validation check to make sure the variable is a DurationString, to avoid the back & forth cast here\n replaceTemplateVariables(spec.minStep as string, context.variableState) as DurationString\n ) ?? datasourceScrapeInterval;\n const timeRange = getPrometheusTimeRange(context.timeRange);\n const step = getRangeStep(timeRange, minStep, undefined, context.suggestedStepMs); // TODO: resolution\n\n // Align the time range so that it's a multiple of the step\n let { start, end } = timeRange;\n const utcOffsetSec = new Date().getTimezoneOffset() * 60;\n\n const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;\n const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;\n start = alignedStart;\n end = alignedEnd;\n\n // Replace template variable placeholders in PromQL query\n const intervalMs = context.suggestedStepMs ?? step * 1000; // Step is in seconds\n let query = replaceTemplateVariable(spec.query, '__interval_ms', intervalMs.toString());\n query = replaceTemplateVariable(spec.query, '__interval', formatDuration(msToPrometheusDuration(intervalMs)));\n\n const scrapeIntervalMs = minStep * 1000;\n // The $__rate_interval variable is meant to be used in the rate function.\n // It is defined as max($__interval + Scrape interval, 4 * Scrape interval), where Scrape interval is the Min step setting (a setting per PromQL query),\n // if any is set, and otherwise the Scrape interval as set in the Prometheus datasource\n const rateIntervalMs = Math.max(intervalMs + scrapeIntervalMs, 4 * scrapeIntervalMs);\n query = replaceTemplateVariable(query, '__rate_interval', formatDuration(msToPrometheusDuration(rateIntervalMs)));\n query = replaceTemplateVariables(query, context.variableState);\n\n let seriesNameFormat = spec.seriesNameFormat;\n // if series name format is defined, replace template variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceTemplateVariables(seriesNameFormat, context.variableState);\n }\n\n // Get the datasource, using the default Prom Datasource if one isn't specified in the query\n const client: PrometheusClient = await context.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_PROM);\n\n // Make the request to Prom\n let response;\n switch (context.mode) {\n case 'instant':\n response = await client.instantQuery({\n query,\n time: end,\n });\n break;\n case 'range':\n default:\n response = await client.rangeQuery({\n query,\n start,\n end,\n step,\n });\n break;\n }\n\n // TODO: What about error responses from Prom that have a response body?\n const result = response.data;\n\n // Custom display for response header warnings, configurable error responses display coming next\n const notices: Notice[] = [];\n if (response.status === 'success') {\n const warnings = response.warnings ?? [];\n const warningMessage = warnings[0] ?? '';\n if (warningMessage !== '') {\n notices.push({\n type: 'warning',\n message: warningMessage,\n });\n }\n }\n\n // Transform response\n const chartData: TimeSeriesData = {\n // Return the time range and step we actually used for the query\n timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },\n stepMs: step * 1000,\n\n series: buildTimeSeries(result, query, seriesNameFormat),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n\nfunction buildVectorData(data: VectorData, query: string, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, value } = res;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n return {\n name,\n values: [parseValueTuple(value)],\n formattedName,\n labels: metric,\n };\n });\n}\n\nfunction buildMatrixData(data: MatrixData, query: string, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, values } = res;\n\n // Account for seriesNameFormat from query editor when determining name to show in legend, tooltip, etc.\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, metric, seriesNameFormat);\n\n return {\n name,\n values: values.map(parseValueTuple),\n formattedName,\n labels: metric,\n };\n });\n}\n\nfunction buildScalarData(data: ScalarData, query: string, seriesNameFormat: string | undefined): TimeSeries[] {\n const { name, formattedName } = getFormattedPrometheusSeriesName(query, {}, seriesNameFormat);\n return [\n {\n name,\n values: [parseValueTuple(data.result)],\n formattedName,\n },\n ];\n}\n\nfunction buildTimeSeries(\n data: MatrixData | VectorData | ScalarData | undefined,\n query: string,\n seriesNameFormat?: string\n): TimeSeries[] {\n if (!data) {\n return [];\n }\n\n const resultType = data.resultType;\n\n switch (resultType) {\n case 'vector':\n return buildVectorData(data, query, seriesNameFormat);\n case 'matrix':\n return buildMatrixData(data, query, seriesNameFormat);\n case 'scalar':\n return buildScalarData(data, query, seriesNameFormat);\n default:\n console.warn('Unknown result type', resultType, data);\n return [];\n }\n}\n"],"names":["formatDuration","msToPrometheusDuration","parseDurationString","replaceTemplateVariables","replaceTemplateVariable","fromUnixTime","milliseconds","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","getFormattedPrometheusSeriesName","DEFAULT_SCRAPE_INTERVAL","getTimeSeriesData","spec","context","query","undefined","series","datasource","datasourceStore","getDatasource","datasourceScrapeInterval","Math","trunc","plugin","scrapeInterval","minStep","variableState","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","floor","alignedStart","intervalMs","toString","scrapeIntervalMs","rateIntervalMs","max","seriesNameFormat","client","getDatasourceClient","response","mode","instantQuery","time","rangeQuery","result","data","notices","status","warnings","warningMessage","push","type","message","chartData","stepMs","buildTimeSeries","metadata","executedQueryString","buildVectorData","map","res","metric","value","name","formattedName","values","labels","buildMatrixData","buildScalarData","resultType","console","warn"],"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,SAGEA,cAAc,EACdC,sBAAsB,EAEtBC,mBAAmB,QAGd,mBAAmB;AAC1B,SAAgCC,wBAAwB,EAAEC,uBAAuB,QAAQ,4BAA4B;AACrH,SAASC,YAAY,EAAEC,YAAY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AAa,EAAE6B,gBAAoC;IAC5F,MAAM,EAAE2B,IAAI,EAAEC,aAAa,EAAE,GAAG9D,iCAAiCK,OAAO,CAAC,GAAG6B;IAC5E,OAAO;QACL;YACE2B;YACAE,QAAQ;gBAACpE,gBAAgBgD,KAAKD,MAAM;aAAE;YACtCoB;QACF;KACD;AACH;AAEA,SAAST,gBACPV,IAAsD,EACtDtC,KAAa,EACb6B,gBAAyB;IAEzB,IAAI,CAACS,MAAM;QACT,OAAO,EAAE;IACX;IAEA,MAAMwB,aAAaxB,KAAKwB,UAAU;IAElC,OAAQA;QACN,KAAK;YACH,OAAOX,gBAAgBb,MAAMtC,OAAO6B;QACtC,KAAK;YACH,OAAO+B,gBAAgBtB,MAAMtC,OAAO6B;QACtC,KAAK;YACH,OAAOgC,gBAAgBvB,MAAMtC,OAAO6B;QACtC;YACEkC,QAAQC,IAAI,CAAC,uBAAuBF,YAAYxB;YAChD,OAAO,EAAE;IACb;AACF"}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAOlD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM,CAMxF;AAyBD,wBAAgB,+BAA+B,CAC7C,YAAY,EAAE;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,EACD,EAAE,cAAc,EAAE,GAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAO,UAqBtD;AAKD,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;;;EAYjG"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils/utils.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAOlD,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,GAAG,MAAM,CAMxF;AAyBD,wBAAgB,+BAA+B,CAC7C,YAAY,EAAE;IACZ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB,EACD,EAAE,cAAc,EAAE,GAAE;IAAE,cAAc,CAAC,EAAE,OAAO,CAAA;CAAO,UAkBtD;AAKD,wBAAgB,gCAAgC,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;;;EAQjG"}
@@ -10,7 +10,6 @@
10
10
  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
- import { isEmptyObject } from '@perses-dev/core';
14
13
  /*
15
14
  * Formatter used for series name display in legends and tooltips.
16
15
  * Regex replaces label {{ name }} with resolved label value.
@@ -40,34 +39,27 @@ import { isEmptyObject } from '@perses-dev/core';
40
39
  return `{${labelStrings.join(',')}}`;
41
40
  }
42
41
  /*
43
- * Metric labels formattter which checks for __name__ and outputs valid PromQL for series name
42
+ * Metric labels formatter which checks for __name__ and outputs valid PromQL for series name
44
43
  */ export function getUniqueKeyForPrometheusResult(metricLabels, { removeExprWrap } = {}) {
45
44
  const metricNameKey = '__name__';
46
- if (metricLabels) {
47
- if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {
48
- const stringifiedLabels = stringifyPrometheusMetricLabels({
49
- ...metricLabels,
50
- [metricNameKey]: undefined
51
- }, removeExprWrap);
52
- if (removeExprWrap === true) {
53
- return `${stringifiedLabels}`;
54
- } else {
55
- return `${metricLabels[metricNameKey]}${stringifiedLabels}`;
56
- }
45
+ if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {
46
+ const stringifiedLabels = stringifyPrometheusMetricLabels({
47
+ ...metricLabels,
48
+ [metricNameKey]: undefined
49
+ }, removeExprWrap);
50
+ if (removeExprWrap) {
51
+ return `${stringifiedLabels}`;
52
+ } else {
53
+ return `${metricLabels[metricNameKey]}${stringifiedLabels}`;
57
54
  }
58
- return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);
59
55
  }
60
- return '';
56
+ return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);
61
57
  }
62
58
  /*
63
59
  * Determine human-readable series name to be used in legend and tooltip
64
60
  */ export function getFormattedPrometheusSeriesName(query, metric, formatter) {
65
61
  // Name the series after the metric labels by default.
66
- // Use the query if no metric or metric labels are empty.
67
- let name = getUniqueKeyForPrometheusResult(metric);
68
- if (name === '' || isEmptyObject(metric)) {
69
- name = query;
70
- }
62
+ const name = getUniqueKeyForPrometheusResult(metric);
71
63
  // Query editor allows you to define an optional seriesNameFormat property.
72
64
  // This controls the regex used to customize legend and tooltip display.
73
65
  const formattedName = formatter ? formatSeriesName(formatter, metric) : name;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/utils/utils.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 { isEmptyObject } from '@perses-dev/core';\nimport { Metric } from '../model/api-types';\n\n/**\n * Types for metric labels, used in seriesNameFormat implementation\n */\nexport type SeriesLabels = Record<string, string>;\n\n/*\n * Formatter used for series name display in legends and tooltips.\n * Regex replaces label {{ name }} with resolved label value.\n * If no resolved value, return empty string instead of the token inside double curly braces.\n */\nexport function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string {\n const resolveLabelsRegex = /\\{\\{\\s*(.+?)\\s*\\}\\}/g;\n return inputFormat.replace(resolveLabelsRegex, (_match, token) => {\n const resolvedValue = seriesLabels[token] ?? '';\n return resolvedValue;\n });\n}\n\n/*\n * Stringifies object of labels into valid PromQL for querying metric by label\n */\nfunction stringifyPrometheusMetricLabels(labels: { [key: string]: unknown }, removeExprWrap?: boolean) {\n const labelStrings: string[] = [];\n Object.keys(labels)\n .sort()\n .forEach((labelName) => {\n const labelValue = labels[labelName];\n if (labelValue !== undefined) {\n if (removeExprWrap) {\n labelStrings.push(`\"${labelName}\":\"${labelValue}\"`);\n } else {\n labelStrings.push(`${labelName}=\"${labelValue}\"`);\n }\n }\n });\n return `{${labelStrings.join(',')}}`;\n}\n\n/*\n * Metric labels formattter which checks for __name__ and outputs valid PromQL for series name\n */\nexport function getUniqueKeyForPrometheusResult(\n metricLabels: {\n [key: string]: string;\n },\n { removeExprWrap }: { removeExprWrap?: boolean } = {}\n) {\n const metricNameKey = '__name__';\n if (metricLabels) {\n if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {\n const stringifiedLabels = stringifyPrometheusMetricLabels(\n {\n ...metricLabels,\n [metricNameKey]: undefined,\n },\n removeExprWrap\n );\n if (removeExprWrap === true) {\n return `${stringifiedLabels}`;\n } else {\n return `${metricLabels[metricNameKey]}${stringifiedLabels}`;\n }\n }\n return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);\n }\n return '';\n}\n\n/*\n * Determine human-readable series name to be used in legend and tooltip\n */\nexport function getFormattedPrometheusSeriesName(query: string, metric: Metric, formatter?: string) {\n // Name the series after the metric labels by default.\n // Use the query if no metric or metric labels are empty.\n let name = getUniqueKeyForPrometheusResult(metric);\n if (name === '' || isEmptyObject(metric)) {\n name = query;\n }\n\n // Query editor allows you to define an optional seriesNameFormat property.\n // This controls the regex used to customize legend and tooltip display.\n const formattedName = formatter ? formatSeriesName(formatter, metric) : name;\n return { name, formattedName };\n}\n"],"names":["isEmptyObject","formatSeriesName","inputFormat","seriesLabels","resolveLabelsRegex","replace","_match","token","resolvedValue","stringifyPrometheusMetricLabels","labels","removeExprWrap","labelStrings","Object","keys","sort","forEach","labelName","labelValue","undefined","push","join","getUniqueKeyForPrometheusResult","metricLabels","metricNameKey","prototype","hasOwnProperty","call","stringifiedLabels","getFormattedPrometheusSeriesName","query","metric","formatter","name","formattedName"],"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,aAAa,QAAQ,mBAAmB;AAQjD;;;;CAIC,GACD,OAAO,SAASC,iBAAiBC,WAAmB,EAAEC,YAA0B;IAC9E,MAAMC,qBAAqB;IAC3B,OAAOF,YAAYG,OAAO,CAACD,oBAAoB,CAACE,QAAQC;YAChCJ;QAAtB,MAAMK,gBAAgBL,CAAAA,sBAAAA,YAAY,CAACI,MAAM,cAAnBJ,iCAAAA,sBAAuB;QAC7C,OAAOK;IACT;AACF;AAEA;;CAEC,GACD,SAASC,gCAAgCC,MAAkC,EAAEC,cAAwB;IACnG,MAAMC,eAAyB,EAAE;IACjCC,OAAOC,IAAI,CAACJ,QACTK,IAAI,GACJC,OAAO,CAAC,CAACC;QACR,MAAMC,aAAaR,MAAM,CAACO,UAAU;QACpC,IAAIC,eAAeC,WAAW;YAC5B,IAAIR,gBAAgB;gBAClBC,aAAaQ,IAAI,CAAC,CAAC,CAAC,EAAEH,UAAU,GAAG,EAAEC,WAAW,CAAC,CAAC;YACpD,OAAO;gBACLN,aAAaQ,IAAI,CAAC,CAAC,EAAEH,UAAU,EAAE,EAAEC,WAAW,CAAC,CAAC;YAClD;QACF;IACF;IACF,OAAO,CAAC,CAAC,EAAEN,aAAaS,IAAI,CAAC,KAAK,CAAC,CAAC;AACtC;AAEA;;CAEC,GACD,OAAO,SAASC,gCACdC,YAEC,EACD,EAAEZ,cAAc,EAAgC,GAAG,CAAC,CAAC;IAErD,MAAMa,gBAAgB;IACtB,IAAID,cAAc;QAChB,IAAIV,OAAOY,SAAS,CAACC,cAAc,CAACC,IAAI,CAACJ,cAAcC,gBAAgB;YACrE,MAAMI,oBAAoBnB,gCACxB;gBACE,GAAGc,YAAY;gBACf,CAACC,cAAc,EAAEL;YACnB,GACAR;YAEF,IAAIA,mBAAmB,MAAM;gBAC3B,OAAO,CAAC,EAAEiB,kBAAkB,CAAC;YAC/B,OAAO;gBACL,OAAO,CAAC,EAAEL,YAAY,CAACC,cAAc,CAAC,EAAEI,kBAAkB,CAAC;YAC7D;QACF;QACA,OAAOnB,gCAAgCc,cAAcZ;IACvD;IACA,OAAO;AACT;AAEA;;CAEC,GACD,OAAO,SAASkB,iCAAiCC,KAAa,EAAEC,MAAc,EAAEC,SAAkB;IAChG,sDAAsD;IACtD,yDAAyD;IACzD,IAAIC,OAAOX,gCAAgCS;IAC3C,IAAIE,SAAS,MAAMjC,cAAc+B,SAAS;QACxCE,OAAOH;IACT;IAEA,2EAA2E;IAC3E,wEAAwE;IACxE,MAAMI,gBAAgBF,YAAY/B,iBAAiB+B,WAAWD,UAAUE;IACxE,OAAO;QAAEA;QAAMC;IAAc;AAC/B"}
1
+ {"version":3,"sources":["../../src/utils/utils.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 { Metric } from '../model/api-types';\n\n/**\n * Types for metric labels, used in seriesNameFormat implementation\n */\nexport type SeriesLabels = Record<string, string>;\n\n/*\n * Formatter used for series name display in legends and tooltips.\n * Regex replaces label {{ name }} with resolved label value.\n * If no resolved value, return empty string instead of the token inside double curly braces.\n */\nexport function formatSeriesName(inputFormat: string, seriesLabels: SeriesLabels): string {\n const resolveLabelsRegex = /\\{\\{\\s*(.+?)\\s*\\}\\}/g;\n return inputFormat.replace(resolveLabelsRegex, (_match, token) => {\n const resolvedValue = seriesLabels[token] ?? '';\n return resolvedValue;\n });\n}\n\n/*\n * Stringifies object of labels into valid PromQL for querying metric by label\n */\nfunction stringifyPrometheusMetricLabels(labels: { [key: string]: unknown }, removeExprWrap?: boolean) {\n const labelStrings: string[] = [];\n Object.keys(labels)\n .sort()\n .forEach((labelName) => {\n const labelValue = labels[labelName];\n if (labelValue !== undefined) {\n if (removeExprWrap) {\n labelStrings.push(`\"${labelName}\":\"${labelValue}\"`);\n } else {\n labelStrings.push(`${labelName}=\"${labelValue}\"`);\n }\n }\n });\n return `{${labelStrings.join(',')}}`;\n}\n\n/*\n * Metric labels formatter which checks for __name__ and outputs valid PromQL for series name\n */\nexport function getUniqueKeyForPrometheusResult(\n metricLabels: {\n [key: string]: string;\n },\n { removeExprWrap }: { removeExprWrap?: boolean } = {}\n) {\n const metricNameKey = '__name__';\n if (Object.prototype.hasOwnProperty.call(metricLabels, metricNameKey)) {\n const stringifiedLabels = stringifyPrometheusMetricLabels(\n {\n ...metricLabels,\n [metricNameKey]: undefined,\n },\n removeExprWrap\n );\n if (removeExprWrap) {\n return `${stringifiedLabels}`;\n } else {\n return `${metricLabels[metricNameKey]}${stringifiedLabels}`;\n }\n }\n return stringifyPrometheusMetricLabels(metricLabels, removeExprWrap);\n}\n\n/*\n * Determine human-readable series name to be used in legend and tooltip\n */\nexport function getFormattedPrometheusSeriesName(query: string, metric: Metric, formatter?: string) {\n // Name the series after the metric labels by default.\n const name = getUniqueKeyForPrometheusResult(metric);\n\n // Query editor allows you to define an optional seriesNameFormat property.\n // This controls the regex used to customize legend and tooltip display.\n const formattedName = formatter ? formatSeriesName(formatter, metric) : name;\n return { name, formattedName };\n}\n"],"names":["formatSeriesName","inputFormat","seriesLabels","resolveLabelsRegex","replace","_match","token","resolvedValue","stringifyPrometheusMetricLabels","labels","removeExprWrap","labelStrings","Object","keys","sort","forEach","labelName","labelValue","undefined","push","join","getUniqueKeyForPrometheusResult","metricLabels","metricNameKey","prototype","hasOwnProperty","call","stringifiedLabels","getFormattedPrometheusSeriesName","query","metric","formatter","name","formattedName"],"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;;;;CAIC,GACD,OAAO,SAASA,iBAAiBC,WAAmB,EAAEC,YAA0B;IAC9E,MAAMC,qBAAqB;IAC3B,OAAOF,YAAYG,OAAO,CAACD,oBAAoB,CAACE,QAAQC;YAChCJ;QAAtB,MAAMK,gBAAgBL,CAAAA,sBAAAA,YAAY,CAACI,MAAM,cAAnBJ,iCAAAA,sBAAuB;QAC7C,OAAOK;IACT;AACF;AAEA;;CAEC,GACD,SAASC,gCAAgCC,MAAkC,EAAEC,cAAwB;IACnG,MAAMC,eAAyB,EAAE;IACjCC,OAAOC,IAAI,CAACJ,QACTK,IAAI,GACJC,OAAO,CAAC,CAACC;QACR,MAAMC,aAAaR,MAAM,CAACO,UAAU;QACpC,IAAIC,eAAeC,WAAW;YAC5B,IAAIR,gBAAgB;gBAClBC,aAAaQ,IAAI,CAAC,CAAC,CAAC,EAAEH,UAAU,GAAG,EAAEC,WAAW,CAAC,CAAC;YACpD,OAAO;gBACLN,aAAaQ,IAAI,CAAC,CAAC,EAAEH,UAAU,EAAE,EAAEC,WAAW,CAAC,CAAC;YAClD;QACF;IACF;IACF,OAAO,CAAC,CAAC,EAAEN,aAAaS,IAAI,CAAC,KAAK,CAAC,CAAC;AACtC;AAEA;;CAEC,GACD,OAAO,SAASC,gCACdC,YAEC,EACD,EAAEZ,cAAc,EAAgC,GAAG,CAAC,CAAC;IAErD,MAAMa,gBAAgB;IACtB,IAAIX,OAAOY,SAAS,CAACC,cAAc,CAACC,IAAI,CAACJ,cAAcC,gBAAgB;QACrE,MAAMI,oBAAoBnB,gCACxB;YACE,GAAGc,YAAY;YACf,CAACC,cAAc,EAAEL;QACnB,GACAR;QAEF,IAAIA,gBAAgB;YAClB,OAAO,CAAC,EAAEiB,kBAAkB,CAAC;QAC/B,OAAO;YACL,OAAO,CAAC,EAAEL,YAAY,CAACC,cAAc,CAAC,EAAEI,kBAAkB,CAAC;QAC7D;IACF;IACA,OAAOnB,gCAAgCc,cAAcZ;AACvD;AAEA;;CAEC,GACD,OAAO,SAASkB,iCAAiCC,KAAa,EAAEC,MAAc,EAAEC,SAAkB;IAChG,sDAAsD;IACtD,MAAMC,OAAOX,gCAAgCS;IAE7C,2EAA2E;IAC3E,wEAAwE;IACxE,MAAMG,gBAAgBF,YAAY/B,iBAAiB+B,WAAWD,UAAUE;IACxE,OAAO;QAAEA;QAAMC;IAAc;AAC/B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@perses-dev/prometheus-plugin",
3
- "version": "0.45.0",
3
+ "version": "0.46.0-rc1",
4
4
  "description": "Prometheus plugin for Perses",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://github.com/perses/perses/blob/main/README.md",
@@ -31,9 +31,9 @@
31
31
  "dependencies": {
32
32
  "@lezer/highlight": "^1.0.0",
33
33
  "@lezer/lr": "^1.2.0",
34
- "@perses-dev/components": "0.45.0",
35
- "@perses-dev/core": "0.45.0",
36
- "@perses-dev/plugin-system": "0.45.0",
34
+ "@perses-dev/components": "0.46.0-rc1",
35
+ "@perses-dev/core": "0.46.0-rc1",
36
+ "@perses-dev/plugin-system": "0.46.0-rc1",
37
37
  "@prometheus-io/codemirror-promql": "^0.43.0",
38
38
  "@uiw/react-codemirror": "^4.19.1",
39
39
  "date-fns": "^2.28.0",
package/plugin.json CHANGED
@@ -41,7 +41,7 @@
41
41
  "pluginType": "TimeSeriesQuery",
42
42
  "kind": "PrometheusTimeSeriesQuery",
43
43
  "display": {
44
- "name": "Prometheus Range Query",
44
+ "name": "Prometheus Query",
45
45
  "description": ""
46
46
  }
47
47
  },