@perses-dev/prometheus-plugin 0.57.0-beta.0 → 0.57.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 → Prometheus.9877d89e.js} +3 -3
- package/__mf/js/async/1728.531c96f9.js +1 -0
- package/__mf/js/async/3499.bef2e2e5.js +1 -0
- package/__mf/js/async/3652.6b591718.js +7 -0
- package/__mf/js/async/392.f1b4a590.js +2 -0
- package/__mf/js/async/425.1ec8867f.js +1 -0
- package/__mf/js/async/4657.f0c3ccd6.js +2 -0
- package/__mf/js/async/54.e6002704.js +22 -0
- package/__mf/js/async/5440.8ced5513.js +2 -0
- package/__mf/js/async/{5440.c13c3533.js.LICENSE.txt → 5440.8ced5513.js.LICENSE.txt} +3 -3
- package/__mf/js/async/9010.ca50fa9e.js +2 -0
- package/__mf/js/async/{9020.c19782f1.js → 9020.ebc1cad3.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusDatasource.6f63e147.js → __federation_expose_PrometheusDatasource.b97f9012.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusExplorer.584a073d.js → __federation_expose_PrometheusExplorer.eba3b416.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusLabelNamesVariable.40984a4d.js → __federation_expose_PrometheusLabelNamesVariable.bd38a89c.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusLabelValuesVariable.bd3eb00c.js → __federation_expose_PrometheusLabelValuesVariable.eb12e168.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusPromQLVariable.5cca8417.js → __federation_expose_PrometheusPromQLVariable.7ccb0601.js} +1 -1
- package/__mf/js/async/{__federation_expose_PrometheusTimeSeriesQuery.f59141f4.js → __federation_expose_PrometheusTimeSeriesQuery.08f11ea9.js} +1 -1
- package/__mf/js/{main.9617b605.js → main.78fc6444.js} +5 -5
- package/lib/bootstrap.js +1 -1
- package/lib/bootstrap.js.map +1 -1
- package/lib/cjs/bootstrap.js +1 -1
- package/lib/cjs/components/PromQLEditor.js +1 -1
- package/lib/cjs/components/TreeNode.js +1 -1
- package/lib/cjs/components/index.js +1 -1
- package/lib/cjs/components/promql/ast.js +1 -1
- package/lib/cjs/components/promql/format.js +1 -1
- package/lib/cjs/components/promql/functionSignatures.js +1 -1
- package/lib/cjs/components/promql/serialize.js +1 -1
- package/lib/cjs/components/promql/utils.js +1 -1
- package/lib/cjs/components/query.js +1 -1
- package/lib/cjs/env.d.js +1 -1
- package/lib/cjs/explore/PrometheusExplorer.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/display/MetricChip.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/display/list/MetricList.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/filter/FilterInputs.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/filter/FinderFilters.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/index.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/overview/MetricOverview.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/overview/tabs/JobTab.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/types.js +1 -1
- package/lib/cjs/explore/PrometheusMetricsFinder/utils.js +1 -1
- package/lib/cjs/explore/index.js +12 -0
- package/lib/cjs/getPluginModule.js +12 -0
- package/lib/cjs/index-federation.js +1 -1
- package/lib/cjs/index.js +12 -0
- package/lib/cjs/model/api-types.js +1 -1
- package/lib/cjs/model/index.js +1 -1
- package/lib/cjs/model/parse-sample-values.js +1 -1
- package/lib/cjs/model/prometheus-client.js +1 -1
- package/lib/cjs/model/prometheus-selectors.js +1 -1
- package/lib/cjs/model/time.js +1 -1
- package/lib/cjs/plugins/MatcherEditor.js +1 -1
- package/lib/cjs/plugins/PrometheusDatasourceEditor.js +1 -1
- package/lib/cjs/plugins/PrometheusLabelNamesVariable.js +12 -0
- package/lib/cjs/plugins/PrometheusLabelValuesVariable.js +12 -0
- package/lib/cjs/plugins/PrometheusPromQLVariable.js +12 -0
- package/lib/cjs/plugins/index.js +12 -0
- package/lib/cjs/plugins/prometheus-datasource.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/index.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/query-editor-model.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/replace-prom-builtin-variables.js +1 -1
- package/lib/cjs/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
- package/lib/cjs/plugins/prometheus-variables.js +1 -1
- package/lib/cjs/plugins/test/setup-tests.js +1 -1
- package/lib/cjs/plugins/types.js +1 -1
- package/lib/cjs/plugins/variable.js +1 -1
- package/lib/cjs/setup-tests.js +1 -1
- package/lib/cjs/utils/index.js +1 -1
- package/lib/cjs/utils/utils.js +1 -1
- package/lib/components/PromQLEditor.js +1 -1
- 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/index.js +1 -1
- package/lib/components/index.js.map +1 -1
- package/lib/components/promql/ast.js +1 -1
- package/lib/components/promql/ast.js.map +1 -1
- package/lib/components/promql/format.js +1 -1
- package/lib/components/promql/format.js.map +1 -1
- package/lib/components/promql/functionSignatures.js +1 -1
- package/lib/components/promql/functionSignatures.js.map +1 -1
- package/lib/components/promql/serialize.js +1 -1
- package/lib/components/promql/serialize.js.map +1 -1
- package/lib/components/promql/utils.js +1 -1
- package/lib/components/promql/utils.js.map +1 -1
- package/lib/components/query.js +1 -1
- package/lib/components/query.js.map +1 -1
- package/lib/env.d.js +1 -1
- package/lib/env.d.js.map +1 -1
- package/lib/explore/PrometheusExplorer.js +1 -1
- 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/index.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/index.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/explore/PrometheusMetricsFinder/overview/tabs/JobTab.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/JobTab.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/types.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/types.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/utils.js +1 -1
- package/lib/explore/PrometheusMetricsFinder/utils.js.map +1 -1
- package/lib/explore/index.d.ts.map +1 -1
- package/lib/explore/index.js +12 -0
- package/lib/explore/index.js.map +1 -1
- package/lib/getPluginModule.d.ts.map +1 -1
- package/lib/getPluginModule.js +12 -0
- package/lib/getPluginModule.js.map +1 -1
- package/lib/index-federation.js +1 -1
- package/lib/index-federation.js.map +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +12 -0
- package/lib/index.js.map +1 -1
- package/lib/model/api-types.js +1 -1
- package/lib/model/api-types.js.map +1 -1
- package/lib/model/index.js +1 -1
- package/lib/model/index.js.map +1 -1
- package/lib/model/parse-sample-values.js +1 -1
- package/lib/model/parse-sample-values.js.map +1 -1
- package/lib/model/prometheus-client.js +1 -1
- package/lib/model/prometheus-client.js.map +1 -1
- package/lib/model/prometheus-selectors.js +1 -1
- package/lib/model/prometheus-selectors.js.map +1 -1
- package/lib/model/time.js +1 -1
- package/lib/model/time.js.map +1 -1
- package/lib/plugins/MatcherEditor.js +1 -1
- package/lib/plugins/MatcherEditor.js.map +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.js +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.js.map +1 -1
- package/lib/plugins/PrometheusLabelNamesVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusLabelNamesVariable.js +12 -0
- package/lib/plugins/PrometheusLabelNamesVariable.js.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.js +12 -0
- package/lib/plugins/PrometheusLabelValuesVariable.js.map +1 -1
- package/lib/plugins/PrometheusPromQLVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusPromQLVariable.js +12 -0
- package/lib/plugins/PrometheusPromQLVariable.js.map +1 -1
- package/lib/plugins/index.d.ts.map +1 -1
- package/lib/plugins/index.js +12 -0
- package/lib/plugins/index.js.map +1 -1
- package/lib/plugins/prometheus-datasource.js +1 -1
- package/lib/plugins/prometheus-datasource.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js +1 -1
- package/lib/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.js +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/index.js +1 -1
- package/lib/plugins/prometheus-time-series-query/index.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/query-editor-model.js +1 -1
- package/lib/plugins/prometheus-time-series-query/query-editor-model.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/replace-prom-builtin-variables.js +1 -1
- package/lib/plugins/prometheus-time-series-query/replace-prom-builtin-variables.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/time-series-query-model.js +1 -1
- package/lib/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
- package/lib/plugins/prometheus-variables.js +1 -1
- package/lib/plugins/prometheus-variables.js.map +1 -1
- package/lib/plugins/test/setup-tests.js +1 -1
- package/lib/plugins/test/setup-tests.js.map +1 -1
- package/lib/plugins/types.js +1 -1
- package/lib/plugins/types.js.map +1 -1
- package/lib/plugins/variable.js +1 -1
- package/lib/plugins/variable.js.map +1 -1
- package/lib/setup-tests.js +1 -1
- package/lib/setup-tests.js.map +1 -1
- package/lib/utils/index.js +1 -1
- package/lib/utils/index.js.map +1 -1
- package/lib/utils/utils.js +1 -1
- package/lib/utils/utils.js.map +1 -1
- package/mf-manifest.json +73 -73
- package/mf-stats.json +73 -73
- package/package.json +6 -6
- package/__mf/js/async/1490.7e5068f1.js +0 -22
- package/__mf/js/async/1728.af16c4ec.js +0 -1
- package/__mf/js/async/2984.7182c2f5.js +0 -1
- package/__mf/js/async/2999.1d8347df.js +0 -1
- package/__mf/js/async/3664.ba8b26b6.js +0 -2
- package/__mf/js/async/392.7cda691a.js +0 -2
- package/__mf/js/async/5440.c13c3533.js +0 -2
- package/__mf/js/async/5501.6166367c.js +0 -2
- package/__mf/js/async/6149.19799c37.js +0 -7
- /package/__mf/js/async/{6149.19799c37.js.LICENSE.txt → 3652.6b591718.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{392.7cda691a.js.LICENSE.txt → 392.f1b4a590.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{3664.ba8b26b6.js.LICENSE.txt → 4657.f0c3ccd6.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{1490.7e5068f1.js.LICENSE.txt → 54.e6002704.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{5501.6166367c.js.LICENSE.txt → 9010.ca50fa9e.js.LICENSE.txt} +0 -0
|
@@ -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 } from '@perses-dev/core';\nimport { HTTPSettingsEditor } from '@perses-dev/plugin-system';\nimport { Box, TextField, Typography, IconButton } from '@mui/material';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport React, { ReactElement, useState, useRef } from 'react';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from './types';\n\ninterface QueryParamEntry {\n // Unique identifier for the entry, added to avoid using array index as key\n id: string;\n key: string;\n value: string;\n}\n\nexport interface PrometheusDatasourceEditorProps {\n value: PrometheusDatasourceSpec;\n onChange: (next: PrometheusDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function PrometheusDatasourceEditor(props: PrometheusDatasourceEditorProps): ReactElement {\n const { value, onChange, isReadonly } = props;\n\n // Counter for generating unique IDs\n const nextIdRef = useRef(0);\n\n // Use local state to maintain an array of entries during editing, instead of\n // manipulating a map directly which causes weird UX.\n const [entries, setEntries] = useState<QueryParamEntry[]>(() => {\n const queryParams = value.queryParams ?? {};\n return Object.entries(queryParams).map(([key, value]) => ({\n id: String(nextIdRef.current++),\n key,\n value,\n }));\n });\n\n // Check for duplicate keys\n const keyMap = new Map<string, number>();\n const duplicateKeys = new Set<string>();\n entries.forEach(({ key }) => {\n if (key !== '') {\n const count = (keyMap.get(key) || 0) + 1;\n keyMap.set(key, count);\n if (count > 1) {\n duplicateKeys.add(key);\n }\n }\n });\n const hasDuplicates = duplicateKeys.size > 0;\n\n // Convert entries array to object and trigger onChange\n const syncToParent = (newEntries: QueryParamEntry[]) => {\n const newParams: Record<string, string> = {};\n newEntries.forEach(({ key, value }) => {\n if (key !== '') {\n newParams[key] = value;\n }\n });\n\n onChange({\n ...value,\n queryParams: Object.keys(newParams).length > 0 ? newParams : undefined,\n });\n };\n\n const handleQueryParamChange = (id: string, field: 'key' | 'value', newValue: string) => {\n const newEntries = entries.map((entry) => {\n if (entry.id !== id) return entry;\n return field === 'key' ? { ...entry, key: newValue } : { ...entry, value: newValue };\n });\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const addQueryParam = () => {\n const newEntries = [...entries, { id: String(nextIdRef.current++), key: '', value: '' }];\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const removeQueryParam = (id: string) => {\n const newEntries = entries.filter((entry) => entry.id !== id);\n setEntries(newEntries);\n syncToParent(newEntries);\n };\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 endpointPattern: '/api/v1/parse_query',\n method: 'POST',\n },\n ],\n url: '',\n },\n },\n };\n\n return (\n <>\n <Typography variant=\"h4\" mb={2}>\n General Settings\n </Typography>\n <TextField\n size=\"small\"\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 helperText=\"Set it to match the typical scrape interval used in your Prometheus instance.\"\n />\n <HTTPSettingsEditor\n value={value}\n onChange={onChange}\n isReadonly={isReadonly}\n initialSpecDirect={initialSpecDirect}\n initialSpecProxy={initialSpecProxy}\n />\n <Typography variant=\"h5\" mt={2} mb={1}>\n Query Parameters\n </Typography>\n {entries.length > 0 && (\n <>\n {entries.map((entry) => (\n <Box key={entry.id} display=\"flex\" alignItems=\"center\" gap={2} mb={1}>\n <TextField\n size=\"small\"\n label=\"Key\"\n value={entry.key}\n placeholder=\"Parameter name\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'key', e.target.value)}\n error={duplicateKeys.has(entry.key)}\n sx={{ minWidth: 150 }}\n />\n <TextField\n size=\"small\"\n label=\"Value\"\n value={entry.value}\n placeholder=\"Parameter value\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'value', e.target.value)}\n sx={{ minWidth: 150, flexGrow: 1 }}\n />\n {!isReadonly && (\n <IconButton onClick={() => removeQueryParam(entry.id)}>\n <MinusIcon />\n </IconButton>\n )}\n </Box>\n ))}\n </>\n )}\n {hasDuplicates && (\n <Typography variant=\"body2\" color=\"error\" mb={1}>\n Duplicate parameter keys detected. Each key must be unique.\n </Typography>\n )}\n {entries.length === 0 && (\n <Typography variant=\"body2\" color=\"textSecondary\">\n No query parameters configured. Use query parameters to pass additional options to Prometheus (e.g.,\n dedup=false for Thanos).\n </Typography>\n )}\n {!isReadonly && (\n <IconButton onClick={addQueryParam}>\n <PlusIcon />\n </IconButton>\n )}\n </>\n );\n}\n"],"names":["HTTPSettingsEditor","Box","TextField","Typography","IconButton","PlusIcon","MinusIcon","React","useState","useRef","DEFAULT_SCRAPE_INTERVAL","PrometheusDatasourceEditor","props","value","onChange","isReadonly","nextIdRef","entries","setEntries","queryParams","Object","map","key","id","String","current","keyMap","Map","duplicateKeys","Set","forEach","count","get","set","add","hasDuplicates","size","syncToParent","newEntries","newParams","keys","length","undefined","handleQueryParamChange","field","newValue","entry","addQueryParam","removeQueryParam","filter","initialSpecDirect","directUrl","initialSpecProxy","proxy","kind","spec","allowedEndpoints","endpointPattern","method","url","variant","mb","fullWidth","label","scrapeInterval","placeholder","InputProps","readOnly","InputLabelProps","shrink","e","target","helperText","mt","display","alignItems","gap","disabled","error","has","sx","minWidth","flexGrow","onClick","color"],"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,kBAAkB,QAAQ,4BAA4B;AAC/D,SAASC,GAAG,EAAEC,SAAS,EAAEC,UAAU,EAAEC,UAAU,QAAQ,gBAAgB;AACvE,OAAOC,cA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ACjB;;;uBAtBGwC,MAAMvB,EAAE;;YA6BvBY,+BACC,KAAChC;gBAAWyD,SAAQ;gBAAQwB,OAAM;gBAAQvB,IAAI;0BAAG;;YAIlD5C,QAAQwB,MAAM,KAAK,mBAClB,KAACtC;gBAAWyD,SAAQ;gBAAQwB,OAAM;0BAAgB;;YAKnD,CAACrE,4BACA,KAACX;gBAAW+E,SAASpC;0BACnB,cAAA,KAAC1C;;;;AAKX"}
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusDatasourceEditor.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport { HTTPSettingsEditor } from '@perses-dev/plugin-system';\nimport { Box, TextField, Typography, IconButton } from '@mui/material';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport React, { ReactElement, useState, useRef } from 'react';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from './types';\n\ninterface QueryParamEntry {\n // Unique identifier for the entry, added to avoid using array index as key\n id: string;\n key: string;\n value: string;\n}\n\nexport interface PrometheusDatasourceEditorProps {\n value: PrometheusDatasourceSpec;\n onChange: (next: PrometheusDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function PrometheusDatasourceEditor(props: PrometheusDatasourceEditorProps): ReactElement {\n const { value, onChange, isReadonly } = props;\n\n // Counter for generating unique IDs\n const nextIdRef = useRef(0);\n\n // Use local state to maintain an array of entries during editing, instead of\n // manipulating a map directly which causes weird UX.\n const [entries, setEntries] = useState<QueryParamEntry[]>(() => {\n const queryParams = value.queryParams ?? {};\n return Object.entries(queryParams).map(([key, value]) => ({\n id: String(nextIdRef.current++),\n key,\n value,\n }));\n });\n\n // Check for duplicate keys\n const keyMap = new Map<string, number>();\n const duplicateKeys = new Set<string>();\n entries.forEach(({ key }) => {\n if (key !== '') {\n const count = (keyMap.get(key) || 0) + 1;\n keyMap.set(key, count);\n if (count > 1) {\n duplicateKeys.add(key);\n }\n }\n });\n const hasDuplicates = duplicateKeys.size > 0;\n\n // Convert entries array to object and trigger onChange\n const syncToParent = (newEntries: QueryParamEntry[]) => {\n const newParams: Record<string, string> = {};\n newEntries.forEach(({ key, value }) => {\n if (key !== '') {\n newParams[key] = value;\n }\n });\n\n onChange({\n ...value,\n queryParams: Object.keys(newParams).length > 0 ? newParams : undefined,\n });\n };\n\n const handleQueryParamChange = (id: string, field: 'key' | 'value', newValue: string) => {\n const newEntries = entries.map((entry) => {\n if (entry.id !== id) return entry;\n return field === 'key' ? { ...entry, key: newValue } : { ...entry, value: newValue };\n });\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const addQueryParam = () => {\n const newEntries = [...entries, { id: String(nextIdRef.current++), key: '', value: '' }];\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const removeQueryParam = (id: string) => {\n const newEntries = entries.filter((entry) => entry.id !== id);\n setEntries(newEntries);\n syncToParent(newEntries);\n };\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 endpointPattern: '/api/v1/parse_query',\n method: 'POST',\n },\n ],\n url: '',\n },\n },\n };\n\n return (\n <>\n <Typography variant=\"h4\" mb={2}>\n General Settings\n </Typography>\n <TextField\n size=\"small\"\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 helperText=\"Set it to match the typical scrape interval used in your Prometheus instance.\"\n />\n <HTTPSettingsEditor\n value={value}\n onChange={onChange}\n isReadonly={isReadonly}\n initialSpecDirect={initialSpecDirect}\n initialSpecProxy={initialSpecProxy}\n />\n <Typography variant=\"h5\" mt={2} mb={1}>\n Query Parameters\n </Typography>\n {entries.length > 0 && (\n <>\n {entries.map((entry) => (\n <Box key={entry.id} display=\"flex\" alignItems=\"center\" gap={2} mb={1}>\n <TextField\n size=\"small\"\n label=\"Key\"\n value={entry.key}\n placeholder=\"Parameter name\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'key', e.target.value)}\n error={duplicateKeys.has(entry.key)}\n sx={{ minWidth: 150 }}\n />\n <TextField\n size=\"small\"\n label=\"Value\"\n value={entry.value}\n placeholder=\"Parameter value\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'value', e.target.value)}\n sx={{ minWidth: 150, flexGrow: 1 }}\n />\n {!isReadonly && (\n <IconButton onClick={() => removeQueryParam(entry.id)}>\n <MinusIcon />\n </IconButton>\n )}\n </Box>\n ))}\n </>\n )}\n {hasDuplicates && (\n <Typography variant=\"body2\" color=\"error\" mb={1}>\n Duplicate parameter keys detected. Each key must be unique.\n </Typography>\n )}\n {entries.length === 0 && (\n <Typography variant=\"body2\" color=\"textSecondary\">\n No query parameters configured. Use query parameters to pass additional options to Prometheus (e.g.,\n dedup=false for Thanos).\n </Typography>\n )}\n {!isReadonly && (\n <IconButton onClick={addQueryParam}>\n <PlusIcon />\n </IconButton>\n )}\n </>\n );\n}\n"],"names":["HTTPSettingsEditor","Box","TextField","Typography","IconButton","PlusIcon","MinusIcon","React","useState","useRef","DEFAULT_SCRAPE_INTERVAL","PrometheusDatasourceEditor","props","value","onChange","isReadonly","nextIdRef","entries","setEntries","queryParams","Object","map","key","id","String","current","keyMap","Map","duplicateKeys","Set","forEach","count","get","set","add","hasDuplicates","size","syncToParent","newEntries","newParams","keys","length","undefined","handleQueryParamChange","field","newValue","entry","addQueryParam","removeQueryParam","filter","initialSpecDirect","directUrl","initialSpecProxy","proxy","kind","spec","allowedEndpoints","endpointPattern","method","url","variant","mb","fullWidth","label","scrapeInterval","placeholder","InputProps","readOnly","InputLabelProps","shrink","e","target","helperText","mt","display","alignItems","gap","disabled","error","has","sx","minWidth","flexGrow","onClick","color"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,kBAAkB,QAAQ,4BAA4B;AAC/D,SAASC,GAAG,EAAEC,SAAS,EAAEC,UAAU,EAAEC,UAAU,QAAQ,gBAAgB;AACvE,OAAOC,cAAc,uBAAuB;AAC5C,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,SAAuBC,QAAQ,EAAEC,MAAM,QAAQ,QAAQ;AAC9D,SAASC,uBAAuB,QAAkC,UAAU;AAe5E,OAAO,SAASC,2BAA2BC,KAAsC;IAC/E,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,UAAU,EAAE,GAAGH;IAExC,oCAAoC;IACpC,MAAMI,YAAYP,OAAO;IAEzB,6EAA6E;IAC7E,qDAAqD;IACrD,MAAM,CA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rometheusLabelNamesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrometheusLabelNamesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,EAMf,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,mCAAmC,EAAE,MAAM,SAAS,CAAC;AAE9D,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CAyB5F,CAAC"}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the \"License\");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an \"AS IS\" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
1
13
|
import { replaceVariables, parseVariables, datasourceSelectValueToSelector, isVariableDatasource } from '@perses-dev/plugin-system';
|
|
2
14
|
import { DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';
|
|
3
15
|
import { stringArrayToVariableOptions, PrometheusLabelNamesVariableEditor } from './prometheus-variables';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"sourcesContent":["// Copyright 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 VariablePlugin,\n GetVariableOptionsContext,\n replaceVariables,\n parseVariables,\n datasourceSelectValueToSelector,\n isVariableDatasource,\n} from '@perses-dev/plugin-system';\nimport { PrometheusClient, DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';\nimport { stringArrayToVariableOptions, PrometheusLabelNamesVariableEditor } from './prometheus-variables';\nimport { PrometheusLabelNamesVariableOptions } from './types';\n\nexport const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelNamesVariableOptions, ctx: GetVariableOptionsContext) => {\n const datasourceSelector =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n ctx.variables,\n await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)\n ) ?? DEFAULT_PROM;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);\n const match = spec.matchers ? spec.matchers.map((m) => replaceVariables(m, ctx.variables)) : undefined;\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelNames({ 'match[]': match, ...timeRange });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelNamesVariableOptions) => {\n const matcherVariables = spec.matchers?.map((m) => parseVariables(m)).flat() || [];\n const datasourceVariables =\n spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];\n return { variables: [...matcherVariables, ...datasourceVariables] };\n },\n OptionsEditorComponent: PrometheusLabelNamesVariableEditor,\n createInitialOptions: () => ({}),\n};\n"],"names":["replaceVariables","parseVariables","datasourceSelectValueToSelector","isVariableDatasource","DEFAULT_PROM","getPrometheusTimeRange","PROM_DATASOURCE_KIND","stringArrayToVariableOptions","PrometheusLabelNamesVariableEditor","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","datasourceSelector","datasource","variables","datasourceStore","listDatasourceSelectItems","client","getDatasourceClient","match","matchers","map","m","undefined","timeRange","data","options","labelNames","dependsOn","matcherVariables","flat","datasourceVariables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAGEA,gBAAgB,EAChBC,cAAc,EACdC,+BAA+B,EAC/BC,oBAAoB,QACf,4BAA4B;AACnC,SAA2BC,YAAY,EAAEC,sBAAsB,EAAEC,oBAAoB,QAAQ,WAAW;AACxG,SAASC,4BAA4B,EAAEC,kCAAkC,QAAQ,yBAAyB;AAG1G,OAAO,MAAMC,+BAAoF;IAC/FC,oBAAoB,OAAOC,MAA2CC;QACpE,MAAMC,qBACJX,gCACES,KAAKG,UAAU,IAAIV,cACnBQ,IAAIG,SAAS,EACb,MAAMH,IAAII,eAAe,CAACC,yBAAyB,CAACX,0BACjDF;QACP,MAAMc,SAA2B,MAAMN,IAAII,eAAe,CAACG,mBAAmB,CAACN;QAC/E,MAAMO,QAAQT,KAAKU,QAAQ,GAAGV,KAAKU,QAAQ,CAACC,GAAG,CAAC,CAACC,IAAMvB,iBAAiBuB,GAAGX,IAAIG,SAAS,KAAKS;QAC7F,MAAMC,YAAYpB,uBAAuBO,IAAIa,SAAS;QAEtD,MAAM,EAAEC,MAAMC,OAAO,EAAE,GAAG,MAAMT,OAAOU,UAAU,CAAC;YAAE,WAAWR;YAAO,GAAGK,SAAS;QAAC;QACnF,OAAO;YACLC,MAAMnB,6BAA6BoB;QACrC;IACF;IACAE,WAAW,CAAClB;QACV,MAAMmB,mBAAmBnB,KAAKU,QAAQ,EAAEC,IAAI,CAACC,IAAMtB,eAAesB,IAAIQ,UAAU,EAAE;QAClF,MAAMC,sBACJrB,KAAKG,UAAU,IAAIX,qBAAqBQ,KAAKG,UAAU,IAAIb,eAAeU,KAAKG,UAAU,IAAI,EAAE;QACjG,OAAO;YAAEC,WAAW;mBAAIe;mBAAqBE;aAAoB;QAAC;IACpE;IACAC,wBAAwBzB;IACxB0B,sBAAsB,IAAO,CAAA,CAAC,CAAA;AAChC,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusLabelValuesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrometheusLabelValuesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,EAMf,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EAAE,oCAAoC,EAAE,MAAM,SAAS,CAAC;AAE/D,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CAkC9F,CAAC"}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the \"License\");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an \"AS IS\" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
1
13
|
import { replaceVariables, parseVariables, datasourceSelectValueToSelector, isVariableDatasource } from '@perses-dev/plugin-system';
|
|
2
14
|
import { DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';
|
|
3
15
|
import { stringArrayToVariableOptions, PrometheusLabelValuesVariableEditor } from './prometheus-variables';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"sourcesContent":["// Copyright 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 VariablePlugin,\n GetVariableOptionsContext,\n replaceVariables,\n parseVariables,\n datasourceSelectValueToSelector,\n isVariableDatasource,\n} from '@perses-dev/plugin-system';\nimport { PrometheusClient, DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';\nimport { stringArrayToVariableOptions, PrometheusLabelValuesVariableEditor } from './prometheus-variables';\nimport { PrometheusLabelValuesVariableOptions } from './types';\n\nexport const PrometheusLabelValuesVariable: VariablePlugin<PrometheusLabelValuesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelValuesVariableOptions, ctx: GetVariableOptionsContext) => {\n const pluginDef = spec;\n const datasourceSelector =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n ctx.variables,\n await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)\n ) ?? DEFAULT_PROM;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);\n const match = pluginDef.matchers ? pluginDef.matchers.map((m) => replaceVariables(m, ctx.variables)) : undefined;\n\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelValues({\n labelName: replaceVariables(pluginDef.labelName, ctx.variables),\n 'match[]': match,\n ...timeRange,\n });\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelValuesVariableOptions) => {\n const matcherVariables = spec.matchers?.map((m) => parseVariables(m)).flat() || [];\n const labelVariables = parseVariables(spec.labelName);\n const datasourceVariables =\n spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];\n return {\n variables: [...matcherVariables, ...labelVariables, ...datasourceVariables],\n };\n },\n OptionsEditorComponent: PrometheusLabelValuesVariableEditor,\n createInitialOptions: () => ({ labelName: '' }),\n};\n"],"names":["replaceVariables","parseVariables","datasourceSelectValueToSelector","isVariableDatasource","DEFAULT_PROM","getPrometheusTimeRange","PROM_DATASOURCE_KIND","stringArrayToVariableOptions","PrometheusLabelValuesVariableEditor","PrometheusLabelValuesVariable","getVariableOptions","spec","ctx","pluginDef","datasourceSelector","datasource","variables","datasourceStore","listDatasourceSelectItems","client","getDatasourceClient","match","matchers","map","m","undefined","timeRange","data","options","labelValues","labelName","dependsOn","matcherVariables","flat","labelVariables","datasourceVariables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAGEA,gBAAgB,EAChBC,cAAc,EACdC,+BAA+B,EAC/BC,oBAAoB,QACf,4BAA4B;AACnC,SAA2BC,YAAY,EAAEC,sBAAsB,EAAEC,oBAAoB,QAAQ,WAAW;AACxG,SAASC,4BAA4B,EAAEC,mCAAmC,QAAQ,yBAAyB;AAG3G,OAAO,MAAMC,gCAAsF;IACjGC,oBAAoB,OAAOC,MAA4CC;QACrE,MAAMC,YAAYF;QAClB,MAAMG,qBACJZ,gCACES,KAAKI,UAAU,IAAIX,cACnBQ,IAAII,SAAS,EACb,MAAMJ,IAAIK,eAAe,CAACC,yBAAyB,CAACZ,0BACjDF;QACP,MAAMe,SAA2B,MAAMP,IAAIK,eAAe,CAACG,mBAAmB,CAACN;QAC/E,MAAMO,QAAQR,UAAUS,QAAQ,GAAGT,UAAUS,QAAQ,CAACC,GAAG,CAAC,CAACC,IAAMxB,iBAAiBwB,GAAGZ,IAAII,SAAS,KAAKS;QAEvG,MAAMC,YAAYrB,uBAAuBO,IAAIc,SAAS;QAEtD,MAAM,EAAEC,MAAMC,OAAO,EAAE,GAAG,MAAMT,OAAOU,WAAW,CAAC;YACjDC,WAAW9B,iBAAiBa,UAAUiB,SAAS,EAAElB,IAAII,SAAS;YAC9D,WAAWK;YACX,GAAGK,SAAS;QACd;QACA,OAAO;YACLC,MAAMpB,6BAA6BqB;QACrC;IACF;IACAG,WAAW,CAACpB;QACV,MAAMqB,mBAAmBrB,KAAKW,QAAQ,EAAEC,IAAI,CAACC,IAAMvB,eAAeuB,IAAIS,UAAU,EAAE;QAClF,MAAMC,iBAAiBjC,eAAeU,KAAKmB,SAAS;QACpD,MAAMK,sBACJxB,KAAKI,UAAU,IAAIZ,qBAAqBQ,KAAKI,UAAU,IAAId,eAAeU,KAAKI,UAAU,IAAI,EAAE;QACjG,OAAO;YACLC,WAAW;mBAAIgB;mBAAqBE;mBAAmBC;aAAoB;QAC7E;IACF;IACAC,wBAAwB5B;IACxB6B,sBAAsB,IAAO,CAAA;YAAEP,WAAW;QAAG,CAAA;AAC/C,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusPromQLVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusPromQLVariable.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrometheusPromQLVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusPromQLVariable.tsx"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,EAMf,MAAM,2BAA2B,CAAC;AAQnC,OAAO,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE1D,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,+BAA+B,CAkCpF,CAAC"}
|
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the \"License\");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an \"AS IS\" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
1
13
|
import { replaceVariables, parseVariables, datasourceSelectValueToSelector, isVariableDatasource } from '@perses-dev/plugin-system';
|
|
2
14
|
import { DEFAULT_PROM, PROM_DATASOURCE_KIND } from '../model';
|
|
3
15
|
import { capturingMatrix, capturingVector, stringArrayToVariableOptions, PrometheusPromQLVariableEditor } from './prometheus-variables';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/PrometheusPromQLVariable.tsx"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusPromQLVariable.tsx"],"sourcesContent":["// Copyright 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 VariablePlugin,\n GetVariableOptionsContext,\n replaceVariables,\n parseVariables,\n datasourceSelectValueToSelector,\n isVariableDatasource,\n} from '@perses-dev/plugin-system';\nimport { PrometheusClient, DEFAULT_PROM, PROM_DATASOURCE_KIND } from '../model';\nimport {\n capturingMatrix,\n capturingVector,\n stringArrayToVariableOptions,\n PrometheusPromQLVariableEditor,\n} from './prometheus-variables';\nimport { PrometheusPromQLVariableOptions } from './types';\n\nexport const PrometheusPromQLVariable: VariablePlugin<PrometheusPromQLVariableOptions> = {\n getVariableOptions: async (spec: PrometheusPromQLVariableOptions, ctx: GetVariableOptionsContext) => {\n const datasourceSelector =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n ctx.variables,\n await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)\n ) ?? DEFAULT_PROM;\n const client: PrometheusClient = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);\n // TODO we may want to manage a range query as well.\n const { data: options } = await client.instantQuery({\n query: replaceVariables(spec.expr, ctx.variables),\n });\n const labelName = replaceVariables(spec.labelName, ctx.variables);\n let values: string[] = [];\n if (options?.resultType === 'matrix') {\n values = capturingMatrix(options, labelName);\n } else if (options?.resultType === 'vector') {\n values = capturingVector(options, labelName);\n }\n\n return {\n data: stringArrayToVariableOptions(values),\n };\n },\n dependsOn: (spec: PrometheusPromQLVariableOptions) => {\n const exprVariables = parseVariables(spec.expr);\n const labelVariables = parseVariables(spec.labelName);\n const datasourceVariables =\n spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];\n return { variables: [...exprVariables, ...labelVariables, ...datasourceVariables] };\n },\n OptionsEditorComponent: PrometheusPromQLVariableEditor,\n createInitialOptions: () => ({ expr: '', labelName: '' }),\n};\n"],"names":["replaceVariables","parseVariables","datasourceSelectValueToSelector","isVariableDatasource","DEFAULT_PROM","PROM_DATASOURCE_KIND","capturingMatrix","capturingVector","stringArrayToVariableOptions","PrometheusPromQLVariableEditor","PrometheusPromQLVariable","getVariableOptions","spec","ctx","datasourceSelector","datasource","variables","datasourceStore","listDatasourceSelectItems","client","getDatasourceClient","data","options","instantQuery","query","expr","labelName","values","resultType","dependsOn","exprVariables","labelVariables","datasourceVariables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAGEA,gBAAgB,EAChBC,cAAc,EACdC,+BAA+B,EAC/BC,oBAAoB,QACf,4BAA4B;AACnC,SAA2BC,YAAY,EAAEC,oBAAoB,QAAQ,WAAW;AAChF,SACEC,eAAe,EACfC,eAAe,EACfC,4BAA4B,EAC5BC,8BAA8B,QACzB,yBAAyB;AAGhC,OAAO,MAAMC,2BAA4E;IACvFC,oBAAoB,OAAOC,MAAuCC;QAChE,MAAMC,qBACJZ,gCACEU,KAAKG,UAAU,IAAIX,cACnBS,IAAIG,SAAS,EACb,MAAMH,IAAII,eAAe,CAACC,yBAAyB,CAACb,0BACjDD;QACP,MAAMe,SAA2B,MAAMN,IAAII,eAAe,CAACG,mBAAmB,CAACN;QAC/E,oDAAoD;QACpD,MAAM,EAAEO,MAAMC,OAAO,EAAE,GAAG,MAAMH,OAAOI,YAAY,CAAC;YAClDC,OAAOxB,iBAAiBY,KAAKa,IAAI,EAAEZ,IAAIG,SAAS;QAClD;QACA,MAAMU,YAAY1B,iBAAiBY,KAAKc,SAAS,EAAEb,IAAIG,SAAS;QAChE,IAAIW,SAAmB,EAAE;QACzB,IAAIL,SAASM,eAAe,UAAU;YACpCD,SAASrB,gBAAgBgB,SAASI;QACpC,OAAO,IAAIJ,SAASM,eAAe,UAAU;YAC3CD,SAASpB,gBAAgBe,SAASI;QACpC;QAEA,OAAO;YACLL,MAAMb,6BAA6BmB;QACrC;IACF;IACAE,WAAW,CAACjB;QACV,MAAMkB,gBAAgB7B,eAAeW,KAAKa,IAAI;QAC9C,MAAMM,iBAAiB9B,eAAeW,KAAKc,SAAS;QACpD,MAAMM,sBACJpB,KAAKG,UAAU,IAAIZ,qBAAqBS,KAAKG,UAAU,IAAId,eAAeW,KAAKG,UAAU,IAAI,EAAE;QACjG,OAAO;YAAEC,WAAW;mBAAIc;mBAAkBC;mBAAmBC;aAAoB;QAAC;IACpF;IACAC,wBAAwBxB;IACxByB,sBAAsB,IAAO,CAAA;YAAET,MAAM;YAAIC,WAAW;QAAG,CAAA;AACzD,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/index.ts"],"names":[],"mappings":"AAaA,cAAc,iBAAiB,CAAC;AAChC,cAAc,yBAAyB,CAAC;AACxC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,wBAAwB,CAAC;AACvC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,iCAAiC,CAAC;AAChD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
|
package/lib/plugins/index.js
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
// Copyright The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the \"License\");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an \"AS IS\" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
1
13
|
export * from './MatcherEditor';
|
|
2
14
|
export * from './prometheus-datasource';
|
|
3
15
|
export * from './prometheus-time-series-query';
|
package/lib/plugins/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/index.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/index.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \\\"License\\\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \\\"AS IS\\\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './MatcherEditor';\nexport * from './prometheus-datasource';\nexport * from './prometheus-time-series-query';\nexport * from './prometheus-variables';\nexport * from './PrometheusDatasourceEditor';\nexport * from './PrometheusLabelNamesVariable';\nexport * from './PrometheusLabelValuesVariable';\nexport * from './PrometheusPromQLVariable';\nexport * from './types';\nexport * from './variable';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,kBAAkB;AAChC,cAAc,0BAA0B;AACxC,cAAc,iCAAiC;AAC/C,cAAc,yBAAyB;AACvC,cAAc,+BAA+B;AAC7C,cAAc,iCAAiC;AAC/C,cAAc,kCAAkC;AAChD,cAAc,6BAA6B;AAC3C,cAAc,UAAU;AACxB,cAAc,aAAa"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/prometheus-datasource.tsx"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/prometheus-datasource.tsx"],"sourcesContent":["// Copyright 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 { BuiltinVariableDefinition } from '@perses-dev/core';\nimport { DatasourcePlugin } from '@perses-dev/plugin-system';\nimport {\n healthCheck,\n instantQuery,\n rangeQuery,\n labelNames,\n labelValues,\n PrometheusClient,\n metricMetadata,\n series,\n parseQuery,\n} from '../model';\nimport { PrometheusDatasourceSpec } from './types';\nimport { PrometheusDatasourceEditor } from './PrometheusDatasourceEditor';\n\n/**\n * Creates a PrometheusClient for a specific datasource spec.\n */\nconst createClient: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient>['createClient'] = (spec, options) => {\n const { directUrl, proxy, queryParams } = spec;\n const { proxyUrl } = options;\n\n // Use the direct URL if specified, but fallback to the proxyUrl by default if not specified\n const datasourceUrl = directUrl ?? proxyUrl;\n if (datasourceUrl === undefined) {\n throw new Error('No URL specified for Prometheus client. You can use directUrl in the spec to configure it.');\n }\n\n const specHeaders = proxy?.spec.headers;\n\n // Could think about this becoming a class, although it definitely doesn't have to be\n return {\n options: {\n datasourceUrl,\n },\n healthCheck: healthCheck({ datasourceUrl, headers: specHeaders, queryParams }),\n instantQuery: (params, headers, abortSignal) =>\n instantQuery(params, { datasourceUrl, headers: headers ?? specHeaders, abortSignal, queryParams }),\n rangeQuery: (params, headers, abortSignal) =>\n rangeQuery(params, { datasourceUrl, headers: headers ?? specHeaders, abortSignal, queryParams }),\n labelNames: (params, headers, abortSignal) =>\n labelNames(params, { datasourceUrl, headers: headers ?? specHeaders, abortSignal, queryParams }),\n labelValues: (params, headers, abortSignal) =>\n labelValues(params, { datasourceUrl, headers: headers ?? specHeaders, abortSignal, queryParams }),\n metricMetadata: (params, headers, abortSignal) =>\n metricMetadata(params, { datasourceUrl, headers: headers ?? specHeaders, abortSignal, queryParams }),\n series: (params, headers, abortSignal) =>\n series(params, { datasourceUrl, headers: headers ?? specHeaders, abortSignal, queryParams }),\n parseQuery: (params, headers, abortSignal) =>\n parseQuery(params, { datasourceUrl, headers: headers ?? specHeaders, abortSignal, queryParams }),\n };\n};\n\nconst getBuiltinVariableDefinitions: () => BuiltinVariableDefinition[] = () => {\n return [\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__interval',\n value: () => '$__interval', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__interval',\n description:\n 'For dynamic queries that adapt across different time ranges, use $__interval instead of hardcoded intervals. It represents the actual spacing between data points: it’s calculated based on the current time range and the panel pixel width (taking the \"Min step\" as a lower bound).',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__interval_ms',\n value: () => '$__interval_ms', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__interval_ms',\n description: 'Same as $__interval but in milliseconds.',\n hidden: true,\n },\n },\n },\n {\n kind: 'BuiltinVariable',\n spec: {\n name: '__rate_interval',\n value: () => '$__rate_interval', // will be overriden when time series query is called\n source: 'Prometheus',\n display: {\n name: '__rate_interval',\n description:\n 'Use this one rather than $__interval as the range parameter of functions like rate, increase, etc. With such function it is advised to choose a range that is at least 4x the scrape interval (this is to allow for various races, and to be resilient to a failed scrape). $__rate_interval provides that, as it is defined as `max($__interval + Min Step, 4 * Min Step)`, where Min Step value should represent the scrape interval of the metrics.',\n hidden: true,\n },\n },\n },\n ] as BuiltinVariableDefinition[];\n};\n\nexport const PrometheusDatasource: DatasourcePlugin<PrometheusDatasourceSpec, PrometheusClient> = {\n createClient,\n getBuiltinVariableDefinitions,\n OptionsEditorComponent: PrometheusDatasourceEditor,\n createInitialOptions: () => ({ directUrl: '' }),\n};\n"],"names":["healthCheck","instantQuery","rangeQuery","labelNames","labelValues","metricMetadata","series","parseQuery","PrometheusDatasourceEditor","createClient","spec","options","directUrl","proxy","queryParams","proxyUrl","datasourceUrl","undefined","Error","specHeaders","headers","params","abortSignal","getBuiltinVariableDefinitions","kind","name","value","source","display","description","hidden","PrometheusDatasource","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,SACEA,WAAW,EACXC,YAAY,EACZC,UAAU,EACVC,UAAU,EACVC,WAAW,EAEXC,cAAc,EACdC,MAAM,EACNC,UAAU,QACL,WAAW;AAElB,SAASC,0BAA0B,QAAQ,+BAA+B;AAE1E;;CAEC,GACD,MAAMC,eAA6F,CAACC,MAAMC;IACxG,MAAM,EAAEC,SAAS,EAAEC,KAAK,EAAEC,WAAW,EAAE,GAAGJ;IAC1C,MAAM,EAAEK,QAAQ,EAAE,GAAGJ;IAErB,4FAA4F;IAC5F,MAAMK,gBAAgBJ,aAAaG;IACnC,IAAIC,kBAAkBC,WAAW;QAC/B,MAAM,IAAIC,MAAM;IAClB;IAEA,MAAMC,cAAcN,OAAOH,KAAKU;IAEhC,qFAAqF;IACrF,OAAO;QACLT,SAAS;YACPK;QACF;QACAhB,aAAaA,YAAY;YAAEgB;YAAeI,SAASD;YAAaL;QAAY;QAC5Eb,cAAc,CAACoB,QAAQD,SAASE,cAC9BrB,aAAaoB,QAAQ;gBAAEL;gBAAeI,SAASA,WAAWD;gBAAaG;gBAAaR;YAAY;QAClGZ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AAA;YAAErB,WAAW;QAAG,CAAA;AAC/C,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQuery.ts"],"sourcesContent":["// Copyright 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 { TimeSeriesQueryPlugin, isVariableDatasource, parseVariables } from '@perses-dev/plugin-system';\nimport { getTimeSeriesData } from './get-time-series-data';\nimport { PrometheusTimeSeriesQueryEditor } from './PrometheusTimeSeriesQueryEditor';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\n/**\n * The core Prometheus TimeSeriesQuery plugin for Perses.\n */\nexport const PrometheusTimeSeriesQuery: TimeSeriesQueryPlugin<PrometheusTimeSeriesQuerySpec> = {\n getTimeSeriesData,\n OptionsEditorComponent: PrometheusTimeSeriesQueryEditor,\n createInitialOptions: () => ({\n query: '',\n datasource: undefined,\n }),\n dependsOn: (spec) => {\n // Variables can be used in the query and/or in the legend format string\n const queryVariables = parseVariables(spec.query);\n const legendVariables = parseVariables(spec.seriesNameFormat || '');\n const datasourceVariable = isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource ?? '') : [];\n const allVariables = [...new Set([...queryVariables, ...legendVariables, ...datasourceVariable])];\n return {\n variables: allVariables,\n };\n },\n};\n"],"names":["isVariableDatasource","parseVariables","getTimeSeriesData","PrometheusTimeSeriesQueryEditor","PrometheusTimeSeriesQuery","OptionsEditorComponent","createInitialOptions","query","datasource","undefined","dependsOn","spec","queryVariables","legendVariables","seriesNameFormat","datasourceVariable","allVariables","Set","variables"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAgCA,oBAAoB,EAAEC,cAAc,QAAQ,4BAA4B;AACxG,SAASC,iBAAiB,QAAQ,yBAAyB;AAC3D,SAASC,+BAA+B,QAAQ,oCAAoC;AAGpF;;CAEC,GACD,OAAO,MAAMC,4BAAkF;IAC7FF;IACAG,wBAAwBF;IACxBG,sBAAsB,IAAO,CAAA;YAC3BC,OAAO;YACPC,YAAYC;QACd,CAAA;IACAC,WAAW,CAACC;QACV,wEAAwE;QACxE,MAAMC,iBAAiBX,eAAeU,KAAKJ,KAAK;QAChD,MAAMM,kBAAkBZ,eAAeU,KAAKG,gBAAgB,IAAI;QAChE,MAAMC,qBAAqBf,qBAAqBW,KAAKH,UAAU,IAAIP,eAAeU,KAAKH,UAAU,IAAI,MAAM,EAAE;QAC7G,MAAMQ,eAAe;eAAI,IAAIC,IAAI;mBAAIL;mBAAmBC;mBAAoBE;aAAmB;SAAE;QACjG,OAAO;YACLG,WAAWF;QACb;IACF;AACF,EAAE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
// Copyright
|
|
2
|
+
// Copyright The Perses Authors
|
|
3
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
4
|
// you may not use this file except in compliance with the License.
|
|
5
5
|
// You may obtain a copy of the License at
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.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 { produce } from 'immer';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n replaceVariables,\n useAllVariableValues,\n useDatasource,\n useDatasourceClient,\n useDatasourceSelectValueToSelector,\n useSuggestedStepMs,\n useTimeRange,\n} from '@perses-dev/plugin-system';\nimport { useId } from '@perses-dev/components';\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport { ReactElement, useContext, useMemo } from 'react';\nimport { PanelEditorContext } from '@perses-dev/dashboards';\nimport {\n DEFAULT_PROM,\n DurationString,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n PrometheusDatasourceSelector,\n} from '../../model';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PromQLEditor } from '../../components';\nimport {\n PrometheusTimeSeriesQueryEditorProps,\n useQueryState,\n useFormatState,\n useMinStepState,\n} from './query-editor-model';\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): ReactElement {\n const {\n onChange,\n value,\n value: { query, datasource },\n isReadonly,\n } = props;\n\n const datasourceSelectValue = datasource ?? DEFAULT_PROM;\n\n const datasourceSelectLabelID = useId('prom-datasource-label'); // for panels with multiple queries, this component is rendered multiple times on the same page\n\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 { data: datasourceResource } = useDatasource(selectedDatasource);\n\n const { handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\n const { minStep, handleMinStepChange, handleMinStepBlur } = useMinStepState(props);\n const minStepPlaceholder =\n minStep ??\n (datasourceResource && (datasourceResource?.plugin.spec as PrometheusDatasourceSpec).scrapeInterval) ??\n DEFAULT_SCRAPE_INTERVAL;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n /* Good to know: The usage of onchange here causes an immediate spec update which eventually updates the panel\n This was probably intentional to allow for quick switching between datasources.\n Could have been triggered only with Run Query button as well.\n */\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n const variableState = useAllVariableValues();\n const { absoluteTimeRange } = useTimeRange();\n const panelEditorContext = useContext(PanelEditorContext);\n const suggestedStepMs = useSuggestedStepMs(panelEditorContext?.preview.previewPanelWidth);\n\n const minStepMs = useMemo(() => {\n /* Try catch is necessary, because when the minStep value is being typed, it will be valid when the duration unit is added. Example: 2m = 2 + m */\n try {\n const durationsSeconds = getDurationStringSeconds(\n replaceVariables(minStepPlaceholder, variableState) as DurationString\n );\n return durationsSeconds !== undefined ? durationsSeconds * 1000 : undefined;\n } catch {\n return undefined;\n }\n }, [variableState, minStepPlaceholder]);\n\n const intervalMs = useMemo(() => {\n const minStepSeconds = (minStepMs ?? 0) / 1000;\n return getRangeStep(getPrometheusTimeRange(absoluteTimeRange), minStepSeconds, undefined, suggestedStepMs) * 1000;\n }, [absoluteTimeRange, minStepMs, suggestedStepMs]);\n\n const treeViewMetadata = useMemo(() => {\n return minStepMs && intervalMs\n ? {\n minStepMs,\n intervalMs,\n }\n : undefined;\n }, [minStepMs, intervalMs]);\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\" fullWidth={false}>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={datasourceSelectValue}\n onChange={handleDatasourceChange}\n labelId={datasourceSelectLabelID}\n label=\"Prometheus Datasource\"\n notched\n readOnly={isReadonly}\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={query} // here we are passing `value.query` and not `query` from useQueryState in order to get updates only on onBlur events\n datasource={selectedDatasource}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n isReadOnly={isReadonly}\n treeViewMetadata={treeViewMetadata}\n />\n <Stack direction=\"row\" spacing={2}>\n <TextField\n fullWidth\n label=\"Legend\"\n placeholder=\"Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...\"\n helperText=\"Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.\"\n value={format ?? ''}\n onChange={(e) => handleFormatChange(e.target.value)}\n onBlur={handleFormatBlur}\n slotProps={{\n inputLabel: { shrink: isReadonly ? true : undefined },\n input: { readOnly: isReadonly },\n }}\n />\n <TextField\n label=\"Min Step\"\n placeholder={minStepPlaceholder}\n helperText=\"Lower bound for the step. If not provided, the scrape interval of the datasource is used.\"\n value={minStep ?? ''}\n onChange={(e) => handleMinStepChange(e.target.value ? (e.target.value as DurationString) : undefined)}\n onBlur={handleMinStepBlur}\n sx={{ width: '250px' }}\n slotProps={{\n inputLabel: { shrink: isReadonly ? true : undefined },\n input: { readOnly: isReadonly },\n }}\n />\n </Stack>\n </Stack>\n );\n}\n"],"names":["produce","DatasourceSelect","replaceVariables","useAllVariableValues","useDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","useSuggestedStepMs","useTimeRange","useId","FormControl","Stack","TextField","useContext","useMemo","PanelEditorContext","DEFAULT_PROM","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","DEFAULT_SCRAPE_INTERVAL","PromQLEditor","useQueryState","useFormatState","useMinStepState","PrometheusTimeSeriesQueryEditor","props","onChange","value","query","datasource","isReadonly","datasourceSelectValue","datasourceSelectLabelID","selectedDatasource","data","client","promURL","options","datasourceUrl","datasourceResource","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","minStep","handleMinStepChange","handleMinStepBlur","minStepPlaceholder","plugin","spec","scrapeInterval","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","variableState","absoluteTimeRange","panelEditorContext","suggestedStepMs","preview","previewPanelWidth","minStepMs","durationsSeconds","intervalMs","minStepSeconds","treeViewMetadata","spacing","margin","fullWidth","datasourcePluginKind","labelId","label","notched","readOnly","completeConfig","remote","url","onBlur","isReadOnly","direction","placeholder","helperText","e","target","slotProps","inputLabel","shrink","input","sx","width"],"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,OAAO,QAAQ,QAAQ;AAChC,SACEC,gBAAgB,EAEhBC,gBAAgB,EAChBC,oBAAoB,EACpBC,aAAa,EACbC,mBAAmB,EACnBC,kCAAkC,EAClCC,kBAAkB,EAClBC,YAAY,QACP,4BAA4B;AACnC,SAASC,KAAK,QAAQ,yBAAyB;AAC/C,SAASC,WAAW,EAAEC,KAAK,EAAEC,SAAS,QAAQ,gBAAgB;AAC9D,SAAuBC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAC1D,SAASC,kBAAkB,QAAQ,yBAAyB;AAC5D,SACEC,YAAY,EAEZC,wBAAwB,EACxBC,sBAAsB,EACtBC,YAAY,EACZC,qBAAqB,EACrBC,8BAA8B,EAC9BC,oBAAoB,QAGf,cAAc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;wBACR2C,WAAW;4BACTC,YAAY;gCAAEC,QAAQ3D,aAAa,OAAO0B;4BAAU;4BACpDkC,OAAO;gCAAEd,UAAU9C;4BAAW;wBAChC;;kCAEF,KAACtB;wBACCkE,OAAM;wBACNS,aAAanC;wBACboC,YAAW;wBACXzD,OAAOkB,WAAW;wBAClBnB,UAAU,CAAC2D,IAAMvC,oBAAoBuC,EAAEC,MAAM,CAAC3D,KAAK,GAAI0D,EAAEC,MAAM,CAAC3D,KAAK,GAAsB6B;wBAC3FwB,QAAQjC;wBACR4C,IAAI;4BAAEC,OAAO;wBAAQ;wBACrBL,WAAW;4BACTC,YAAY;gCAAEC,QAAQ3D,aAAa,OAAO0B;4BAAU;4BACpDkC,OAAO;gCAAEd,UAAU9C;4BAAW;wBAChC;;;;;;AAKV"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/PrometheusTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 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 { produce } from 'immer';\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n replaceVariables,\n useAllVariableValues,\n useDatasource,\n useDatasourceClient,\n useDatasourceSelectValueToSelector,\n useSuggestedStepMs,\n useTimeRange,\n} from '@perses-dev/plugin-system';\nimport { useId } from '@perses-dev/components';\nimport { FormControl, Stack, TextField } from '@mui/material';\nimport { ReactElement, useContext, useMemo } from 'react';\nimport { PanelEditorContext } from '@perses-dev/dashboards';\nimport {\n DEFAULT_PROM,\n DurationString,\n getDurationStringSeconds,\n getPrometheusTimeRange,\n getRangeStep,\n isDefaultPromSelector,\n isPrometheusDatasourceSelector,\n PROM_DATASOURCE_KIND,\n PrometheusClient,\n PrometheusDatasourceSelector,\n} from '../../model';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from '../types';\nimport { PromQLEditor } from '../../components';\nimport {\n PrometheusTimeSeriesQueryEditorProps,\n useQueryState,\n useFormatState,\n useMinStepState,\n} from './query-editor-model';\n/**\n * The options editor component for editing a PrometheusTimeSeriesQuery's spec.\n */\nexport function PrometheusTimeSeriesQueryEditor(props: PrometheusTimeSeriesQueryEditorProps): ReactElement {\n const {\n onChange,\n value,\n value: { query, datasource },\n isReadonly,\n } = props;\n\n const datasourceSelectValue = datasource ?? DEFAULT_PROM;\n\n const datasourceSelectLabelID = useId('prom-datasource-label'); // for panels with multiple queries, this component is rendered multiple times on the same page\n\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 { data: datasourceResource } = useDatasource(selectedDatasource);\n\n const { handleQueryChange, handleQueryBlur } = useQueryState(props);\n const { format, handleFormatChange, handleFormatBlur } = useFormatState(props);\n const { minStep, handleMinStepChange, handleMinStepBlur } = useMinStepState(props);\n const minStepPlaceholder =\n minStep ??\n (datasourceResource && (datasourceResource?.plugin.spec as PrometheusDatasourceSpec).scrapeInterval) ??\n DEFAULT_SCRAPE_INTERVAL;\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (next) => {\n if (isPrometheusDatasourceSelector(next)) {\n /* Good to know: The usage of onchange here causes an immediate spec update which eventually updates the panel\n This was probably intentional to allow for quick switching between datasources.\n Could have been triggered only with Run Query button as well.\n */\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultPromSelector(next) ? undefined : next;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non-Prometheus datasource selector');\n };\n\n const variableState = useAllVariableValues();\n const { absoluteTimeRange } = useTimeRange();\n const panelEditorContext = useContext(PanelEditorContext);\n const suggestedStepMs = useSuggestedStepMs(panelEditorContext?.preview.previewPanelWidth);\n\n const minStepMs = useMemo(() => {\n /* Try catch is necessary, because when the minStep value is being typed, it will be valid when the duration unit is added. Example: 2m = 2 + m */\n try {\n const durationsSeconds = getDurationStringSeconds(\n replaceVariables(minStepPlaceholder, variableState) as DurationString\n );\n return durationsSeconds !== undefined ? durationsSeconds * 1000 : undefined;\n } catch {\n return undefined;\n }\n }, [variableState, minStepPlaceholder]);\n\n const intervalMs = useMemo(() => {\n const minStepSeconds = (minStepMs ?? 0) / 1000;\n return getRangeStep(getPrometheusTimeRange(absoluteTimeRange), minStepSeconds, undefined, suggestedStepMs) * 1000;\n }, [absoluteTimeRange, minStepMs, suggestedStepMs]);\n\n const treeViewMetadata = useMemo(() => {\n return minStepMs && intervalMs\n ? {\n minStepMs,\n intervalMs,\n }\n : undefined;\n }, [minStepMs, intervalMs]);\n\n return (\n <Stack spacing={2}>\n <FormControl margin=\"dense\" fullWidth={false}>\n <DatasourceSelect\n datasourcePluginKind={PROM_DATASOURCE_KIND}\n value={datasourceSelectValue}\n onChange={handleDatasourceChange}\n labelId={datasourceSelectLabelID}\n label=\"Prometheus Datasource\"\n notched\n readOnly={isReadonly}\n />\n </FormControl>\n <PromQLEditor\n completeConfig={{ remote: { url: promURL } }}\n value={query} // here we are passing `value.query` and not `query` from useQueryState in order to get updates only on onBlur events\n datasource={selectedDatasource}\n onChange={handleQueryChange}\n onBlur={handleQueryBlur}\n isReadOnly={isReadonly}\n treeViewMetadata={treeViewMetadata}\n />\n <Stack direction=\"row\" spacing={2}>\n <TextField\n fullWidth\n label=\"Legend\"\n placeholder=\"Example: '{{instance}}' will generate series names like 'webserver-123', 'webserver-456'...\"\n helperText=\"Text to be displayed in the legend and the tooltip. Use {{label_name}} to interpolate label values.\"\n value={format ?? ''}\n onChange={(e) => handleFormatChange(e.target.value)}\n onBlur={handleFormatBlur}\n slotProps={{\n inputLabel: { shrink: isReadonly ? true : undefined },\n input: { readOnly: isReadonly },\n }}\n />\n <TextField\n label=\"Min Step\"\n placeholder={minStepPlaceholder}\n helperText=\"Lower bound for the step. If not provided, the scrape interval of the datasource is used.\"\n value={minStep ?? ''}\n onChange={(e) => handleMinStepChange(e.target.value ? (e.target.value as DurationString) : undefined)}\n onBlur={handleMinStepBlur}\n sx={{ width: '250px' }}\n slotProps={{\n inputLabel: { shrink: isReadonly ? true : undefined },\n input: { readOnly: isReadonly },\n }}\n />\n </Stack>\n </Stack>\n );\n}\n"],"names":["produce","DatasourceSelect","replaceVariables","useAllVariableValues","useDatasource","useDatasourceClient","useDatasourceSelectValueToSelector","useSuggestedStepMs","useTimeRange","useId","FormControl","Stack","TextField","useContext","useMemo","PanelEditorContext","DEFAULT_PROM","getDurationStringSeconds","getPrometheusTimeRange","getRangeStep","isDefaultPromSelector","isPrometheusDatasourceSelector","PROM_DATASOURCE_KIND","DEFAULT_SCRAPE_INTERVAL","PromQLEditor","useQueryState","useFormatState","useMinStepState","PrometheusTimeSeriesQueryEditor","props","onChange","value","query","datasource","isReadonly","datasourceSelectValue","datasourceSelectLabelID","selectedDatasource","data","client","promURL","options","datasourceUrl","datasourceResource","handleQueryChange","handleQueryBlur","format","handleFormatChange","handleFormatBlur","minStep","handleMinStepChange","handleMinStepBlur","minStepPlaceholder","plugin","spec","scrapeInterval","handleDatasourceChange","next","draft","nextDatasource","undefined","Error","variableState","absoluteTimeRange","panelEditorContext","suggestedStepMs","preview","previewPanelWidth","minStepMs","durationsSeconds","intervalMs","minStepSeconds","treeViewMetadata","spacing","margin","fullWidth","datasourcePluginKind","labelId","label","notched","readOnly","completeConfig","remote","url","onBlur","isReadOnly","direction","placeholder","helperText","e","target","slotProps","inputLabel","shrink","input","sx","width"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;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D;QAAM8D,SAAS;;0BACd,KAAC/D;gBAAYgE,QAAO;gBAAQC,WAAW;0BACrC,cAAA,KAAC1E;oBACC2E,sBAAsBtD;oBACtBS,OAAOI;oBACPL,UAAU0B;oBACVqB,SAASzC;oBACT0C,OAAM;oBACNC,OAAO;oBACPC,UAAU9C;;;0BAGd,KAACV;gBACCyD,gBAAgB;oBAAEC,QAAQ;wBAAEC,KAAK3C;oBAAQ;gBAAE;gBAC3CT,OAAOC;gBACPC,YAAYI;gBACZP,UAAUc;gBACVwC,QAAQvC;gBACRwC,YAAYnD;gBACZsC,kBAAkBA;;0BAEpB,MAAC7D;gBAAM2E,WAAU;gBAAMb,SAAS;;kCAC9B,KAAC7D;wBACC+D,SAAS;wBACTG,OAAM;wBACNS,aAAY;wBACZC,YAAW;wBACXzD,OAAOe,UAAU;wBACjBhB,UAAU,CAAC2D,IAAM1C,mBAAmB0C,EAAEC,MAAM,CAAC3D,KAAK;wBAClDqD,QAAQpC;wBACR2C,WAAW;4BACTC,YAAY;gCAAEC,QAAQ3D,aAAa,OAAO0B;4BAAU;4BACpDkC,OAAO;gCAAEd,UAAU9C;4BAAW;wBAChC;;kCAEF,KAACtB;wBACCkE,OAAM;wBACNS,aAAanC;wBACboC,YAAW;wBACXzD,OAAOkB,WAAW;wBAClBnB,UAAU,CAAC2D,IAAMvC,oBAAoBuC,EAAEC,MAAM,CAAC3D,KAAK,GAAI0D,EAAEC,MAAM,CAAC3D,KAAK,GAAsB6B;wBAC3FwB,QAAQjC;wBACR4C,IAAI;4BAAEC,OAAO;wBAAQ;wBACrBL,WAAW;4BACTC,YAAY;gCAAEC,QAAQ3D,aAAa,OAAO0B;4BAAU;4BACpDkC,OAAO;gCAAEd,UAAU9C;4BAAW;wBAChC;;;;;;AAKV"}
|
|
@@ -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\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,Y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YAActE,gBAAgB;wBAACsE,SAAS,CAAC,EAAE;wBAAEA,SAAS,CAAC,EAAE,CAACK,GAAG;qBAAC;gBACtFC,YAAYA,WAAWV,GAAG,CAAC,CAACI,YAAcA;YAC5C;QACF;QAEA,OAAO;YACLC;YACAC;YACAC,QAAQL;YACRM,QAAQA,OAAOR,GAAG,CAAClE;QACrB;IACF;AACF;AAEA,SAAS8E,gBAAgBjE,KAAa,EAAEuC,IAAgB,EAAET,gBAAoC;IAC5F,MAAM,EAAE4B,IAAI,EAAEC,aAAa,EAAE,GAAGlE,iCAAiCO,OAAO,CAAC,GAAG8B;IAC5E,OAAO;QACL;YACE4B;YACAG,QAAQ;gBAAC1E,gBAAgBoD,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 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,+BAA+B;AAC/B,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,M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gBjE,KAAa,EAAEuC,IAAgB,EAAET,gBAAoC;IAC5F,MAAM,EAAE4B,IAAI,EAAEC,aAAa,EAAE,GAAGlE,iCAAiCO,OAAO,CAAC,GAAG8B;IAC5E,OAAO;QACL;YACE4B;YACAG,QAAQ;gBAAC1E,gBAAgBoD,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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/index.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/index.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './PrometheusTimeSeriesQuery';\nexport * from './PrometheusTimeSeriesQueryEditor';\nexport * from './get-time-series-data';\nexport * from './replace-prom-builtin-variables';\nexport * from './query-editor-model';\nexport * from './time-series-query-model';\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,8BAA8B;AAC5C,cAAc,oCAAoC;AAClD,cAAc,yBAAyB;AACvC,cAAc,mCAAmC;AACjD,cAAc,uBAAuB;AACrC,cAAc,4BAA4B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/query-editor-model.ts"],"sourcesContent":["// Copyright 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 { useState } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorProps } from '@perses-dev/plugin-system';\nimport { DurationString } from '@perses-dev/core';\nimport { PrometheusTimeSeriesQuerySpec } from './time-series-query-model';\n\nexport type PrometheusTimeSeriesQueryEditorProps = OptionsEditorProps<PrometheusTimeSeriesQuerySpec>;\n\n/**\n * A hook for managing the `query` state in PrometheusTimeSeriesQuerySpec. Returns the `query` value, along with\n * `onChange` and `onBlur` event handlers to the input. Keeps a local copy of the user's input and only syncs those\n * changes with the overall spec value once the input is blurred to prevent re-running queries in the panel's preview\n * every time the user types.\n */\nexport function useQueryState(props: PrometheusTimeSeriesQueryEditorProps): {\n query: string;\n handleQueryChange: (e: string) => void;\n handleQueryBlur: () => void;\n} {\n const { onChange, value } = props;\n\n // Local copy of the query's value\n const [query, setQuery] = useState(value.query);\n\n // This is basically \"getDerivedStateFromProps\" to make sure if spec's value changes external to this component,\n // we render with the latest value\n const [lastSyncedQuery, setLastSyncedQuery] = useState(value.query);\n if (value.query !== lastSyncedQuery) {\n setQuery(value.query);\n setLastSyncedQuery(value.query);\n }\n\n // Update our local state's copy as the user types\n const handleQueryChange = (e: string): void => {\n setQuery(e);\n };\n\n // Propagate changes to the query's value when the input is blurred to avoid constantly re-running queries in the\n // PanelPreview\n const handleQueryBlur = (): void => {\n setLastSyncedQuery(query);\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n return { query, handleQueryChange, handleQueryBlur };\n}\n\n/**\n * Hook to manage `seriesNameFormat` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useFormatState(props: PrometheusTimeSeriesQueryEditorProps): {\n format: string | undefined;\n handleFormatChange: (e: string) => void;\n handleFormatBlur: () => void;\n} {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [format, setFormat] = useState(value.seriesNameFormat);\n const [lastSyncedFormat, setLastSyncedFormat] = useState(value.seriesNameFormat);\n if (value.seriesNameFormat !== lastSyncedFormat) {\n setFormat(value.seriesNameFormat);\n setLastSyncedFormat(value.seriesNameFormat);\n }\n\n // Update our local state as the user types\n const handleFormatChange = (e: string): void => {\n setFormat(e);\n };\n\n // Propagate changes to the panel preview component when seriesNameFormat TextField is blurred\n const handleFormatBlur = (): void => {\n setLastSyncedFormat(format);\n onChange(\n produce(value, (draft) => {\n draft.seriesNameFormat = format;\n })\n );\n };\n\n return { format, handleFormatChange, handleFormatBlur };\n}\n\n/**\n * Hook to manage `minStep` state to ensure panel preview does not rerender until text input is blurred\n */\nexport function useMinStepState(props: PrometheusTimeSeriesQueryEditorProps): {\n minStep: string | undefined;\n handleMinStepChange: (e: DurationString | undefined) => void;\n handleMinStepBlur: () => void;\n} {\n const { onChange, value } = props;\n\n // TODO: reusable hook or helper util instead of duplicating from useQueryState\n const [minStep, setMinStep] = useState(value.minStep);\n const [lastSyncedMinStep, setLastSyncedMinStep] = useState(value.minStep);\n if (value.minStep !== lastSyncedMinStep) {\n setMinStep(value.minStep);\n setLastSyncedMinStep(value.minStep);\n }\n\n // Update our local state as the user types\n const handleMinStepChange = (e: DurationString | undefined): void => {\n setMinStep(e);\n };\n\n // Propagate changes to the panel preview component when minStep TextField is blurred\n const handleMinStepBlur = (): void => {\n setLastSyncedMinStep(minStep);\n onChange(\n produce(value, (draft) => {\n draft.minStep = minStep;\n })\n );\n };\n\n return { minStep, handleMinStepChange, handleMinStepBlur };\n}\n"],"names":["useState","produce","useQueryState","props","onChange","value","query","setQuery","lastSyncedQuery","setLastSyncedQuery","handleQueryChange","e","handleQueryBlur","draft","useFormatState","format","setFormat","seriesNameFormat","lastSyncedFormat","setLastSyncedFormat","handleFormatChange","handleFormatBlur","useMinStepState","minStep","setMinStep","lastSyncedMinStep","setLastSyncedMinStep","handleMinStepChange","handleMinStepBlur"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,QAAQ,QAAQ,QAAQ;AACjC,SAASC,OAAO,QAAQ,QAAQ;AAOhC;;;;;CAKC,GACD,OAAO,SAASC,cAAcC,KAA2C;IAKvE,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAE5B,kCAAkC;IAClC,MAAM,CAACG,OAAOC,SAAS,GAAGP,SAASK,MAAMC,KAAK;IAE9C,gHAAgH;IAChH,kCAAkC;IAClC,MAAM,CAACE,iBAAiBC,mBAAmB,GAAGT,SAASK,MAAMC,KAAK;IAClE,IAAID,MAAMC,KAAK,KAAKE,iBAAiB;QACnCD,SAASF,MAAMC,KAAK;QACpBG,mBAAmBJ,MAAMC,KAAK;IAChC;IAEA,kDAAk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AsB,CAAChB;QAC3Ba,WAAWb;IACb;IAEA,qFAAqF;IACrF,MAAMiB,oBAAoB;QACxBF,qBAAqBH;QACrBnB,SACEH,QAAQI,OAAO,CAACQ;YACdA,MAAMU,OAAO,GAAGA;QAClB;IAEJ;IAEA,OAAO;QAAEA;QAASI;QAAqBC;IAAkB;AAC3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/replace-prom-builtin-variables.ts"],"sourcesContent":["// Copyright
|
|
1
|
+
{"version":3,"sources":["../../../../src/plugins/prometheus-time-series-query/replace-prom-builtin-variables.ts"],"sourcesContent":["// Copyright 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 { replaceVariable } from '@perses-dev/plugin-system';\nimport { formatDuration, msToPrometheusDuration } from '@perses-dev/core';\n\n/*\n * Replace variable placeholders in a PromQL query\n\n * @param query The base promQL expression that contains variable placeholders\n * @param minStepMs the lower bound of the interval between data points, in milliseconds\n * @param intervalMs the actual interval between data points, in milliseconds\n * \n * @returns a PromQL expression with variable placeholders replaced by their values\n */\nexport function replacePromBuiltinVariables(query: string, minStepMs: number, intervalMs: number): string {\n let updatedQuery = replaceVariable(query, '__interval_ms', intervalMs.toString());\n updatedQuery = replaceVariable(updatedQuery, '__interval', formatDuration(msToPrometheusDuration(intervalMs)));\n\n // The $__rate_interval variable is meant to be used with the rate() promQL function.\n // It is defined as max($__interval + Min step, 4 * Min step)\n const rateIntervalMs = Math.max(intervalMs + minStepMs, 4 * minStepMs);\n updatedQuery = replaceVariable(\n updatedQuery,\n '__rate_interval',\n formatDuration(msToPrometheusDuration(rateIntervalMs))\n );\n\n return updatedQuery;\n}\n"],"names":["replaceVariable","formatDuration","msToPrometheusDuration","replacePromBuiltinVariables","query","minStepMs","intervalMs","updatedQuery","toString","rateIntervalMs","Math","max"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,eAAe,QAAQ,4BAA4B;AAC5D,SAASC,cAAc,EAAEC,sBAAsB,QAAQ,mBAAmB;AAE1E;;;;;;;;CAQC,GACD,OAAO,SAASC,4BAA4BC,KAAa,EAAEC,SAAiB,EAAEC,UAAkB;IAC9F,IAAIC,eAAeP,gBAAgBI,OAAO,iBAAiBE,WAAWE,QAAQ;IAC9ED,eAAeP,gBAAgBO,cAAc,cAAcN,eAAeC,uBAAuBI;IAEjG,qFAAqF;IACrF,6DAA6D;IAC7D,MAAMG,iBAAiBC,KAAKC,GAAG,CAACL,aAAaD,WAAW,IAAIA;IAC5DE,eAAeP,gBACbO,cACA,mBACAN,eAAeC,uBAAuBO;IAGxC,OAAOF;AACT"}
|