@perses-dev/prometheus-plugin 0.58.0-beta.0 → 0.58.0-beta.2
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.e5d7ce90.js +7 -0
- package/__mf/js/async/1728.bbe08f31.js +1 -0
- package/__mf/js/async/2177.adb95f75.js +7 -0
- package/__mf/js/async/2228.53db17f4.js +2 -0
- package/__mf/js/async/{7462.e9a1c8bc.js.LICENSE.txt → 2228.53db17f4.js.LICENSE.txt} +17 -1
- package/__mf/js/async/2979.1d711dae.js +1 -0
- package/__mf/js/async/3075.08023434.js +1 -0
- package/__mf/js/async/3613.8ccc0992.js +22 -0
- package/__mf/js/async/425.b9d2dc6f.js +1 -0
- package/__mf/js/async/4626.90ae092f.js +1 -0
- package/__mf/js/async/5440.9f33f7a9.js +2 -0
- package/__mf/js/async/{5440.52ec91ad.js.LICENSE.txt → 5440.9f33f7a9.js.LICENSE.txt} +3 -3
- package/__mf/js/async/7729.2e55d1c3.js +3 -0
- package/__mf/js/async/8356.6a2bfd53.js +1 -0
- package/__mf/js/async/9020.058fd99c.js +1 -0
- package/__mf/js/async/9537.d1466e1b.js +1 -0
- package/__mf/js/async/9594.d1a3d0d9.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusDatasource.ef5f1df2.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusExplorer.e3461057.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.31fc9961.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.c3dbff14.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.cfc93e6f.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.0e2db857.js +1 -0
- package/__mf/js/main.0a0f0efb.js +7 -0
- package/lib/cjs/components/promql/format.js +6 -6
- package/lib/cjs/components/promql/serialize.js +4 -4
- package/lib/cjs/components/query.js +9 -2
- package/lib/cjs/explore/PrometheusMetricsFinder/utils.js +17 -4
- package/lib/cjs/model/prometheus-client.js +4 -4
- package/lib/cjs/model/time.js +2 -2
- package/lib/cjs/plugins/PrometheusLabelValuesVariable.js +72 -6
- package/lib/cjs/plugins/interpolation.js +7 -0
- package/lib/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +2 -2
- package/lib/cjs/plugins/prometheus-time-series-query/replace-prom-builtin-variables.js +3 -3
- package/lib/components/TreeNode.d.ts.map +1 -1
- package/lib/components/TreeNode.js.map +1 -1
- package/lib/components/promql/format.d.ts.map +1 -1
- package/lib/components/promql/format.js +6 -6
- package/lib/components/promql/format.js.map +1 -1
- package/lib/components/promql/serialize.js +4 -4
- package/lib/components/promql/serialize.js.map +1 -1
- package/lib/components/query.d.ts +2 -1
- package/lib/components/query.d.ts.map +1 -1
- package/lib/components/query.js +10 -3
- package/lib/components/query.js.map +1 -1
- package/lib/explore/PrometheusExplorer.d.ts.map +1 -1
- package/lib/explore/PrometheusExplorer.js +1 -1
- package/lib/explore/PrometheusExplorer.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/PrometheusMetricsFinder.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/display/list/MetricList.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FilterInputs.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/filter/FinderFilters.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/MetricOverview.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/JobTab.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/JobTab.d.ts.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.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.d.ts.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.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.d.ts.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.d.ts +1 -1
- package/lib/explore/PrometheusMetricsFinder/types.js.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/utils.d.ts +2 -1
- package/lib/explore/PrometheusMetricsFinder/utils.d.ts.map +1 -1
- package/lib/explore/PrometheusMetricsFinder/utils.js +18 -5
- package/lib/explore/PrometheusMetricsFinder/utils.js.map +1 -1
- package/lib/model/api-types.d.ts +1 -1
- package/lib/model/api-types.js.map +1 -1
- package/lib/model/prometheus-client.d.ts +1 -1
- package/lib/model/prometheus-client.d.ts.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.d.ts +1 -1
- package/lib/model/prometheus-selectors.d.ts.map +1 -1
- package/lib/model/prometheus-selectors.js.map +1 -1
- package/lib/model/time.d.ts +1 -1
- package/lib/model/time.d.ts.map +1 -1
- package/lib/model/time.js +1 -1
- package/lib/model/time.js.map +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.d.ts.map +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.js.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.js +72 -6
- package/lib/plugins/PrometheusLabelValuesVariable.js.map +1 -1
- package/lib/plugins/interpolation.d.ts +2 -1
- package/lib/plugins/interpolation.d.ts.map +1 -1
- package/lib/plugins/interpolation.js +4 -0
- package/lib/plugins/interpolation.js.map +1 -1
- package/lib/plugins/prometheus-datasource.d.ts.map +1 -1
- package/lib/plugins/prometheus-datasource.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.js +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/query-editor-model.d.ts +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 +3 -3
- 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.d.ts +1 -1
- package/lib/plugins/prometheus-time-series-query/time-series-query-model.d.ts.map +1 -1
- package/lib/plugins/prometheus-time-series-query/time-series-query-model.js.map +1 -1
- package/lib/plugins/types.d.ts +1 -1
- package/lib/plugins/types.d.ts.map +1 -1
- package/lib/plugins/types.js.map +1 -1
- package/mf-manifest.json +125 -119
- package/mf-stats.json +127 -121
- package/package.json +9 -7
- package/__mf/js/Prometheus.c5cd832d.js +0 -7
- package/__mf/js/async/1728.310a7d33.js +0 -1
- package/__mf/js/async/2292.27a5ec4d.js +0 -4
- package/__mf/js/async/2292.27a5ec4d.js.LICENSE.txt +0 -15
- package/__mf/js/async/3829.f250b55a.js +0 -7
- package/__mf/js/async/4402.99ae853d.js +0 -1
- package/__mf/js/async/4626.e7ed0d7d.js +0 -1
- package/__mf/js/async/4800.cc42977e.js +0 -22
- package/__mf/js/async/4887.8af3673d.js +0 -1
- package/__mf/js/async/5440.52ec91ad.js +0 -2
- package/__mf/js/async/5697.e17ba256.js +0 -1
- package/__mf/js/async/7462.e9a1c8bc.js +0 -2
- package/__mf/js/async/8292.11dc2ca3.js +0 -1
- package/__mf/js/async/8356.e845a073.js +0 -1
- package/__mf/js/async/8634.e3cfb057.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusDatasource.d4892cae.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusExplorer.681841d8.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.86c44577.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.ff683936.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.bac03b61.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.9a495e56.js +0 -1
- package/__mf/js/main.afe2fc64.js +0 -7
- /package/__mf/css/async/{3829.85c2cbf6.css → 2177.85c2cbf6.css} +0 -0
- /package/__mf/js/async/{3829.f250b55a.js.LICENSE.txt → 2177.adb95f75.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{4800.cc42977e.js.LICENSE.txt → 3613.8ccc0992.js.LICENSE.txt} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OverviewTab.d.ts","sourceRoot":"","sources":["../../../../../../src/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":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C1B,UAAU,EACV,UAAU,EACV,OAAO,EACP,WAAW,EACX,GAAG,KAAK,EACT,EAAE,gBAAgB,GAAG,YAAY,CA2DjC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
1
2
|
// Copyright The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,7 +11,6 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
14
14
|
import { useMemo, useState } from 'react';
|
|
15
15
|
import { Autocomplete, Button, Chip, CircularProgress, Divider, IconButton, MenuItem, Select, Skeleton, Stack, TextField, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
16
16
|
import PlusIcon from 'mdi-material-ui/Plus';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.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 { DatasourceSelector } from '@perses-dev/core';\nimport { ReactElement, useMemo, useState } from 'react';\nimport {\n Autocomplete,\n Button,\n Chip,\n CircularProgress,\n Divider,\n IconButton,\n MenuItem,\n Select,\n SelectChangeEvent,\n Skeleton,\n Stack,\n StackProps,\n TextField,\n Typography,\n useMediaQuery,\n useTheme,\n} from '@mui/material';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport CheckIcon from 'mdi-material-ui/Check';\nimport CloseIcon from 'mdi-material-ui/Close';\nimport { ErrorAlert } from '@perses-dev/components';\nimport { LabelFilter, LabelValueCounter, Operator } from '../../types';\nimport { ListboxComponent } from '../../filter/FilterInputs';\nimport { useMetricMetadata, useSeriesStates } from '../../utils';\nimport { MetricChip } from '../../display/MetricChip';\n\nexport interface LabelValuesRowProps extends StackProps {\n label: string;\n valueCounters: LabelValueCounter[];\n onFilterAdd: (filter: LabelFilter) => void;\n orderBy?: 'asc' | 'amount';\n}\n\nexport function LabelValuesRow({ label, valueCounters, onFilterAdd, ...props }: LabelValuesRowProps): ReactElement {\n const [isAddingFilter, setIsAddingFilter] = useState(false);\n const [operator, setOperator] = useState<Operator>('=');\n const [value, setValue] = useState('');\n const [showAllValues, setShowAllValues] = useState(false);\n const isMobileSize = useMediaQuery(useTheme().breakpoints.down('md'));\n\n const displayedValueCounters = useMemo(() => {\n if (showAllValues) {\n return valueCounters;\n }\n return valueCounters.slice(0, 5);\n }, [showAllValues, valueCounters]);\n\n return (\n <Stack\n key={label}\n sx={{ width: '100%' }}\n direction={isMobileSize ? 'column' : 'row'}\n alignItems=\"center\"\n gap={2}\n {...props}\n >\n <Stack\n sx={{ width: '100%', height: '100%' }}\n justifyContent=\"space-between\"\n alignContent=\"center\"\n direction={isMobileSize ? 'column' : 'row'}\n >\n <Typography sx={{ fontFamily: 'monospace' }} pl={isMobileSize ? 0 : 1}>\n {label}\n </Typography>\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n {isAddingFilter ? (\n <>\n <Select\n size=\"small\"\n value={operator}\n variant=\"outlined\"\n onChange={(event: SelectChangeEvent) => {\n setOperator(event.target.value as Operator);\n }}\n >\n <MenuItem value=\"=\">=</MenuItem>\n <MenuItem value=\"!=\">!=</MenuItem>\n <MenuItem value=\"=~\">=~</MenuItem>\n <MenuItem value=\"!~\">!~</MenuItem>\n </Select>\n <Autocomplete\n freeSolo\n limitTags={1}\n disableClearable\n options={valueCounters.map((counters) => counters.labelValue)}\n value={value}\n ListboxComponent={ListboxComponent}\n sx={{ width: 250 }}\n renderInput={(params) => {\n return <TextField {...params} label=\"Value\" variant=\"outlined\" fullWidth size=\"small\" />;\n }}\n onInputChange={(_, newValue) => {\n setValue(newValue);\n }}\n />\n <IconButton\n aria-label=\"confirm\"\n onClick={() => {\n onFilterAdd({ label, labelValues: [value], operator });\n setIsAddingFilter(false);\n }}\n >\n <CheckIcon />\n </IconButton>\n <IconButton\n aria-label=\"cancel\"\n onClick={() => {\n setIsAddingFilter(false);\n }}\n >\n <CloseIcon />\n </IconButton>\n </>\n ) : (\n <Button startIcon={<PlusIcon />} aria-label=\"add filter\" onClick={() => setIsAddingFilter(true)}>\n Add filter\n </Button>\n )}\n </Stack>\n </Stack>\n\n <Stack sx={{ width: '100%' }} gap={0.5}>\n <Stack direction=\"row\" gap={0.5}>\n <Typography variant=\"subtitle1\">{valueCounters.length} values</Typography>\n {valueCounters.length > 5 && (\n <Button variant=\"text\" size=\"small\" sx={{ padding: 0 }} onClick={() => setShowAllValues((prev) => !prev)}>\n {showAllValues ? '[-]' : '[+]'}\n </Button>\n )}\n </Stack>\n\n <Stack sx={{ overflow: isMobileSize ? 'auto' : 'unset' }}>\n {displayedValueCounters.map((labelValueCounter) => (\n <Stack key={`${label}-${labelValueCounter.labelValue}`} direction=\"row\" gap={2}>\n <Typography\n sx={{\n color: (theme) => theme.palette.success.main,\n fontFamily: 'monospace',\n ':hover': { backgroundColor: 'rgba(127,127,127,0.35)', cursor: 'pointer' },\n textWrap: isMobileSize ? 'nowrap' : 'unset',\n }}\n onClick={() => onFilterAdd({ label, labelValues: [labelValueCounter.labelValue], operator: '=' })}\n >\n {labelValueCounter.labelValue}\n </Typography>\n <Typography sx={{ textWrap: 'nowrap' }}>({labelValueCounter.counter} series)</Typography>\n </Stack>\n ))}\n </Stack>\n <Stack width=\"100%\" textAlign={isMobileSize ? 'center' : 'unset'}>\n {showAllValues ? (\n <Button variant=\"text\" sx={{ width: 'fit-content' }} onClick={() => setShowAllValues(false)}>\n Hide full values\n </Button>\n ) : (\n <>\n {valueCounters.length > 5 && (\n <Button variant=\"text\" sx={{ width: 'fit-content' }} onClick={() => setShowAllValues(true)}>\n Show {valueCounters.length - 5} more values\n </Button>\n )}\n </>\n )}\n </Stack>\n </Stack>\n </Stack>\n );\n}\n\nexport interface LabelValuesTableProps extends StackProps {\n labelValueCounters: Map<string, LabelValueCounter[]>;\n isLoading?: boolean;\n onFilterAdd: (filter: LabelFilter) => void;\n}\n\nexport function LabelValuesTable({\n labelValueCounters,\n isLoading,\n onFilterAdd,\n ...props\n}: LabelValuesTableProps): ReactElement {\n const labels: string[] = useMemo(() => {\n return [...labelValueCounters.keys()].sort();\n }, [labelValueCounters]);\n\n if (isLoading) {\n return (\n <Stack width=\"100%\" sx={{ alignItems: 'center', justifyContent: 'center' }}>\n <CircularProgress />\n </Stack>\n );\n }\n\n return (\n <Stack sx={{ width: '100%' }} divider={<Divider flexItem orientation=\"horizontal\" />} gap={2} {...props}>\n <Stack gap={2} direction=\"row\" sx={{ width: '100%' }}>\n <Stack sx={{ width: '100%' }}>\n <Typography variant=\"h3\">Label</Typography>\n </Stack>\n <Stack sx={{ width: '100%' }}>\n <Typography variant=\"h3\">Values</Typography>\n </Stack>\n </Stack>\n {labels.map((label) => (\n <LabelValuesRow\n key={label}\n label={label}\n valueCounters={labelValueCounters.get(label) ?? []}\n onFilterAdd={onFilterAdd}\n />\n ))}\n </Stack>\n );\n}\n\nexport interface OverviewTabProps extends StackProps {\n metricName: string;\n datasource: DatasourceSelector;\n filters: LabelFilter[];\n onFilterAdd: (filter: LabelFilter) => void;\n}\n\nexport function OverviewTab({\n metricName,\n datasource,\n filters,\n onFilterAdd,\n ...props\n}: OverviewTabProps): ReactElement {\n const { metadata, isLoading: isMetadataLoading, error: metadataError } = useMetricMetadata(metricName, datasource);\n const { series, labelValueCounters, isLoading, error } = useSeriesStates(metricName, filters, datasource);\n\n return (\n <Stack gap={2} {...props}>\n <Stack direction=\"row\" gap={3} mt={1} justifyContent=\"space-between\">\n <Stack gap={1}>\n <Typography variant=\"h1\" sx={{ fontFamily: 'monospace' }}>\n {metricName}\n </Typography>\n <Typography>Description:</Typography>\n {isMetadataLoading ? (\n <Skeleton variant=\"text\" width={180} />\n ) : (\n <Typography style={{ fontStyle: metadata?.help ? 'initial' : 'italic' }}>\n {metadataError ? 'Failed to fetch metadata' : (metadata?.help ?? 'unknown')}\n </Typography>\n )}\n </Stack>\n <Stack gap={1} justifyContent=\"center\">\n {isMetadataLoading ? (\n <Skeleton variant=\"rounded\" width={75} />\n ) : metadataError ? (\n <Chip label=\"failed to fetch\" color=\"error\" sx={{ fontStyle: 'italic' }} />\n ) : (\n <MetricChip label={metadata?.type ?? 'unknown'} />\n )}\n <Typography>\n Result:{' '}\n {isLoading ? (\n <Skeleton variant=\"text\" width={20} sx={{ display: 'inline-block' }} />\n ) : error ? (\n <strong>failed to fetch series</strong>\n ) : (\n <strong>{series?.length ?? 'unknown'} series</strong>\n )}\n </Typography>\n </Stack>\n </Stack>\n\n {error ? (\n <ErrorAlert\n error={{\n name: `Failed to fetch series ${error?.status && `(${error.status})`}`,\n message: error?.message ?? 'Failed to fetch series',\n }}\n />\n ) : series?.length === 0 ? (\n <Stack {...props}>\n <Typography sx={{ color: (theme) => theme.palette.warning.main }}>\n No series found with current filters.\n </Typography>\n </Stack>\n ) : (\n <LabelValuesTable labelValueCounters={labelValueCounters} onFilterAdd={onFilterAdd} isLoading={isLoading} />\n )}\n </Stack>\n );\n}\n"],"names":["useMemo","useState","Autocomplete","Button","Chip","CircularProgress","Divider","IconButton","MenuItem","Select","Skeleton","Stack","TextField","Typography","useMediaQuery","useTheme","PlusIcon","CheckIcon","CloseIcon","ErrorAlert","ListboxComponent","useMetricMetadata","useSeriesStates","MetricChip","LabelValuesRow","label","valueCounters","onFilterAdd","props","isAddingFilter","setIsAddingFilter","operator","setOperator","value","setValue","showAllValues","setShowAllValues","isMobileSize","breakpoints","down","displayedValueCounters","slice","sx","width","direction","alignItems","gap","height","justifyContent","alignContent","fontFamily","pl","size","variant","onChange","event","target","freeSolo","limitTags","disableClearable","options","map","counters","labelValue","renderInput","params","fullWidth","onInputChange","_","newValue","aria-label","onClick","labelValues","startIcon","length","padding","prev","overflow","labelValueCounter","color","theme","palette","success","main","backgroundColor","cursor","textWrap","counter","textAlign","LabelValuesTable","labelValueCounters","isLoading","labels","keys","sort","divider","flexItem","orientation","get","OverviewTab","metricName","datasource","filters","metadata","isMetadataLoading","error","metadataError","series","mt","style","fontStyle","help","type","display","strong","name","status","message","warning"],"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,SAAuBA,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACxD,SACEC,YAAY,EACZC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,OAAO,EACPC,UAAU,EACVC,QAAQ,EACRC,MAAM,EAENC,QAAQ,EACRC,KAAK,EAELC,SAAS,EACTC,UAAU,EACVC,aAAa,EACbC,QAAQ,QACH,gBAAgB;AACvB,OAAOC,cAAc,uBAAuB;AAC5C,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,eAAe,wBAAwB;AAC9C,SAASC,UAAU,QAAQ,yBAAyB;AAEpD,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,iBAAiB,EAAEC,eAAe,QAAQ,cAAc;AACjE,SAASC,UAAU,QAAQ,2BAA2B;AAStD,OAAO,SAASC,eAAe,EAAEC,KAAK,EAAEC,aAAa,EAAEC,WAAW,EAAE,GAAGC,OAA4B;IACjG,MAAM,CAACC,g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gCAAS2C,SAAQ;gCAAUV,OAAO;iCACjC+D,8BACF,KAACtG;gCAAKqB,OAAM;gCAAkBsD,OAAM;gCAAQrC,IAAI;oCAAEoE,WAAW;gCAAS;+CAEtE,KAACvF;gCAAWE,OAAO8E,UAAUS,QAAQ;;0CAEvC,MAACnG;;oCAAW;oCACF;oCACP8E,0BACC,KAACjF;wCAAS2C,SAAQ;wCAAOV,OAAO;wCAAID,IAAI;4CAAEuE,SAAS;wCAAe;yCAChER,sBACF,KAACS;kDAAO;uDAER,MAACA;;4CAAQP,QAAQjC,UAAU;4CAAU;;;;;;;;;YAM5C+B,sBACC,KAACtF;gBACCsF,OAAO;oBACLU,MAAM,CAAC,uBAAuB,EAAEV,OAAOW,UAAU,CAAC,CAAC,EAAEX,MAAMW,MAAM,CAAC,CAAC,CAAC,EAAE;oBACtEC,SAASZ,OAAOY,WAAW;gBAC7B;iBAEAV,QAAQjC,WAAW,kBACrB,KAAC/D;gBAAO,GAAGiB,KAAK;0BACd,cAAA,KAACf;oBAAW6B,IAAI;wBAAEqC,OAAO,CAACC,QAAUA,MAAMC,OAAO,CAACqC,OAAO,CAACnC,IAAI;oBAAC;8BAAG;;+BAKpE,KAACM;gBAAiBC,oBAAoBA;gBAAoB/D,aAAaA;gBAAagE,WAAWA;;;;AAIvG"}
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/explore/PrometheusMetricsFinder/overview/tabs/OverviewTab.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 { ReactElement, useMemo, useState } from 'react';\nimport {\n Autocomplete,\n Button,\n Chip,\n CircularProgress,\n Divider,\n IconButton,\n MenuItem,\n Select,\n SelectChangeEvent,\n Skeleton,\n Stack,\n StackProps,\n TextField,\n Typography,\n useMediaQuery,\n useTheme,\n} from '@mui/material';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport CheckIcon from 'mdi-material-ui/Check';\nimport CloseIcon from 'mdi-material-ui/Close';\nimport { ErrorAlert } from '@perses-dev/components';\nimport { DatasourceSelector } from '@perses-dev/spec';\nimport { LabelFilter, LabelValueCounter, Operator } from '../../types';\nimport { ListboxComponent } from '../../filter/FilterInputs';\nimport { useMetricMetadata, useSeriesStates } from '../../utils';\nimport { MetricChip } from '../../display/MetricChip';\n\nexport interface LabelValuesRowProps extends StackProps {\n label: string;\n valueCounters: LabelValueCounter[];\n onFilterAdd: (filter: LabelFilter) => void;\n orderBy?: 'asc' | 'amount';\n}\n\nexport function LabelValuesRow({ label, valueCounters, onFilterAdd, ...props }: LabelValuesRowProps): ReactElement {\n const [isAddingFilter, setIsAddingFilter] = useState(false);\n const [operator, setOperator] = useState<Operator>('=');\n const [value, setValue] = useState('');\n const [showAllValues, setShowAllValues] = useState(false);\n const isMobileSize = useMediaQuery(useTheme().breakpoints.down('md'));\n\n const displayedValueCounters = useMemo(() => {\n if (showAllValues) {\n return valueCounters;\n }\n return valueCounters.slice(0, 5);\n }, [showAllValues, valueCounters]);\n\n return (\n <Stack\n key={label}\n sx={{ width: '100%' }}\n direction={isMobileSize ? 'column' : 'row'}\n alignItems=\"center\"\n gap={2}\n {...props}\n >\n <Stack\n sx={{ width: '100%', height: '100%' }}\n justifyContent=\"space-between\"\n alignContent=\"center\"\n direction={isMobileSize ? 'column' : 'row'}\n >\n <Typography sx={{ fontFamily: 'monospace' }} pl={isMobileSize ? 0 : 1}>\n {label}\n </Typography>\n <Stack direction=\"row\" gap={1} alignItems=\"center\">\n {isAddingFilter ? (\n <>\n <Select\n size=\"small\"\n value={operator}\n variant=\"outlined\"\n onChange={(event: SelectChangeEvent) => {\n setOperator(event.target.value as Operator);\n }}\n >\n <MenuItem value=\"=\">=</MenuItem>\n <MenuItem value=\"!=\">!=</MenuItem>\n <MenuItem value=\"=~\">=~</MenuItem>\n <MenuItem value=\"!~\">!~</MenuItem>\n </Select>\n <Autocomplete\n freeSolo\n limitTags={1}\n disableClearable\n options={valueCounters.map((counters) => counters.labelValue)}\n value={value}\n ListboxComponent={ListboxComponent}\n sx={{ width: 250 }}\n renderInput={(params) => {\n return <TextField {...params} label=\"Value\" variant=\"outlined\" fullWidth size=\"small\" />;\n }}\n onInputChange={(_, newValue) => {\n setValue(newValue);\n }}\n />\n <IconButton\n aria-label=\"confirm\"\n onClick={() => {\n onFilterAdd({ label, labelValues: [value], operator });\n setIsAddingFilter(false);\n }}\n >\n <CheckIcon />\n </IconButton>\n <IconButton\n aria-label=\"cancel\"\n onClick={() => {\n setIsAddingFilter(false);\n }}\n >\n <CloseIcon />\n </IconButton>\n </>\n ) : (\n <Button startIcon={<PlusIcon />} aria-label=\"add filter\" onClick={() => setIsAddingFilter(true)}>\n Add filter\n </Button>\n )}\n </Stack>\n </Stack>\n\n <Stack sx={{ width: '100%' }} gap={0.5}>\n <Stack direction=\"row\" gap={0.5}>\n <Typography variant=\"subtitle1\">{valueCounters.length} values</Typography>\n {valueCounters.length > 5 && (\n <Button variant=\"text\" size=\"small\" sx={{ padding: 0 }} onClick={() => setShowAllValues((prev) => !prev)}>\n {showAllValues ? '[-]' : '[+]'}\n </Button>\n )}\n </Stack>\n\n <Stack sx={{ overflow: isMobileSize ? 'auto' : 'unset' }}>\n {displayedValueCounters.map((labelValueCounter) => (\n <Stack key={`${label}-${labelValueCounter.labelValue}`} direction=\"row\" gap={2}>\n <Typography\n sx={{\n color: (theme) => theme.palette.success.main,\n fontFamily: 'monospace',\n ':hover': { backgroundColor: 'rgba(127,127,127,0.35)', cursor: 'pointer' },\n textWrap: isMobileSize ? 'nowrap' : 'unset',\n }}\n onClick={() => onFilterAdd({ label, labelValues: [labelValueCounter.labelValue], operator: '=' })}\n >\n {labelValueCounter.labelValue}\n </Typography>\n <Typography sx={{ textWrap: 'nowrap' }}>({labelValueCounter.counter} series)</Typography>\n </Stack>\n ))}\n </Stack>\n <Stack width=\"100%\" textAlign={isMobileSize ? 'center' : 'unset'}>\n {showAllValues ? (\n <Button variant=\"text\" sx={{ width: 'fit-content' }} onClick={() => setShowAllValues(false)}>\n Hide full values\n </Button>\n ) : (\n <>\n {valueCounters.length > 5 && (\n <Button variant=\"text\" sx={{ width: 'fit-content' }} onClick={() => setShowAllValues(true)}>\n Show {valueCounters.length - 5} more values\n </Button>\n )}\n </>\n )}\n </Stack>\n </Stack>\n </Stack>\n );\n}\n\nexport interface LabelValuesTableProps extends StackProps {\n labelValueCounters: Map<string, LabelValueCounter[]>;\n isLoading?: boolean;\n onFilterAdd: (filter: LabelFilter) => void;\n}\n\nexport function LabelValuesTable({\n labelValueCounters,\n isLoading,\n onFilterAdd,\n ...props\n}: LabelValuesTableProps): ReactElement {\n const labels: string[] = useMemo(() => {\n return [...labelValueCounters.keys()].sort();\n }, [labelValueCounters]);\n\n if (isLoading) {\n return (\n <Stack width=\"100%\" sx={{ alignItems: 'center', justifyContent: 'center' }}>\n <CircularProgress />\n </Stack>\n );\n }\n\n return (\n <Stack sx={{ width: '100%' }} divider={<Divider flexItem orientation=\"horizontal\" />} gap={2} {...props}>\n <Stack gap={2} direction=\"row\" sx={{ width: '100%' }}>\n <Stack sx={{ width: '100%' }}>\n <Typography variant=\"h3\">Label</Typography>\n </Stack>\n <Stack sx={{ width: '100%' }}>\n <Typography variant=\"h3\">Values</Typography>\n </Stack>\n </Stack>\n {labels.map((label) => (\n <LabelValuesRow\n key={label}\n label={label}\n valueCounters={labelValueCounters.get(label) ?? []}\n onFilterAdd={onFilterAdd}\n />\n ))}\n </Stack>\n );\n}\n\nexport interface OverviewTabProps extends StackProps {\n metricName: string;\n datasource: DatasourceSelector;\n filters: LabelFilter[];\n onFilterAdd: (filter: LabelFilter) => void;\n}\n\nexport function OverviewTab({\n metricName,\n datasource,\n filters,\n onFilterAdd,\n ...props\n}: OverviewTabProps): ReactElement {\n const { metadata, isLoading: isMetadataLoading, error: metadataError } = useMetricMetadata(metricName, datasource);\n const { series, labelValueCounters, isLoading, error } = useSeriesStates(metricName, filters, datasource);\n\n return (\n <Stack gap={2} {...props}>\n <Stack direction=\"row\" gap={3} mt={1} justifyContent=\"space-between\">\n <Stack gap={1}>\n <Typography variant=\"h1\" sx={{ fontFamily: 'monospace' }}>\n {metricName}\n </Typography>\n <Typography>Description:</Typography>\n {isMetadataLoading ? (\n <Skeleton variant=\"text\" width={180} />\n ) : (\n <Typography style={{ fontStyle: metadata?.help ? 'initial' : 'italic' }}>\n {metadataError ? 'Failed to fetch metadata' : (metadata?.help ?? 'unknown')}\n </Typography>\n )}\n </Stack>\n <Stack gap={1} justifyContent=\"center\">\n {isMetadataLoading ? (\n <Skeleton variant=\"rounded\" width={75} />\n ) : metadataError ? (\n <Chip label=\"failed to fetch\" color=\"error\" sx={{ fontStyle: 'italic' }} />\n ) : (\n <MetricChip label={metadata?.type ?? 'unknown'} />\n )}\n <Typography>\n Result:{' '}\n {isLoading ? (\n <Skeleton variant=\"text\" width={20} sx={{ display: 'inline-block' }} />\n ) : error ? (\n <strong>failed to fetch series</strong>\n ) : (\n <strong>{series?.length ?? 'unknown'} series</strong>\n )}\n </Typography>\n </Stack>\n </Stack>\n\n {error ? (\n <ErrorAlert\n error={{\n name: `Failed to fetch series ${error?.status && `(${error.status})`}`,\n message: error?.message ?? 'Failed to fetch series',\n }}\n />\n ) : series?.length === 0 ? (\n <Stack {...props}>\n <Typography sx={{ color: (theme) => theme.palette.warning.main }}>\n No series found with current filters.\n </Typography>\n </Stack>\n ) : (\n <LabelValuesTable labelValueCounters={labelValueCounters} onFilterAdd={onFilterAdd} isLoading={isLoading} />\n )}\n </Stack>\n );\n}\n"],"names":["useMemo","useState","Autocomplete","Button","Chip","CircularProgress","Divider","IconButton","MenuItem","Select","Skeleton","Stack","TextField","Typography","useMediaQuery","useTheme","PlusIcon","CheckIcon","CloseIcon","ErrorAlert","ListboxComponent","useMetricMetadata","useSeriesStates","MetricChip","LabelValuesRow","label","valueCounters","onFilterAdd","props","isAddingFilter","setIsAddingFilter","operator","setOperator","value","setValue","showAllValues","setShowAllValues","isMobileSize","breakpoints","down","displayedValueCounters","slice","sx","width","direction","alignItems","gap","height","justifyContent","alignContent","fontFamily","pl","size","variant","onChange","event","target","freeSolo","limitTags","disableClearable","options","map","counters","labelValue","renderInput","params","fullWidth","onInputChange","_","newValue","aria-label","onClick","labelValues","startIcon","length","padding","prev","overflow","labelValueCounter","color","theme","palette","success","main","backgroundColor","cursor","textWrap","counter","textAlign","LabelValuesTable","labelValueCounters","isLoading","labels","keys","sort","divider","flexItem","orientation","get","OverviewTab","metricName","datasource","filters","metadata","isMetadataLoading","error","metadataError","series","mt","style","fontStyle","help","type","display","strong","name","status","message","warning"],"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,SAAuBA,OAAO,EAAEC,QAAQ,QAAQ,QAAQ;AACxD,SACEC,YAAY,EACZC,MAAM,EACNC,IAAI,EACJC,gBAAgB,EAChBC,OAAO,EACPC,UAAU,EACVC,QAAQ,EACRC,MAAM,EAENC,QAAQ,EACRC,KAAK,EAELC,SAAS,EACTC,UAAU,EACVC,aAAa,EACbC,QAAQ,QACH,gBAAgB;AACvB,OAAOC,cAAc,uBAAuB;AAC5C,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,eAAe,wBAAwB;AAC9C,SAASC,UAAU,QAAQ,yBAAyB;AAGpD,SAASC,gBAAgB,QAAQ,4BAA4B;AAC7D,SAASC,iBAAiB,EAAEC,eAAe,QAAQ,cAAc;AACjE,SAASC,UAAU,QAAQ,2BAA2B;AA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BAA8BH,UAAUQ,QAAQ;;;;kCAIvE,MAACpG;wBAAMmC,KAAK;wBAAGE,gBAAe;;4BAC3BwD,kCACC,KAAC9F;gCAAS2C,SAAQ;gCAAUV,OAAO;iCACjC+D,8BACF,KAACtG;gCAAKqB,OAAM;gCAAkBsD,OAAM;gCAAQrC,IAAI;oCAAEoE,WAAW;gCAAS;+CAEtE,KAACvF;gCAAWE,OAAO8E,UAAUS,QAAQ;;0CAEvC,MAACnG;;oCAAW;oCACF;oCACP8E,0BACC,KAACjF;wCAAS2C,SAAQ;wCAAOV,OAAO;wCAAID,IAAI;4CAAEuE,SAAS;wCAAe;yCAChER,sBACF,KAACS;kDAAO;uDAER,MAACA;;4CAAQP,QAAQjC,UAAU;4CAAU;;;;;;;;;YAM5C+B,sBACC,KAACtF;gBACCsF,OAAO;oBACLU,MAAM,CAAC,uBAAuB,EAAEV,OAAOW,UAAU,CAAC,CAAC,EAAEX,MAAMW,MAAM,CAAC,CAAC,CAAC,EAAE;oBACtEC,SAASZ,OAAOY,WAAW;gBAC7B;iBAEAV,QAAQjC,WAAW,kBACrB,KAAC/D;gBAAO,GAAGiB,KAAK;0BACd,cAAA,KAACf;oBAAW6B,IAAI;wBAAEqC,OAAO,CAACC,QAAUA,MAAMC,OAAO,CAACqC,OAAO,CAACnC,IAAI;oBAAC;8BAAG;;+BAKpE,KAACM;gBAAiBC,oBAAoBA;gBAAoB/D,aAAaA;gBAAagE,WAAWA;;;;AAIvG"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { DatasourceSelector } from '@perses-dev/core';
|
|
2
1
|
import { StackProps } from '@mui/material';
|
|
3
2
|
import { ReactElement } from 'react';
|
|
3
|
+
import { DatasourceSelector } from '@perses-dev/spec';
|
|
4
4
|
import { LabelFilter } from '../../types';
|
|
5
5
|
export interface SimilarTabProps extends StackProps {
|
|
6
6
|
filters: LabelFilter[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SimilarTab.d.ts","sourceRoot":"","sources":["../../../../../../src/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.tsx"],"names":[],"mappings":"AAaA,OAAO,
|
|
1
|
+
{"version":3,"file":"SimilarTab.d.ts","sourceRoot":"","sources":["../../../../../../src/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.tsx"],"names":[],"mappings":"AAaA,OAAO,EAA2B,UAAU,EAAE,MAAM,eAAe,CAAC;AACpE,OAAO,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,MAAM,WAAW,eAAgB,SAAQ,UAAU;IACjD,OAAO,EAAE,WAAW,EAAE,CAAC;IACvB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,SAAS,EAAE,CAAC,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;CACzC;AAED,wBAAgB,UAAU,CAAC,EACzB,OAAO,EACP,UAAU,EACV,iBAAiB,EACjB,SAAS,EACT,GAAG,KAAK,EACT,EAAE,eAAe,GAAG,YAAY,CAwBhC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
2
|
// Copyright The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,7 +11,6 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { CircularProgress, Stack } from '@mui/material';
|
|
15
15
|
import { useMemo } from 'react';
|
|
16
16
|
import { MetricList } from '../../display/list/MetricList';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../src/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.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 {
|
|
1
|
+
{"version":3,"sources":["../../../../../../src/explore/PrometheusMetricsFinder/overview/tabs/SimilarTab.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 { CircularProgress, Stack, StackProps } from '@mui/material';\nimport { ReactElement, useMemo } from 'react';\nimport { DatasourceSelector } from '@perses-dev/spec';\nimport { MetricList } from '../../display/list/MetricList';\nimport { LabelFilter } from '../../types';\nimport { useLabelValues } from '../../utils';\n\nexport interface SimilarTabProps extends StackProps {\n filters: LabelFilter[];\n datasource: DatasourceSelector;\n isMetadataEnabled?: boolean;\n onExplore: (metricName: string) => void;\n}\n\nexport function SimilarTab({\n filters,\n datasource,\n isMetadataEnabled,\n onExplore,\n ...props\n}: SimilarTabProps): ReactElement {\n const filtersWithoutName: LabelFilter[] = useMemo(() => {\n return filters.filter((filter) => filter.label !== '__name__');\n }, [filters]);\n const { data, isLoading } = useLabelValues('__name__', filtersWithoutName, datasource);\n\n if (isLoading) {\n return (\n <Stack width=\"100%\" sx={{ alignItems: 'center', justifyContent: 'center' }}>\n <CircularProgress />\n </Stack>\n );\n }\n\n return (\n <MetricList\n metricNames={data?.data ?? []}\n datasource={datasource}\n filters={filtersWithoutName}\n isMetadataEnabled={isMetadataEnabled}\n onExplore={onExplore}\n {...props}\n />\n );\n}\n"],"names":["CircularProgress","Stack","useMemo","MetricList","useLabelValues","SimilarTab","filters","datasource","isMetadataEnabled","onExplore","props","filtersWithoutName","filter","label","data","isLoading","width","sx","alignItems","justifyContent","metricNames"],"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,gBAAgB,EAAEC,KAAK,QAAoB,gBAAgB;AACpE,SAAuBC,OAAO,QAAQ,QAAQ;AAE9C,SAASC,UAAU,QAAQ,gCAAgC;AAE3D,SAASC,cAAc,QAAQ,cAAc;AAS7C,OAAO,SAASC,WAAW,EACzBC,OAAO,EACPC,UAAU,EACVC,iBAAiB,EACjBC,SAAS,EACT,GAAGC,OACa;IAChB,MAAMC,qBAAoCT,QAAQ;QAChD,OAAOI,QAAQM,MAAM,CAAC,CAACA,SAAWA,OAAOC,KAAK,KAAK;IACrD,GAAG;QAACP;KAAQ;IACZ,MAAM,EAAEQ,IAAI,EAAEC,SAAS,EAAE,GAAGX,eAAe,YAAYO,oBAAoBJ;IAE3E,IAAIQ,WAAW;QACb,qBACE,KAACd;YAAMe,OAAM;YAAOC,IAAI;gBAAEC,YAAY;gBAAUC,gBAAgB;YAAS;sBACvE,cAAA,KAACnB;;IAGP;IAEA,qBACE,KAACG;QACCiB,aAAaN,MAAMA,QAAQ,EAAE;QAC7BP,YAAYA;QACZD,SAASK;QACTH,mBAAmBA;QACnBC,WAAWA;QACV,GAAGC,KAAK;;AAGf"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/explore/PrometheusMetricsFinder/types.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 { DatasourceSelector } from '@perses-dev/
|
|
1
|
+
{"version":3,"sources":["../../../../src/explore/PrometheusMetricsFinder/types.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 { DatasourceSelector } from '@perses-dev/spec';\n\nexport type Operator = '=' | '!=' | '=~' | '!~';\n\nexport interface Settings {\n isMetadataEnabled: boolean;\n isPanelEnabled: boolean;\n}\n\nexport interface FinderQueryParams {\n datasource?: DatasourceSelector;\n filters?: LabelFilter[];\n exploredMetric?: string;\n}\n\nexport interface LabelFilter {\n label: string;\n labelValues: string[];\n operator: Operator;\n}\n\nexport function computeFilterExpr(filters: LabelFilter[]): string {\n return `${filters.map((filter) => `${filter.label}${filter.operator}\"${filter.labelValues.join('|')}\"`).join(',')}`;\n}\n\nexport interface LabelValueCounter {\n labelValue: string;\n counter: number;\n}\n"],"names":["computeFilterExpr","filters","map","filter","label","operator","labelValues","join"],"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;AAuBjC,OAAO,SAASA,kBAAkBC,OAAsB;IACtD,OAAO,GAAGA,QAAQC,GAAG,CAAC,CAACC,SAAW,GAAGA,OAAOC,KAAK,GAAGD,OAAOE,QAAQ,CAAC,CAAC,EAAEF,OAAOG,WAAW,CAACC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAEA,IAAI,CAAC,MAAM;AACrH"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { DatasourceSelector, StatusError } from '@perses-dev/core';
|
|
2
1
|
import { UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import { DatasourceSelector } from '@perses-dev/spec';
|
|
3
|
+
import { StatusError } from '@perses-dev/client';
|
|
3
4
|
import { LabelValuesResponse, Metric, MetricMetadata } from '../../model';
|
|
4
5
|
import { LabelFilter } from './types';
|
|
5
6
|
export declare function useMetricMetadata(metricName: string, datasource: DatasourceSelector, enabled?: boolean): {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/explore/PrometheusMetricsFinder/utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../src/explore/PrometheusMetricsFinder/utils.ts"],"names":[],"mappings":"AAcA,OAAO,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEjE,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAGL,mBAAmB,EACnB,MAAM,EACN,cAAc,EAMf,MAAM,aAAa,CAAC;AAErB,OAAO,EAAqB,WAAW,EAAqB,MAAM,SAAS,CAAC;AAG5E,wBAAgB,iBAAiB,CAC/B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,kBAAkB,EAC9B,OAAO,CAAC,EAAE,OAAO,GAChB;IACD,SAAS,EAAE,KAAK,GAAG,IAAI,CAAC;IACxB,QAAQ,EAAE,cAAc,GAAG,SAAS,CAAC;IACrC,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;CAC3B,CA+BA;AAED,wBAAgB,SAAS,CACvB,OAAO,EAAE,WAAW,EAAE,EACtB,UAAU,EAAE,kBAAkB,GAC7B,cAAc,CAAC,mBAAmB,EAAE,WAAW,CAAC,CAyBlD;AAGD,wBAAgB,cAAc,CAC5B,SAAS,EAAE,MAAM,EACjB,OAAO,EAAE,WAAW,EAAE,EACtB,UAAU,EAAE,kBAAkB,GAC7B,cAAc,CAAC,mBAAmB,EAAE,WAAW,CAAC,CA0BlD;AAID,wBAAgB,eAAe,CAC7B,UAAU,EAAE,MAAM,EAClB,OAAO,EAAE,WAAW,EAAE,EACtB,UAAU,EAAE,kBAAkB,GAC7B;IACD,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,CAAC;IAC7B,kBAAkB,EAAE,GAAG,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC,CAAC;IAChF,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,WAAW,GAAG,IAAI,CAAC;CAC3B,CAwDA"}
|
|
@@ -10,13 +10,16 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { useDatasourceClient, useTimeRange } from '@perses-dev/plugin-system';
|
|
13
|
+
import { useDatasourceClient, useTimeRange, useVariableValues, useDatasourceStore } from '@perses-dev/plugin-system';
|
|
14
14
|
import { useQuery } from '@tanstack/react-query';
|
|
15
15
|
import { useMemo } from 'react';
|
|
16
|
+
import { getInterpolatedRequestOptions } from '../../plugins/interpolation';
|
|
16
17
|
import { computeFilterExpr } from './types';
|
|
17
18
|
// Retrieve metric metadata from the Prometheus API
|
|
18
19
|
export function useMetricMetadata(metricName, datasource, enabled) {
|
|
19
20
|
const { data: client } = useDatasourceClient(datasource);
|
|
21
|
+
const datasourceStore = useDatasourceStore();
|
|
22
|
+
const variableState = useVariableValues();
|
|
20
23
|
// histograms and summaries timeseries desc are not always added to prefixed timeseries
|
|
21
24
|
const name = metricName.replace(/(_count|_sum|_bucket)$/, '');
|
|
22
25
|
const { data, isLoading, error } = useQuery({
|
|
@@ -29,7 +32,8 @@ export function useMetricMetadata(metricName, datasource, enabled) {
|
|
|
29
32
|
const params = {
|
|
30
33
|
metric: name
|
|
31
34
|
};
|
|
32
|
-
|
|
35
|
+
const interpolatedOptions = await getInterpolatedRequestOptions(datasourceStore, datasource, variableState);
|
|
36
|
+
return await client.metricMetadata(params, interpolatedOptions);
|
|
33
37
|
}
|
|
34
38
|
});
|
|
35
39
|
// Find the first result with help text
|
|
@@ -53,6 +57,8 @@ export function useMetricMetadata(metricName, datasource, enabled) {
|
|
|
53
57
|
export function useLabels(filters, datasource) {
|
|
54
58
|
const { absoluteTimeRange: { start, end } } = useTimeRange();
|
|
55
59
|
const { data: client } = useDatasourceClient(datasource);
|
|
60
|
+
const datasourceStore = useDatasourceStore();
|
|
61
|
+
const variableState = useVariableValues();
|
|
56
62
|
return useQuery({
|
|
57
63
|
enabled: !!client,
|
|
58
64
|
queryKey: [
|
|
@@ -76,7 +82,8 @@ export function useLabels(filters, datasource) {
|
|
|
76
82
|
`{${computeFilterExpr(filters)}}`
|
|
77
83
|
];
|
|
78
84
|
}
|
|
79
|
-
|
|
85
|
+
const interpolatedOptions = await getInterpolatedRequestOptions(datasourceStore, datasource, variableState);
|
|
86
|
+
return await client.labelNames(params, interpolatedOptions);
|
|
80
87
|
}
|
|
81
88
|
});
|
|
82
89
|
}
|
|
@@ -84,6 +91,8 @@ export function useLabels(filters, datasource) {
|
|
|
84
91
|
export function useLabelValues(labelName, filters, datasource) {
|
|
85
92
|
const { absoluteTimeRange: { start, end } } = useTimeRange();
|
|
86
93
|
const { data: client } = useDatasourceClient(datasource);
|
|
94
|
+
const datasourceStore = useDatasourceStore();
|
|
95
|
+
const variableState = useVariableValues();
|
|
87
96
|
return useQuery({
|
|
88
97
|
enabled: !!client,
|
|
89
98
|
queryKey: [
|
|
@@ -108,7 +117,8 @@ export function useLabelValues(labelName, filters, datasource) {
|
|
|
108
117
|
`{${computeFilterExpr(filters)}}`
|
|
109
118
|
];
|
|
110
119
|
}
|
|
111
|
-
|
|
120
|
+
const interpolatedOptions = await getInterpolatedRequestOptions(datasourceStore, datasource, variableState);
|
|
121
|
+
return await client.labelValues(params, interpolatedOptions);
|
|
112
122
|
}
|
|
113
123
|
});
|
|
114
124
|
}
|
|
@@ -117,6 +127,8 @@ export function useLabelValues(labelName, filters, datasource) {
|
|
|
117
127
|
export function useSeriesStates(metricName, filters, datasource) {
|
|
118
128
|
const { absoluteTimeRange: { start, end } } = useTimeRange();
|
|
119
129
|
const { data: client } = useDatasourceClient(datasource);
|
|
130
|
+
const datasourceStore = useDatasourceStore();
|
|
131
|
+
const variableState = useVariableValues();
|
|
120
132
|
const { data: seriesData, isLoading, isError, error } = useQuery({
|
|
121
133
|
enabled: !!client,
|
|
122
134
|
queryKey: [
|
|
@@ -138,7 +150,8 @@ export function useSeriesStates(metricName, filters, datasource) {
|
|
|
138
150
|
start: start.valueOf() / 1000,
|
|
139
151
|
end: end.valueOf() / 1000
|
|
140
152
|
};
|
|
141
|
-
|
|
153
|
+
const interpolatedOptions = await getInterpolatedRequestOptions(datasourceStore, datasource, variableState);
|
|
154
|
+
return await client.series(params, interpolatedOptions);
|
|
142
155
|
}
|
|
143
156
|
});
|
|
144
157
|
const labelValueCounters = useMemo(()=>{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/explore/PrometheusMetricsFinder/utils.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 { DatasourceSelector, StatusError } from '@perses-dev/core';\nimport { useDatasourceClient, useTimeRange } from '@perses-dev/plugin-system';\nimport { useQuery, UseQueryResult } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport {\n LabelNamesRequestParameters,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n Metric,\n MetricMetadata,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n PrometheusClient,\n SeriesRequestParameters,\n SeriesResponse,\n} from '../../model';\nimport { computeFilterExpr, LabelFilter, LabelValueCounter } from './types';\n\n// Retrieve metric metadata from the Prometheus API\nexport function useMetricMetadata(\n metricName: string,\n datasource: DatasourceSelector,\n enabled?: boolean\n): {\n isLoading: false | true;\n metadata: MetricMetadata | undefined;\n error: StatusError | null;\n} {\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n // histograms and summaries timeseries desc are not always added to prefixed timeseries\n const name = metricName.replace(/(_count|_sum|_bucket)$/, '');\n\n const { data, isLoading, error } = useQuery<MetricMetadataResponse, StatusError>({\n enabled: !!client && enabled,\n queryKey: ['metricMetadata', name], // Not indexed on datasource, assuming a metric metadata should be similar across datasources\n queryFn: async () => {\n const params: MetricMetadataRequestParameters = { metric: name };\n\n return await client!.metricMetadata(params);\n },\n });\n\n // Find the first result with help text\n const metadata: MetricMetadata | undefined = useMemo(() => {\n for (const metric of data?.data?.[name] ?? []) {\n if (metric.help.length > 0) {\n return metric;\n }\n }\n return undefined;\n }, [data, name]);\n\n return { metadata, isLoading, error };\n}\n\nexport function useLabels(\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): UseQueryResult<LabelValuesResponse, StatusError> {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n return useQuery<LabelValuesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['labels', 'datasource', datasource.name, 'start', start, 'end', end, 'filters', ...filters],\n queryFn: async () => {\n const params: LabelNamesRequestParameters = {\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n if (filters.length) {\n params['match[]'] = [`{${computeFilterExpr(filters)}}`];\n }\n\n return await client!.labelNames(params);\n },\n });\n}\n\n// Retrieve label values from the Prometheus API for a given label name and filters\nexport function useLabelValues(\n labelName: string,\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): UseQueryResult<LabelValuesResponse, StatusError> {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n return useQuery<LabelValuesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['labelValues', labelName, 'datasource', datasource.name, 'start', start, 'end', 'filters', ...filters],\n queryFn: async () => {\n const params: LabelValuesRequestParameters = {\n labelName: labelName,\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n if (filters.length) {\n params['match[]'] = [`{${computeFilterExpr(filters)}}`];\n }\n\n return await client!.labelValues(params);\n },\n });\n}\n\n// Retrieve series from the Prometheus API for a given metric name and filters\n// Also computes the number of times a label value appears for the given metric name and filters\nexport function useSeriesStates(\n metricName: string,\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): {\n series: Metric[] | undefined;\n labelValueCounters: Map<string, Array<{ labelValue: string; counter: number }>>;\n isLoading: boolean;\n isError: boolean;\n error: StatusError | null;\n} {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n\n const {\n data: seriesData,\n isLoading,\n isError,\n error,\n } = useQuery<SeriesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['series', metricName, 'datasource', datasource, 'start', start, 'end', 'filters', ...filters],\n queryFn: async () => {\n const params: SeriesRequestParameters = {\n 'match[]': [`{${computeFilterExpr(filters)}}`],\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n\n return await client!.series(params);\n },\n });\n\n const labelValueCounters: Map<string, Array<{ labelValue: string; counter: number }>> = useMemo(() => {\n const result = new Map<string, LabelValueCounter[]>();\n if (seriesData?.data === undefined) {\n return result;\n }\n\n for (const series of seriesData.data) {\n for (const [label, value] of Object.entries(series)) {\n const labelCounters = result.get(label);\n if (labelCounters === undefined) {\n result.set(label, [{ labelValue: value, counter: 1 }]);\n continue;\n }\n\n const labelValueCounter = labelCounters.find((counter) => counter.labelValue === value);\n if (labelValueCounter === undefined) {\n labelCounters.push({ labelValue: value, counter: 1 });\n } else {\n labelValueCounter.counter += 1;\n }\n }\n }\n\n return result;\n }, [seriesData]);\n\n return { series: seriesData?.data, labelValueCounters, isLoading, isError, error };\n}\n"],"names":["useDatasourceClient","useTimeRange","useQuery","useMemo","computeFilterExpr","useMetricMetadata","metricName","datasource","enabled","data","client","name","replace","isLoading","error","queryKey","queryFn","params","metric","metricMetadata","metadata","help","length","undefined","useLabels","filters","absoluteTimeRange","start","end","valueOf","labelNames","useLabelValues","labelName","labelValues","useSeriesStates","seriesData","isError","series","labelValueCounters","result","Map","label","value","Object","entries","labelCounters","get","set","labelValue","counter","labelValueCounter","find","push"],"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,mBAAmB,EAAEC,YAAY,QAAQ,4BAA4B;AAC9E,SAASC,QAAQ,QAAwB,wBAAwB;AACjE,SAASC,OAAO,QAAQ,QAAQ;AAahC,SAASC,iBAAiB,QAAwC,UAAU;AAE5E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AAW;oBAAC,CAAC,CAAC,EAAEb,kBAAkBqB,SAAS,CAAC,CAAC;iBAAC;gBAC9CE,OAAOA,MAAME,OAAO,KAAK;gBACzBD,KAAKA,IAAIC,OAAO,KAAK;YACvB;YAEA,OAAO,MAAMnB,OAAQ2B,MAAM,CAACpB;QAC9B;IACF;IAEA,MAAMqB,qBAAkFnC,QAAQ;QAC9F,MAAMoC,SAAS,IAAIC;QACnB,IAAIL,YAAY1B,SAASc,WAAW;YAClC,OAAOgB;QACT;QAEA,KAAK,MAAMF,UAAUF,WAAW1B,IAAI,CAAE;YACpC,KAAK,MAAM,CAACgC,OAAOC,MAAM,IAAIC,OAAOC,OAAO,CAACP,QAAS;gBACnD,MAAMQ,gBAAgBN,OAAOO,GAAG,CAACL;gBACjC,IAAII,kBAAkBtB,WAAW;oBAC/BgB,OAAOQ,GAAG,CAACN,OAAO;wBAAC;4BAAEO,YAAYN;4BAAOO,SAAS;wBAAE;qBAAE;oBACrD;gBACF;gBAEA,MAAMC,oBAAoBL,cAAcM,IAAI,CAAC,CAACF,UAAYA,QAAQD,UAAU,KAAKN;gBACjF,IAAIQ,sBAAsB3B,WAAW;oBACnCsB,cAAcO,IAAI,CAAC;wBAAEJ,YAAYN;wBAAOO,SAAS;oBAAE;gBACrD,OAAO;oBACLC,kBAAkBD,OAAO,IAAI;gBAC/B;YACF;QACF;QAEA,OAAOV;IACT,GAAG;QAACJ;KAAW;IAEf,OAAO;QAAEE,QAAQF,YAAY1B;QAAM6B;QAAoBzB;QAAWuB;QAAStB;IAAM;AACnF"}
|
|
1
|
+
{"version":3,"sources":["../../../../src/explore/PrometheusMetricsFinder/utils.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 { useDatasourceClient, useTimeRange, useVariableValues, useDatasourceStore } from '@perses-dev/plugin-system';\nimport { useQuery, UseQueryResult } from '@tanstack/react-query';\nimport { useMemo } from 'react';\nimport { DatasourceSelector } from '@perses-dev/spec';\nimport { StatusError } from '@perses-dev/client';\nimport {\n LabelNamesRequestParameters,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n Metric,\n MetricMetadata,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n PrometheusClient,\n SeriesRequestParameters,\n SeriesResponse,\n} from '../../model';\nimport { getInterpolatedRequestOptions } from '../../plugins/interpolation';\nimport { computeFilterExpr, LabelFilter, LabelValueCounter } from './types';\n\n// Retrieve metric metadata from the Prometheus API\nexport function useMetricMetadata(\n metricName: string,\n datasource: DatasourceSelector,\n enabled?: boolean\n): {\n isLoading: false | true;\n metadata: MetricMetadata | undefined;\n error: StatusError | null;\n} {\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n const datasourceStore = useDatasourceStore();\n const variableState = useVariableValues();\n\n // histograms and summaries timeseries desc are not always added to prefixed timeseries\n const name = metricName.replace(/(_count|_sum|_bucket)$/, '');\n\n const { data, isLoading, error } = useQuery<MetricMetadataResponse, StatusError>({\n enabled: !!client && enabled,\n queryKey: ['metricMetadata', name], // Not indexed on datasource, assuming a metric metadata should be similar across datasources\n queryFn: async () => {\n const params: MetricMetadataRequestParameters = { metric: name };\n\n const interpolatedOptions = await getInterpolatedRequestOptions(datasourceStore, datasource, variableState);\n\n return await client!.metricMetadata(params, interpolatedOptions);\n },\n });\n\n // Find the first result with help text\n const metadata: MetricMetadata | undefined = useMemo(() => {\n for (const metric of data?.data?.[name] ?? []) {\n if (metric.help.length > 0) {\n return metric;\n }\n }\n return undefined;\n }, [data, name]);\n\n return { metadata, isLoading, error };\n}\n\nexport function useLabels(\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): UseQueryResult<LabelValuesResponse, StatusError> {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n const datasourceStore = useDatasourceStore();\n const variableState = useVariableValues();\n\n return useQuery<LabelValuesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['labels', 'datasource', datasource.name, 'start', start, 'end', end, 'filters', ...filters],\n queryFn: async () => {\n const params: LabelNamesRequestParameters = {\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n if (filters.length) {\n params['match[]'] = [`{${computeFilterExpr(filters)}}`];\n }\n\n const interpolatedOptions = await getInterpolatedRequestOptions(datasourceStore, datasource, variableState);\n\n return await client!.labelNames(params, interpolatedOptions);\n },\n });\n}\n\n// Retrieve label values from the Prometheus API for a given label name and filters\nexport function useLabelValues(\n labelName: string,\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): UseQueryResult<LabelValuesResponse, StatusError> {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n const datasourceStore = useDatasourceStore();\n const variableState = useVariableValues();\n\n return useQuery<LabelValuesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['labelValues', labelName, 'datasource', datasource.name, 'start', start, 'end', 'filters', ...filters],\n queryFn: async () => {\n const params: LabelValuesRequestParameters = {\n labelName: labelName,\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n if (filters.length) {\n params['match[]'] = [`{${computeFilterExpr(filters)}}`];\n }\n\n const interpolatedOptions = await getInterpolatedRequestOptions(datasourceStore, datasource, variableState);\n\n return await client!.labelValues(params, interpolatedOptions);\n },\n });\n}\n\n// Retrieve series from the Prometheus API for a given metric name and filters\n// Also computes the number of times a label value appears for the given metric name and filters\nexport function useSeriesStates(\n metricName: string,\n filters: LabelFilter[],\n datasource: DatasourceSelector\n): {\n series: Metric[] | undefined;\n labelValueCounters: Map<string, Array<{ labelValue: string; counter: number }>>;\n isLoading: boolean;\n isError: boolean;\n error: StatusError | null;\n} {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<PrometheusClient>(datasource);\n const datasourceStore = useDatasourceStore();\n const variableState = useVariableValues();\n\n const {\n data: seriesData,\n isLoading,\n isError,\n error,\n } = useQuery<SeriesResponse, StatusError>({\n enabled: !!client,\n queryKey: ['series', metricName, 'datasource', datasource, 'start', start, 'end', 'filters', ...filters],\n queryFn: async () => {\n const params: SeriesRequestParameters = {\n 'match[]': [`{${computeFilterExpr(filters)}}`],\n start: start.valueOf() / 1000,\n end: end.valueOf() / 1000,\n };\n\n const interpolatedOptions = await getInterpolatedRequestOptions(datasourceStore, datasource, variableState);\n\n return await client!.series(params, interpolatedOptions);\n },\n });\n\n const labelValueCounters: Map<string, Array<{ labelValue: string; counter: number }>> = useMemo(() => {\n const result = new Map<string, LabelValueCounter[]>();\n if (seriesData?.data === undefined) {\n return result;\n }\n\n for (const series of seriesData.data) {\n for (const [label, value] of Object.entries(series)) {\n const labelCounters = result.get(label);\n if (labelCounters === undefined) {\n result.set(label, [{ labelValue: value, counter: 1 }]);\n continue;\n }\n\n const labelValueCounter = labelCounters.find((counter) => counter.labelValue === value);\n if (labelValueCounter === undefined) {\n labelCounters.push({ labelValue: value, counter: 1 });\n } else {\n labelValueCounter.counter += 1;\n }\n }\n }\n\n return result;\n }, [seriesData]);\n\n return { series: seriesData?.data, labelValueCounters, isLoading, isError, error };\n}\n"],"names":["useDatasourceClient","useTimeRange","useVariableValues","useDatasourceStore","useQuery","useMemo","getInterpolatedRequestOptions","computeFilterExpr","useMetricMetadata","metricName","datasource","enabled","data","client","datasourceStore","variableState","name","replace","isLoading","error","queryKey","queryFn","params","metric","interpolatedOptions","metricMetadata","metadata","help","length","undefined","useLabels","filters","absoluteTimeRange","start","end","valueOf","labelNames","useLabelValues","labelName","labelValues","useSeriesStates","seriesData","isError","series","labelValueCounters","result","Map","label","value","Object","entries","labelCounters","get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WAAW7B,IAAI,CAAE;YACpC,KAAK,MAAM,CAACmC,OAAOC,MAAM,IAAIC,OAAOC,OAAO,CAACP,QAAS;gBACnD,MAAMQ,gBAAgBN,OAAOO,GAAG,CAACL;gBACjC,IAAII,kBAAkBtB,WAAW;oBAC/BgB,OAAOQ,GAAG,CAACN,OAAO;wBAAC;4BAAEO,YAAYN;4BAAOO,SAAS;wBAAE;qBAAE;oBACrD;gBACF;gBAEA,MAAMC,oBAAoBL,cAAcM,IAAI,CAAC,CAACF,UAAYA,QAAQD,UAAU,KAAKN;gBACjF,IAAIQ,sBAAsB3B,WAAW;oBACnCsB,cAAcO,IAAI,CAAC;wBAAEJ,YAAYN;wBAAOO,SAAS;oBAAE;gBACrD,OAAO;oBACLC,kBAAkBD,OAAO,IAAI;gBAC/B;YACF;QACF;QAEA,OAAOV;IACT,GAAG;QAACJ;KAAW;IAEf,OAAO;QAAEE,QAAQF,YAAY7B;QAAMgC;QAAoB1B;QAAWwB;QAASvB;IAAM;AACnF"}
|
package/lib/model/api-types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/api-types.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 { DurationString } from '@perses-dev/
|
|
1
|
+
{"version":3,"sources":["../../../src/model/api-types.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 { DurationString } from '@perses-dev/spec';\nimport ASTNode from '../components/promql/ast';\n\n// Just reuse dashboard model's type and re-export\nexport type { DurationString };\n\nexport interface SuccessResponse<T> {\n status: 'success';\n data: T;\n warnings?: string[];\n infos?: string[];\n}\n\nexport interface ErrorResponse<T> {\n status: 'error';\n data?: T;\n errorType: string;\n error: string;\n}\n\nexport type ApiResponse<T> = SuccessResponse<T> | ErrorResponse<T>;\n\nexport type DurationSeconds = number;\n\nexport type UnixTimestampSeconds = number;\n\nexport type ValueTuple = [unixTimeSeconds: UnixTimestampSeconds, sampleValue: string];\n\nexport type BucketTuple = [bucket: number, upperBound: string, lowerBound: string, count: string];\n\nexport type HistogramValue = { count: number; sum: string; buckets?: BucketTuple[] };\n\nexport type HistogramTuple = [unixTimeSeconds: UnixTimestampSeconds, value: HistogramValue];\n\nexport type Metric = Record<string, string>;\n\nexport interface VectorData {\n resultType: 'vector';\n result: Array<{\n metric: Metric;\n value: ValueTuple;\n histogram?: HistogramTuple;\n }>;\n}\n\nexport interface MatrixData {\n resultType: 'matrix';\n result: Array<{\n metric: Metric;\n values: ValueTuple[];\n histograms?: HistogramTuple[];\n }>;\n}\n\nexport interface ScalarData {\n resultType: 'scalar';\n result: ValueTuple;\n}\n\nexport interface StringData {\n resultType: 'string';\n result: ValueTuple;\n}\n\nexport interface InstantQueryRequestParameters {\n query: string;\n time?: UnixTimestampSeconds;\n timeout?: DurationString;\n}\n\nexport type InstantQueryResultType = MatrixData | VectorData | ScalarData | StringData;\n\n// Ref https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries\nexport type InstantQueryResponse = ApiResponse<InstantQueryResultType>;\n\nexport type MonitoredInstantQueryResponse = InstantQueryResponse & {\n responseTime: number;\n};\n\nexport interface RangeQueryRequestParameters {\n query: string;\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n step: DurationSeconds;\n timeout?: DurationString;\n}\n\nexport type RangeQueryResponse = ApiResponse<MatrixData>;\n\nexport interface SeriesRequestParameters {\n 'match[]': string[];\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n limit?: number;\n}\n\nexport type SeriesResponse = ApiResponse<Metric[]>;\n\nexport interface LabelNamesRequestParameters {\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n limit?: number;\n}\n\nexport type LabelNamesResponse = ApiResponse<string[]>;\n\nexport interface LabelValuesRequestParameters {\n labelName: string;\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n limit?: number;\n}\n\nexport type LabelValuesResponse = ApiResponse<string[]>;\n\nexport interface MetricMetadata {\n type: string;\n help: string;\n unit?: string;\n}\n\nexport interface MetricMetadataRequestParameters {\n limit?: number;\n metric?: string;\n}\n\nexport type MetricMetadataResponse = ApiResponse<Record<string, MetricMetadata[]>>;\n\n// ref: https://prometheus.io/docs/prometheus/3.0/querying/api/#parsing-a-promql-expressions-into-a-abstract-syntax-tree-ast\nexport interface ParseQueryRequestParameters {\n query: string;\n}\n\nexport type ParseQueryResponse = ApiResponse<ASTNode>;\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;AAyIjC,WAAsD"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { QueryParamValues } from '@perses-dev/components';
|
|
2
|
-
import { RequestHeaders } from '@perses-dev/core';
|
|
3
2
|
import { DatasourceClient } from '@perses-dev/plugin-system';
|
|
3
|
+
import { RequestHeaders } from '@perses-dev/client';
|
|
4
4
|
import { InstantQueryRequestParameters, InstantQueryResponse, LabelNamesRequestParameters, LabelNamesResponse, LabelValuesRequestParameters, LabelValuesResponse, MetricMetadataRequestParameters, MetricMetadataResponse, ParseQueryRequestParameters, ParseQueryResponse, RangeQueryRequestParameters, RangeQueryResponse, SeriesRequestParameters, SeriesResponse } from './api-types';
|
|
5
5
|
interface PrometheusClientOptions {
|
|
6
6
|
datasourceUrl: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,
|
|
1
|
+
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EAAa,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,+BAA+B,EAC/B,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,2BAA2B,EAC3B,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EAEf,MAAM,aAAa,CAAC;AAErB,UAAU,uBAAuB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED,MAAM,WAAW,oBAAoB;IACnC,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,WAAW,CAAC,EAAE,gBAAgB,CAAC;CAChC;AAED,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,OAAO,EAAE,uBAAuB,CAAC;IACjC,YAAY,CAAC,MAAM,EAAE,6BAA6B,EAAE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CAAC,CAE/B;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,2BAA2B,EACnC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,kBAAkB,CAAC,CAE7B;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,2BAA2B,EACnC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,kBAAkB,CAAC,CAE7B;AAED;;GAEG;AACH,wBAAgB,WAAW,CACzB,MAAM,EAAE,4BAA4B,EACpC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,mBAAmB,CAAC,CAa9B;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC5B,MAAM,EAAE,+BAA+B,EACvC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,sBAAsB,CAAC,CAGjC;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,uBAAuB,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAG3G;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,2BAA2B,EACnC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,kBAAkB,CAAC,CAG7B"}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import {
|
|
13
|
+
import { fetchJson } from '@perses-dev/client';
|
|
14
14
|
/**
|
|
15
15
|
* Builds a query string from datasource-level query parameters.
|
|
16
16
|
* Optionally merges with existing URLSearchParams.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/prometheus-client.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 { QueryParamValues } from '@perses-dev/components';\nimport { fetch, fetchJson, RequestHeaders } from '@perses-dev/core';\nimport { DatasourceClient } from '@perses-dev/plugin-system';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n ParseQueryRequestParameters,\n ParseQueryResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n SeriesRequestParameters,\n SeriesResponse,\n SuccessResponse,\n} from './api-types';\n\ninterface PrometheusClientOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\nexport interface ClientRequestOptions {\n headers?: RequestHeaders;\n signal?: AbortSignal;\n queryParams?: QueryParamValues;\n}\n\nexport interface PrometheusClient extends DatasourceClient {\n options: PrometheusClientOptions;\n instantQuery(params: InstantQueryRequestParameters, options?: ClientRequestOptions): Promise<InstantQueryResponse>;\n rangeQuery(params: RangeQueryRequestParameters, options?: ClientRequestOptions): Promise<RangeQueryResponse>;\n labelNames(params: LabelNamesRequestParameters, options?: ClientRequestOptions): Promise<LabelNamesResponse>;\n labelValues(params: LabelValuesRequestParameters, options?: ClientRequestOptions): Promise<LabelValuesResponse>;\n metricMetadata(\n params: MetricMetadataRequestParameters,\n options?: ClientRequestOptions\n ): Promise<MetricMetadataResponse>;\n series(params: SeriesRequestParameters, options?: ClientRequestOptions): Promise<SeriesResponse>;\n parseQuery(params: ParseQueryRequestParameters, options?: ClientRequestOptions): Promise<ParseQueryResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n signal?: AbortSignal;\n queryParams?: QueryParamValues;\n}\n\n/**\n * Builds a query string from datasource-level query parameters.\n * Optionally merges with existing URLSearchParams.\n * Returns empty string if no parameters, otherwise returns query string with leading '?'.\n */\nfunction buildQueryString(queryParams?: QueryParamValues, initialParams?: URLSearchParams): string {\n const urlParams = initialParams || new URLSearchParams();\n\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n if (initialParams?.has(key)) return;\n\n if (Array.isArray(value)) {\n value.forEach((v) => urlParams.append(key, v));\n } else {\n urlParams.set(key, value);\n }\n });\n }\n\n const queryString = urlParams.toString();\n return queryString !== '' ? `?${queryString}` : '';\n}\n\nexport function mergeQueryParams(\n defaults?: QueryParamValues,\n overrides?: QueryParamValues\n): QueryParamValues | undefined {\n if (!defaults && !overrides) return undefined;\n return { ...defaults, ...overrides };\n}\n\n/**\n * Calls the `/-/healthy` endpoint to check if the datasource is healthy.\n */\nexport function healthCheck(queryOptions: QueryOptions) {\n return async (): Promise<boolean> => {\n const url = `${queryOptions.datasourceUrl}/-/healthy${buildQueryString(queryOptions.queryParams)}`;\n\n try {\n const resp = await fetch(url, { headers: queryOptions.headers, signal: queryOptions.signal });\n return resp.status === 200;\n } catch {\n return false;\n }\n };\n}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(\n params: InstantQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<InstantQueryResponse> {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(\n params: RangeQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<RangeQueryResponse> {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(\n params: LabelNamesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelNamesResponse> {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(\n params: LabelValuesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelValuesResponse> {\n const { labelName, ...searchParams } = params;\n\n // In case label name is empty, we'll receive a 404, so we can replace it by an empty list, which is less confusing.\n // Note that an empty list is the prometheus result if the label does not exist.\n if (labelName.length === 0) {\n return new Promise((resolve) => {\n resolve({ data: [] as string[] } as SuccessResponse<string[]>);\n });\n }\n\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function metricMetadata(\n params: MetricMetadataRequestParameters,\n queryOptions: QueryOptions\n): Promise<MetricMetadataResponse> {\n const apiURI = `/api/v1/metadata`;\n return fetchWithGet<MetricMetadataRequestParameters, MetricMetadataResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/series` endpoint to finding series by label matchers.\n */\nexport function series(params: SeriesRequestParameters, queryOptions: QueryOptions): Promise<SeriesResponse> {\n const apiURI = `/api/v1/series`;\n return fetchWithPost<SeriesRequestParameters, SeriesResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/parse_query` to parse the given promQL expresion into an abstract syntax tree (AST).\n */\nexport function parseQuery(\n params: ParseQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<ParseQueryResponse> {\n const apiURI = `/api/v1/parse_query`;\n return fetchWithPost<ParseQueryRequestParameters, ParseQueryResponse>(apiURI, params, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, queryParams, signal } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams, createSearchParams(params))}`;\n return fetchJson<TResponse>(url, { method: 'GET', headers, signal });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, signal, queryParams } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams)}`;\n\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n ...headers,\n },\n signal,\n body: createSearchParams(params),\n };\n return fetchJson<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T): URLSearchParams {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n"],"names":["fetch","fetchJson","buildQueryString","queryParams","initialParams","urlParams","URLSearchParams","Object","entries","forEach","key","value","has","Array","isArray","v","append","set","queryString","toString","mergeQueryParams","defaults","overrides","undefined","healthCheck","queryOptions","url","datasourceUrl","resp","headers","signal","status","instantQuery","params","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","length","Promise","resolve","data","apiURI","encodeURIComponent","fetchWithGet","metricMetadata","series","parseQuery","createSearchParams","method","init","body","val"],"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;A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AAS,EACTR,YAA0B;IAE1B,MAAM,EAAEE,aAAa,EAAEE,OAAO,EAAEC,MAAM,EAAE3B,WAAW,EAAE,GAAGsB;IACxD,MAAMC,MAAM,GAAGC,gBAAgBiB,SAAS1C,iBAAiBC,cAAc;IAEvE,MAAMiD,OAAO;QACXD,QAAQ;QACRtB,SAAS;YACP,gBAAgB;YAChB,GAAGA,OAAO;QACZ;QACAC;QACAuB,MAAMH,mBAAmBjB;IAC3B;IACA,OAAOhC,UAAqByB,KAAK0B;AACnC;AAWA;;CAEC,GACD,SAASF,mBAA+CjB,MAAS;IAC/D,MAAMM,eAAe,IAAIjC;IACzB,IAAK,MAAMI,OAAOuB,OAAQ;QACxB,MAAMtB,QAAoBsB,MAAM,CAACvB,IAAI;QACrC,IAAIC,UAAUY,WAAW;QAEzB,IAAI,OAAOZ,UAAU,UAAU;YAC7B4B,aAAavB,MAAM,CAACN,KAAKC;YACzB;QACF;QAEA,IAAI,OAAOA,UAAU,UAAU;YAC7B4B,aAAavB,MAAM,CAACN,KAAKC,MAAMQ,QAAQ;YACvC;QACF;QAEA,KAAK,MAAMmC,OAAO3C,MAAO;YACvB4B,aAAavB,MAAM,CAACN,KAAK4C;QAC3B;IACF;IACA,OAAOf;AACT"}
|
|
1
|
+
{"version":3,"sources":["../../../src/model/prometheus-client.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 { QueryParamValues } from '@perses-dev/components';\nimport { DatasourceClient } from '@perses-dev/plugin-system';\nimport { fetchJson, RequestHeaders } from '@perses-dev/client';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n ParseQueryRequestParameters,\n ParseQueryResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n SeriesRequestParameters,\n SeriesResponse,\n SuccessResponse,\n} from './api-types';\n\ninterface PrometheusClientOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\nexport interface ClientRequestOptions {\n headers?: RequestHeaders;\n signal?: AbortSignal;\n queryParams?: QueryParamValues;\n}\n\nexport interface PrometheusClient extends DatasourceClient {\n options: PrometheusClientOptions;\n instantQuery(params: InstantQueryRequestParameters, options?: ClientRequestOptions): Promise<InstantQueryResponse>;\n rangeQuery(params: RangeQueryRequestParameters, options?: ClientRequestOptions): Promise<RangeQueryResponse>;\n labelNames(params: LabelNamesRequestParameters, options?: ClientRequestOptions): Promise<LabelNamesResponse>;\n labelValues(params: LabelValuesRequestParameters, options?: ClientRequestOptions): Promise<LabelValuesResponse>;\n metricMetadata(\n params: MetricMetadataRequestParameters,\n options?: ClientRequestOptions\n ): Promise<MetricMetadataResponse>;\n series(params: SeriesRequestParameters, options?: ClientRequestOptions): Promise<SeriesResponse>;\n parseQuery(params: ParseQueryRequestParameters, options?: ClientRequestOptions): Promise<ParseQueryResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n signal?: AbortSignal;\n queryParams?: QueryParamValues;\n}\n\n/**\n * Builds a query string from datasource-level query parameters.\n * Optionally merges with existing URLSearchParams.\n * Returns empty string if no parameters, otherwise returns query string with leading '?'.\n */\nfunction buildQueryString(queryParams?: QueryParamValues, initialParams?: URLSearchParams): string {\n const urlParams = initialParams || new URLSearchParams();\n\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n if (initialParams?.has(key)) return;\n\n if (Array.isArray(value)) {\n value.forEach((v) => urlParams.append(key, v));\n } else {\n urlParams.set(key, value);\n }\n });\n }\n\n const queryString = urlParams.toString();\n return queryString !== '' ? `?${queryString}` : '';\n}\n\nexport function mergeQueryParams(\n defaults?: QueryParamValues,\n overrides?: QueryParamValues\n): QueryParamValues | undefined {\n if (!defaults && !overrides) return undefined;\n return { ...defaults, ...overrides };\n}\n\n/**\n * Calls the `/-/healthy` endpoint to check if the datasource is healthy.\n */\nexport function healthCheck(queryOptions: QueryOptions) {\n return async (): Promise<boolean> => {\n const url = `${queryOptions.datasourceUrl}/-/healthy${buildQueryString(queryOptions.queryParams)}`;\n\n try {\n const resp = await fetch(url, { headers: queryOptions.headers, signal: queryOptions.signal });\n return resp.status === 200;\n } catch {\n return false;\n }\n };\n}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(\n params: InstantQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<InstantQueryResponse> {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(\n params: RangeQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<RangeQueryResponse> {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(\n params: LabelNamesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelNamesResponse> {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(\n params: LabelValuesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelValuesResponse> {\n const { labelName, ...searchParams } = params;\n\n // In case label name is empty, we'll receive a 404, so we can replace it by an empty list, which is less confusing.\n // Note that an empty list is the prometheus result if the label does not exist.\n if (labelName.length === 0) {\n return new Promise((resolve) => {\n resolve({ data: [] as string[] } as SuccessResponse<string[]>);\n });\n }\n\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function metricMetadata(\n params: MetricMetadataRequestParameters,\n queryOptions: QueryOptions\n): Promise<MetricMetadataResponse> {\n const apiURI = `/api/v1/metadata`;\n return fetchWithGet<MetricMetadataRequestParameters, MetricMetadataResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/series` endpoint to finding series by label matchers.\n */\nexport function series(params: SeriesRequestParameters, queryOptions: QueryOptions): Promise<SeriesResponse> {\n const apiURI = `/api/v1/series`;\n return fetchWithPost<SeriesRequestParameters, SeriesResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/parse_query` to parse the given promQL expresion into an abstract syntax tree (AST).\n */\nexport function parseQuery(\n params: ParseQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<ParseQueryResponse> {\n const apiURI = `/api/v1/parse_query`;\n return fetchWithPost<ParseQueryRequestParameters, ParseQueryResponse>(apiURI, params, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, queryParams, signal } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams, createSearchParams(params))}`;\n return fetchJson<TResponse>(url, { method: 'GET', headers, signal });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, signal, queryParams } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams)}`;\n\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n ...headers,\n },\n signal,\n body: createSearchParams(params),\n };\n return fetchJson<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T): URLSearchParams {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n"],"names":["fetchJson","buildQueryString","queryParams","initialParams","urlParams","URLSearchParams","Object","entries","forEach","key","value","has","Array","isArray","v","append","set","queryString","toString","mergeQueryParams","defaults","overrides","undefined","healthCheck","queryOptions","url","datasourceUrl","resp","fetch","headers","signal","status","instantQuery","params","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","length","Promise","resolve","data","apiURI","encodeURIComponent","fetchWithGet","metricMetadata","series","parseQuery","createSearchParams","method","init","body","val"],"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,SAASA,SAAS,QAAwB,qBAAqB;AAmD/D;;;;CAIC,GACD,SAASC,iBAAiBC,WAA8B,EAAEC,aAA+B;IACvF,MAAMC,YAAYD,iBAAiB,IAAIE;IAEvC,IAAIH,aAAa;QACfI,OAAOC,OAAO,CAACL,aAAaM,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YAC/C,IAAIP,eAAeQ,IAAIF,MAAM;YAE7B,IAAIG,MA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OAAOjC,UAAqByB,KAAK2B;AACnC;AAWA;;CAEC,GACD,SAASF,mBAA+CjB,MAAS;IAC/D,MAAMM,eAAe,IAAIlC;IACzB,IAAK,MAAMI,OAAOwB,OAAQ;QACxB,MAAMvB,QAAoBuB,MAAM,CAACxB,IAAI;QACrC,IAAIC,UAAUY,WAAW;QAEzB,IAAI,OAAOZ,UAAU,UAAU;YAC7B6B,aAAaxB,MAAM,CAACN,KAAKC;YACzB;QACF;QAEA,IAAI,OAAOA,UAAU,UAAU;YAC7B6B,aAAaxB,MAAM,CAACN,KAAKC,MAAMQ,QAAQ;YACvC;QACF;QAEA,KAAK,MAAMoC,OAAO5C,MAAO;YACvB6B,aAAaxB,MAAM,CAACN,KAAK6C;QAC3B;IACF;IACA,OAAOf;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { DatasourceSelector } from '@perses-dev/core';
|
|
2
1
|
import { DatasourceSelectValue } from '@perses-dev/plugin-system';
|
|
2
|
+
import { DatasourceSelector } from '@perses-dev/spec';
|
|
3
3
|
export declare const PROM_DATASOURCE_KIND: "PrometheusDatasource";
|
|
4
4
|
/**
|
|
5
5
|
* DatasourceSelector for Prom Datasources.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prometheus-selectors.d.ts","sourceRoot":"","sources":["../../../src/model/prometheus-selectors.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"prometheus-selectors.d.ts","sourceRoot":"","sources":["../../../src/model/prometheus-selectors.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,qBAAqB,EAAwB,MAAM,2BAA2B,CAAC;AACxF,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,eAAO,MAAM,oBAAoB,EAAG,sBAA+B,CAAC;AAEpE;;GAEG;AACH,MAAM,WAAW,4BAA6B,SAAQ,kBAAkB;IACtE,IAAI,EAAE,OAAO,oBAAoB,CAAC;CACnC;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,4BAA6D,CAAC;AAEzF;;GAEG;AACH,wBAAgB,qBAAqB,CACnC,qBAAqB,EAAE,qBAAqB,CAAC,4BAA4B,CAAC,GACzE,OAAO,CAET;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAC5C,qBAAqB,EAAE,qBAAqB,CAAC,kBAAkB,CAAC,GAC/D,qBAAqB,IAAI,4BAA4B,CAEvD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/prometheus-selectors.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 {
|
|
1
|
+
{"version":3,"sources":["../../../src/model/prometheus-selectors.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 { DatasourceSelectValue, isVariableDatasource } from '@perses-dev/plugin-system';\nimport { DatasourceSelector } from '@perses-dev/spec';\n\nexport const PROM_DATASOURCE_KIND = 'PrometheusDatasource' as const;\n\n/**\n * DatasourceSelector for Prom Datasources.\n */\nexport interface PrometheusDatasourceSelector extends DatasourceSelector {\n kind: typeof PROM_DATASOURCE_KIND;\n}\n\n/**\n * A default selector that asks for the default Prom Datasource.\n */\nexport const DEFAULT_PROM: PrometheusDatasourceSelector = { kind: PROM_DATASOURCE_KIND };\n\n/**\n * Returns true if the provided datasourceSelectValue is the default PrometheusDatasourceSelector.\n */\nexport function isDefaultPromSelector(\n datasourceSelectValue: DatasourceSelectValue<PrometheusDatasourceSelector>\n): boolean {\n return !isVariableDatasource(datasourceSelectValue) && datasourceSelectValue.name === undefined;\n}\n\n/**\n * Type guard to make sure a datasourceSelectValue is a Prometheus one.\n */\nexport function isPrometheusDatasourceSelector(\n datasourceSelectValue: DatasourceSelectValue<DatasourceSelector>\n): datasourceSelectValue is PrometheusDatasourceSelector {\n return isVariableDatasource(datasourceSelectValue) || datasourceSelectValue.kind === PROM_DATASOURCE_KIND;\n}\n"],"names":["isVariableDatasource","PROM_DATASOURCE_KIND","DEFAULT_PROM","kind","isDefaultPromSelector","datasourceSelectValue","name","undefined","isPrometheusDatasourceSelector"],"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,QAAQ,4BAA4B;AAGxF,OAAO,MAAMC,uBAAuB,uBAAgC;AASpE;;CAEC,GACD,OAAO,MAAMC,eAA6C;IAAEC,MAAMF;AAAqB,EAAE;AAEzF;;CAEC,GACD,OAAO,SAASG,sBACdC,qBAA0E;IAE1E,OAAO,CAACL,qBAAqBK,0BAA0BA,sBAAsBC,IAAI,KAAKC;AACxF;AAEA;;CAEC,GACD,OAAO,SAASC,+BACdH,qBAAgE;IAEhE,OAAOL,qBAAqBK,0BAA0BA,sBAAsBF,IAAI,KAAKF;AACvF"}
|
package/lib/model/time.d.ts
CHANGED
package/lib/model/time.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/time.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../../src/model/time.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,iBAAiB,EAAE,cAAc,EAAuB,MAAM,kBAAkB,CAAC;AAC1F,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,oBAAoB,CAAC;IAC5B,GAAG,EAAE,oBAAoB,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,SAAS,EAAE,iBAAiB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAMnG;AAMD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,SAAS,EAAE,mBAAmB,EAC9B,cAAc,SAAK,EACnB,UAAU,SAAI,EACd,eAAe,SAAI,GAClB,MAAM,CAUR;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc,GAAG,MAAM,GAAG,SAAS,CAM5F"}
|
package/lib/model/time.js
CHANGED
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
11
|
// See the License for the specific language governing permissions and
|
|
12
12
|
// limitations under the License.
|
|
13
|
-
import { parseDurationString } from '@perses-dev/core';
|
|
14
13
|
import { milliseconds, getUnixTime } from 'date-fns';
|
|
14
|
+
import { parseDurationString } from '@perses-dev/spec';
|
|
15
15
|
/**
|
|
16
16
|
* Converts an AbsoluteTimeRange to Prometheus time in Unix time (i.e. in seconds).
|
|
17
17
|
*/ export function getPrometheusTimeRange(timeRange) {
|
package/lib/model/time.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/time.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 {
|
|
1
|
+
{"version":3,"sources":["../../../src/model/time.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 { milliseconds, getUnixTime } from 'date-fns';\nimport { AbsoluteTimeRange, DurationString, parseDurationString } from '@perses-dev/spec';\nimport { UnixTimestampSeconds } from './api-types';\n\nexport interface PrometheusTimeRange {\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n}\n\n/**\n * Converts an AbsoluteTimeRange to Prometheus time in Unix time (i.e. in seconds).\n */\nexport function getPrometheusTimeRange(timeRange: AbsoluteTimeRange): { start: number; end: number } {\n const { start, end } = timeRange;\n return {\n start: Math.ceil(getUnixTime(start)),\n end: Math.ceil(getUnixTime(end)),\n };\n}\n\n// Max data points to allow returning from a Prom Query, used to calculate a\n// \"safe\" step for a range query\nconst MAX_PROM_DATA_POINTS = 10000;\n\n/**\n * Gets the step to use for a Prom range query. Tries to take into account a suggested step size (probably based on the\n * width of a visualization where the data will be graphed), any minimum step/resolution set by the user, and a \"safe\"\n * step based on the max data points we want to allow returning from a Prom query.\n */\nexport function getRangeStep(\n timeRange: PrometheusTimeRange,\n minStepSeconds = 15,\n resolution = 1,\n suggestedStepMs = 0\n): number {\n const suggestedStepSeconds = suggestedStepMs / 1000;\n const queryRangeSeconds = timeRange.end - timeRange.start;\n\n let safeStep = queryRangeSeconds / MAX_PROM_DATA_POINTS;\n if (safeStep > 1) {\n safeStep = Math.ceil(safeStep);\n }\n\n return Math.max(suggestedStepSeconds * resolution, minStepSeconds, safeStep);\n}\n\n/**\n * Converts a DurationString to seconds, rounding down.\n */\nexport function getDurationStringSeconds(durationString?: DurationString): number | undefined {\n if (!durationString) return undefined;\n\n const duration = parseDurationString(durationString);\n const ms = milliseconds(duration);\n return Math.floor(ms / 1000);\n}\n"],"names":["milliseconds","getUnixTime","parseDurationString","getPrometheusTimeRange","timeRange","start","end","Math","ceil","MAX_PROM_DATA_POINTS","getRangeStep","minStepSeconds","resolution","suggestedStepMs","suggestedStepSeconds","queryRangeSeconds","safeStep","max","getDurationStringSeconds","durationString","undefined","duration","ms","floor"],"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,YAAY,EAAEC,WAAW,QAAQ,WAAW;AACrD,SAA4CC,mBAAmB,QAAQ,mBAAmB;AAQ1F;;CAEC,GACD,OAAO,SAASC,uBAAuBC,SAA4B;IACjE,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAE,GAAGF;IACvB,OAAO;QACLC,OAAOE,KAAKC,IAAI,CAACP,YAAYI;QAC7BC,KAAKC,KAAKC,IAAI,CAACP,YAAYK;IAC7B;AACF;AAEA,4EAA4E;AAC5E,gCAAgC;AAChC,MAAMG,uBAAuB;AAE7B;;;;CAIC,GACD,OAAO,SAASC,aACdN,SAA8B,EAC9BO,iBAAiB,EAAE,EACnBC,aAAa,CAAC,EACdC,kBAAkB,CAAC;IAEnB,MAAMC,uBAAuBD,kBAAkB;IAC/C,MAAME,oBAAoBX,UAAUE,GAAG,GAAGF,UAAUC,KAAK;IAEzD,IAAIW,WAAWD,oBAAoBN;IACnC,IAAIO,WAAW,GAAG;QAChBA,WAAWT,KAAKC,IAAI,CAACQ;IACvB;IAEA,OAAOT,KAAKU,GAAG,CAACH,uBAAuBF,YAAYD,gBAAgBK;AACrE;AAEA;;CAEC,GACD,OAAO,SAASE,yBAAyBC,cAA+B;IACtE,IAAI,CAACA,gBAAgB,OAAOC;IAE5B,MAAMC,WAAWnB,oBAAoBiB;IACrC,MAAMG,KAAKtB,aAAaqB;IACxB,OAAOd,KAAKgB,KAAK,CAACD,KAAK;AACzB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusDatasourceEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusDatasourceEditor.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrometheusDatasourceEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusDatasourceEditor.tsx"],"names":[],"mappings":"AAkBA,OAAO,EAAE,YAAY,EAAoB,MAAM,OAAO,CAAC;AAEvD,OAAO,EAA2B,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAS5E,MAAM,WAAW,+BAA+B;IAC9C,KAAK,EAAE,wBAAwB,CAAC;IAChC,QAAQ,EAAE,CAAC,IAAI,EAAE,wBAAwB,KAAK,IAAI,CAAC;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,GAAG,YAAY,CAgM/F"}
|