@perses-dev/plugin-system 0.55.0-beta.9 → 0.55.0-rc.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/DatasourceSelect/DatasourceSelect.d.ts.map +1 -1
- package/dist/components/DatasourceSelect/DatasourceSelect.js +0 -1
- package/dist/components/DatasourceSelect/DatasourceSelect.js.map +1 -1
- package/dist/components/DatasourceTestConnectionButton/DatasourceTestConnectionButton.d.ts.map +1 -1
- package/dist/components/DatasourceTestConnectionButton/DatasourceTestConnectionButton.js +2 -7
- package/dist/components/DatasourceTestConnectionButton/DatasourceTestConnectionButton.js.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPProxyOAuthPassthroughEditor.d.ts +11 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyOAuthPassthroughEditor.d.ts.map +1 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyOAuthPassthroughEditor.js +62 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyOAuthPassthroughEditor.js.map +1 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyTimeoutEditor.d.ts +11 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyTimeoutEditor.d.ts.map +1 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyTimeoutEditor.js +58 -0
- package/dist/components/HTTPSettingsEditor/HTTPProxyTimeoutEditor.js.map +1 -0
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.d.ts.map +1 -1
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js +44 -15
- package/dist/components/HTTPSettingsEditor/HTTPSettingsEditor.js.map +1 -1
- package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.d.ts.map +1 -1
- package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js +7 -1
- package/dist/components/ItemSelectionActionsOptionsEditor/ItemSelectionActionsOptionsEditor.js.map +1 -1
- package/dist/components/LinksEditor/LinksEditor.js +5 -0
- package/dist/components/LinksEditor/LinksEditor.js.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.d.ts.map +1 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js +16 -1
- package/dist/components/MultiQueryEditor/MultiQueryEditor.js.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.d.ts.map +1 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js +4 -1
- package/dist/components/PanelSpecEditor/PanelSpecEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +7 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js +54 -41
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts +14 -0
- package/dist/components/PluginKindSelect/PluginKindSelect.d.ts.map +1 -1
- package/dist/components/PluginKindSelect/PluginKindSelect.js +187 -23
- package/dist/components/PluginKindSelect/PluginKindSelect.js.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.d.ts.map +1 -1
- package/dist/components/PluginRegistry/PluginRegistry.js +72 -7
- package/dist/components/PluginRegistry/PluginRegistry.js.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.d.ts +1 -0
- package/dist/components/PluginRegistry/plugin-indexes.d.ts.map +1 -1
- package/dist/components/PluginRegistry/plugin-indexes.js +6 -1
- package/dist/components/PluginRegistry/plugin-indexes.js.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js +6 -2
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.d.ts.map +1 -1
- package/dist/components/TimeRangeControls/TimeRangeControls.js +0 -2
- package/dist/components/TimeRangeControls/TimeRangeControls.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js +1 -1
- package/dist/components/Variables/VariableEditorForm/VariablePreview.js.map +1 -1
- package/dist/components/Variables/variable-model.d.ts.map +1 -1
- package/dist/components/Variables/variable-model.js +7 -2
- package/dist/components/Variables/variable-model.js.map +1 -1
- package/dist/model/datasource.d.ts +3 -0
- package/dist/model/datasource.d.ts.map +1 -1
- package/dist/model/datasource.js.map +1 -1
- package/dist/model/plugin-loading.d.ts +1 -0
- package/dist/model/plugin-loading.d.ts.map +1 -1
- package/dist/model/plugin-loading.js.map +1 -1
- package/dist/model/plugins.d.ts +11 -0
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/remote/PluginLoaderComponent.d.ts.map +1 -1
- package/dist/remote/PluginLoaderComponent.js +28 -15
- package/dist/remote/PluginLoaderComponent.js.map +1 -1
- package/dist/remote/PluginRuntime.d.ts.map +1 -1
- package/dist/remote/PluginRuntime.js +32 -24
- package/dist/remote/PluginRuntime.js.map +1 -1
- package/dist/remote/remotePluginLoader.d.ts.map +1 -1
- package/dist/remote/remotePluginLoader.js +1 -0
- package/dist/remote/remotePluginLoader.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +21 -15
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js +23 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProvider.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts +3 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.d.ts.map +1 -1
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js +2 -2
- package/dist/runtime/TimeRangeProvider/TimeRangeProviders.js.map +1 -1
- package/dist/runtime/TimeRangeProvider/query-params.js +7 -9
- package/dist/runtime/TimeRangeProvider/query-params.js.map +1 -1
- package/dist/runtime/UsageMetricsProvider.d.ts.map +1 -1
- package/dist/runtime/UsageMetricsProvider.js +24 -20
- package/dist/runtime/UsageMetricsProvider.js.map +1 -1
- package/dist/runtime/alerts-queries.d.ts.map +1 -1
- package/dist/runtime/alerts-queries.js +6 -2
- package/dist/runtime/alerts-queries.js.map +1 -1
- package/dist/runtime/annotations.d.ts +8 -0
- package/dist/runtime/annotations.d.ts.map +1 -1
- package/dist/runtime/annotations.js +47 -83
- package/dist/runtime/annotations.js.map +1 -1
- package/dist/runtime/datasources.d.ts +4 -0
- package/dist/runtime/datasources.d.ts.map +1 -1
- package/dist/runtime/datasources.js +4 -3
- package/dist/runtime/datasources.js.map +1 -1
- package/dist/runtime/log-queries.d.ts.map +1 -1
- package/dist/runtime/log-queries.js +3 -1
- package/dist/runtime/log-queries.js.map +1 -1
- package/dist/runtime/plugin-registry.d.ts +23 -8
- package/dist/runtime/plugin-registry.d.ts.map +1 -1
- package/dist/runtime/plugin-registry.js +52 -16
- package/dist/runtime/plugin-registry.js.map +1 -1
- package/dist/runtime/profile-queries.d.ts.map +1 -1
- package/dist/runtime/profile-queries.js +3 -1
- package/dist/runtime/profile-queries.js.map +1 -1
- package/dist/runtime/silences-queries.d.ts.map +1 -1
- package/dist/runtime/silences-queries.js +6 -2
- package/dist/runtime/silences-queries.js.map +1 -1
- package/dist/runtime/time-series-queries.d.ts.map +1 -1
- package/dist/runtime/time-series-queries.js +10 -3
- package/dist/runtime/time-series-queries.js.map +1 -1
- package/dist/runtime/trace-queries.d.ts.map +1 -1
- package/dist/runtime/trace-queries.js +6 -2
- package/dist/runtime/trace-queries.js.map +1 -1
- package/dist/runtime/variables.d.ts +6 -0
- package/dist/runtime/variables.d.ts.map +1 -1
- package/dist/runtime/variables.js +17 -1
- package/dist/runtime/variables.js.map +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/plugin-versions.d.ts +18 -0
- package/dist/utils/plugin-versions.d.ts.map +1 -0
- package/dist/utils/plugin-versions.js +52 -0
- package/dist/utils/plugin-versions.js.map +1 -0
- package/package.json +6 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/TimeRangeProvider/query-params.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 type { TimeRangeValue, DurationString, AbsoluteTimeRange } from '@perses-dev/spec';\nimport { isRelativeTimeRange, isDurationString } from '@perses-dev/spec';\nimport { getUnixTime, isDate } from 'date-fns';\nimport { useMemo, useCallback, useEffect, useState } from 'react';\nimport type { QueryParamConfig } from 'use-query-params';\nimport { useQueryParams, StringParam } from 'use-query-params';\n\nimport type { TimeRange } from './TimeRangeProvider';\n\nexport type TimeOptionValue = Date | DurationString | null | undefined;\n\n/* Interprets an encoded string and returns either the string or null/undefined if not available */\nfunction getEncodedValue(\n input: string | Array<string | null> | null | undefined,\n allowEmptyString?: boolean,\n): string | null | undefined {\n // '' or []\n if (!input || (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== '')))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str === null || str === undefined) {\n return str;\n }\n if (!allowEmptyString && str === '') {\n return null;\n }\n\n return str;\n}\n\n/* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */\nexport function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined {\n if (!timeOptionValue) {\n return timeOptionValue;\n }\n\n if (typeof timeOptionValue === 'string') {\n if (isDurationString(timeOptionValue)) {\n return timeOptionValue;\n }\n }\n return (getUnixTime(timeOptionValue) * 1000).toString();\n}\n\n/* Converts param input to supported relative or absolute time range format */\nexport function decodeTimeRangeValue(\n input: string | Array<string | null> | null | undefined,\n): Date | DurationString | null | undefined {\n const paramString = getEncodedValue(input);\n if (!paramString) return null;\n return isDurationString(paramString) ? paramString : new Date(Number(paramString));\n}\n\n/**\n * Custom TimeRangeValue param type\n * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types\n */\nexport const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue> = {\n encode: encodeTimeRangeValue,\n decode: decodeTimeRangeValue,\n equals: (valueA: TimeOptionValue, valueB: TimeOptionValue) => {\n if (valueA === valueB) return true;\n if (!valueA || !valueB) return valueA === valueB;\n return valueA.valueOf() === valueB.valueOf();\n },\n};\n\nexport const timeRangeQueryConfig = {\n start: TimeRangeParam,\n end: TimeRangeParam,\n};\n\nexport const refreshIntervalQueryConfig = {\n refresh: TimeRangeParam,\n};\n\nexport const timeZoneQueryConfig = {\n tz: StringParam,\n};\n\n/**\n * Gets the initial time range taking into account URL params and dashboard JSON duration\n * Sets start query param if it is empty on page load\n */\nexport function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue {\n const [query] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n const { start, end } = query;\n\n return useMemo(() => {\n let initialTimeRange: TimeRangeValue = { pastDuration: dashboardDuration };\n if (!start) {\n return initialTimeRange;\n }\n const startStr = start.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = { pastDuration: startStr };\n } else if (isDate(start) && isDate(end)) {\n initialTimeRange = { start: start, end: end } as AbsoluteTimeRange;\n }\n return initialTimeRange;\n }, [start, end, dashboardDuration]);\n}\n\n/**\n * Returns time range getter and setter, taking the URL query params.\n */\nexport function useTimeRangeParams(initialTimeRange: TimeRangeValue): Pick<TimeRange, 'timeRange' | 'setTimeRange'> {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n const { start } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (!paramsLoaded && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n setParamsLoaded(true);\n }\n }\n }, [initialTimeRange, paramsLoaded, start, setQuery]);\n\n const setTimeRange: TimeRange['setTimeRange'] = useCallback(\n (value: TimeRangeValue) => {\n if (isRelativeTimeRange(value)) {\n setQuery({ start: value.pastDuration, end: undefined });\n } else {\n setQuery(value);\n }\n },\n [setQuery],\n );\n\n return { timeRange: initialTimeRange, setTimeRange: setTimeRange };\n}\n\n/**\n * Gets the initial refresh interval taking into account URL params and dashboard JSON duration\n * Sets refresh query param if it is empty on page load\n */\nexport function useInitialRefreshInterval(dashboardDuration: DurationString): DurationString {\n const [query] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n const { refresh } = query;\n return useMemo(() => {\n let initialTimeRange: DurationString = dashboardDuration;\n if (!refresh) {\n return initialTimeRange;\n }\n const startStr = refresh.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = startStr;\n }\n return initialTimeRange;\n }, [dashboardDuration, refresh]);\n}\n\n/**\n * Returns refresh interval getter and setter, taking the URL query params.\n */\nexport function useSetRefreshIntervalParams(\n initialRefreshInterval?: DurationString,\n): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval'> {\n const [query, setQuery] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n\n // determine whether initial param had previously been populated to fix back btn\n const [paramsLoaded, setParamsLoaded] = useState<boolean>(false);\n\n const { refresh } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard refresh interval\n if (!paramsLoaded && !refresh) {\n setQuery({ refresh: initialRefreshInterval });\n setParamsLoaded(true);\n }\n }, [initialRefreshInterval, paramsLoaded, refresh, setQuery]);\n\n const setRefreshInterval: TimeRange['setRefreshInterval'] = useCallback(\n (refresh: DurationString) => setQuery({ refresh }),\n [setQuery],\n );\n\n return {\n refreshInterval: initialRefreshInterval,\n setRefreshInterval: setRefreshInterval,\n };\n}\n\n/**\n * Returns timezone getter and setter, taking the URL query params.\n * Defaults to 'local' when not set.\n */\nexport function useTimeZoneParams(initialTimeZone?: string): { timeZone: string; setTimeZone: (tz: string) => void } {\n const [query, setQuery] = useQueryParams(timeZoneQueryConfig, { updateType: 'replaceIn' });\n const { tz } = query;\n\n const timeZone = (tz as string | undefined) ?? initialTimeZone ?? 'local';\n\n const setTimeZone = useCallback(\n (newTz: string) => {\n setQuery({ tz: newTz });\n },\n [setQuery],\n );\n\n return { timeZone, setTimeZone };\n}\n"],"names":["isRelativeTimeRange","isDurationString","getUnixTime","isDate","useMemo","useCallback","useEffect","useState","useQueryParams","StringParam","getEncodedValue","input","allowEmptyString","length","str","Array","undefined","encodeTimeRangeValue","timeOptionValue","toString","decodeTimeRangeValue","paramString","Date","Number","TimeRangeParam","encode","decode","equals","valueA","valueB","valueOf","timeRangeQueryConfig","start","end","refreshIntervalQueryConfig","refresh","timeZoneQueryConfig","tz","useInitialTimeRange","dashboardDuration","query","updateType","initialTimeRange","pastDuration","startStr","useTimeRangeParams","setQuery","paramsLoaded","setParamsLoaded","setTimeRange","value","timeRange","useInitialRefreshInterval","useSetRefreshIntervalParams","initialRefreshInterval","setRefreshInterval","refreshInterval","useTimeZoneParams","initialTimeZone","timeZone","setTimeZone","newTz"],"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,gBAAgB,QAAQ,mBAAmB;AACzE,SAASC,WAAW,EAAEC,MAAM,Q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AAY;IAAY;IACxF,MAAM,EAAEJ,EAAE,EAAE,GAAGG;IAEf,MAAMmB,WAAW,AAACtB,MAA6BqB,mBAAmB;IAElE,MAAME,cAAcvD,YAClB,CAACwD;QACCf,SAAS;YAAET,IAAIwB;QAAM;IACvB,GACA;QAACf;KAAS;IAGZ,OAAO;QAAEa;QAAUC;IAAY;AACjC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/TimeRangeProvider/query-params.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 type { TimeRangeValue, DurationString, AbsoluteTimeRange } from '@perses-dev/spec';\nimport { isRelativeTimeRange, isDurationString } from '@perses-dev/spec';\nimport { getUnixTime, isDate } from 'date-fns';\nimport { useMemo, useCallback, useEffect, useRef } from 'react';\nimport type { QueryParamConfig } from 'use-query-params';\nimport { useQueryParams, StringParam } from 'use-query-params';\n\nimport type { TimeRange } from './TimeRangeProvider';\n\nexport type TimeOptionValue = Date | DurationString | null | undefined;\n\n/* Interprets an encoded string and returns either the string or null/undefined if not available */\nfunction getEncodedValue(\n input: string | Array<string | null> | null | undefined,\n allowEmptyString?: boolean,\n): string | null | undefined {\n // '' or []\n if (!input || (input.length === 0 && (!allowEmptyString || (allowEmptyString && input !== '')))) {\n return null;\n }\n\n const str = input instanceof Array ? input[0] : input;\n if (str === null || str === undefined) {\n return str;\n }\n if (!allowEmptyString && str === '') {\n return null;\n }\n\n return str;\n}\n\n/* Encodes individual TimeRangeValue as a string, depends on whether start is relative or absolute */\nexport function encodeTimeRangeValue(timeOptionValue: TimeOptionValue): string | null | undefined {\n if (!timeOptionValue) {\n return timeOptionValue;\n }\n\n if (typeof timeOptionValue === 'string') {\n if (isDurationString(timeOptionValue)) {\n return timeOptionValue;\n }\n }\n return (getUnixTime(timeOptionValue) * 1000).toString();\n}\n\n/* Converts param input to supported relative or absolute time range format */\nexport function decodeTimeRangeValue(\n input: string | Array<string | null> | null | undefined,\n): Date | DurationString | null | undefined {\n const paramString = getEncodedValue(input);\n if (!paramString) return null;\n return isDurationString(paramString) ? paramString : new Date(Number(paramString));\n}\n\n/**\n * Custom TimeRangeValue param type\n * See: https://github.com/pbeshai/use-query-params/tree/master/packages/serialize-query-params#param-types\n */\nexport const TimeRangeParam: QueryParamConfig<TimeOptionValue, TimeOptionValue> = {\n encode: encodeTimeRangeValue,\n decode: decodeTimeRangeValue,\n equals: (valueA: TimeOptionValue, valueB: TimeOptionValue) => {\n if (valueA === valueB) return true;\n if (!valueA || !valueB) return valueA === valueB;\n return valueA.valueOf() === valueB.valueOf();\n },\n};\n\nexport const timeRangeQueryConfig = {\n start: TimeRangeParam,\n end: TimeRangeParam,\n};\n\nexport const refreshIntervalQueryConfig = {\n refresh: TimeRangeParam,\n};\n\nexport const timeZoneQueryConfig = {\n tz: StringParam,\n};\n\n/**\n * Gets the initial time range taking into account URL params and dashboard JSON duration\n * Sets start query param if it is empty on page load\n */\nexport function useInitialTimeRange(dashboardDuration: DurationString): TimeRangeValue {\n const [query] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n const { start, end } = query;\n\n return useMemo(() => {\n let initialTimeRange: TimeRangeValue = { pastDuration: dashboardDuration };\n if (!start) {\n return initialTimeRange;\n }\n const startStr = start.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = { pastDuration: startStr };\n } else if (isDate(start) && isDate(end)) {\n initialTimeRange = { start: start, end: end } as AbsoluteTimeRange;\n }\n return initialTimeRange;\n }, [start, end, dashboardDuration]);\n}\n\n/**\n * Returns time range getter and setter, taking the URL query params.\n */\nexport function useTimeRangeParams(initialTimeRange: TimeRangeValue): Pick<TimeRange, 'timeRange' | 'setTimeRange'> {\n const [query, setQuery] = useQueryParams(timeRangeQueryConfig, { updateType: 'replaceIn' });\n // determine whether initial param had previously been populated to fix back btn\n const paramsLoaded = useRef(false);\n\n const { start } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard duration\n if (!paramsLoaded.current && !start) {\n if (isRelativeTimeRange(initialTimeRange)) {\n setQuery({ start: initialTimeRange.pastDuration, end: undefined });\n paramsLoaded.current = true;\n }\n }\n }, [initialTimeRange, start, setQuery]);\n\n const setTimeRange: TimeRange['setTimeRange'] = useCallback(\n (value: TimeRangeValue) => {\n if (isRelativeTimeRange(value)) {\n setQuery({ start: value.pastDuration, end: undefined });\n } else {\n setQuery(value);\n }\n },\n [setQuery],\n );\n\n return { timeRange: initialTimeRange, setTimeRange: setTimeRange };\n}\n\n/**\n * Gets the initial refresh interval taking into account URL params and dashboard JSON duration\n * Sets refresh query param if it is empty on page load\n */\nexport function useInitialRefreshInterval(dashboardDuration: DurationString): DurationString {\n const [query] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n const { refresh } = query;\n return useMemo(() => {\n let initialTimeRange: DurationString = dashboardDuration;\n if (!refresh) {\n return initialTimeRange;\n }\n const startStr = refresh.toString();\n if (isDurationString(startStr)) {\n initialTimeRange = startStr;\n }\n return initialTimeRange;\n }, [dashboardDuration, refresh]);\n}\n\n/**\n * Returns refresh interval getter and setter, taking the URL query params.\n */\nexport function useSetRefreshIntervalParams(\n initialRefreshInterval?: DurationString,\n): Pick<TimeRange, 'refreshInterval' | 'setRefreshInterval'> {\n const [query, setQuery] = useQueryParams(refreshIntervalQueryConfig, { updateType: 'replaceIn' });\n\n // determine whether initial param had previously been populated to fix back btn\n const paramsLoaded = useRef(false);\n\n const { refresh } = query;\n\n useEffect(() => {\n // when dashboard loaded with no params, default to dashboard refresh interval\n if (!paramsLoaded.current && !refresh) {\n setQuery({ refresh: initialRefreshInterval });\n paramsLoaded.current = true;\n }\n }, [initialRefreshInterval, refresh, setQuery]);\n\n const setRefreshInterval: TimeRange['setRefreshInterval'] = useCallback(\n (refresh: DurationString) => setQuery({ refresh }),\n [setQuery],\n );\n\n return {\n refreshInterval: initialRefreshInterval,\n setRefreshInterval: setRefreshInterval,\n };\n}\n\n/**\n * Returns timezone getter and setter, taking the URL query params.\n * Defaults to 'local' when not set.\n */\nexport function useTimeZoneParams(initialTimeZone?: string): { timeZone: string; setTimeZone: (tz: string) => void } {\n const [query, setQuery] = useQueryParams(timeZoneQueryConfig, { updateType: 'replaceIn' });\n const { tz } = query;\n\n const timeZone = (tz as string | undefined) ?? initialTimeZone ?? 'local';\n\n const setTimeZone = useCallback(\n (newTz: string) => {\n setQuery({ tz: newTz });\n },\n [setQuery],\n );\n\n return { timeZone, setTimeZone };\n}\n"],"names":["isRelativeTimeRange","isDurationString","getUnixTime","isDate","useMemo","useCallback","useEffect","useRef","useQueryParams","StringParam","getEncodedValue","input","allowEmptyString","length","str","Array","undefined","encodeTimeRangeValue","timeOptionValue","toString","decodeTimeRangeValue","paramString","Date","Number","TimeRangeParam","encode","decode","equals","valueA","valueB","valueOf","timeRangeQueryConfig","start","end","refreshIntervalQueryConfig","refresh","timeZoneQueryConfig","tz","useInitialTimeRange","dashboardDuration","query","updateType","initialTimeRange","pastDuration","startStr","useTimeRangeParams","setQuery","paramsLoaded","current","setTimeRange","value","timeRange","useInitialRefreshInterval","useSetRefreshIntervalParams","initialRefreshInterval","setRefreshInterval","refreshInterval","useTimeZoneParams","initialTimeZone","timeZone","setTimeZone","newTz"],"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,gBAAgB,QAAQ,mBAAmB;AACzE,SAASC,WAAW,EAAEC,MAAM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D,CAAC;AAEF,eAAO,MAAM,eAAe,QAAO,
|
|
1
|
+
{"version":3,"file":"UsageMetricsProvider.d.ts","sourceRoot":"","sources":["../../src/runtime/UsageMetricsProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGrD,KAAK,UAAU,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,CAAC;AAElD,UAAU,YAAY;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,EAAE,MAAM,CAAC;IACxB,gBAAgB,EAAE,MAAM,CAAC;IACzB,gBAAgB,EAAE,MAAM,CAAC;IACzB,cAAc,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,UAAU,iBAAiB;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAED,UAAU,sBAAsB;IAC9B,SAAS,EAAE,CAAC,UAAU,EAAE,eAAe,EAAE,KAAK,EAAE,UAAU,KAAK,IAAI,CAAC;CACrE;AAED,eAAO,MAAM,mBAAmB,mDAAqD,CAAC;AAEtF,eAAO,MAAM,sBAAsB,QAAO,YAAY,GAAG,SAExD,CAAC;AAEF,eAAO,MAAM,eAAe,QAAO,sBAWlC,CAAC;AAsCF,eAAO,MAAM,oBAAoB,gDAAiD,iBAAiB,KAAG,YAgBrG,CAAC"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
14
|
import { useFetch } from "@perses-dev/client";
|
|
15
|
-
import { createContext, useContext } from "react";
|
|
15
|
+
import { createContext, useContext, useState } from "react";
|
|
16
16
|
export const UsageMetricsContext = /*#__PURE__*/ createContext(undefined);
|
|
17
17
|
export const useUsageMetricsContext = ()=>{
|
|
18
18
|
return useContext(UsageMetricsContext);
|
|
@@ -24,27 +24,30 @@ export const useUsageMetrics = ()=>{
|
|
|
24
24
|
if (ctx === undefined) {
|
|
25
25
|
return;
|
|
26
26
|
}
|
|
27
|
-
|
|
28
|
-
if (ctx.pendingQueries.has(definitionKey) && newState === 'pending') {
|
|
29
|
-
// Never allow transitions back to pending, to avoid re-sending stats on a re-render.
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
if (ctx.pendingQueries.get(definitionKey) !== newState) {
|
|
33
|
-
ctx.pendingQueries.set(definitionKey, newState);
|
|
34
|
-
if (newState === 'error') {
|
|
35
|
-
ctx.renderErrorCount += 1;
|
|
36
|
-
}
|
|
37
|
-
const allDone = [
|
|
38
|
-
...ctx.pendingQueries.values()
|
|
39
|
-
].every((p)=>p !== 'pending');
|
|
40
|
-
if (ctx.renderDurationMs === 0 && allDone) {
|
|
41
|
-
ctx.renderDurationMs = Date.now() - ctx.startRenderTime;
|
|
42
|
-
submitMetrics(ctx);
|
|
43
|
-
}
|
|
44
|
-
}
|
|
27
|
+
recordQuery(ctx, definition, newState);
|
|
45
28
|
}
|
|
46
29
|
};
|
|
47
30
|
};
|
|
31
|
+
function recordQuery(ctx, definition, newState) {
|
|
32
|
+
const definitionKey = JSON.stringify(definition);
|
|
33
|
+
if (ctx.pendingQueries.has(definitionKey) && newState === 'pending') {
|
|
34
|
+
// Never allow transitions back to pending, to avoid re-sending stats on a re-render.
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
if (ctx.pendingQueries.get(definitionKey) !== newState) {
|
|
38
|
+
ctx.pendingQueries.set(definitionKey, newState);
|
|
39
|
+
if (newState === 'error') {
|
|
40
|
+
ctx.renderErrorCount += 1;
|
|
41
|
+
}
|
|
42
|
+
const allDone = [
|
|
43
|
+
...ctx.pendingQueries.values()
|
|
44
|
+
].every((p)=>p !== 'pending');
|
|
45
|
+
if (ctx.renderDurationMs === 0 && allDone) {
|
|
46
|
+
ctx.renderDurationMs = Date.now() - ctx.startRenderTime;
|
|
47
|
+
submitMetrics(ctx);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
48
51
|
const submitMetrics = async (stats)=>{
|
|
49
52
|
await stats.fetchFn(`${stats.apiPrefix ?? ''}/api/v1/view`, {
|
|
50
53
|
method: 'POST',
|
|
@@ -61,11 +64,12 @@ const submitMetrics = async (stats)=>{
|
|
|
61
64
|
};
|
|
62
65
|
export const UsageMetricsProvider = ({ apiPrefix, project, dashboard, children })=>{
|
|
63
66
|
const { fetch } = useFetch();
|
|
67
|
+
const [startRenderTime] = useState(()=>Date.now());
|
|
64
68
|
const ctx = {
|
|
65
69
|
project: project,
|
|
66
70
|
dashboard: dashboard,
|
|
67
71
|
renderErrorCount: 0,
|
|
68
|
-
startRenderTime
|
|
72
|
+
startRenderTime,
|
|
69
73
|
renderDurationMs: 0,
|
|
70
74
|
pendingQueries: new Map(),
|
|
71
75
|
apiPrefix,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/UsageMetricsProvider.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 type { FetchFn } from '@perses-dev/client';\nimport { useFetch } from '@perses-dev/client';\nimport type { QueryDefinition } from '@perses-dev/spec';\nimport type { ReactElement, ReactNode } from 'react';\nimport { createContext, useContext } from 'react';\n\ntype QueryState = 'pending' | 'success' | 'error';\n\ninterface UsageMetrics {\n project: string;\n dashboard: string;\n startRenderTime: number;\n renderDurationMs: number;\n renderErrorCount: number;\n pendingQueries: Map<string, QueryState>;\n apiPrefix?: string;\n fetchFn: FetchFn;\n}\n\ninterface UsageMetricsProps {\n project: string;\n dashboard: string;\n apiPrefix?: string;\n children: ReactNode;\n}\n\ninterface UseUsageMetricsResults {\n markQuery: (definition: QueryDefinition, state: QueryState) => void;\n}\n\nexport const UsageMetricsContext = createContext<UsageMetrics | undefined>(undefined);\n\nexport const useUsageMetricsContext = (): UsageMetrics | undefined => {\n return useContext(UsageMetricsContext);\n};\n\nexport const useUsageMetrics = (): UseUsageMetricsResults => {\n const ctx = useUsageMetricsContext();\n\n return {\n markQuery: (definition: QueryDefinition, newState: QueryState): void => {\n if (ctx === undefined) {\n return;\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/UsageMetricsProvider.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 type { FetchFn } from '@perses-dev/client';\nimport { useFetch } from '@perses-dev/client';\nimport type { QueryDefinition } from '@perses-dev/spec';\nimport type { ReactElement, ReactNode } from 'react';\nimport { createContext, useContext, useState } from 'react';\n\ntype QueryState = 'pending' | 'success' | 'error';\n\ninterface UsageMetrics {\n project: string;\n dashboard: string;\n startRenderTime: number;\n renderDurationMs: number;\n renderErrorCount: number;\n pendingQueries: Map<string, QueryState>;\n apiPrefix?: string;\n fetchFn: FetchFn;\n}\n\ninterface UsageMetricsProps {\n project: string;\n dashboard: string;\n apiPrefix?: string;\n children: ReactNode;\n}\n\ninterface UseUsageMetricsResults {\n markQuery: (definition: QueryDefinition, state: QueryState) => void;\n}\n\nexport const UsageMetricsContext = createContext<UsageMetrics | undefined>(undefined);\n\nexport const useUsageMetricsContext = (): UsageMetrics | undefined => {\n return useContext(UsageMetricsContext);\n};\n\nexport const useUsageMetrics = (): UseUsageMetricsResults => {\n const ctx = useUsageMetricsContext();\n\n return {\n markQuery: (definition: QueryDefinition, newState: QueryState): void => {\n if (ctx === undefined) {\n return;\n }\n recordQuery(ctx, definition, newState);\n },\n };\n};\n\nfunction recordQuery(ctx: UsageMetrics, definition: QueryDefinition, newState: QueryState): void {\n const definitionKey = JSON.stringify(definition);\n if (ctx.pendingQueries.has(definitionKey) && newState === 'pending') {\n // Never allow transitions back to pending, to avoid re-sending stats on a re-render.\n return;\n }\n\n if (ctx.pendingQueries.get(definitionKey) !== newState) {\n ctx.pendingQueries.set(definitionKey, newState);\n if (newState === 'error') {\n ctx.renderErrorCount += 1;\n }\n\n const allDone = [...ctx.pendingQueries.values()].every((p) => p !== 'pending');\n if (ctx.renderDurationMs === 0 && allDone) {\n ctx.renderDurationMs = Date.now() - ctx.startRenderTime;\n submitMetrics(ctx);\n }\n }\n}\n\nconst submitMetrics = async (stats: UsageMetrics): Promise<void> => {\n await stats.fetchFn(`${stats.apiPrefix ?? ''}/api/v1/view`, {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/json',\n },\n body: JSON.stringify({\n project: stats.project,\n dashboard: stats.dashboard,\n render_time: stats.renderDurationMs / 1000,\n render_errors: stats.renderErrorCount,\n }),\n });\n};\n\nexport const UsageMetricsProvider = ({ apiPrefix, project, dashboard, children }: UsageMetricsProps): ReactElement => {\n const { fetch } = useFetch();\n const [startRenderTime] = useState(() => Date.now());\n\n const ctx: UsageMetrics = {\n project: project,\n dashboard: dashboard,\n renderErrorCount: 0,\n startRenderTime,\n renderDurationMs: 0,\n pendingQueries: new Map(),\n apiPrefix,\n fetchFn: fetch,\n };\n\n return <UsageMetricsContext.Provider value={ctx}>{children}</UsageMetricsContext.Provider>;\n};\n"],"names":["useFetch","createContext","useContext","useState","UsageMetricsContext","undefined","useUsageMetricsContext","useUsageMetrics","ctx","markQuery","definition","newState","recordQuery","definitionKey","JSON","stringify","pendingQueries","has","get","set","renderErrorCount","allDone","values","every","p","renderDurationMs","Date","now","startRenderTime","submitMetrics","stats","fetchFn","apiPrefix","method","headers","body","project","dashboard","render_time","render_errors","UsageMetricsProvider","children","fetch","Map","Provider","value"],"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,QAAQ,QAAQ,qBAAqB;AAG9C,SAASC,aAAa,EAAEC,UAAU,EAAEC,QAAQ,QAAQ,QAAQ;AA0B5D,OAAO,MAAMC,oCAAsBH,cAAwCI,WAAW;AAEtF,OAAO,MAAMC,yBAAyB;IACpC,OAAOJ,WAAWE;AACpB,EAAE;AAEF,OAAO,MAAMG,kBAAkB;IAC7B,MAAMC,MAAMF;IAEZ,OAAO;QACLG,WAAW,CAACC,YAA6BC;YACvC,IAAIH,QAAQH,WAAW;gBACrB;YACF;YACAO,YAAYJ,KAAKE,YAAYC;QAC/B;IACF;AACF,EAAE;AAEF,SAASC,YAAYJ,GAAiB,EAAEE,UAA2B,EAAEC,QAAoB;IACvF,MAAME,gBAAgBC,KAAKC,SAAS,CAACL;IACrC,IAAIF,IAAIQ,cAAc,CAACC,GAAG,CAACJ,kBAAkBF,aAAa,WAAW;QACnE,qFAAqF;QACrF;IACF;IAEA,IAAIH,IAAIQ,cAAc,CAACE,GAAG,CAACL,mBAAmBF,UAAU;QACtDH,IAAIQ,cAAc,CAACG,GAAG,CAACN,eAA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AM,kBAAkB,CAAC;AACjF,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAStE,MAAM,MAAM,qBAAqB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AACzG,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,qBAAqB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"alerts-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/alerts-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACjF,OAAO,KAAK,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAStE,MAAM,MAAM,qBAAqB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,aAAa,EAAE,UAAU,CAAC,CAAC;AACzG,eAAO,MAAM,gBAAgB,gBAAgB,CAAC;AAE9C;;;;GAIG;AACH,wBAAgB,gBAAgB,CAAC,WAAW,EAAE,qBAAqB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,UAAU,CAAC,CAAC,CAsCxG"}
|
|
@@ -24,7 +24,9 @@ export const ALERTS_QUERY_KEY = 'AlertsQuery';
|
|
|
24
24
|
const { getPlugin } = usePluginRegistry();
|
|
25
25
|
const context = useAlertsQueryContext();
|
|
26
26
|
const pluginLoaderResponse = usePlugins('AlertsQuery', definitions.map((d)=>({
|
|
27
|
-
kind: d.spec.plugin.kind
|
|
27
|
+
kind: d.spec.plugin.kind,
|
|
28
|
+
version: d.spec.plugin.metadata?.version,
|
|
29
|
+
registry: d.spec.plugin.metadata?.registry
|
|
28
30
|
})));
|
|
29
31
|
return useQueries({
|
|
30
32
|
queries: definitions.map((definition, idx)=>{
|
|
@@ -45,7 +47,9 @@ export const ALERTS_QUERY_KEY = 'AlertsQuery';
|
|
|
45
47
|
queryFn: async ({ signal })=>{
|
|
46
48
|
const plugin = await getPlugin({
|
|
47
49
|
kind: ALERTS_QUERY_KEY,
|
|
48
|
-
name: alertsQueryKind
|
|
50
|
+
name: alertsQueryKind,
|
|
51
|
+
version: definition.spec.plugin.metadata?.version,
|
|
52
|
+
registry: definition.spec.plugin.metadata?.registry
|
|
49
53
|
});
|
|
50
54
|
const data = await plugin.getAlertsData(definition.spec.plugin.spec, context, signal);
|
|
51
55
|
return data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/alerts-queries.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 type { AlertsData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { AlertsQueryContext, AlertsQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport type AlertsQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'AlertsQuery', PluginSpec>;\nexport const ALERTS_QUERY_KEY = 'AlertsQuery';\n\n/**\n * Run an alerts query using an AlertsQuery plugin and return the results.\n * Alerts represent current state and are NOT time-range dependent.\n * @param definitions: dashboard definition for an alerts query\n */\nexport function useAlertsQueries(definitions: AlertsQueryDefinition[]): Array<UseQueryResult<AlertsData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAlertsQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'AlertsQuery',\n definitions.map((d) => ({
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/alerts-queries.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 type { AlertsData, QueryDefinition, UnknownSpec } from '@perses-dev/spec';\nimport type { QueryKey, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries } from '@tanstack/react-query';\n\nimport type { AlertsQueryContext, AlertsQueryPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry, usePlugins } from './plugin-registry';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport type AlertsQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'AlertsQuery', PluginSpec>;\nexport const ALERTS_QUERY_KEY = 'AlertsQuery';\n\n/**\n * Run an alerts query using an AlertsQuery plugin and return the results.\n * Alerts represent current state and are NOT time-range dependent.\n * @param definitions: dashboard definition for an alerts query\n */\nexport function useAlertsQueries(definitions: AlertsQueryDefinition[]): Array<UseQueryResult<AlertsData>> {\n const { getPlugin } = usePluginRegistry();\n const context = useAlertsQueryContext();\n\n const pluginLoaderResponse = usePlugins(\n 'AlertsQuery',\n definitions.map((d) => ({\n kind: d.spec.plugin.kind,\n version: d.spec.plugin.metadata?.version,\n registry: d.spec.plugin.metadata?.registry,\n })),\n );\n\n return useQueries({\n queries: definitions.map((definition, idx) => {\n const plugin = pluginLoaderResponse[idx]?.data;\n const { queryEnabled, queryKey } = getQueryOptions({ context, definition, plugin });\n const alertsQueryKind = definition?.spec?.plugin?.kind;\n return {\n enabled: queryEnabled,\n queryKey: queryKey,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: 60_000,\n queryFn: async ({ signal }: { signal?: AbortSignal }): Promise<AlertsData> => {\n const plugin = await getPlugin({\n kind: ALERTS_QUERY_KEY,\n name: alertsQueryKind,\n version: definition.spec.plugin.metadata?.version,\n registry: definition.spec.plugin.metadata?.registry,\n });\n const data = await plugin.getAlertsData(definition.spec.plugin.spec, context, signal);\n return data;\n },\n };\n }),\n });\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: AlertsQueryPlugin;\n definition: AlertsQueryDefinition;\n context: AlertsQueryContext;\n}): {\n queryKey: QueryKey;\n queryEnabled: boolean;\n} {\n const { variableState } = context;\n\n const dependencies = plugin?.dependsOn ? plugin.dependsOn(definition.spec.plugin.spec, context) : {};\n const variableDependencies = dependencies?.variables;\n\n const filteredVariabledState = filterVariableStateMap(variableState, variableDependencies);\n const variablesValueKey = getVariableValuesKey(filteredVariabledState);\n // Note: no absoluteTimeRange in query key since alerts are current state\n const queryKey = ['query', ALERTS_QUERY_KEY, definition, variablesValueKey] as const;\n\n let waitToLoad = false;\n if (variableDependencies) {\n waitToLoad = variableDependencies.some((v) => variableState[v]?.loading);\n }\n\n const queryEnabled = plugin !== undefined && !waitToLoad;\n return {\n queryKey,\n queryEnabled,\n };\n}\n\nfunction useAlertsQueryContext(): AlertsQueryContext {\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n };\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","usePlugins","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","ALERTS_QUERY_KEY","useAlertsQueries","definitions","getPlugin","context","useAlertsQueryContext","pluginLoaderResponse","map","d","kind","spec","plugin","version","metadata","registry","queries","definition","idx","data","queryEnabled","queryKey","getQueryOptions","alertsQueryKind","enabled","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","queryFn","signal","name","getAlertsData","variableState","dependencies","dependsOn","variableDependencies","variables","filteredVariabledState","variablesValueKey","waitToLoad","some","v","loading","undefined","datasourceStore"],"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,UAAU,QAAQ,wBAAwB;AAGnD,SAASC,kBAAkB,QAAQ,mBAAgB;AACnD,SAASC,iBAAiB,EAAEC,UAAU,QAAQ,uBAAoB;AAClE,SAASC,sBAAsB,EAAEC,oBAAoB,QAAQ,aAAU;AACvE,SAASC,oBAAoB,QAAQ,iBAAc;AAGnD,OAAO,MAAMC,mBAAmB,cAAc;AAE9C;;;;CAIC,GACD,OAAO,SAASC,iBAAiBC,WAAoC;IACnE,MAAM,EAAEC,SAAS,EAAE,GAAGR;IACtB,MAAMS,UAAUC;IAEhB,MAAMC,uBAAuBV,WAC3B,eACAM,YAAYK,GAAG,CAAC,CAACC,IAAO,CAAA;YACtBC,MAAMD,EAAEE,IAAI,CAACC,MAAM,CAACF,IAAI;YACxBG,SAASJ,EAAEE,IAAI,CAACC,MAAM,CAACE,QAAQ,EAAED;YACjCE,UAAUN,EAAEE,IAAI,CAACC,MAAM,CAACE,QAAQ,EAAEC;QACpC,CAAA;IAGF,OAAOrB,WAAW;QAChBsB,SAASb,YAAYK,GAAG,CAAC,CAACS,YAAYC;YACpC,MAAMN,SAASL,oBAAoB,CAACW,IAAI,EAAEC;YAC1C,MAAM,EAAEC,YAAY,EAAEC,QAAQ,EAAE,GAAGC,gBAAgB;gBAAEjB;gBAASY;gBAAYL;YAAO;YACjF,MAAMW,kBAAkBN,YAAYN,MAAMC,QAAQF;YAClD,OAAO;gB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ationSpec } from '@perses-dev/spec';
|
|
2
2
|
import type { UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
export declare const ANNOTATION_KEY = "Annotation";
|
|
4
|
+
/**
|
|
5
|
+
* Resolves annotation specs through the shared query cache. Panels requesting the same spec,
|
|
6
|
+
* absolute time range, and variable values share both in-flight requests and cached data with previews.
|
|
7
|
+
*/
|
|
4
8
|
export declare function useAnnotations(definitions: AnnotationSpec[]): Array<UseQueryResult<AnnotationData[]>>;
|
|
9
|
+
/**
|
|
10
|
+
* Resolves one annotation spec using the same cache and fetch policy as {@link useAnnotations}.
|
|
11
|
+
* Used by annotation previews; also exposes loading, error, and refetch state to individual consumers.
|
|
12
|
+
*/
|
|
5
13
|
export declare function useAnnotationData(spec: AnnotationSpec): UseQueryResult<AnnotationData[]>;
|
|
6
14
|
//# sourceMappingURL=annotations.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/runtime/annotations.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"annotations.d.ts","sourceRoot":"","sources":["../../src/runtime/annotations.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACvE,OAAO,KAAK,EAAmB,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAU7E,eAAO,MAAM,cAAc,eAAe,CAAC;AAgD3C;;;GAGG;AACH,wBAAgB,cAAc,CAAC,WAAW,EAAE,cAAc,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,EAAE,CAAC,CAAC,CAiBrG;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,EAAE,cAAc,GAAG,cAAc,CAAC,cAAc,EAAE,CAAC,CAQxF"}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
// limitations under the License.
|
|
13
13
|
import { useQueries, useQuery } from "@tanstack/react-query";
|
|
14
14
|
import { useDatasourceStore } from "./datasources.js";
|
|
15
|
-
import { usePlugin,
|
|
15
|
+
import { usePlugin, usePlugins } from "./plugin-registry.js";
|
|
16
16
|
import { useTimeRange } from "./TimeRangeProvider/index.js";
|
|
17
17
|
import { filterVariableStateMap, getVariableValuesKey } from "./utils.js";
|
|
18
18
|
import { useAllVariableValues } from "./variables.js";
|
|
@@ -29,101 +29,65 @@ function useAnnotationContext() {
|
|
|
29
29
|
}
|
|
30
30
|
function getQueryOptions({ plugin, definition, context }) {
|
|
31
31
|
const { variableState, absoluteTimeRange } = context;
|
|
32
|
-
const dependencies = plugin?.dependsOn
|
|
33
|
-
const
|
|
34
|
-
const filteredVariableState = filterVariableStateMap(variableState, variableDependencies);
|
|
32
|
+
const dependencies = plugin?.dependsOn?.(definition.plugin.spec, context);
|
|
33
|
+
const filteredVariableState = filterVariableStateMap(variableState, dependencies?.variables);
|
|
35
34
|
const variablesValueKey = getVariableValuesKey(filteredVariableState);
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
definition,
|
|
39
|
-
absoluteTimeRange,
|
|
40
|
-
variablesValueKey
|
|
41
|
-
];
|
|
42
|
-
let waitToLoad = false;
|
|
43
|
-
if (variableDependencies) {
|
|
44
|
-
waitToLoad = variableDependencies.some((v)=>variableState[v]?.loading);
|
|
45
|
-
}
|
|
46
|
-
const queryEnabled = plugin !== undefined && !waitToLoad;
|
|
35
|
+
// Only declared variable dependencies delay the query, like other query plugins.
|
|
36
|
+
const waitToLoad = dependencies?.variables?.some((name)=>variableState[name]?.loading) ?? false;
|
|
47
37
|
return {
|
|
48
|
-
|
|
49
|
-
|
|
38
|
+
// ['annotation', spec] prefix: refreshed by TimeRangeProvider and invalidated by the annotation editor preview.
|
|
39
|
+
queryKey: [
|
|
40
|
+
'annotation',
|
|
41
|
+
definition,
|
|
42
|
+
absoluteTimeRange,
|
|
43
|
+
variablesValueKey
|
|
44
|
+
],
|
|
45
|
+
enabled: plugin !== undefined && !waitToLoad,
|
|
46
|
+
refetchOnMount: false,
|
|
47
|
+
refetchOnWindowFocus: false,
|
|
48
|
+
refetchOnReconnect: false,
|
|
49
|
+
staleTime: Infinity,
|
|
50
|
+
queryFn: async ({ signal })=>{
|
|
51
|
+
if (plugin === undefined) {
|
|
52
|
+
throw new Error('Expected annotation plugin to be loaded');
|
|
53
|
+
}
|
|
54
|
+
const data = await plugin.getAnnotationData(definition.plugin.spec, context, signal);
|
|
55
|
+
return data;
|
|
56
|
+
}
|
|
50
57
|
};
|
|
51
58
|
}
|
|
52
|
-
|
|
53
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Resolves annotation specs through the shared query cache. Panels requesting the same spec,
|
|
61
|
+
* absolute time range, and variable values share both in-flight requests and cached data with previews.
|
|
62
|
+
*/ export function useAnnotations(definitions) {
|
|
54
63
|
const context = useAnnotationContext();
|
|
55
64
|
const pluginLoaderResponse = usePlugins('Annotation', definitions.map((d)=>({
|
|
56
|
-
kind: d.plugin.kind
|
|
65
|
+
kind: d.plugin.kind,
|
|
66
|
+
version: d.plugin.metadata?.version,
|
|
67
|
+
registry: d.plugin.metadata?.registry
|
|
57
68
|
})));
|
|
58
|
-
// useQueries() handles data fetching from query plugins
|
|
59
69
|
return useQueries({
|
|
60
|
-
queries: definitions.map((definition,
|
|
61
|
-
const plugin = pluginLoaderResponse[idx]?.data;
|
|
62
|
-
const { queryEnabled, queryKey } = getQueryOptions({
|
|
70
|
+
queries: definitions.map((definition, index)=>getQueryOptions({
|
|
63
71
|
context,
|
|
64
72
|
definition,
|
|
65
|
-
plugin
|
|
66
|
-
})
|
|
67
|
-
const annotationKind = definition?.plugin?.kind;
|
|
68
|
-
return {
|
|
69
|
-
enabled: queryEnabled,
|
|
70
|
-
queryKey: queryKey,
|
|
71
|
-
refetchOnMount: false,
|
|
72
|
-
refetchOnWindowFocus: false,
|
|
73
|
-
refetchOnReconnect: false,
|
|
74
|
-
staleTime: Infinity,
|
|
75
|
-
queryFn: async ({ signal })=>{
|
|
76
|
-
const plugin = await getPlugin({
|
|
77
|
-
kind: ANNOTATION_KEY,
|
|
78
|
-
name: annotationKind
|
|
79
|
-
});
|
|
80
|
-
const data = await plugin.getAnnotationData(definition.plugin.spec, context, signal);
|
|
81
|
-
return data;
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
})
|
|
73
|
+
plugin: pluginLoaderResponse[index]?.data
|
|
74
|
+
}))
|
|
85
75
|
});
|
|
86
76
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
datasourceStore,
|
|
95
|
-
variableState: allVariables
|
|
96
|
-
};
|
|
97
|
-
let dependsOnVariables = Object.keys(allVariables); // Default to all variables
|
|
98
|
-
if (annotationPlugin?.dependsOn) {
|
|
99
|
-
const dependencies = annotationPlugin.dependsOn(spec.plugin.spec, variablePluginCtx);
|
|
100
|
-
dependsOnVariables = dependencies.variables ? dependencies.variables : dependsOnVariables;
|
|
101
|
-
}
|
|
102
|
-
const variables = useAllVariableValues(dependsOnVariables);
|
|
103
|
-
let waitToLoad = false;
|
|
104
|
-
if (dependsOnVariables) {
|
|
105
|
-
waitToLoad = dependsOnVariables.some((v)=>variables[v]?.loading);
|
|
106
|
-
}
|
|
107
|
-
const variablesValueKey = getVariableValuesKey(variables);
|
|
108
|
-
return useQuery({
|
|
109
|
-
queryKey: [
|
|
110
|
-
'annotation',
|
|
111
|
-
spec,
|
|
112
|
-
timeRange,
|
|
113
|
-
variablesValueKey
|
|
114
|
-
],
|
|
115
|
-
queryFn: async ({ signal })=>{
|
|
116
|
-
const resp = await annotationPlugin?.getAnnotationData(spec.plugin.spec, {
|
|
117
|
-
...variablePluginCtx,
|
|
118
|
-
variableState: variables
|
|
119
|
-
}, signal);
|
|
120
|
-
if (!resp?.length) {
|
|
121
|
-
return [];
|
|
122
|
-
}
|
|
123
|
-
return resp;
|
|
124
|
-
},
|
|
125
|
-
enabled: !!annotationPlugin || waitToLoad
|
|
77
|
+
/**
|
|
78
|
+
* Resolves one annotation spec using the same cache and fetch policy as {@link useAnnotations}.
|
|
79
|
+
* Used by annotation previews; also exposes loading, error, and refetch state to individual consumers.
|
|
80
|
+
*/ export function useAnnotationData(spec) {
|
|
81
|
+
const { data: plugin } = usePlugin(ANNOTATION_KEY, spec.plugin.kind, {
|
|
82
|
+
version: spec.plugin.metadata?.version,
|
|
83
|
+
registry: spec.plugin.metadata?.registry
|
|
126
84
|
});
|
|
85
|
+
const context = useAnnotationContext();
|
|
86
|
+
return useQuery(getQueryOptions({
|
|
87
|
+
plugin,
|
|
88
|
+
definition: spec,
|
|
89
|
+
context
|
|
90
|
+
}));
|
|
127
91
|
}
|
|
128
92
|
|
|
129
93
|
//# sourceMappingURL=annotations.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/annotations.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 type { AnnotationData, AnnotationSpec } from '@perses-dev/spec';\nimport type {
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/annotations.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 type { AnnotationData, AnnotationSpec } from '@perses-dev/spec';\nimport type { UseQueryOptions, UseQueryResult } from '@tanstack/react-query';\nimport { useQueries, useQuery } from '@tanstack/react-query';\n\nimport type { AnnotationContext, AnnotationPlugin } from '../model';\nimport { useDatasourceStore } from './datasources';\nimport { usePlugin, usePlugins } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { filterVariableStateMap, getVariableValuesKey } from './utils';\nimport { useAllVariableValues } from './variables';\n\nexport const ANNOTATION_KEY = 'Annotation';\n\nfunction useAnnotationContext(): AnnotationContext {\n const { absoluteTimeRange } = useTimeRange();\n const variableState = useAllVariableValues();\n const datasourceStore = useDatasourceStore();\n\n return {\n variableState,\n datasourceStore,\n absoluteTimeRange,\n };\n}\n\nfunction getQueryOptions({\n plugin,\n definition,\n context,\n}: {\n plugin?: AnnotationPlugin;\n definition: AnnotationSpec;\n context: AnnotationContext;\n}): UseQueryOptions<AnnotationData[]> {\n const { variableState, absoluteTimeRange } = context;\n const dependencies = plugin?.dependsOn?.(definition.plugin.spec, context);\n const filteredVariableState = filterVariableStateMap(variableState, dependencies?.variables);\n const variablesValueKey = getVariableValuesKey(filteredVariableState);\n // Only declared variable dependencies delay the query, like other query plugins.\n const waitToLoad = dependencies?.variables?.some((name) => variableState[name]?.loading) ?? false;\n\n return {\n // ['annotation', spec] prefix: refreshed by TimeRangeProvider and invalidated by the annotation editor preview.\n queryKey: ['annotation', definition, absoluteTimeRange, variablesValueKey],\n enabled: plugin !== undefined && !waitToLoad,\n refetchOnMount: false,\n refetchOnWindowFocus: false,\n refetchOnReconnect: false,\n staleTime: Infinity,\n queryFn: async ({ signal }): Promise<AnnotationData[]> => {\n if (plugin === undefined) {\n throw new Error('Expected annotation plugin to be loaded');\n }\n const data = await plugin.getAnnotationData(definition.plugin.spec, context, signal);\n return data;\n },\n };\n}\n\n/**\n * Resolves annotation specs through the shared query cache. Panels requesting the same spec,\n * absolute time range, and variable values share both in-flight requests and cached data with previews.\n */\nexport function useAnnotations(definitions: AnnotationSpec[]): Array<UseQueryResult<AnnotationData[]>> {\n const context = useAnnotationContext();\n\n const pluginLoaderResponse = usePlugins(\n 'Annotation',\n definitions.map((d) => ({\n kind: d.plugin.kind,\n version: d.plugin.metadata?.version,\n registry: d.plugin.metadata?.registry,\n })),\n );\n\n return useQueries({\n queries: definitions.map((definition, index) =>\n getQueryOptions({ context, definition, plugin: pluginLoaderResponse[index]?.data }),\n ),\n });\n}\n\n/**\n * Resolves one annotation spec using the same cache and fetch policy as {@link useAnnotations}.\n * Used by annotation previews; also exposes loading, error, and refetch state to individual consumers.\n */\nexport function useAnnotationData(spec: AnnotationSpec): UseQueryResult<AnnotationData[]> {\n const { data: plugin } = usePlugin(ANNOTATION_KEY, spec.plugin.kind, {\n version: spec.plugin.metadata?.version,\n registry: spec.plugin.metadata?.registry,\n });\n const context = useAnnotationContext();\n\n return useQuery(getQueryOptions({ plugin, definition: spec, context }));\n}\n"],"names":["useQueries","useQuery","useDatasourceStore","usePlugin","usePlugins","useTimeRange","filterVariableStateMap","getVariableValuesKey","useAllVariableValues","ANNOTATION_KEY","useAnnotationContext","absoluteTimeRange","variableState","datasourceStore","getQueryOptions","plugin","definition","context","dependencies","dependsOn","spec","filteredVariableState","variables","variablesValueKey","waitToLoad","some","name","loading","queryKey","enabled","undefined","refetchOnMount","refetchOnWindowFocus","refetchOnReconnect","staleTime","Infinity","queryFn","signal","Error","data","getAnnotationData","useAnnotations","definitions","pluginLoaderResponse","map","d","kind","version","metadata","registry","queries","index","useAnnotationData"],"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,UAAU,EAAEC,QAAQ,QAAQ,wB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,WAC3B,cACAsC,YAAYE,GAAG,CAAC,CAACC,IAAO,CAAA;YACtBC,MAAMD,EAAE9B,MAAM,CAAC+B,IAAI;YACnBC,SAASF,EAAE9B,MAAM,CAACiC,QAAQ,EAAED;YAC5BE,UAAUJ,EAAE9B,MAAM,CAACiC,QAAQ,EAAEC;QAC/B,CAAA;IAGF,OAAOjD,WAAW;QAChBkD,SAASR,YAAYE,GAAG,CAAC,CAAC5B,YAAYmC,QACpCrC,gBAAgB;gBAAEG;gBAASD;gBAAYD,QAAQ4B,oBAAoB,CAACQ,MAAM,EAAEZ;YAAK;IAErF;AACF;AAEA;;;CAGC,GACD,OAAO,SAASa,kBAAkBhC,IAAoB;IACpD,MAAM,EAAEmB,MAAMxB,MAAM,EAAE,GAAGZ,UAAUM,gBAAgBW,KAAKL,MAAM,CAAC+B,IAAI,EAAE;QACnEC,SAAS3B,KAAKL,MAAM,CAACiC,QAAQ,EAAED;QAC/BE,UAAU7B,KAAKL,MAAM,CAACiC,QAAQ,EAAEC;IAClC;IACA,MAAMhC,UAAUP;IAEhB,OAAOT,SAASa,gBAAgB;QAAEC;QAAQC,YAAYI;QAAMH;IAAQ;AACtE"}
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import type { DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';
|
|
2
2
|
import type { UseQueryResult } from '@tanstack/react-query';
|
|
3
3
|
export interface DatasourceStore {
|
|
4
|
+
/**
|
|
5
|
+
* Project whose datasources are listed alongside global ones. Undefined for a global-only scope.
|
|
6
|
+
*/
|
|
7
|
+
project?: string;
|
|
4
8
|
getDatasource(selector: DatasourceSelector): Promise<DatasourceSpec>;
|
|
5
9
|
/**
|
|
6
10
|
* Gets a cached datasource spec synchronously if available.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datasources.d.ts","sourceRoot":"","sources":["../../src/runtime/datasources.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAA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EAAE,oBAAoB,EAAE,CAAC;CAC/B;AAED,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,QAAQ,EAAE,4BAA4B,CAAC;CACxC;AAED;;GAEG;AACH,MAAM,WAAW,4BAA6B,SAAQ,kBAAkB;IACtE;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,eAAO,MAAM,sBAAsB,sDAAwD,CAAC;AAE5F,wBAAgB,kBAAkB,IAAI,eAAe,CAMpD;AAED;;;GAGG;AACH,wBAAgB,4BAA4B,CAC1C,oBAAoB,EAAE,MAAM,EAC5B,OAAO,CAAC,EAAE,MAAM,GACf,cAAc,CAAC,yBAAyB,EAAE,CAAC,CAO7C;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,QAAQ,EAAE,kBAAkB,GAAG,cAAc,CAAC,MAAM,CAAC,CAMhG;AAED,wBAAgB,aAAa,CAAC,QAAQ,EAAE,kBAAkB,GAAG,cAAc,CAAC,cAAc,CAAC,CAM1F"}
|
|
@@ -24,14 +24,15 @@ export function useDatasourceStore() {
|
|
|
24
24
|
* Lists all available Datasource selection items for a given datasource plugin kind.
|
|
25
25
|
* Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)
|
|
26
26
|
*/ export function useListDatasourceSelectItems(datasourcePluginName, project) {
|
|
27
|
-
const
|
|
27
|
+
const store = useDatasourceStore();
|
|
28
|
+
// Results are scoped by the store's project; the explicit parameter only remains as a fallback discriminator.
|
|
28
29
|
return useQuery({
|
|
29
30
|
queryKey: [
|
|
30
31
|
'listDatasourceSelectItems',
|
|
31
32
|
datasourcePluginName,
|
|
32
|
-
project
|
|
33
|
+
store.project ?? project
|
|
33
34
|
],
|
|
34
|
-
queryFn: ()=>listDatasourceSelectItems(datasourcePluginName)
|
|
35
|
+
queryFn: ()=>store.listDatasourceSelectItems(datasourcePluginName)
|
|
35
36
|
});
|
|
36
37
|
}
|
|
37
38
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/datasources.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 type { DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { createContext, useContext } from 'react';\n\nexport interface DatasourceStore {\n // TODO: Do we even need this method?\n getDatasource(selector: DatasourceSelector): Promise<DatasourceSpec>;\n\n /**\n * Gets a cached datasource spec synchronously if available.\n * Used by variable dependency resolution to avoid async calls in dependsOn().\n * Returns undefined if the spec is not cached.\n */\n getDatasourceSpecSync?(selector: DatasourceSelector): DatasourceSpec | undefined;\n\n /**\n * Given a DatasourceSelector, gets a `Client` object from the corresponding Datasource plugin.\n */\n getDatasourceClient<Client>(selector: DatasourceSelector): Promise<Client>;\n\n /**\n * Gets a list of datasource selection items for a plugin kind.\n */\n listDatasourceSelectItems(datasourcePluginName: string): Promise<DatasourceSelectItemGroup[]>;\n\n /**\n * Gets the list of datasources defined in the dashboard\n */\n getLocalDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources defined in the dashboard\n */\n setLocalDatasources(datasources: Record<string, DatasourceSpec>): void;\n\n /**\n * Gets the list of datasources that are available in the dashboard (i.e. dashboards that have been created on the server side that we can use).\n */\n getSavedDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources that are saved in the dashboard\n */\n setSavedDatasources(datasources: Record<string, DatasourceSpec>): void;\n}\n\nexport interface DatasourceSelectItemGroup {\n group?: string;\n editLink?: string;\n items: DatasourceSelectItem[];\n}\n\nexport interface DatasourceSelectItem {\n name: string;\n overridden?: boolean;\n overriding?: boolean;\n saved?: boolean;\n selector: DatasourceSelectItemSelector;\n}\n\n/**\n * Datasource Selector used by the frontend only to differentiate datasources coming from different group.\n */\nexport interface DatasourceSelectItemSelector extends DatasourceSelector {\n /**\n * Group of the datasource.\n * Omit it if you don't store datasource by group.\n */\n group?: string;\n}\n\nexport const DatasourceStoreContext = createContext<DatasourceStore | undefined>(undefined);\n\nexport function useDatasourceStore(): DatasourceStore {\n const ctx = useContext(DatasourceStoreContext);\n if (ctx === undefined) {\n throw new Error('No DatasourceStoreContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Lists all available Datasource selection items for a given datasource plugin kind.\n * Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)\n */\nexport function useListDatasourceSelectItems(\n datasourcePluginName: string,\n project?: string,\n): UseQueryResult<DatasourceSelectItemGroup[]> {\n const
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/datasources.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 type { DatasourceSelector, DatasourceSpec } from '@perses-dev/spec';\nimport type { UseQueryResult } from '@tanstack/react-query';\nimport { useQuery } from '@tanstack/react-query';\nimport { createContext, useContext } from 'react';\n\nexport interface DatasourceStore {\n /**\n * Project whose datasources are listed alongside global ones. Undefined for a global-only scope.\n */\n project?: string;\n\n // TODO: Do we even need this method?\n getDatasource(selector: DatasourceSelector): Promise<DatasourceSpec>;\n\n /**\n * Gets a cached datasource spec synchronously if available.\n * Used by variable dependency resolution to avoid async calls in dependsOn().\n * Returns undefined if the spec is not cached.\n */\n getDatasourceSpecSync?(selector: DatasourceSelector): DatasourceSpec | undefined;\n\n /**\n * Given a DatasourceSelector, gets a `Client` object from the corresponding Datasource plugin.\n */\n getDatasourceClient<Client>(selector: DatasourceSelector): Promise<Client>;\n\n /**\n * Gets a list of datasource selection items for a plugin kind.\n */\n listDatasourceSelectItems(datasourcePluginName: string): Promise<DatasourceSelectItemGroup[]>;\n\n /**\n * Gets the list of datasources defined in the dashboard\n */\n getLocalDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources defined in the dashboard\n */\n setLocalDatasources(datasources: Record<string, DatasourceSpec>): void;\n\n /**\n * Gets the list of datasources that are available in the dashboard (i.e. dashboards that have been created on the server side that we can use).\n */\n getSavedDatasources(): Record<string, DatasourceSpec>;\n\n /**\n * Sets the list of datasources that are saved in the dashboard\n */\n setSavedDatasources(datasources: Record<string, DatasourceSpec>): void;\n}\n\nexport interface DatasourceSelectItemGroup {\n group?: string;\n editLink?: string;\n items: DatasourceSelectItem[];\n}\n\nexport interface DatasourceSelectItem {\n name: string;\n overridden?: boolean;\n overriding?: boolean;\n saved?: boolean;\n selector: DatasourceSelectItemSelector;\n}\n\n/**\n * Datasource Selector used by the frontend only to differentiate datasources coming from different group.\n */\nexport interface DatasourceSelectItemSelector extends DatasourceSelector {\n /**\n * Group of the datasource.\n * Omit it if you don't store datasource by group.\n */\n group?: string;\n}\n\nexport const DatasourceStoreContext = createContext<DatasourceStore | undefined>(undefined);\n\nexport function useDatasourceStore(): DatasourceStore {\n const ctx = useContext(DatasourceStoreContext);\n if (ctx === undefined) {\n throw new Error('No DatasourceStoreContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\n/**\n * Lists all available Datasource selection items for a given datasource plugin kind.\n * Returns a list, with all information that can be used in a datasource selection context (group, name, selector, kind, ...)\n */\nexport function useListDatasourceSelectItems(\n datasourcePluginName: string,\n project?: string,\n): UseQueryResult<DatasourceSelectItemGroup[]> {\n const store = useDatasourceStore();\n // Results are scoped by the store's project; the explicit parameter only remains as a fallback discriminator.\n return useQuery<DatasourceSelectItemGroup[]>({\n queryKey: ['listDatasourceSelectItems', datasourcePluginName, store.project ?? project],\n queryFn: () => store.listDatasourceSelectItems(datasourcePluginName),\n });\n}\n\n/**\n * Provides a convenience hook for getting a DatasourceClient for a given DatasourceSelector.\n */\nexport function useDatasourceClient<Client>(selector: DatasourceSelector): UseQueryResult<Client> {\n const store = useDatasourceStore();\n return useQuery<Client>({\n queryKey: ['getDatasourceClient', selector],\n queryFn: () => store.getDatasourceClient<Client>(selector),\n });\n}\n\nexport function useDatasource(selector: DatasourceSelector): UseQueryResult<DatasourceSpec> {\n const store = useDatasourceStore();\n return useQuery<DatasourceSpec>({\n queryKey: ['getDatasource', selector],\n queryFn: () => store.getDatasource(selector),\n });\n}\n"],"names":["useQuery","createContext","useContext","DatasourceStoreContext","undefined","useDatasourceStore","ctx","Error","useListDatasourceSelectItems","datasourcePluginName","project","store","queryKey","queryFn","listDatasourceSelectItems","useDatasourceClient","selector","getDatasourceClient","useDatasource","getDatasource"],"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,QAAQ,QAAQ,wBAAwB;AACjD,SAASC,aAAa,EAAEC,UAAU,QAAQ,QAAQ;AA0ElD,OAAO,MAAMC,yBAAyBF,cAA2CG,WAAW;AAE5F,OAAO,SAASC;IACd,MAAMC,MAAMJ,WAAWC;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA;;;CAGC,GACD,OAAO,SAASE,6BACdC,oBAA4B,EAC5BC,OAAgB;IAEhB,MAAMC,QAAQN;IACd,8GAA8G;IAC9G,OAAOL,SAAsC;QAC3CY,UAAU;YAAC;YAA6BH;YAAsBE,MAAMD,OAAO,IAAIA;SAAQ;QACvFG,SAAS,IAAMF,MAAMG,yBAAyB,CAACL;IACjD;AACF;AAEA;;CAEC,GACD,OAAO,SAASM,oBAA4BC,QAA4B;IACtE,MAAML,QAAQN;IACd,OAAOL,SAAiB;QACtBY,UAAU;YAAC;YAAuBI;SAAS;QAC3CH,SAAS,IAAMF,MAAMM,mBAAmB,CAASD;IACnD;AACF;AAEA,OAAO,SAASE,cAAcF,QAA4B;IACxD,MAAML,QAAQN;IACd,OAAOL,SAAyB;QAC9BY,UAAU;YAAC;YAAiBI;SAAS;QACrCH,SAAS,IAAMF,MAAMQ,aAAa,CAACH;IACrC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"log-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/log-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,MAAM,MAAM,kBAAkB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AACnG,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC,wBAAgB,aAAa,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"log-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/log-queries.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACrE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG5D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAM3D,MAAM,MAAM,kBAAkB,CAAC,UAAU,GAAG,WAAW,IAAI,eAAe,CAAC,UAAU,EAAE,UAAU,CAAC,CAAC;AACnG,eAAO,MAAM,aAAa,aAAa,CAAC;AAExC,wBAAgB,aAAa,CAAC,WAAW,EAAE,kBAAkB,EAAE,GAAG,KAAK,CAAC,cAAc,CAAC,cAAc,CAAC,CAAC,CAsCtG"}
|
|
@@ -46,7 +46,9 @@ export function useLogQueries(definitions) {
|
|
|
46
46
|
queryFn: async ({ signal })=>{
|
|
47
47
|
const plugin = await getPlugin({
|
|
48
48
|
kind: LOG_QUERY_KEY,
|
|
49
|
-
name: logQueryKind
|
|
49
|
+
name: logQueryKind,
|
|
50
|
+
version: definition.spec.plugin.metadata?.version,
|
|
51
|
+
registry: definition.spec.plugin.metadata?.registry
|
|
50
52
|
});
|
|
51
53
|
const data = await plugin.getLogData(definition.spec.plugin.spec, context, signal);
|
|
52
54
|
return data;
|