@perses-dev/prometheus-plugin 0.56.0 → 0.57.0-beta.0
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.
- package/__mf/js/Prometheus.2bb892ab.js +6 -0
- package/__mf/js/async/1233.0ab88b51.js +1 -0
- package/__mf/js/async/1324.ce01eced.js +1 -0
- package/__mf/js/async/1432.0c3e4ed0.js +1 -0
- package/__mf/js/async/1490.7e5068f1.js +22 -0
- package/__mf/js/async/1605.dc180cb8.js +110 -0
- package/__mf/js/async/1616.7587ce79.js +1 -0
- package/__mf/js/async/1728.af16c4ec.js +1 -0
- package/__mf/js/async/1969.372d36b8.js +1 -0
- package/__mf/js/async/2043.d0fbb886.js +2 -0
- package/__mf/js/async/2186.e58838a5.js +38 -0
- package/__mf/js/async/2506.1e336b3b.js +1 -0
- package/__mf/js/async/2984.7182c2f5.js +1 -0
- package/__mf/js/async/2999.1d8347df.js +1 -0
- package/__mf/js/async/3184.6b4ad42e.js +1 -0
- package/__mf/js/async/3664.ba8b26b6.js +2 -0
- package/__mf/js/async/392.7cda691a.js +2 -0
- package/__mf/js/async/3963.5fef6ffb.js +1 -0
- package/__mf/js/async/3996.69a9c1dc.js +1 -0
- package/__mf/js/async/{1964.1d168a86.js → 4121.828d661d.js} +2 -2
- package/__mf/js/async/4626.173e602a.js +1 -0
- package/__mf/js/async/4987.c12b89cb.js +1 -0
- package/__mf/js/async/{8930.700a5439.js → 5002.e4f54e8e.js} +1 -1
- package/__mf/js/async/5071.e1c33fa7.js +1 -0
- package/__mf/js/async/529.2303b01b.js +1 -0
- package/__mf/js/async/5440.c13c3533.js +2 -0
- package/__mf/js/async/5501.6166367c.js +2 -0
- package/__mf/js/async/{5214.0fca84ed.js → 5587.4d72fc35.js} +1 -1
- package/__mf/js/async/5763.4ba478ff.js +1 -0
- package/__mf/js/async/5922.d1619ac1.js +1 -0
- package/__mf/js/async/6149.19799c37.js +7 -0
- package/__mf/js/async/6274.478a68f8.js +2 -0
- package/__mf/js/async/6283.181cb622.js +2 -0
- package/__mf/js/async/6969.b959b6f8.js +1 -0
- package/__mf/js/async/{4062.06f48b93.js → 7177.205c9aaf.js} +1 -1
- package/__mf/js/async/7192.d835931b.js +1 -0
- package/__mf/js/async/7894.9c5245d7.js +1 -0
- package/__mf/js/async/7968.6ac0ce96.js +1 -0
- package/__mf/js/async/7978.9532d5b8.js +1 -0
- package/__mf/js/async/8356.789e1dfb.js +1 -0
- package/__mf/js/async/8470.9b14a625.js +2 -0
- package/__mf/js/async/873.448eab23.js +1 -0
- package/__mf/js/async/8888.59eb50a2.js +1 -0
- package/__mf/js/async/9020.c19782f1.js +1 -0
- package/__mf/js/async/9184.43a8d927.js +1 -0
- package/__mf/js/async/9235.36c3cd8c.js +1 -0
- package/__mf/js/async/9351.715f25c3.js +1 -0
- package/__mf/js/async/941.53b13124.js +2 -0
- package/__mf/js/async/9518.38e38a33.js +1 -0
- package/__mf/js/async/9588.9081c7de.js +1 -0
- package/__mf/js/async/9605.a92ec9c1.js +1 -0
- package/__mf/js/async/9836.00da6086.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusDatasource.6f63e147.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusExplorer.584a073d.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.40984a4d.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.bd3eb00c.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.5cca8417.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.f59141f4.js +1 -0
- package/__mf/js/main.9617b605.js +6 -0
- package/lib/bootstrap.js +1 -1
- package/lib/bootstrap.js.map +1 -1
- package/lib/cjs/components/PromQLEditor.js +4 -7
- package/lib/cjs/components/promql/ast.js +10 -10
- package/lib/cjs/components/promql/format.js +3 -3
- package/lib/cjs/components/promql/utils.js +5 -5
- package/lib/cjs/components/query.js +3 -3
- package/lib/cjs/explore/PrometheusExplorer.js +10 -6
- package/lib/cjs/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js +4 -4
- package/lib/cjs/explore/PrometheusMetricsFinder/display/list/MetricList.js +3 -3
- package/lib/cjs/explore/PrometheusMetricsFinder/filter/FilterInputs.js +4 -4
- package/lib/cjs/explore/PrometheusMetricsFinder/overview/MetricOverview.js +3 -3
- package/lib/cjs/explore/PrometheusMetricsFinder/overview/tabs/JobTab.js +4 -4
- package/lib/cjs/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.js +4 -4
- package/lib/cjs/explore/PrometheusMetricsFinder/utils.js +5 -5
- package/lib/cjs/index-federation.js +12 -12
- package/lib/cjs/model/parse-sample-values.js +3 -3
- package/lib/cjs/model/prometheus-client.js +29 -19
- package/lib/cjs/model/prometheus-selectors.js +5 -5
- package/lib/cjs/model/time.js +4 -4
- package/lib/cjs/plugins/PrometheusDatasourceEditor.js +175 -2
- package/lib/cjs/plugins/prometheus-datasource.js +17 -9
- package/lib/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +36 -1
- package/lib/cjs/plugins/prometheus-time-series-query/query-editor-model.js +4 -4
- package/lib/cjs/plugins/prometheus-variables.js +52 -33
- package/lib/cjs/utils/utils.js +4 -4
- package/lib/components/PromQLEditor.d.ts +5 -1
- package/lib/components/PromQLEditor.d.ts.map +1 -1
- package/lib/components/PromQLEditor.js +5 -8
- package/lib/components/PromQLEditor.js.map +1 -1
- package/lib/components/TreeNode.js +1 -1
- package/lib/components/TreeNode.js.map +1 -1
- package/lib/components/promql/format.js +1 -1
- package/lib/components/promql/format.js.map +1 -1
- package/lib/explore/PrometheusExplorer.d.ts.map +1 -1
- package/lib/explore/PrometheusExplorer.js +10 -6
- package/lib/explore/PrometheusExplorer.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/MetricChip.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/MetricChip.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.js.map +1 -1
- package/lib/model/prometheus-client.d.ts +1 -0
- package/lib/model/prometheus-client.d.ts.map +1 -1
- package/lib/model/prometheus-client.js +19 -9
- package/lib/model/prometheus-client.js.map +1 -1
- package/lib/plugins/MatcherEditor.js +1 -1
- package/lib/plugins/MatcherEditor.js.map +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.d.ts.map +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.js +135 -3
- package/lib/plugins/PrometheusDatasourceEditor.js.map +1 -1
- package/lib/plugins/prometheus-datasource.js +17 -9
- package/lib/plugins/prometheus-datasource.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.d.ts.map +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +39 -4
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/lib/plugins/prometheus-variables.d.ts.map +1 -1
- package/lib/plugins/prometheus-variables.js +47 -28
- package/lib/plugins/prometheus-variables.js.map +1 -1
- package/lib/plugins/types.d.ts +1 -0
- package/lib/plugins/types.d.ts.map +1 -1
- package/lib/plugins/types.js.map +1 -1
- package/mf-manifest.json +268 -253
- package/mf-stats.json +271 -254
- package/package.json +7 -7
- package/__mf/js/Prometheus.4d0d5812.js +0 -5
- package/__mf/js/async/1339.194207db.js +0 -1
- package/__mf/js/async/1441.c735f7dd.js +0 -1
- package/__mf/js/async/1576.8eac7ce9.js +0 -1
- package/__mf/js/async/212.5fcca998.js +0 -1
- package/__mf/js/async/2292.57d8fd0d.js +0 -2
- package/__mf/js/async/3224.b63f87bf.js +0 -1
- package/__mf/js/async/3507.f1653337.js +0 -101
- package/__mf/js/async/3749.3ecd9372.js +0 -1
- package/__mf/js/async/3863.7192dfdf.js +0 -2
- package/__mf/js/async/3960.3eedafbd.js +0 -2
- package/__mf/js/async/3980.0b0d272c.js +0 -2
- package/__mf/js/async/4075.dab1b7b8.js +0 -1
- package/__mf/js/async/4238.c48b1950.js +0 -1
- package/__mf/js/async/4421.1fcb466e.js +0 -1
- package/__mf/js/async/4535.f24704ea.js +0 -1
- package/__mf/js/async/4557.f3eb9456.js +0 -2
- package/__mf/js/async/4576.f42daf99.js +0 -1
- package/__mf/js/async/4665.cad36935.js +0 -1
- package/__mf/js/async/4676.b7a22f90.js +0 -22
- package/__mf/js/async/5257.ce463cb7.js +0 -1
- package/__mf/js/async/5409.955ffd51.js +0 -1
- package/__mf/js/async/5614.cce8ba96.js +0 -1
- package/__mf/js/async/5724.794828e3.js +0 -1
- package/__mf/js/async/5774.a3fae698.js +0 -1
- package/__mf/js/async/5790.a9b31ca8.js +0 -1
- package/__mf/js/async/58.1c9a8daa.js +0 -2
- package/__mf/js/async/5981.eb502d27.js +0 -2
- package/__mf/js/async/6292.2afe0c6d.js +0 -1
- package/__mf/js/async/6341.20eccf91.js +0 -7
- package/__mf/js/async/6377.c40920f2.js +0 -2
- package/__mf/js/async/6770.7099bb3b.js +0 -1
- package/__mf/js/async/684.4495f632.js +0 -1
- package/__mf/js/async/694.8462a746.js +0 -1
- package/__mf/js/async/7272.6fa2f127.js +0 -1
- package/__mf/js/async/7376.2e948f2b.js +0 -1
- package/__mf/js/async/738.a1ffff79.js +0 -1
- package/__mf/js/async/7740.a8777825.js +0 -1
- package/__mf/js/async/8045.7f554a45.js +0 -10
- package/__mf/js/async/8164.bb3d3363.js +0 -1
- package/__mf/js/async/8216.e689c178.js +0 -1
- package/__mf/js/async/8488.cbbe542b.js +0 -1
- package/__mf/js/async/8587.40df6f5c.js +0 -1
- package/__mf/js/async/8706.89677575.js +0 -1
- package/__mf/js/async/9010.bdb2ef97.js +0 -1
- package/__mf/js/async/9173.915b80af.js +0 -2
- package/__mf/js/async/9550.642ce5ad.js +0 -38
- package/__mf/js/async/9817.70eae424.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusDatasource.45ee94e2.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusExplorer.b8e555e1.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.00dfb1dd.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.956ef2d0.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.59f2d170.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.d7143352.js +0 -1
- package/__mf/js/main.afc2ee60.js +0 -5
- /package/__mf/css/async/{1339.d3010b86.css → 1233.d3010b86.css} +0 -0
- /package/__mf/css/async/{1576.d3010b86.css → 1324.d3010b86.css} +0 -0
- /package/__mf/css/async/{4576.d3010b86.css → 9518.d3010b86.css} +0 -0
- /package/__mf/js/async/{4676.b7a22f90.js.LICENSE.txt → 1490.7e5068f1.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{8045.7f554a45.js.LICENSE.txt → 1605.dc180cb8.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{2292.57d8fd0d.js.LICENSE.txt → 2043.d0fbb886.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{58.1c9a8daa.js.LICENSE.txt → 3664.ba8b26b6.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{5981.eb502d27.js.LICENSE.txt → 392.7cda691a.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{1964.1d168a86.js.LICENSE.txt → 4121.828d661d.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{6377.c40920f2.js.LICENSE.txt → 5440.c13c3533.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{4557.f3eb9456.js.LICENSE.txt → 5501.6166367c.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{6341.20eccf91.js.LICENSE.txt → 6149.19799c37.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{3960.3eedafbd.js.LICENSE.txt → 6274.478a68f8.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{3980.0b0d272c.js.LICENSE.txt → 6283.181cb622.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{9173.915b80af.js.LICENSE.txt → 8470.9b14a625.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{3863.7192dfdf.js.LICENSE.txt → 941.53b13124.js.LICENSE.txt} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 2025 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 Notice,\n parseDurationString,\n TimeSeries,\n TimeSeriesData,\n} from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, datasourceSelectValueToSelector, replaceVariables } 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 InstantQueryResultType,\n PROM_DATASOURCE_KIND,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\nimport { replacePromBuiltinVariables } from './replace-prom-builtin-variables';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context,\n abortSignal\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 listDatasourceSelectItems = await context.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND);\n\n const selectedDatasource =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n context.variableState,\n listDatasourceSelectItems\n ) ?? DEFAULT_PROM;\n\n const datasource = (await context.datasourceStore.getDatasource(\n selectedDatasource\n )) as DatasourceSpec<PrometheusDatasourceSpec>;\n const datasourceScrapeInterval = Math.trunc(\n milliseconds(parseDurationString(datasource.plugin.spec.scrapeInterval ?? DEFAULT_SCRAPE_INTERVAL)) / 1000\n );\n\n // Min step is the lower bound of the interval between data points\n // If no value is provided for it, it should default to the scrape interval of the datasource\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 replaceVariables(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\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 /* Ensure end is always greater than start:\n If the step is greater than equal to the diff of end and start,\n both start, and end will eventually be rounded to the same value,\n Consequently, the time range will be zero, which does not return any valid value\n */\n if (end === start) {\n end = start + step;\n console.warn(`Step (${step}) was larger than the time range! end of time range was set accordingly.`);\n }\n\n // Replace variable placeholders in PromQL query\n const intervalMs = step * 1000;\n const minStepMs = minStep * 1000;\n let query = replacePromBuiltinVariables(spec.query, minStepMs, intervalMs);\n query = replaceVariables(query, context.variableState);\n\n let seriesNameFormat = spec.seriesNameFormat;\n // if series name format is defined, replace variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceVariables(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(selectedDatasource);\n\n // Make the request to Prom\n\n let response;\n switch (context.mode) {\n case 'instant':\n response = await client.instantQuery(\n {\n query,\n time: end,\n },\n undefined,\n abortSignal\n );\n break;\n case 'range':\n default:\n response = await client.rangeQuery(\n {\n query,\n start,\n end,\n step,\n },\n undefined,\n abortSignal\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(query, result, seriesNameFormat),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n\nfunction buildVectorData(query: string, data: VectorData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, value, histogram } = 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 if (histogram) {\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple([histogram[0], histogram[1].sum])],\n histograms: [histogram],\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple(value)],\n };\n });\n}\n\nfunction buildMatrixData(query: string, data: MatrixData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, values, histograms } = 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 if (histograms) {\n return {\n name,\n formattedName,\n labels: metric,\n values: histograms.map((histogram) => parseValueTuple([histogram[0], histogram[1].sum])),\n histograms: histograms.map((histogram) => histogram),\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: values.map(parseValueTuple),\n };\n });\n}\n\nfunction buildScalarData(query: string, data: ScalarData, 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(query: string, data?: InstantQueryResultType, seriesNameFormat?: string): TimeSeries[] {\n if (!data) {\n return [];\n }\n\n const resultType = data.resultType;\n switch (resultType) {\n case 'vector':\n return buildVectorData(query, data, seriesNameFormat);\n case 'matrix':\n return buildMatrixData(query, data, seriesNameFormat);\n case 'scalar':\n return buildScalarData(query, data, seriesNameFormat);\n default:\n console.warn('Unknown result type', resultType, data);\n return [];\n }\n}\n"],"names":["parseDurationString","datasourceSelectValueToSelector","replaceVariables","fromUnixTime","milliseconds","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","PROM_DATASOURCE_KIND","getFormattedPrometheusSeriesName","DEFAULT_SCRAPE_INTERVAL","replacePromBuiltinVariables","getTimeSeriesData","spec","context","abortSignal","query","undefined","series","listDatasourceSelectItems","datasourceStore","selectedDatasource","datasource","variableState","getDatasource","datasourceScrapeInterval","Math","trunc","plugin","scrapeInterval","minStep","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","floor","alignedStart","console","warn","intervalMs","minStepMs","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","histogram","name","formattedName","labels","values","sum","histograms","buildMatrixData","buildScalarData","resultType"],"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,SAIEA,mBAAmB,QAGd,mBAAmB;AAC1B,SAAgCC,+BAA+B,EAAEC,gBAAgB,QAAQ,4BAA4B;AACrH,SAASC,YAAY,EAAEC,YAAY,QAAQ,WAAW;AACtD,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,EAKZC,oBAAoB,QACf,cAAc;AACrB,SAASC,gCAAgC,QAAQ,cAAc;AAC/D,SAASC,uBAAuB,QAAkC,WAAW;AAE7E,SAASC,2BAA2B,QAAQ,mCAAmC;AAE/E,OAAO,MAAMC,oBAA+F,OAC1GC,MACAC,SACAC;IAEA,IAAIF,KAAKG,KAAK,KAAKC,aAAaJ,KAAKG,KAAK,KAAK,QAAQH,KAAKG,KAAK,KAAK,IAAI;QACxE,+EAA+E;QAC/E,OAAO;YAAEE,QAAQ,EAAE;QAAC;I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,KAAKD,MAAM;aAAE;YACtCqB;QACF;KACD;AACH;AAEA,SAASV,gBAAgBjD,KAAa,EAAEuC,IAA6B,EAAET,gBAAyB;IAC9F,IAAI,CAACS,MAAM;QACT,OAAO,EAAE;IACX;IAEA,MAAM2B,aAAa3B,KAAK2B,UAAU;IAClC,OAAQA;QACN,KAAK;YACH,OAAOd,gBAAgBpD,OAAOuC,MAAMT;QACtC,KAAK;YACH,OAAOkC,gBAAgBhE,OAAOuC,MAAMT;QACtC,KAAK;YACH,OAAOmC,gBAAgBjE,OAAOuC,MAAMT;QACtC;YACEJ,QAAQC,IAAI,CAAC,uBAAuBuC,YAAY3B;YAChD,OAAO,EAAE;IACb;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/get-time-series-data.ts"],"sourcesContent":["// Copyright 2025 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 Notice,\n parseDurationString,\n TimeSeries,\n TimeSeriesData,\n} from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, datasourceSelectValueToSelector, replaceVariables } 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 InstantQueryResultType,\n PROM_DATASOURCE_KIND,\n} from '../../model';\nimport { getFormattedPrometheusSeriesName } from '../../utils';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\nimport { replacePromBuiltinVariables } from './replace-prom-builtin-variables';\n\nexport const getTimeSeriesData: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context,\n abortSignal\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 listDatasourceSelectItems = await context.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND);\n\n const selectedDatasource =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n context.variableState,\n listDatasourceSelectItems\n ) ?? DEFAULT_PROM;\n\n const datasource = (await context.datasourceStore.getDatasource(\n selectedDatasource\n )) as DatasourceSpec<PrometheusDatasourceSpec>;\n const datasourceScrapeInterval = Math.trunc(\n milliseconds(parseDurationString(datasource.plugin.spec.scrapeInterval ?? DEFAULT_SCRAPE_INTERVAL)) / 1000\n );\n\n // Min step is the lower bound of the interval between data points\n // If no value is provided for it, it should default to the scrape interval of the datasource\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 replaceVariables(spec.minStep as string, context.variableState) as DurationString\n ) ?? datasourceScrapeInterval;\n\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\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 /* Ensure end is always greater than start:\n If the step is greater than equal to the diff of end and start,\n both start, and end will eventually be rounded to the same value,\n Consequently, the time range will be zero, which does not return any valid value\n */\n if (end === start) {\n end = start + step;\n console.warn(`Step (${step}) was larger than the time range! end of time range was set accordingly.`);\n }\n\n // Replace variable placeholders in PromQL query\n const intervalMs = step * 1000;\n const minStepMs = minStep * 1000;\n\n let query = replacePromBuiltinVariables(spec.query, minStepMs, intervalMs);\n query = replaceVariables(query, context.variableState);\n\n let seriesNameFormat = spec.seriesNameFormat;\n // if series name format is defined, replace variable placeholders in series name format\n if (seriesNameFormat) {\n seriesNameFormat = replaceVariables(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(selectedDatasource);\n\n // Make the request to Prom\n\n let response;\n switch (context.mode) {\n case 'instant':\n response = await client.instantQuery(\n {\n query,\n time: end,\n },\n undefined,\n abortSignal\n );\n break;\n case 'range':\n default:\n response = await client.rangeQuery(\n {\n query,\n start,\n end,\n step,\n },\n undefined,\n abortSignal\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(query, result, seriesNameFormat),\n metadata: {\n notices,\n executedQueryString: query,\n },\n };\n\n return chartData;\n};\n\nfunction buildVectorData(query: string, data: VectorData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, value, histogram } = 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 if (histogram) {\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple([histogram[0], histogram[1].sum])],\n histograms: [histogram],\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: [parseValueTuple(value)],\n };\n });\n}\n\nfunction buildMatrixData(query: string, data: MatrixData, seriesNameFormat: string | undefined): TimeSeries[] {\n return data.result.map((res) => {\n const { metric, values, histograms } = 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 if (histograms) {\n return {\n name,\n formattedName,\n labels: metric,\n values: histograms.map((histogram) => parseValueTuple([histogram[0], histogram[1].sum])),\n histograms: histograms.map((histogram) => histogram),\n };\n }\n\n return {\n name,\n formattedName,\n labels: metric,\n values: values.map(parseValueTuple),\n };\n });\n}\n\nfunction buildScalarData(query: string, data: ScalarData, 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(query: string, data?: InstantQueryResultType, seriesNameFormat?: string): TimeSeries[] {\n if (!data) {\n return [];\n }\n\n const resultType = data.resultType;\n switch (resultType) {\n case 'vector':\n return buildVectorData(query, data, seriesNameFormat);\n case 'matrix':\n return buildMatrixData(query, data, seriesNameFormat);\n case 'scalar':\n return buildScalarData(query, data, seriesNameFormat);\n default:\n console.warn('Unknown result type', resultType, data);\n return [];\n }\n}\n"],"names":["parseDurationString","datasourceSelectValueToSelector","replaceVariables","fromUnixTime","milliseconds","parseValueTuple","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","DEFAULT_PROM","PROM_DATASOURCE_KIND","getFormattedPrometheusSeriesName","DEFAULT_SCRAPE_INTERVAL","replacePromBuiltinVariables","getTimeSeriesData","spec","context","abortSignal","query","undefined","series","listDatasourceSelectItems","datasourceStore","selectedDatasource","datasource","variableState","getDatasource","datasourceScrapeInterval","Math","trunc","plugin","scrapeInterval","minStep","timeRange","step","suggestedStepMs","start","end","utcOffsetSec","Date","getTimezoneOffset","alignedEnd","floor","alignedStart","console","warn","intervalMs","minStepMs","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","histogram","name","formattedName","labels","values","sum","histograms","buildMatrixData","buildScalarData","resultType"],"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,SAIEA,mBAAmB,QAGd,mBAAmB;AAC1B,SAAgCC,+BAA+B,EAAEC,gBAAgB,QAAQ,4BAA4B;AACrH,SAASC,YAAY,EAAEC,YAAY,QAAQ,WAAW;AACtD,SACEC,eAAe,EAEfC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,YAAY,EAKZC,oBAAoB,QACf,cAAc;AACrB,SAASC,gCAAgC,QAAQ,cAAc;AAC/D,SAASC,uBAAuB,QAAkC,WAAW;AAE7E,SAASC,2BAA2B,QAAQ,mCAAmC;AAE/E,OAAO,MAAMC,oBAA+F,OAC1GC,MACAC,SACAC;IAEA,IAAIF,KAAKG,KAAK,KAAKC,aAAaJ,KAAKG,KAAK,KAAK,QAAQH,KAAKG,KAAK,KAAK,IAAI;QACxE,+EAA+E;QAC/E,OAAO;YAAEE,QAAQ,EAAE;QAAC;IACtB;IAEA,MAAMC,4BAA4B,MAAML,QAAQM,eAAe,CAACD,yBAAyB,CAACX;IAE1F,MAAMa,qBACJtB,gCACEc,KAAKS,UAAU,IAAIf,cACnBO,QAAQS,aAAa,EACrBJ,8BACGZ;IAEP,MAAMe,aAAc,MAAMR,QAAQM,eAAe,CAACI,aAAa,CAC7DH;IAEF,MAAMI,2BAA2BC,KAAKC,KAAK,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QACtC,KAAK;YACH,OAAOkC,gBAAgBhE,OAAOuC,MAAMT;QACtC,KAAK;YACH,OAAOmC,gBAAgBjE,OAAOuC,MAAMT;QACtC;YACEJ,QAAQC,IAAI,CAAC,uBAAuBuC,YAAY3B;YAChD,OAAO,EAAE;IACb;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAGlB,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,
|
|
1
|
+
{"version":3,"file":"prometheus-variables.d.ts","sourceRoot":"","sources":["../../../src/plugins/prometheus-variables.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAGlB,cAAc,EACf,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAwC,MAAM,OAAO,CAAC;AAE3E,OAAO,EAIL,UAAU,EAIV,UAAU,EACX,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,mCAAmC,EACnC,oCAAoC,EACpC,+BAA+B,EAChC,MAAM,SAAS,CAAC;AAEjB,wBAAgB,mCAAmC,CACjD,KAAK,EAAE,kBAAkB,CAAC,oCAAoC,CAAC,GAC9D,YAAY,CA6Ed;AAED,wBAAgB,kCAAkC,CAChD,KAAK,EAAE,kBAAkB,CAAC,mCAAmC,CAAC,GAC7D,YAAY,CAuDd;AAED,wBAAgB,8BAA8B,CAC5C,KAAK,EAAE,kBAAkB,CAAC,+BAA+B,CAAC,GACzD,YAAY,CAsFd;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAS/E;AAED,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,MAAM,EAAE,CAS/E;AAED;;GAEG;AACH,eAAO,MAAM,4BAA4B,GAAI,SAAS,MAAM,EAAE,KAAG,cAAc,EAM9E,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
1
2
|
// Copyright 2024 The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,19 +11,16 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
14
|
import { FormControl, Stack, TextField } from '@mui/material';
|
|
15
15
|
import { DatasourceSelect, isVariableDatasource, useDatasourceClient, useDatasourceSelectValueToSelector } from '@perses-dev/plugin-system';
|
|
16
16
|
import { produce } from 'immer';
|
|
17
|
-
import { useCallback
|
|
17
|
+
import { useCallback } from 'react';
|
|
18
18
|
import { PromQLEditor } from '../components';
|
|
19
19
|
import { DEFAULT_PROM, isDefaultPromSelector, isPrometheusDatasourceSelector, PROM_DATASOURCE_KIND } from '../model';
|
|
20
20
|
import { MatcherEditor } from './MatcherEditor';
|
|
21
21
|
export function PrometheusLabelValuesVariableEditor(props) {
|
|
22
22
|
const { onChange, value, value: { datasource } } = props;
|
|
23
23
|
const selectedDatasource = datasource ?? DEFAULT_PROM;
|
|
24
|
-
const [labelValue, setLabelValue] = useState(props.value.labelName);
|
|
25
|
-
const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);
|
|
26
24
|
const handleDatasourceChange = useCallback((next)=>{
|
|
27
25
|
if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {
|
|
28
26
|
onChange(produce(value, (draft)=>{
|
|
@@ -37,11 +35,21 @@ export function PrometheusLabelValuesVariableEditor(props) {
|
|
|
37
35
|
value
|
|
38
36
|
]);
|
|
39
37
|
const handleLabelChange = useCallback((e)=>{
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
38
|
+
onChange(produce(value, (draft)=>{
|
|
39
|
+
draft.labelName = e.target.value;
|
|
40
|
+
}));
|
|
41
|
+
}, [
|
|
42
|
+
onChange,
|
|
43
|
+
value
|
|
44
|
+
]);
|
|
45
|
+
const handleMatchEditorsChange = useCallback((matchers)=>{
|
|
46
|
+
onChange(produce(value, (draft)=>{
|
|
47
|
+
draft.matchers = matchers;
|
|
48
|
+
}));
|
|
49
|
+
}, [
|
|
50
|
+
onChange,
|
|
51
|
+
value
|
|
52
|
+
]);
|
|
45
53
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
46
54
|
spacing: 2,
|
|
47
55
|
children: [
|
|
@@ -59,14 +67,16 @@ export function PrometheusLabelValuesVariableEditor(props) {
|
|
|
59
67
|
/*#__PURE__*/ _jsx(TextField, {
|
|
60
68
|
label: "Label Name",
|
|
61
69
|
required: true,
|
|
62
|
-
value:
|
|
70
|
+
value: props.value.labelName,
|
|
63
71
|
onChange: handleLabelChange,
|
|
64
|
-
|
|
65
|
-
|
|
72
|
+
slotProps: {
|
|
73
|
+
input: {
|
|
74
|
+
readOnly: props.isReadonly
|
|
75
|
+
}
|
|
66
76
|
}
|
|
67
77
|
}),
|
|
68
78
|
/*#__PURE__*/ _jsx(MatcherEditor, {
|
|
69
|
-
matchers:
|
|
79
|
+
matchers: props.value.matchers ?? [],
|
|
70
80
|
onChange: handleMatchEditorsChange,
|
|
71
81
|
isReadonly: props.isReadonly
|
|
72
82
|
})
|
|
@@ -76,7 +86,6 @@ export function PrometheusLabelValuesVariableEditor(props) {
|
|
|
76
86
|
export function PrometheusLabelNamesVariableEditor(props) {
|
|
77
87
|
const { onChange, value, value: { datasource } } = props;
|
|
78
88
|
const selectedDatasource = datasource ?? DEFAULT_PROM;
|
|
79
|
-
const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);
|
|
80
89
|
const handleDatasourceChange = useCallback((next)=>{
|
|
81
90
|
if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {
|
|
82
91
|
onChange(produce(value, (draft)=>{
|
|
@@ -90,9 +99,14 @@ export function PrometheusLabelNamesVariableEditor(props) {
|
|
|
90
99
|
onChange,
|
|
91
100
|
value
|
|
92
101
|
]);
|
|
93
|
-
const handleMatchEditorChange = useCallback((
|
|
94
|
-
|
|
95
|
-
|
|
102
|
+
const handleMatchEditorChange = useCallback((matchers)=>{
|
|
103
|
+
onChange(produce(value, (draft)=>{
|
|
104
|
+
draft.matchers = matchers;
|
|
105
|
+
}));
|
|
106
|
+
}, [
|
|
107
|
+
onChange,
|
|
108
|
+
value
|
|
109
|
+
]);
|
|
96
110
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
97
111
|
spacing: 2,
|
|
98
112
|
children: [
|
|
@@ -108,7 +122,7 @@ export function PrometheusLabelNamesVariableEditor(props) {
|
|
|
108
122
|
})
|
|
109
123
|
}),
|
|
110
124
|
/*#__PURE__*/ _jsx(MatcherEditor, {
|
|
111
|
-
matchers:
|
|
125
|
+
matchers: props.value.matchers ?? [],
|
|
112
126
|
isReadonly: props.isReadonly,
|
|
113
127
|
onChange: handleMatchEditorChange
|
|
114
128
|
})
|
|
@@ -121,7 +135,6 @@ export function PrometheusPromQLVariableEditor(props) {
|
|
|
121
135
|
const selectedDatasource = useDatasourceSelectValueToSelector(datasourceSelectValue, PROM_DATASOURCE_KIND);
|
|
122
136
|
const { data: client } = useDatasourceClient(selectedDatasource);
|
|
123
137
|
const promURL = client?.options.datasourceUrl;
|
|
124
|
-
const [labelValue, setLabelValue] = useState(props.value.labelName);
|
|
125
138
|
const handleDatasourceChange = useCallback((next)=>{
|
|
126
139
|
if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {
|
|
127
140
|
onChange(produce(value, (draft)=>{
|
|
@@ -136,17 +149,21 @@ export function PrometheusPromQLVariableEditor(props) {
|
|
|
136
149
|
onChange
|
|
137
150
|
]);
|
|
138
151
|
const handleOnBlurPromQlChange = useCallback((e)=>{
|
|
139
|
-
onChange({
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
});
|
|
152
|
+
onChange(produce(value, (draft)=>{
|
|
153
|
+
draft.expr = e.target.textContent ?? '';
|
|
154
|
+
}));
|
|
143
155
|
}, [
|
|
144
156
|
onChange,
|
|
145
157
|
value
|
|
146
158
|
]);
|
|
147
159
|
const handleLabelNameChange = useCallback((e)=>{
|
|
148
|
-
|
|
149
|
-
|
|
160
|
+
onChange(produce(value, (draft)=>{
|
|
161
|
+
draft.labelName = e.target.value;
|
|
162
|
+
}));
|
|
163
|
+
}, [
|
|
164
|
+
onChange,
|
|
165
|
+
value
|
|
166
|
+
]);
|
|
150
167
|
return /*#__PURE__*/ _jsxs(Stack, {
|
|
151
168
|
spacing: 2,
|
|
152
169
|
children: [
|
|
@@ -176,9 +193,11 @@ export function PrometheusPromQLVariableEditor(props) {
|
|
|
176
193
|
/*#__PURE__*/ _jsx(TextField, {
|
|
177
194
|
label: "Label Name",
|
|
178
195
|
required: true,
|
|
179
|
-
value:
|
|
180
|
-
|
|
181
|
-
|
|
196
|
+
value: props.value.labelName,
|
|
197
|
+
slotProps: {
|
|
198
|
+
input: {
|
|
199
|
+
readOnly: props.isReadonly
|
|
200
|
+
}
|
|
182
201
|
},
|
|
183
202
|
onChange: handleLabelNameChange
|
|
184
203
|
})
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-variables.tsx"],"sourcesContent":["// Copyright 2024 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.\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceClient,\n useDatasourceSelectValueToSelector,\n VariableOption,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport { ReactElement, useCallback, useState } from 'react';\nimport { PromQLEditor } from '../components';\nimport {\n DEFAULT_PROM,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n PrometheusDatasourceSelector,\n VectorData,\n} from '../model';\nimport { MatcherEditor } from './MatcherEditor';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\n\nexport function PrometheusLabelValuesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n } = props;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n const [labelValue, setLabelValue] = useState(props.value.labelName);\n const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (next) => {\n if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [onChange, value]\n );\n\n const handleLabelChange = useCallback((e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLabelValue(e.target.value);\n }, []);\n\n const handleMatchEditorsChange = useCallback((e: string[]) => {\n setMatchersValues(e);\n }, []);\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n readOnly={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <TextField\n label=\"Label Name\"\n required\n value={labelValue}\n onChange={handleLabelChange}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n />\n <MatcherEditor matchers={matchersValues} onChange={handleMatchEditorsChange} isReadonly={props.isReadonly} />\n </Stack>\n );\n}\n\nexport function PrometheusLabelNamesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n } = props;\n\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n const [matchersValues, setMatchersValues] = useState(props.value.matchers ?? []);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (next) => {\n if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [onChange, value]\n );\n\n const handleMatchEditorChange = useCallback((e: string[]) => {\n setMatchersValues(e);\n }, []);\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n disabled={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <MatcherEditor matchers={matchersValues} isReadonly={props.isReadonly} onChange={handleMatchEditorChange} />\n </Stack>\n );\n}\n\nexport function PrometheusPromQLVariableEditor(\n props: OptionsEditorProps<PrometheusPromQLVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n } = props;\n const datasourceSelectValue = datasource ?? DEFAULT_PROM;\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n PROM_DATASOURCE_KIND\n ) as PrometheusDatasourceSelector;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n const [labelValue, setLabelValue] = useState(props.value.labelName);\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (next) => {\n if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [value, onChange]\n );\n\n const handleOnBlurPromQlChange = useCallback(\n (e: React.FocusEvent<HTMLDivElement, Element>) => {\n onChange({ ...value, expr: e.target.textContent ?? '' });\n },\n [onChange, value]\n );\n\n const handleLabelNameChange = useCallback((e: React.ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n setLabelValue(e.target.value);\n }, []);\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={datasourceSelectValue}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n disabled={props.isReadonly}\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={value.expr}\n datasource={selectedDatasource}\n onBlur={handleOnBlurPromQlChange}\n readOnly={props.isReadonly}\n width=\"100%\"\n />\n <TextField\n label=\"Label Name\"\n required\n value={labelValue}\n InputProps={{\n readOnly: props.isReadonly,\n }}\n onChange={handleLabelNameChange}\n />\n </Stack>\n );\n}\n\nexport function capturingMatrix(matrix: MatrixData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of matrix.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\nexport function capturingVector(vector: VectorData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of vector.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\n/**\n * Takes a list of strings and returns a list of VariableOptions\n */\nexport const stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n"],"names":["FormControl","Stack","TextField","DatasourceSelect","isVariableDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","produce","useCallback","useState","PromQLEditor","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","labelValue","setLabelValue","labelName","matchersValues","setMatchersValues","matchers","handleDatasourceChange","next","draft","undefined","Error","handleLabelChange","e","target","handleMatchEditorsChange","spacing","margin","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","InputProps","PrometheusLabelNamesVariableEditor","handleMatchEditorChange","disabled","PrometheusPromQLVariableEditor","datasourceSelectValue","data","client","promURL","options","datasourceUrl","handleOnBlurPromQlChange","expr","textContent","handleLabelNameChange","completeConfig","remote","url","onBlur","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map"],"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;;AACjC,SAASA,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC9D,SACEC,gBAAgB,EAEhBC,oBAAoB,EAEpBC,mBAAmB,EACnBC,kCAAkC,QAE7B,4BAA4B;AACnC,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAAuBC,WAAW,EAAEC,QAAQ,QAAQ,QAAQ;AA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;IACnE,MAAM2C,WAAW,IAAIC;IACrB,KAAK,MAAMC,UAAUH,OAAOI,MAAM,CAAE;QAClC,MAAMnD,QAAQkD,OAAOE,MAAM,CAAC/C,UAAU;QACtC,IAAIL,UAAUY,WAAW;YACvBoC,SAASK,GAAG,CAACrD;QACf;IACF;IACA,OAAOsD,MAAMC,IAAI,CAACP,SAASQ,MAAM;AACnC;AAEA,OAAO,SAASC,gBAAgBC,MAAkB,EAAErD,SAAiB;IACnE,MAAM2C,WAAW,IAAIC;IACrB,KAAK,MAAMC,UAAUQ,OAAOP,MAAM,CAAE;QAClC,MAAMnD,QAAQkD,OAAOE,MAAM,CAAC/C,UAAU;QACtC,IAAIL,UAAUY,WAAW;YACvBoC,SAASK,GAAG,CAACrD;QACf;IACF;IACA,OAAOsD,MAAMC,IAAI,CAACP,SAASQ,MAAM;AACnC;AAEA;;CAEC,GACD,OAAO,MAAMG,+BAA+B,CAACH;IAC3C,IAAI,CAACA,QAAQ,OAAO,EAAE;IACtB,OAAOA,OAAOI,GAAG,CAAC,CAAC5D,QAAW,CAAA;YAC5BA;YACAwB,OAAOxB;QACT,CAAA;AACF,EAAE"}
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-variables.tsx"],"sourcesContent":["// Copyright 2024 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.\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceClient,\n useDatasourceSelectValueToSelector,\n VariableOption,\n} from '@perses-dev/plugin-system';\nimport { produce } from 'immer';\nimport { ReactElement, useCallback, ChangeEvent, FocusEvent } from 'react';\nimport { PromQLEditor } from '../components';\nimport {\n DEFAULT_PROM,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n MatrixData,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n PrometheusDatasourceSelector,\n VectorData,\n} from '../model';\nimport { MatcherEditor } from './MatcherEditor';\nimport {\n PrometheusLabelNamesVariableOptions,\n PrometheusLabelValuesVariableOptions,\n PrometheusPromQLVariableOptions,\n} from './types';\n\nexport function PrometheusLabelValuesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelValuesVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n } = props;\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (next) => {\n if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [onChange, value]\n );\n\n const handleLabelChange = useCallback(\n (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n onChange(\n produce(value, (draft) => {\n draft.labelName = e.target.value;\n })\n );\n },\n [onChange, value]\n );\n\n const handleMatchEditorsChange = useCallback(\n (matchers: string[]) => {\n onChange(\n produce(value, (draft) => {\n draft.matchers = matchers;\n })\n );\n },\n [onChange, value]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n readOnly={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <TextField\n label=\"Label Name\"\n required\n value={props.value.labelName}\n onChange={handleLabelChange}\n slotProps={{\n input: {\n readOnly: props.isReadonly,\n },\n }}\n />\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n onChange={handleMatchEditorsChange}\n isReadonly={props.isReadonly}\n />\n </Stack>\n );\n}\n\nexport function PrometheusLabelNamesVariableEditor(\n props: OptionsEditorProps<PrometheusLabelNamesVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n } = props;\n\n const selectedDatasource = datasource ?? DEFAULT_PROM;\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (next) => {\n if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [onChange, value]\n );\n\n const handleMatchEditorChange = useCallback(\n (matchers: string[]) => {\n onChange(\n produce(value, (draft) => {\n draft.matchers = matchers;\n })\n );\n },\n [onChange, value]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <DatasourceSelect\n datasourcePluginKind=\"PrometheusDatasource\"\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n disabled={props.isReadonly}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n />\n </FormControl>\n <MatcherEditor\n matchers={props.value.matchers ?? []}\n isReadonly={props.isReadonly}\n onChange={handleMatchEditorChange}\n />\n </Stack>\n );\n}\n\nexport function PrometheusPromQLVariableEditor(\n props: OptionsEditorProps<PrometheusPromQLVariableOptions>\n): ReactElement {\n const {\n onChange,\n value,\n value: { datasource },\n } = props;\n const datasourceSelectValue = datasource ?? DEFAULT_PROM;\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n PROM_DATASOURCE_KIND\n ) as PrometheusDatasourceSelector;\n\n const { data: client } = useDatasourceClient<PrometheusClient>(selectedDatasource);\n const promURL = client?.options.datasourceUrl;\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = useCallback(\n (next) => {\n if (isVariableDatasource(next) || isPrometheusDatasourceSelector(next)) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n draft.datasource = !isVariableDatasource(next) && isDefaultPromSelector(next) ? undefined : next;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n },\n [value, onChange]\n );\n\n const handleOnBlurPromQlChange = useCallback(\n (e: FocusEvent<HTMLDivElement>) => {\n onChange(\n produce(value, (draft) => {\n draft.expr = e.target.textContent ?? '';\n })\n );\n },\n [onChange, value]\n );\n\n const handleLabelNameChange = useCallback(\n (e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement>) => {\n onChange(\n produce(value, (draft) => {\n draft.labelName = e.target.value;\n })\n );\n },\n [onChange, value]\n );\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\">\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={datasourceSelectValue}\n onChange={handleDatasourceChange}\n labelId=\"prom-datasource-label\"\n label=\"Prometheus Datasource\"\n disabled={props.isReadonly}\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={value.expr}\n datasource={selectedDatasource}\n onBlur={handleOnBlurPromQlChange}\n readOnly={props.isReadonly}\n width=\"100%\"\n />\n <TextField\n label=\"Label Name\"\n required\n value={props.value.labelName}\n slotProps={{\n input: {\n readOnly: props.isReadonly,\n },\n }}\n onChange={handleLabelNameChange}\n />\n </Stack>\n );\n}\n\nexport function capturingMatrix(matrix: MatrixData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of matrix.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\nexport function capturingVector(vector: VectorData, labelName: string): string[] {\n const captured = new Set<string>();\n for (const sample of vector.result) {\n const value = sample.metric[labelName];\n if (value !== undefined) {\n captured.add(value);\n }\n }\n return Array.from(captured.values());\n}\n\n/**\n * Takes a list of strings and returns a list of VariableOptions\n */\nexport const stringArrayToVariableOptions = (values?: string[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value,\n label: value,\n }));\n};\n"],"names":["FormControl","Stack","TextField","DatasourceSelect","isVariableDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","produce","useCallback","PromQLEditor","DEFAULT_PROM","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","MatcherEditor","PrometheusLabelValuesVariableEditor","props","onChange","value","datasource","selectedDatasource","handleDatasourceChange","next","draft","undefined","Error","handleLabelChange","e","labelName","target","handleMatchEditorsChange","matchers","spacing","margin","datasourcePluginKind","readOnly","isReadonly","labelId","label","required","slotProps","input","PrometheusLabelNamesVariableEditor","handleMatchEditorChange","disabled","PrometheusPromQLVariableEditor","datasourceSelectValue","data","client","promURL","options","datasourceUrl","handleOnBlurPromQlChange","expr","textContent","handleLabelNameChange","completeConfig","remote","url","onBlur","width","capturingMatrix","matrix","captured","Set","sample","result","metric","add","Array","from","values","capturingVector","vector","stringArrayToVariableOptions","map"],"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;AACjC,SAASA,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC9D,SACEC,gBAAgB,EAEhBC,oBAAoB,EAEpBC,mBAAmB,EACnBC,kCAAkC,QAE7B,4BAA4B;AACnC,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAAuBC,WAAW,QAAiC,QAAQ;AAC3E,SAASC,YAAY,QAAQ,gBAAgB;AAC7C,SACEC,YAAY,EACZC,qBAAqB,EACrBC,8BAA8B,EAE9BC,oBAAoB,QAIf,WAAW;AA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KAAK,MAAMC,UAAUH,OAAOI,MAAM,CAAE;QAClC,MAAMhD,QAAQ+C,OAAOE,MAAM,CAACvC,UAAU;QACtC,IAAIV,UAAUM,WAAW;YACvBuC,SAASK,GAAG,CAAClD;QACf;IACF;IACA,OAAOmD,MAAMC,IAAI,CAACP,SAASQ,MAAM;AACnC;AAEA,OAAO,SAASC,gBAAgBC,MAAkB,EAAE7C,SAAiB;IACnE,MAAMmC,WAAW,IAAIC;IACrB,KAAK,MAAMC,UAAUQ,OAAOP,MAAM,CAAE;QAClC,MAAMhD,QAAQ+C,OAAOE,MAAM,CAACvC,UAAU;QACtC,IAAIV,UAAUM,WAAW;YACvBuC,SAASK,GAAG,CAAClD;QACf;IACF;IACA,OAAOmD,MAAMC,IAAI,CAACP,SAASQ,MAAM;AACnC;AAEA;;CAEC,GACD,OAAO,MAAMG,+BAA+B,CAACH;IAC3C,IAAI,CAACA,QAAQ,OAAO,EAAE;IACtB,OAAOA,OAAOI,GAAG,CAAC,CAACzD,QAAW,CAAA;YAC5BA;YACAoB,OAAOpB;QACT,CAAA;AACF,EAAE"}
|
package/lib/plugins/types.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ export interface PrometheusDatasourceSpec {
|
|
|
6
6
|
directUrl?: string;
|
|
7
7
|
proxy?: HTTPProxy;
|
|
8
8
|
scrapeInterval?: DurationString;
|
|
9
|
+
queryParams?: Record<string, string>;
|
|
9
10
|
}
|
|
10
11
|
export interface PrometheusVariableOptionsBase {
|
|
11
12
|
datasource?: DatasourceSelectValue<PrometheusDatasourceSelector>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,uBAAuB,EAAE,cAAqB,CAAC;AAE5D,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,cAAc,CAAC,EAAE,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/plugins/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,4BAA4B,EAAE,MAAM,UAAU,CAAC;AAExD,eAAO,MAAM,uBAAuB,EAAE,cAAqB,CAAC;AAE5D,MAAM,WAAW,wBAAwB;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,cAAc,CAAC,EAAE,cAAc,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACtC;AAED,MAAM,WAAW,6BAA6B;IAC5C,UAAU,CAAC,EAAE,qBAAqB,CAAC,4BAA4B,CAAC,CAAC;CAClE;AAED,MAAM,MAAM,mCAAmC,GAAG,6BAA6B,GAAG;IAChF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,oCAAoC,GAAG,6BAA6B,GAAG;IACjF,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;CACrB,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG,6BAA6B,GAAG;IAE5E,IAAI,EAAE,MAAM,CAAC;IAGb,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC"}
|
package/lib/plugins/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/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, HTTPProxy } from '@perses-dev/core';\nimport { DatasourceSelectValue } from '@perses-dev/plugin-system';\nimport { PrometheusDatasourceSelector } from '../model';\n\nexport const DEFAULT_SCRAPE_INTERVAL: DurationString = '1m';\n\nexport interface PrometheusDatasourceSpec {\n directUrl?: string;\n proxy?: HTTPProxy;\n scrapeInterval?: DurationString; // default to 1m\n}\n\nexport interface PrometheusVariableOptionsBase {\n datasource?: DatasourceSelectValue<PrometheusDatasourceSelector>;\n}\n\nexport type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {\n matchers?: string[];\n};\n\nexport type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n labelName: string;\n matchers?: string[];\n};\n\nexport type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {\n // expr is the PromQL expression.\n expr: string;\n // labelName is the name of the label that will be used after the PromQL query is performed to select the label value.\n // Note: This field is not part of the Prometheus API.\n labelName: string;\n};\n"],"names":["DEFAULT_SCRAPE_INTERVAL"],"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;AAMjC,OAAO,MAAMA,0BAA0C,KAAK"}
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/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, HTTPProxy } from '@perses-dev/core';\nimport { DatasourceSelectValue } from '@perses-dev/plugin-system';\nimport { PrometheusDatasourceSelector } from '../model';\n\nexport const DEFAULT_SCRAPE_INTERVAL: DurationString = '1m';\n\nexport interface PrometheusDatasourceSpec {\n directUrl?: string;\n proxy?: HTTPProxy;\n scrapeInterval?: DurationString; // default to 1m\n queryParams?: Record<string, string>;\n}\n\nexport interface PrometheusVariableOptionsBase {\n datasource?: DatasourceSelectValue<PrometheusDatasourceSelector>;\n}\n\nexport type PrometheusLabelNamesVariableOptions = PrometheusVariableOptionsBase & {\n matchers?: string[];\n};\n\nexport type PrometheusLabelValuesVariableOptions = PrometheusVariableOptionsBase & {\n labelName: string;\n matchers?: string[];\n};\n\nexport type PrometheusPromQLVariableOptions = PrometheusVariableOptionsBase & {\n // expr is the PromQL expression.\n expr: string;\n // labelName is the name of the label that will be used after the PromQL query is performed to select the label value.\n // Note: This field is not part of the Prometheus API.\n labelName: string;\n};\n"],"names":["DEFAULT_SCRAPE_INTERVAL"],"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;AAMjC,OAAO,MAAMA,0BAA0C,KAAK"}
|