@perses-dev/plugin-system 0.52.0-beta.3 → 0.52.0-beta.4
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/cjs/components/DatasourceEditorForm/DatasourceEditorForm.js +1 -0
- package/dist/cjs/components/MultiQueryEditor/QueryEditorContainer.js +1 -0
- package/dist/cjs/components/PluginEditor/PluginEditor.js +27 -4
- package/dist/cjs/components/PluginSpecEditor/PluginSpecEditor.js +13 -9
- package/dist/cjs/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -0
- package/dist/cjs/model/log-queries.js +16 -0
- package/dist/cjs/runtime/DataQueriesProvider/DataQueriesProvider.js +10 -2
- package/dist/cjs/runtime/DataQueriesProvider/model.js +17 -4
- package/dist/cjs/runtime/RouterProvider.js +2 -1
- package/dist/cjs/runtime/log-queries.js +68 -0
- package/dist/cjs/runtime/variables.js +15 -0
- package/dist/cjs/test/mock-data.js +24 -0
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.d.ts.map +1 -1
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js +1 -0
- package/dist/components/DatasourceEditorForm/DatasourceEditorForm.js.map +1 -1
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js +1 -0
- package/dist/components/MultiQueryEditor/QueryEditorContainer.js.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.d.ts.map +1 -1
- package/dist/components/PluginEditor/PluginEditor.js +27 -4
- package/dist/components/PluginEditor/PluginEditor.js.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.d.ts +1 -0
- package/dist/components/PluginEditor/plugin-editor-api.d.ts.map +1 -1
- package/dist/components/PluginEditor/plugin-editor-api.js.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.d.ts.map +1 -1
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js +13 -9
- package/dist/components/PluginSpecEditor/PluginSpecEditor.js.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.d.ts.map +1 -1
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js +1 -0
- package/dist/components/Variables/VariableEditorForm/VariableEditorForm.js.map +1 -1
- package/dist/model/log-queries.d.ts +24 -0
- package/dist/model/log-queries.d.ts.map +1 -0
- package/dist/model/log-queries.js +15 -0
- package/dist/model/log-queries.js.map +1 -0
- package/dist/model/plugin-base.d.ts +4 -0
- package/dist/model/plugin-base.d.ts.map +1 -1
- package/dist/model/plugin-base.js.map +1 -1
- package/dist/model/plugins.d.ts +2 -0
- package/dist/model/plugins.d.ts.map +1 -1
- package/dist/model/plugins.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js +10 -2
- package/dist/runtime/DataQueriesProvider/DataQueriesProvider.js.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.d.ts.map +1 -1
- package/dist/runtime/DataQueriesProvider/model.js +17 -4
- package/dist/runtime/DataQueriesProvider/model.js.map +1 -1
- package/dist/runtime/RouterProvider.d.ts +2 -2
- package/dist/runtime/RouterProvider.d.ts.map +1 -1
- package/dist/runtime/RouterProvider.js +2 -1
- package/dist/runtime/RouterProvider.js.map +1 -1
- package/dist/runtime/log-queries.d.ts +7 -0
- package/dist/runtime/log-queries.d.ts.map +1 -0
- package/dist/runtime/log-queries.js +52 -0
- package/dist/runtime/log-queries.js.map +1 -0
- package/dist/runtime/variables.d.ts +1 -0
- package/dist/runtime/variables.d.ts.map +1 -1
- package/dist/runtime/variables.js +13 -0
- package/dist/runtime/variables.js.map +1 -1
- package/dist/test/mock-data.d.ts +2 -1
- package/dist/test/mock-data.d.ts.map +1 -1
- package/dist/test/mock-data.js +21 -0
- package/dist/test/mock-data.js.map +1 -1
- package/package.json +3 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, ReactElement, useCallback, useContext, useMemo } from 'react';\nimport { QueryType, TimeSeriesQueryDefinition } from '@perses-dev/core';\nimport { useTimeSeriesQueries } from '../time-series-queries';\nimport { useTraceQueries, TraceQueryDefinition } from '../trace-queries';\nimport { useProfileQueries, ProfileQueryDefinition } from '../profile-queries';\n\nimport { useUsageMetrics } from '../UsageMetricsProvider';\nimport {\n DataQueriesProviderProps,\n UseDataQueryResults,\n transformQueryResults,\n DataQueriesContextType,\n QueryData,\n useQueryType,\n} from './model';\n\nexport const DataQueriesContext = createContext<DataQueriesContextType | undefined>(undefined);\n\nexport function useDataQueriesContext(): DataQueriesContextType {\n const ctx = useContext(DataQueriesContext);\n if (ctx === undefined) {\n throw new Error('No DataQueriesContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useDataQueries<T extends keyof QueryType>(queryType: T): UseDataQueryResults<QueryType[T]> {\n const ctx = useDataQueriesContext();\n\n // Filter the query results based on the specified query type\n const filteredQueryResults = ctx.queryResults.filter(\n (queryResult) => queryResult?.definition?.kind === queryType\n ) as Array<QueryData<QueryType[T]>>;\n\n // Filter the errors based on the specified query type\n const filteredErrors = ctx.errors.filter((errors, index) => ctx.queryResults[index]?.definition?.kind === queryType);\n\n // Create a new context object with the filtered results and errors\n const filteredCtx = {\n queryResults: filteredQueryResults,\n isFetching: filteredQueryResults.some((result) => result.isFetching),\n isLoading: filteredQueryResults.some((result) => result.isLoading),\n refetchAll: ctx.refetchAll,\n errors: filteredErrors,\n };\n\n return filteredCtx;\n}\n\nexport function DataQueriesProvider(props: DataQueriesProviderProps): ReactElement {\n const { definitions, options, children, queryOptions } = props;\n\n // Returns a query kind, for example \"TimeSeriesQuery\" = getQueryType(\"PrometheusTimeSeriesQuery\")\n const getQueryType = useQueryType();\n\n const queryDefinitions = definitions.map((definition) => {\n const type = getQueryType(definition.kind);\n return {\n kind: type,\n spec: {\n plugin: definition,\n },\n };\n });\n\n const usageMetrics = useUsageMetrics();\n\n // Filter definitions for time series query and other future query plugins\n const timeSeriesQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'TimeSeriesQuery'\n ) as TimeSeriesQueryDefinition[];\n const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options, queryOptions);\n const traceQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'TraceQuery'\n ) as TraceQueryDefinition[];\n const traceResults = useTraceQueries(traceQueries);\n const profileQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'ProfileQuery'\n ) as ProfileQueryDefinition[];\n const profileResults = useProfileQueries(profileQueries);\n\n const refetchAll = useCallback(() => {\n timeSeriesResults.forEach((result) => result.refetch());\n traceResults.forEach((result) => result.refetch());\n profileResults.forEach((result) => result.refetch());\n }, [timeSeriesResults, traceResults, profileResults]);\n\n const ctx = useMemo(() => {\n const mergedQueryResults = [\n ...transformQueryResults(timeSeriesResults, timeSeriesQueries),\n ...transformQueryResults(traceResults, traceQueries),\n ...transformQueryResults(profileResults, profileQueries),\n ];\n\n if (queryOptions?.enabled) {\n for (const result of mergedQueryResults) {\n if (!result.isLoading && !result.isFetching && !result.error) {\n usageMetrics.markQuery(result.definition, 'success');\n } else if (result.error) {\n usageMetrics.markQuery(result.definition, 'error');\n } else {\n usageMetrics.markQuery(result.definition, 'pending');\n }\n }\n }\n\n return {\n queryResults: mergedQueryResults,\n isFetching: mergedQueryResults.some((result) => result.isFetching),\n isLoading: mergedQueryResults.some((result) => result.isLoading),\n refetchAll,\n errors: mergedQueryResults.map((result) => result.error),\n };\n }, [\n timeSeriesQueries,\n timeSeriesResults,\n traceQueries,\n traceResults,\n profileQueries,\n profileResults,\n refetchAll,\n queryOptions?.enabled,\n usageMetrics,\n ]);\n\n return <DataQueriesContext.Provider value={ctx}>{children}</DataQueriesContext.Provider>;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useTimeSeriesQueries","useTraceQueries","useProfileQueries","useUsageMetrics","transformQueryResults","useQueryType","DataQueriesContext","undefined","useDataQueriesContext","ctx","Error","useDataQueries","queryType","filteredQueryResults","queryResults","filter","queryResult","definition","kind","filteredErrors","errors","index","filteredCtx","isFetching","some","result","isLoading","refetchAll","DataQueriesProvider","props","definitions","options","children","queryOptions","getQueryType","queryDefinitions","map","type","spec","plugin","usageMetrics","timeSeriesQueries","timeSeriesResults","traceQueries","traceResults","profileQueries","profileResults","forEach","refetch","mergedQueryResults","enabled","error","markQuery","Provider","value"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,aAAa,EAAgBC,WAAW,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAEtF,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,eAAe,QAA8B,mBAAmB;AACzE,SAASC,iBAAiB,QAAgC,qBAAqB;AAE/E,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAGEC,qBAAqB,EAGrBC,YAAY,QACP,UAAU;AAEjB,OAAO,MAAMC,
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/DataQueriesProvider.tsx"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, ReactElement, useCallback, useContext, useMemo } from 'react';\nimport { QueryType, TimeSeriesQueryDefinition } from '@perses-dev/core';\nimport { useTimeSeriesQueries } from '../time-series-queries';\nimport { useTraceQueries, TraceQueryDefinition } from '../trace-queries';\nimport { useProfileQueries, ProfileQueryDefinition } from '../profile-queries';\n\nimport { useUsageMetrics } from '../UsageMetricsProvider';\nimport { LogQueryDefinition, useLogQueries } from '../log-queries';\nimport {\n DataQueriesProviderProps,\n UseDataQueryResults,\n transformQueryResults,\n DataQueriesContextType,\n QueryData,\n useQueryType,\n} from './model';\n\nexport const DataQueriesContext = createContext<DataQueriesContextType | undefined>(undefined);\n\nexport function useDataQueriesContext(): DataQueriesContextType {\n const ctx = useContext(DataQueriesContext);\n if (ctx === undefined) {\n throw new Error('No DataQueriesContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useDataQueries<T extends keyof QueryType>(queryType: T): UseDataQueryResults<QueryType[T]> {\n const ctx = useDataQueriesContext();\n\n // Filter the query results based on the specified query type\n const filteredQueryResults = ctx.queryResults.filter(\n (queryResult) => queryResult?.definition?.kind === queryType\n ) as Array<QueryData<QueryType[T]>>;\n\n // Filter the errors based on the specified query type\n const filteredErrors = ctx.errors.filter((errors, index) => ctx.queryResults[index]?.definition?.kind === queryType);\n\n // Create a new context object with the filtered results and errors\n const filteredCtx = {\n queryResults: filteredQueryResults,\n isFetching: filteredQueryResults.some((result) => result.isFetching),\n isLoading: filteredQueryResults.some((result) => result.isLoading),\n refetchAll: ctx.refetchAll,\n errors: filteredErrors,\n };\n\n return filteredCtx;\n}\n\nexport function DataQueriesProvider(props: DataQueriesProviderProps): ReactElement {\n const { definitions, options, children, queryOptions } = props;\n\n // Returns a query kind, for example \"TimeSeriesQuery\" = getQueryType(\"PrometheusTimeSeriesQuery\")\n const getQueryType = useQueryType();\n\n const queryDefinitions = definitions.map((definition) => {\n const type = getQueryType(definition.kind);\n return {\n kind: type,\n spec: {\n plugin: definition,\n },\n };\n });\n\n const usageMetrics = useUsageMetrics();\n\n // Filter definitions for time series query and other future query plugins\n const timeSeriesQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'TimeSeriesQuery'\n ) as TimeSeriesQueryDefinition[];\n const timeSeriesResults = useTimeSeriesQueries(timeSeriesQueries, options, queryOptions);\n\n const traceQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'TraceQuery'\n ) as TraceQueryDefinition[];\n const traceResults = useTraceQueries(traceQueries);\n\n const profileQueries = queryDefinitions.filter(\n (definition) => definition.kind === 'ProfileQuery'\n ) as ProfileQueryDefinition[];\n const profileResults = useProfileQueries(profileQueries);\n\n const logQueries = queryDefinitions.filter((definition) => definition.kind === 'LogQuery') as LogQueryDefinition[];\n const logResults = useLogQueries(logQueries);\n\n const refetchAll = useCallback(() => {\n timeSeriesResults.forEach((result) => result.refetch());\n traceResults.forEach((result) => result.refetch());\n profileResults.forEach((result) => result.refetch());\n logResults.forEach((result) => result.refetch());\n }, [timeSeriesResults, traceResults, profileResults, logResults]);\n\n const ctx = useMemo(() => {\n const mergedQueryResults = [\n ...transformQueryResults(timeSeriesResults, timeSeriesQueries),\n ...transformQueryResults(traceResults, traceQueries),\n ...transformQueryResults(profileResults, profileQueries),\n ...transformQueryResults(logResults, logQueries),\n ];\n\n if (queryOptions?.enabled) {\n for (const result of mergedQueryResults) {\n if (!result.isLoading && !result.isFetching && !result.error) {\n usageMetrics.markQuery(result.definition, 'success');\n } else if (result.error) {\n usageMetrics.markQuery(result.definition, 'error');\n } else {\n usageMetrics.markQuery(result.definition, 'pending');\n }\n }\n }\n\n return {\n queryResults: mergedQueryResults,\n isFetching: mergedQueryResults.some((result) => result.isFetching),\n isLoading: mergedQueryResults.some((result) => result.isLoading),\n refetchAll,\n errors: mergedQueryResults.map((result) => result.error),\n };\n }, [\n timeSeriesQueries,\n timeSeriesResults,\n traceQueries,\n traceResults,\n profileQueries,\n profileResults,\n logQueries,\n logResults,\n refetchAll,\n queryOptions?.enabled,\n usageMetrics,\n ]);\n\n return <DataQueriesContext.Provider value={ctx}>{children}</DataQueriesContext.Provider>;\n}\n"],"names":["createContext","useCallback","useContext","useMemo","useTimeSeriesQueries","useTraceQueries","useProfileQueries","useUsageMetrics","useLogQueries","transformQueryResults","useQueryType","DataQueriesContext","undefined","useDataQueriesContext","ctx","Error","useDataQueries","queryType","filteredQueryResults","queryResults","filter","queryResult","definition","kind","filteredErrors","errors","index","filteredCtx","isFetching","some","result","isLoading","refetchAll","DataQueriesProvider","props","definitions","options","children","queryOptions","getQueryType","queryDefinitions","map","type","spec","plugin","usageMetrics","timeSeriesQueries","timeSeriesResults","traceQueries","traceResults","profileQueries","profileResults","logQueries","logResults","forEach","refetch","mergedQueryResults","enabled","error","markQuery","Provider","value"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,aAAa,EAAgBC,WAAW,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAEtF,SAASC,oBAAoB,QAAQ,yBAAyB;AAC9D,SAASC,eAAe,QAA8B,mBAAmB;AACzE,SAASC,iBAAiB,QAAgC,qBAAqB;AAE/E,SAASC,eAAe,QAAQ,0BAA0B;AAC1D,SAA6BC,aAAa,QAAQ,iBAAiB;AACnE,SAGEC,qBAAqB,EAGrBC,YAAY,QACP,UAAU;AAEjB,OAAO,MAAMC,mCAAqBX,cAAkDY,WAAW;AAE/F,OAAO,SAASC;IACd,MAAMC,MAAMZ,WAAWS;IACvB,IAAIG,QAAQF,WAAW;QACrB,MAAM,IAAIG,MAAM;IAClB;IACA,OAAOD;AACT;AAEA,OAAO,SAASE,eAA0CC,S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,SAAQ,IAAI,CAAC,sBAAsB,EAAE,cAAc,CAAC;IAC1F,YAAY,EAAE,KAAK,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;CACnC;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,GAAG,aAAa,IAAI;IACzC,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,UAAU,EAAE,eAAe,CAAC;IAC5B,KAAK,EAAE,OAAO,CAAC;IACf,UAAU,EAAE,OAAO,CAAC;IACpB,SAAS,EAAE,OAAO,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAEF,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,cAAc,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,GAAG,SAAS,EAAE,CAW5G;AAED,wBAAgB,YAAY,IAAI,CAAC,UAAU,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAwFzE"}
|
|
@@ -34,12 +34,16 @@ export function useQueryType() {
|
|
|
34
34
|
const { data: profileQueryPlugins, isLoading: isProfileQueryPluginLoading } = useListPluginMetadata([
|
|
35
35
|
'ProfileQuery'
|
|
36
36
|
]);
|
|
37
|
+
const { data: logQueries, isLoading: isLogQueryPluginLoading } = useListPluginMetadata([
|
|
38
|
+
'LogQuery'
|
|
39
|
+
]);
|
|
37
40
|
// For example, `map: {"TimeSeriesQuery":["PrometheusTimeSeriesQuery"],"TraceQuery":["TempoTraceQuery"]}`
|
|
38
41
|
const queryTypeMap = useMemo(()=>{
|
|
39
42
|
const map = {
|
|
40
43
|
TimeSeriesQuery: [],
|
|
41
44
|
TraceQuery: [],
|
|
42
|
-
ProfileQuery: []
|
|
45
|
+
ProfileQuery: [],
|
|
46
|
+
LogQuery: []
|
|
43
47
|
};
|
|
44
48
|
if (timeSeriesQueryPlugins) {
|
|
45
49
|
timeSeriesQueryPlugins.forEach((plugin)=>{
|
|
@@ -56,11 +60,17 @@ export function useQueryType() {
|
|
|
56
60
|
map[plugin.kind]?.push(plugin.spec.name);
|
|
57
61
|
});
|
|
58
62
|
}
|
|
63
|
+
if (logQueries) {
|
|
64
|
+
logQueries.forEach((plugin)=>{
|
|
65
|
+
map[plugin.kind]?.push(plugin.spec.name);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
59
68
|
return map;
|
|
60
69
|
}, [
|
|
61
70
|
timeSeriesQueryPlugins,
|
|
62
71
|
traceQueryPlugins,
|
|
63
|
-
profileQueryPlugins
|
|
72
|
+
profileQueryPlugins,
|
|
73
|
+
logQueries
|
|
64
74
|
]);
|
|
65
75
|
const getQueryType = useCallback((pluginKind)=>{
|
|
66
76
|
const isLoading = (pluginKind)=>{
|
|
@@ -71,8 +81,10 @@ export function useQueryType() {
|
|
|
71
81
|
return isTraceQueryPluginLoading;
|
|
72
82
|
case 'PyroscopeProfileQuery':
|
|
73
83
|
return isProfileQueryPluginLoading;
|
|
84
|
+
case 'LokiLogQuery':
|
|
85
|
+
return isLogQueryPluginLoading;
|
|
74
86
|
}
|
|
75
|
-
return isTraceQueryPluginLoading || isTimeSeriesQueryLoading || isProfileQueryPluginLoading;
|
|
87
|
+
return isTraceQueryPluginLoading || isTimeSeriesQueryLoading || isProfileQueryPluginLoading || isLogQueryPluginLoading;
|
|
76
88
|
};
|
|
77
89
|
if (isLoading(pluginKind)) {
|
|
78
90
|
return undefined;
|
|
@@ -87,7 +99,8 @@ export function useQueryType() {
|
|
|
87
99
|
queryTypeMap,
|
|
88
100
|
isTimeSeriesQueryLoading,
|
|
89
101
|
isTraceQueryPluginLoading,
|
|
90
|
-
isProfileQueryPluginLoading
|
|
102
|
+
isProfileQueryPluginLoading,
|
|
103
|
+
isLogQueryPluginLoading
|
|
91
104
|
]);
|
|
92
105
|
return getQueryType;
|
|
93
106
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/core';\nimport { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { ReactNode, useCallback, useMemo } from 'react';\nimport { useListPluginMetadata } from '../plugin-registry';\n\nexport type QueryOptions = Record<string, unknown>;\nexport interface DataQueriesProviderProps<QueryPluginSpec = UnknownSpec> {\n definitions: Array<Definition<QueryPluginSpec>>;\n children?: ReactNode;\n options?: QueryOptions;\n queryOptions?: Omit<QueryObserverOptions, 'queryKey'>;\n}\n\nexport interface DataQueriesContextType {\n queryResults: QueryData[];\n refetchAll: () => void;\n isFetching: boolean;\n isLoading: boolean;\n errors: unknown[];\n}\n\nexport interface UseDataQueryResults<T> extends Omit<DataQueriesContextType, 'queryResults'> {\n queryResults: Array<QueryData<T>>;\n}\n\nexport type QueryData<T = QueryDataType> = {\n data?: T;\n definition: QueryDefinition;\n error: unknown;\n isFetching: boolean;\n isLoading: boolean;\n refetch?: () => void;\n};\n\nexport function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]): QueryData[] {\n return results.map(({ data, isFetching, isLoading, refetch, error }, i) => {\n return {\n definition: definitions[i],\n data,\n isFetching,\n isLoading,\n refetch,\n error,\n } as QueryData;\n });\n}\n\nexport function useQueryType(): (pluginKind: string) => string | undefined {\n const { data: timeSeriesQueryPlugins, isLoading: isTimeSeriesQueryLoading } = useListPluginMetadata([\n 'TimeSeriesQuery',\n ]);\n const { data: traceQueryPlugins, isLoading: isTraceQueryPluginLoading } = useListPluginMetadata(['TraceQuery']);\n const { data: profileQueryPlugins, isLoading: isProfileQueryPluginLoading } = useListPluginMetadata(['ProfileQuery']);\n\n // For example, `map: {\"TimeSeriesQuery\":[\"PrometheusTimeSeriesQuery\"],\"TraceQuery\":[\"TempoTraceQuery\"]}`\n const queryTypeMap = useMemo(() => {\n const map: Record<string, string[]> = {\n TimeSeriesQuery: [],\n TraceQuery: [],\n ProfileQuery: [],\n };\n\n if (timeSeriesQueryPlugins) {\n timeSeriesQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n if (traceQueryPlugins) {\n traceQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n if (profileQueryPlugins) {\n profileQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n return map;\n }, [timeSeriesQueryPlugins, traceQueryPlugins, profileQueryPlugins]);\n\n const getQueryType = useCallback(\n (pluginKind: string) => {\n const isLoading = (pluginKind: string): boolean => {\n switch (pluginKind) {\n case 'PrometheusTimeSeriesQuery':\n return isTimeSeriesQueryLoading;\n case 'TempoTraceQuery':\n return isTraceQueryPluginLoading;\n case 'PyroscopeProfileQuery':\n return isProfileQueryPluginLoading;\n }\n\n return isTraceQueryPluginLoading
|
|
1
|
+
{"version":3,"sources":["../../../src/runtime/DataQueriesProvider/model.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Definition, QueryDefinition, UnknownSpec, QueryDataType } from '@perses-dev/core';\nimport { QueryObserverOptions, UseQueryResult } from '@tanstack/react-query';\nimport { ReactNode, useCallback, useMemo } from 'react';\nimport { useListPluginMetadata } from '../plugin-registry';\n\nexport type QueryOptions = Record<string, unknown>;\nexport interface DataQueriesProviderProps<QueryPluginSpec = UnknownSpec> {\n definitions: Array<Definition<QueryPluginSpec>>;\n children?: ReactNode;\n options?: QueryOptions;\n queryOptions?: Omit<QueryObserverOptions, 'queryKey'>;\n}\n\nexport interface DataQueriesContextType {\n queryResults: QueryData[];\n refetchAll: () => void;\n isFetching: boolean;\n isLoading: boolean;\n errors: unknown[];\n}\n\nexport interface UseDataQueryResults<T> extends Omit<DataQueriesContextType, 'queryResults'> {\n queryResults: Array<QueryData<T>>;\n}\n\nexport type QueryData<T = QueryDataType> = {\n data?: T;\n definition: QueryDefinition;\n error: unknown;\n isFetching: boolean;\n isLoading: boolean;\n refetch?: () => void;\n};\n\nexport function transformQueryResults(results: UseQueryResult[], definitions: QueryDefinition[]): QueryData[] {\n return results.map(({ data, isFetching, isLoading, refetch, error }, i) => {\n return {\n definition: definitions[i],\n data,\n isFetching,\n isLoading,\n refetch,\n error,\n } as QueryData;\n });\n}\n\nexport function useQueryType(): (pluginKind: string) => string | undefined {\n const { data: timeSeriesQueryPlugins, isLoading: isTimeSeriesQueryLoading } = useListPluginMetadata([\n 'TimeSeriesQuery',\n ]);\n const { data: traceQueryPlugins, isLoading: isTraceQueryPluginLoading } = useListPluginMetadata(['TraceQuery']);\n const { data: profileQueryPlugins, isLoading: isProfileQueryPluginLoading } = useListPluginMetadata(['ProfileQuery']);\n const { data: logQueries, isLoading: isLogQueryPluginLoading } = useListPluginMetadata(['LogQuery']);\n\n // For example, `map: {\"TimeSeriesQuery\":[\"PrometheusTimeSeriesQuery\"],\"TraceQuery\":[\"TempoTraceQuery\"]}`\n const queryTypeMap = useMemo(() => {\n const map: Record<string, string[]> = {\n TimeSeriesQuery: [],\n TraceQuery: [],\n ProfileQuery: [],\n LogQuery: [],\n };\n\n if (timeSeriesQueryPlugins) {\n timeSeriesQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n if (traceQueryPlugins) {\n traceQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n if (profileQueryPlugins) {\n profileQueryPlugins.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n if (logQueries) {\n logQueries.forEach((plugin) => {\n map[plugin.kind]?.push(plugin.spec.name);\n });\n }\n\n return map;\n }, [timeSeriesQueryPlugins, traceQueryPlugins, profileQueryPlugins, logQueries]);\n\n const getQueryType = useCallback(\n (pluginKind: string) => {\n const isLoading = (pluginKind: string): boolean => {\n switch (pluginKind) {\n case 'PrometheusTimeSeriesQuery':\n return isTimeSeriesQueryLoading;\n case 'TempoTraceQuery':\n return isTraceQueryPluginLoading;\n case 'PyroscopeProfileQuery':\n return isProfileQueryPluginLoading;\n case 'LokiLogQuery':\n return isLogQueryPluginLoading;\n }\n\n return (\n isTraceQueryPluginLoading ||\n isTimeSeriesQueryLoading ||\n isProfileQueryPluginLoading ||\n isLogQueryPluginLoading\n );\n };\n\n if (isLoading(pluginKind)) {\n return undefined;\n }\n\n for (const queryType in queryTypeMap) {\n if (queryTypeMap[queryType]?.includes(pluginKind)) {\n return queryType;\n }\n }\n\n throw new Error(`Unable to determine the query type: ${pluginKind}`);\n },\n [\n queryTypeMap,\n isTimeSeriesQueryLoading,\n isTraceQueryPluginLoading,\n isProfileQueryPluginLoading,\n isLogQueryPluginLoading,\n ]\n );\n\n return getQueryType;\n}\n"],"names":["useCallback","useMemo","useListPluginMetadata","transformQueryResults","results","definitions","map","data","isFetching","isLoading","refetch","error","i","definition","useQueryType","timeSeriesQueryPlugins","isTimeSeriesQueryLoading","traceQueryPlugins","isTraceQueryPluginLoading","profileQueryPlugins","isProfileQueryPluginLoading","logQueries","isLogQueryPluginLoading","queryTypeMap","TimeSeriesQuery","TraceQuery","ProfileQuery","LogQuery","forEach","plugin","kind","push","spec","name","getQueryType","pluginKind","undefined","queryType","includes","Error"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AA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ACzBvB,GAAG,CAACuB,OAAOC,IAAI,CAAC,EAAEC,KAAKF,OAAOG,IAAI,CAACC,IAAI;YACzC;QACF;QAEA,IAAId,qBAAqB;YACvBA,oBAAoBS,OAAO,CAAC,CAACC;gBAC3BvB,GAAG,CAACuB,OAAOC,IAAI,CAAC,EAAEC,KAAKF,OAAOG,IAAI,CAACC,IAAI;YACzC;QACF;QAEA,IAAIZ,YAAY;YACdA,WAAWO,OAAO,CAAC,CAACC;gBAClBvB,GAAG,CAACuB,OAAOC,IAAI,CAAC,EAAEC,KAAKF,OAAOG,IAAI,CAACC,IAAI;YACzC;QACF;QAEA,OAAO3B;IACT,GAAG;QAACS;QAAwBE;QAAmBE;QAAqBE;KAAW;IAE/E,MAAMa,eAAelC,YACnB,CAACmC;QACC,MAAM1B,YAAY,CAAC0B;YACjB,OAAQA;gBACN,KAAK;oBACH,OAAOnB;gBACT,KAAK;oBACH,OAAOE;gBACT,KAAK;oBACH,OAAOE;gBACT,KAAK;oBACH,OAAOE;YACX;YAEA,OACEJ,6BACAF,4BACAI,+BACAE;QAEJ;QAEA,IAAIb,UAAU0B,aAAa;YACzB,OAAOC;QACT;QAEA,IAAK,MAAMC,aAAad,aAAc;YACpC,IAAIA,YAAY,CAACc,UAAU,EAAEC,SAASH,aAAa;gBACjD,OAAOE;YACT;QACF;QAEA,MAAM,IAAIE,MAAM,CAAC,oCAAoC,EAAEJ,YAAY;IACrE,GACA;QACEZ;QACAP;QACAE;QACAE;QACAE;KACD;IAGH,OAAOY;AACT"}
|
|
@@ -3,8 +3,8 @@ interface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
|
|
|
3
3
|
to: string;
|
|
4
4
|
}
|
|
5
5
|
export interface RouterContextType {
|
|
6
|
-
RouterComponent
|
|
7
|
-
navigate
|
|
6
|
+
RouterComponent?: (props: LinkProps & React.RefAttributes<HTMLAnchorElement>) => ReactNode;
|
|
7
|
+
navigate?: (to: string) => void;
|
|
8
8
|
}
|
|
9
9
|
export declare const RouterContext: React.Context<RouterContextType | undefined>;
|
|
10
10
|
export declare function useRouterContext(): RouterContextType;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RouterProvider.d.ts","sourceRoot":"","sources":["../../src/runtime/RouterProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,EAA6B,SAAS,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAG3F,UAAU,SAAU,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC;IACvE,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,iBAAiB;IAChC,eAAe,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC,KAAK,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"RouterProvider.d.ts","sourceRoot":"","sources":["../../src/runtime/RouterProvider.tsx"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,EAA6B,SAAS,EAAE,YAAY,EAAW,MAAM,OAAO,CAAC;AAG3F,UAAU,SAAU,SAAQ,KAAK,CAAC,oBAAoB,CAAC,iBAAiB,CAAC;IACvE,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,MAAM,WAAW,iBAAiB;IAChC,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,SAAS,GAAG,KAAK,CAAC,aAAa,CAAC,iBAAiB,CAAC,KAAK,SAAS,CAAC;IAC3F,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CACjC;AAED,eAAO,MAAM,aAAa,8CAA0D,CAAC;AAErF,wBAAgB,gBAAgB,IAAI,iBAAiB,CAOpD;AAED,UAAU,mBAAmB;IAC3B,eAAe,EAAE,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IACtD,QAAQ,EAAE,iBAAiB,CAAC,UAAU,CAAC,CAAC;IACxC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,mBAAmB,GAAG,YAAY,CAQvE;AAED,UAAU,wBAAwB;IAChC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B;AAED,kGAAkG;AAClG,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,wBAAwB,GAAG,YAAY,CASjF"}
|
|
@@ -17,7 +17,8 @@ export const RouterContext = /*#__PURE__*/ createContext(undefined);
|
|
|
17
17
|
export function useRouterContext() {
|
|
18
18
|
const ctx = useContext(RouterContext);
|
|
19
19
|
if (ctx === undefined) {
|
|
20
|
-
|
|
20
|
+
console.warn('No RouterContext found. Did you forget a <RouterProvider>?');
|
|
21
|
+
return {};
|
|
21
22
|
}
|
|
22
23
|
return ctx;
|
|
23
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/RouterProvider.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { createContext, useContext, ReactNode, ReactElement, useMemo } from 'react';\nimport { Link as RouterLink, useNavigate } from 'react-router-dom';\n\ninterface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\n to: string;\n}\n\nexport interface RouterContextType {\n RouterComponent
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/RouterProvider.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport React, { createContext, useContext, ReactNode, ReactElement, useMemo } from 'react';\nimport { Link as RouterLink, useNavigate } from 'react-router-dom';\n\ninterface LinkProps extends React.AnchorHTMLAttributes<HTMLAnchorElement> {\n to: string;\n}\n\nexport interface RouterContextType {\n RouterComponent?: (props: LinkProps & React.RefAttributes<HTMLAnchorElement>) => ReactNode;\n navigate?: (to: string) => void;\n}\n\nexport const RouterContext = createContext<RouterContextType | undefined>(undefined);\n\nexport function useRouterContext(): RouterContextType {\n const ctx = useContext(RouterContext);\n if (ctx === undefined) {\n console.warn('No RouterContext found. Did you forget a <RouterProvider>?');\n return {};\n }\n return ctx;\n}\n\ninterface RouterProviderProps {\n RouterComponent: RouterContextType['RouterComponent'];\n navigate: RouterContextType['navigate'];\n children?: React.ReactNode;\n}\n\n/**\n * Some panel plugins (TraceTable, ScatterPlot, TracingGanttChart) support linking to other pages,\n * e.g. clicking on a trace in the TraceTable should navigate to the TracingGanttChart.\n *\n * We can't use react-router in the panel, because panels might be embedded into React applications\n * which use a different routing library, or a different major version of react-router.\n *\n * This provider abstracts the basic routing functionality, to remove the dependency on the exact version of react-router.\n */\nexport function RouterProvider(props: RouterProviderProps): ReactElement {\n const { RouterComponent, navigate, children } = props;\n\n const ctx = useMemo(() => {\n return { RouterComponent, navigate };\n }, [RouterComponent, navigate]);\n\n return <RouterContext.Provider value={ctx}>{children}</RouterContext.Provider>;\n}\n\ninterface ReactRouterProviderProps {\n children?: React.ReactNode;\n}\n\n/** An implementation of RouterProvider for using the react-router library, shipped with Perses */\nexport function ReactRouterProvider(props: ReactRouterProviderProps): ReactElement {\n const { children } = props;\n const navigate = useNavigate();\n\n return (\n <RouterProvider RouterComponent={RouterLink} navigate={navigate}>\n {children}\n </RouterProvider>\n );\n}\n"],"names":["React","createContext","useContext","useMemo","Link","RouterLink","useNavigate","RouterContext","undefined","useRouterContext","ctx","console","warn","RouterProvider","props","RouterComponent","navigate","children","Provider","value","ReactRouterProvider"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,OAAOA,SAASC,aAAa,EAAEC,UAAU,EAA2BC,OAAO,QAAQ,QAAQ;AAC3F,SAASC,QAAQC,UAAU,EAAEC,WAAW,QAAQ,mBAAmB;AAWnE,OAAO,MAAMC,8BAAgBN,cAA6CO,WAAW;AAErF,OAAO,SAASC;IACd,MAAMC,MAAMR,WAAWK;IACvB,IAAIG,QAAQF,WAAW;QACrBG,QAAQC,IAAI,CAAC;QACb,OAAO,CAAC;IACV;IACA,OAAOF;AACT;AAQA;;;;;;;;CAQC,GACD,OAAO,SAASG,eAAeC,KAA0B;IACvD,MAAM,EAAEC,eAAe,EAAEC,QAAQ,EAAEC,QAAQ,EAAE,GAAGH;IAEhD,MAAMJ,MAAMP,QAAQ;QAClB,OAAO;YAAEY;YAAiBC;QAAS;IACrC,GAAG;QAACD;QAAiBC;KAAS;IAE9B,qBAAO,KAACT,cAAcW,QAAQ;QAACC,OAAOT;kBAAMO;;AAC9C;AAMA,gGAAgG,GAChG,OAAO,SAASG,oBAAoBN,KAA+B;IACjE,MAAM,EAAEG,QAAQ,EAAE,GAAGH;IACrB,MAAME,WAAWV;IAEjB,qBACE,KAACO;QAAeE,iBAAiBV;QAAYW,UAAUA;kBACpDC;;AAGP"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { QueryDefinition, UnknownSpec } from '@perses-dev/core';
|
|
2
|
+
import { UseQueryResult } from '@tanstack/react-query';
|
|
3
|
+
import { LogQueryResult } from '../model/log-queries';
|
|
4
|
+
export type LogQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'LogQuery', PluginSpec>;
|
|
5
|
+
export declare const LOG_QUERY_KEY = "LogQuery";
|
|
6
|
+
export declare function useLogQueries(definitions: LogQueryDefinition[]): Array<UseQueryResult<LogQueryResult>>;
|
|
7
|
+
//# sourceMappingURL=log-queries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log-queries.d.ts","sourceRoot":"","sources":["../../src/runtime/log-queries.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAChE,OAAO,EAAc,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAMtD,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,CA6BtG"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright 2025 The Perses Authors
|
|
2
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
|
+
// you may not use this file except in compliance with the License.
|
|
4
|
+
// You may obtain a copy of the License at
|
|
5
|
+
//
|
|
6
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
//
|
|
8
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
9
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
10
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
|
+
// See the License for the specific language governing permissions and
|
|
12
|
+
// limitations under the License.
|
|
13
|
+
import { useQueries } from '@tanstack/react-query';
|
|
14
|
+
import { useDatasourceStore } from './datasources';
|
|
15
|
+
import { usePluginRegistry } from './plugin-registry';
|
|
16
|
+
import { useTimeRange } from './TimeRangeProvider';
|
|
17
|
+
import { useVariableValues } from './variables';
|
|
18
|
+
export const LOG_QUERY_KEY = 'LogQuery';
|
|
19
|
+
export function useLogQueries(definitions) {
|
|
20
|
+
const { getPlugin } = usePluginRegistry();
|
|
21
|
+
const datasourceStore = useDatasourceStore();
|
|
22
|
+
const { absoluteTimeRange } = useTimeRange();
|
|
23
|
+
const variableValues = useVariableValues();
|
|
24
|
+
const context = {
|
|
25
|
+
timeRange: absoluteTimeRange,
|
|
26
|
+
variableState: variableValues,
|
|
27
|
+
datasourceStore,
|
|
28
|
+
refreshKey: ''
|
|
29
|
+
};
|
|
30
|
+
return useQueries({
|
|
31
|
+
queries: definitions.map((definition)=>{
|
|
32
|
+
const queryKey = [
|
|
33
|
+
definition,
|
|
34
|
+
datasourceStore,
|
|
35
|
+
absoluteTimeRange,
|
|
36
|
+
variableValues
|
|
37
|
+
];
|
|
38
|
+
const logQueryKind = definition?.spec?.plugin?.kind;
|
|
39
|
+
return {
|
|
40
|
+
queryKey: queryKey,
|
|
41
|
+
queryFn: async ()=>{
|
|
42
|
+
const plugin = await getPlugin(LOG_QUERY_KEY, logQueryKind);
|
|
43
|
+
const data = await plugin.getLogData(definition.spec.plugin.spec, context);
|
|
44
|
+
return data;
|
|
45
|
+
},
|
|
46
|
+
structuralSharing: false
|
|
47
|
+
};
|
|
48
|
+
})
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=log-queries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/log-queries.ts"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { QueryDefinition, UnknownSpec } from '@perses-dev/core';\nimport { useQueries, UseQueryResult } from '@tanstack/react-query';\nimport { LogQueryResult } from '../model/log-queries';\nimport { useDatasourceStore } from './datasources';\nimport { usePluginRegistry } from './plugin-registry';\nimport { useTimeRange } from './TimeRangeProvider';\nimport { useVariableValues } from './variables';\n\nexport type LogQueryDefinition<PluginSpec = UnknownSpec> = QueryDefinition<'LogQuery', PluginSpec>;\nexport const LOG_QUERY_KEY = 'LogQuery';\n\nexport function useLogQueries(definitions: LogQueryDefinition[]): Array<UseQueryResult<LogQueryResult>> {\n const { getPlugin } = usePluginRegistry();\n const datasourceStore = useDatasourceStore();\n const { absoluteTimeRange } = useTimeRange();\n const variableValues = useVariableValues();\n\n const context = {\n timeRange: absoluteTimeRange,\n variableState: variableValues,\n datasourceStore,\n refreshKey: '',\n };\n\n return useQueries({\n queries: definitions.map((definition) => {\n const queryKey = [definition, datasourceStore, absoluteTimeRange, variableValues] as const;\n const logQueryKind = definition?.spec?.plugin?.kind;\n return {\n queryKey: queryKey,\n queryFn: async (): Promise<LogQueryResult> => {\n const plugin = await getPlugin(LOG_QUERY_KEY, logQueryKind);\n const data = await plugin.getLogData(definition.spec.plugin.spec, context);\n return data;\n },\n\n structuralSharing: false,\n };\n }),\n });\n}\n"],"names":["useQueries","useDatasourceStore","usePluginRegistry","useTimeRange","useVariableValues","LOG_QUERY_KEY","useLogQueries","definitions","getPlugin","datasourceStore","absoluteTimeRange","variableValues","context","timeRange","variableState","refreshKey","queries","map","definition","queryKey","logQueryKind","spec","plugin","kind","queryFn","data","getLogData","structuralSharing"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,UAAU,QAAwB,wBAAwB;AAEnE,SAASC,kBAAkB,QAAQ,gBAAgB;AACnD,SAASC,iBAAiB,QAAQ,oBAAoB;AACtD,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,iBAAiB,QAAQ,cAAc;AAGhD,OAAO,MAAMC,gBAAgB,WAAW;AAExC,OAAO,SAASC,cAAcC,WAAiC;IAC7D,MAAM,EAAEC,SAAS,EAAE,GAAGN;IACtB,MAAMO,kBAAkBR;IACxB,MAAM,EAAES,iBAAiB,EAAE,GAAGP;IAC9B,MAAMQ,iBAAiBP;IAEvB,MAAMQ,UAAU;QACdC,WAAWH;QACXI,eAAeH;QACfF;QACAM,YAAY;IACd;IAEA,OAAOf,WAAW;QAChBgB,SAAST,YAAYU,GAAG,CAAC,CAACC;YACxB,MAAMC,WAAW;gBAACD;gBAAYT;gBAAiBC;gBAAmBC;aAAe;YACjF,MAAMS,eAAeF,YAAYG,MAAMC,QAAQC;YAC/C,OAAO;gBACLJ,UAAUA;gBACVK,SAAS;oBACP,MAAMF,SAAS,MAAMd,UAAUH,eAAee;oBAC9C,MAAMK,OAAO,MAAMH,OAAOI,UAAU,CAACR,WAAWG,IAAI,CAACC,MAAM,CAACD,IAAI,EAAET;oBAClE,OAAOa;gBACT;gBAEAE,mBAAmB;YACrB;QACF;IACF;AACF"}
|
|
@@ -73,5 +73,6 @@ export type VariableSrv = {
|
|
|
73
73
|
export declare const VariableContext: import("react").Context<VariableSrv | undefined>;
|
|
74
74
|
export declare function useVariableValues(names?: string[]): VariableStateMap;
|
|
75
75
|
export declare function useAllVariableValues(names?: string[]): VariableStateMap;
|
|
76
|
+
export declare function replaceVariablesInString(text: string, variableValues: VariableStateMap, extraVariables?: Record<string, string>): string;
|
|
76
77
|
export declare function useReplaceVariablesInString(str: string | undefined): string | undefined;
|
|
77
78
|
//# sourceMappingURL=variables.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1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AqB;IAChC;;;OAGG;IACH,CAAC,SAAS,CAAC,UAAQ;IAEnB,OAAO,CAAC,QAAQ,CAAC,yBAAyB,CAAM;IAChD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAqD;IAE5E;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,gBAAgB,GAAG,aAAa,GAAG,SAAS;IAIrD;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,gBAAgB,EAAE,KAAK,EAAE,aAAa,GAAG,aAAa,GAAG,SAAS;IAS3E;;;OAGG;IACH,GAAG,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO;IAInC;;;OAGG;IACH,MAAM,CAAC,GAAG,EAAE,gBAAgB,GAAG,OAAO;IAiBtC,OAAO,CAAC,WAAW;IAInB,OAAO,CAAC,oBAAoB;CAG7B;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,KAAK,EAAE,gBAAgB,CAAC;CACzB,CAAC;AAEF,eAAO,MAAM,eAAe,kDAAoD,CAAC;AAUjF,wBAAgB,iBAAiB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAmBpE;AAGD,wBAAgB,oBAAoB,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,gBAAgB,CAOvE;AAGD,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,MAAM,EACZ,cAAc,EAAE,gBAAgB,EAChC,cAAc,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACtC,MAAM,CAMR;AAGD,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAKvF"}
|
|
@@ -113,6 +113,19 @@ export function useAllVariableValues(names) {
|
|
|
113
113
|
builtinVariableValues
|
|
114
114
|
]);
|
|
115
115
|
}
|
|
116
|
+
// Simple wrapper around replaceVariables() with support for extra string variables.
|
|
117
|
+
export function replaceVariablesInString(text, variableValues, extraVariables) {
|
|
118
|
+
const vars = {
|
|
119
|
+
...variableValues
|
|
120
|
+
}; // shallow clone to avoid modifying the original object
|
|
121
|
+
for (const [key, value] of Object.entries(extraVariables ?? {})){
|
|
122
|
+
vars[key] = {
|
|
123
|
+
value,
|
|
124
|
+
loading: false
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
return replaceVariables(text, vars);
|
|
128
|
+
}
|
|
116
129
|
// Convenience hook for replacing variables in a string
|
|
117
130
|
export function useReplaceVariablesInString(str) {
|
|
118
131
|
const variablesInString = str ? parseVariables(str) : [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/runtime/variables.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, useContext, useMemo } from 'react';\nimport { VariableValue } from '@perses-dev/core';\nimport { immerable } from 'immer';\nimport { VariableOption } from '../model';\nimport { parseVariables, replaceVariables } from '../utils';\nimport { useBuiltinVariableValues } from './builtin-variables';\n\nexport type VariableState = {\n value: VariableValue;\n options?: VariableOption[];\n loading: boolean;\n error?: Error;\n /**\n * If a local variable is overriding an external variable, local var will have the flag ``overriding=true``.\n */\n overriding?: boolean;\n /**\n * If a local variable is overriding an external variable, external var will have the flag ``overridden=true``.\n */\n overridden?: boolean;\n defaultValue?: VariableValue;\n};\n\nexport type VariableStateMap = Record<string, VariableState>;\n\n/**\n * Structure used as key in the {@link VariableStoreStateMap}.\n */\nexport type VariableStateKey = {\n /**\n * name of the variable we want to access in the state.\n */\n name: string;\n /**\n * source of the variable we want to access in the state.\n * Defined only for external variables.\n */\n source?: string;\n};\n\n/**\n * A state map with two entry keys, materialized by {@link VariableStateKey} structure.\n */\nexport class VariableStoreStateMap {\n /**\n * \"Immerable\" is mandatory to be able to use this class in an immer context.\n * Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas\n */\n [immerable] = true;\n\n private readonly DEFAULT_LOCAL_SOURCE_NAME = '';\n private readonly _state: Record<string, Record<string, VariableState>> = {};\n\n /**\n * Get variable state by key.\n * @param key\n */\n get(key: VariableStateKey): VariableState | undefined {\n return this._sourceStatesOrEmpty(key.source)[key.name];\n }\n\n /**\n * Set variable state by key.\n * @param key\n * @param value\n */\n set(key: VariableStateKey, value: VariableState): VariableState | undefined {\n const sourceName = this._sourceName(key.source);\n if (!this._state[sourceName]) {\n this._state[sourceName] = {};\n }\n this._sourceStatesOrEmpty(key.source)[key.name] = value;\n return value;\n }\n\n /**\n * Check presence of variable state by key.\n * @param key\n */\n has(key: VariableStateKey): boolean {\n return this._sourceStatesOrEmpty(key.source)[key.name] !== undefined;\n }\n\n /**\n * Delete variable state by key.\n * @param key\n */\n delete(key: VariableStateKey): boolean {\n const result = this.has(key);\n const sourceName = this._sourceName(key.source);\n const sourceStates = this._state[sourceName];\n\n // Delete var from source state\n if (sourceStates) {\n delete sourceStates[key.name];\n }\n\n // Delete source state from state if empty\n if (Object.keys(sourceStates ?? {})?.length === 0) {\n delete this._state[sourceName];\n }\n return result;\n }\n\n private _sourceName(source: string | undefined): string {\n return source ?? this.DEFAULT_LOCAL_SOURCE_NAME;\n }\n\n private _sourceStatesOrEmpty(source: string | undefined): Record<string, VariableState> {\n return this._state[this._sourceName(source)] ?? {};\n }\n}\n\nexport type VariableSrv = {\n state: VariableStateMap;\n};\n\nexport const VariableContext = createContext<VariableSrv | undefined>(undefined);\n\nfunction useVariableContext(): VariableSrv {\n const ctx = useContext(VariableContext);\n if (ctx === undefined) {\n throw new Error('No VariableContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useVariableValues(names?: string[]): VariableStateMap {\n const { state } = useVariableContext();\n\n const values = useMemo(() => {\n const values: VariableStateMap = {};\n names?.forEach((name) => {\n const s = state[name];\n if (s) {\n values[name] = s;\n }\n });\n return values;\n }, [state, names]);\n\n if (names === undefined) {\n return state;\n }\n\n return values;\n}\n\n// useAllVariableValues wraps user-defined variables with built-in variables\nexport function useAllVariableValues(names?: string[]): VariableStateMap {\n const variableValues = useVariableValues(names);\n const builtinVariableValues = useBuiltinVariableValues(names);\n\n return useMemo(() => {\n return { ...variableValues, ...builtinVariableValues } as VariableStateMap;\n }, [variableValues, builtinVariableValues]);\n}\n\n// Convenience hook for replacing variables in a string\nexport function useReplaceVariablesInString(str: string | undefined): string | undefined {\n const variablesInString = str ? parseVariables(str) : [];\n const variableValues = useAllVariableValues(variablesInString);\n if (!str) return undefined;\n return replaceVariables(str, variableValues);\n}\n"],"names":["createContext","useContext","useMemo","immerable","parseVariables","replaceVariables","useBuiltinVariableValues","VariableStoreStateMap","DEFAULT_LOCAL_SOURCE_NAME","_state","get","key","_sourceStatesOrEmpty","source","name","set","value","sourceName","_sourceName","has","undefined","delete","result","sourceStates","Object","keys","length","VariableContext","useVariableContext","ctx","Error","useVariableValues","names","state","values","forEach","s","useAllVariableValues","variableValues","builtinVariableValues","useReplaceVariablesInString","str","variablesInString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,aAAa,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAE3D,SAASC,SAAS,QAAQ,QAAQ;AAElC,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,WAAW;AAC5D,SAASC,wBAAwB,QAAQ,sBAAsB;AAmC/D;;CAEC,GACD,OAAO,MAAMC;IACX;;;GAGC,GACD,CAACJ,UAAU,GAAG,KAAK;IAEFK,4BAA4B,GAA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QAAQ,IAAI,CAAC;IACnD;AACF;AAMA,OAAO,MAAMc,kBAAkB3B,cAAuCoB,WAAW;AAEjF,SAASQ;IACP,MAAMC,MAAM5B,WAAW0B;IACvB,IAAIE,QAAQT,WAAW;QACrB,MAAM,IAAIU,MAAM;IAClB;IACA,OAAOD;AACT;AAEA,OAAO,SAASE,kBAAkBC,KAAgB;IAChD,MAAM,EAAEC,KAAK,EAAE,GAAGL;IAElB,MAAMM,SAAShC,QAAQ;QACrB,MAAMgC,SAA2B,CAAC;QAClCF,OAAOG,QAAQ,CAACrB;YACd,MAAMsB,IAAIH,KAAK,CAACnB,KAAK;YACrB,IAAIsB,GAAG;gBACLF,MAAM,CAACpB,KAAK,GAAGsB;YACjB;QACF;QACA,OAAOF;IACT,GAAG;QAACD;QAAOD;KAAM;IAEjB,IAAIA,UAAUZ,WAAW;QACvB,OAAOa;IACT;IAEA,OAAOC;AACT;AAEA,4EAA4E;AAC5E,OAAO,SAASG,qBAAqBL,KAAgB;IACnD,MAAMM,iBAAiBP,kBAAkBC;IACzC,MAAMO,wBAAwBjC,yBAAyB0B;IAEvD,OAAO9B,QAAQ;QACb,OAAO;YAAE,GAAGoC,cAAc;YAAE,GAAGC,qBAAqB;QAAC;IACvD,GAAG;QAACD;QAAgBC;KAAsB;AAC5C;AAEA,uDAAuD;AACvD,OAAO,
|
|
1
|
+
{"version":3,"sources":["../../src/runtime/variables.ts"],"sourcesContent":["// Copyright 2024 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { createContext, useContext, useMemo } from 'react';\nimport { VariableValue } from '@perses-dev/core';\nimport { immerable } from 'immer';\nimport { VariableOption } from '../model';\nimport { parseVariables, replaceVariables } from '../utils';\nimport { useBuiltinVariableValues } from './builtin-variables';\n\nexport type VariableState = {\n value: VariableValue;\n options?: VariableOption[];\n loading: boolean;\n error?: Error;\n /**\n * If a local variable is overriding an external variable, local var will have the flag ``overriding=true``.\n */\n overriding?: boolean;\n /**\n * If a local variable is overriding an external variable, external var will have the flag ``overridden=true``.\n */\n overridden?: boolean;\n defaultValue?: VariableValue;\n};\n\nexport type VariableStateMap = Record<string, VariableState>;\n\n/**\n * Structure used as key in the {@link VariableStoreStateMap}.\n */\nexport type VariableStateKey = {\n /**\n * name of the variable we want to access in the state.\n */\n name: string;\n /**\n * source of the variable we want to access in the state.\n * Defined only for external variables.\n */\n source?: string;\n};\n\n/**\n * A state map with two entry keys, materialized by {@link VariableStateKey} structure.\n */\nexport class VariableStoreStateMap {\n /**\n * \"Immerable\" is mandatory to be able to use this class in an immer context.\n * Ref: https://docs.pmnd.rs/zustand/integrations/immer-middleware#gotchas\n */\n [immerable] = true;\n\n private readonly DEFAULT_LOCAL_SOURCE_NAME = '';\n private readonly _state: Record<string, Record<string, VariableState>> = {};\n\n /**\n * Get variable state by key.\n * @param key\n */\n get(key: VariableStateKey): VariableState | undefined {\n return this._sourceStatesOrEmpty(key.source)[key.name];\n }\n\n /**\n * Set variable state by key.\n * @param key\n * @param value\n */\n set(key: VariableStateKey, value: VariableState): VariableState | undefined {\n const sourceName = this._sourceName(key.source);\n if (!this._state[sourceName]) {\n this._state[sourceName] = {};\n }\n this._sourceStatesOrEmpty(key.source)[key.name] = value;\n return value;\n }\n\n /**\n * Check presence of variable state by key.\n * @param key\n */\n has(key: VariableStateKey): boolean {\n return this._sourceStatesOrEmpty(key.source)[key.name] !== undefined;\n }\n\n /**\n * Delete variable state by key.\n * @param key\n */\n delete(key: VariableStateKey): boolean {\n const result = this.has(key);\n const sourceName = this._sourceName(key.source);\n const sourceStates = this._state[sourceName];\n\n // Delete var from source state\n if (sourceStates) {\n delete sourceStates[key.name];\n }\n\n // Delete source state from state if empty\n if (Object.keys(sourceStates ?? {})?.length === 0) {\n delete this._state[sourceName];\n }\n return result;\n }\n\n private _sourceName(source: string | undefined): string {\n return source ?? this.DEFAULT_LOCAL_SOURCE_NAME;\n }\n\n private _sourceStatesOrEmpty(source: string | undefined): Record<string, VariableState> {\n return this._state[this._sourceName(source)] ?? {};\n }\n}\n\nexport type VariableSrv = {\n state: VariableStateMap;\n};\n\nexport const VariableContext = createContext<VariableSrv | undefined>(undefined);\n\nfunction useVariableContext(): VariableSrv {\n const ctx = useContext(VariableContext);\n if (ctx === undefined) {\n throw new Error('No VariableContext found. Did you forget a Provider?');\n }\n return ctx;\n}\n\nexport function useVariableValues(names?: string[]): VariableStateMap {\n const { state } = useVariableContext();\n\n const values = useMemo(() => {\n const values: VariableStateMap = {};\n names?.forEach((name) => {\n const s = state[name];\n if (s) {\n values[name] = s;\n }\n });\n return values;\n }, [state, names]);\n\n if (names === undefined) {\n return state;\n }\n\n return values;\n}\n\n// useAllVariableValues wraps user-defined variables with built-in variables\nexport function useAllVariableValues(names?: string[]): VariableStateMap {\n const variableValues = useVariableValues(names);\n const builtinVariableValues = useBuiltinVariableValues(names);\n\n return useMemo(() => {\n return { ...variableValues, ...builtinVariableValues } as VariableStateMap;\n }, [variableValues, builtinVariableValues]);\n}\n\n// Simple wrapper around replaceVariables() with support for extra string variables.\nexport function replaceVariablesInString(\n text: string,\n variableValues: VariableStateMap,\n extraVariables?: Record<string, string>\n): string {\n const vars = { ...variableValues }; // shallow clone to avoid modifying the original object\n for (const [key, value] of Object.entries(extraVariables ?? {})) {\n vars[key] = { value, loading: false };\n }\n return replaceVariables(text, vars);\n}\n\n// Convenience hook for replacing variables in a string\nexport function useReplaceVariablesInString(str: string | undefined): string | undefined {\n const variablesInString = str ? parseVariables(str) : [];\n const variableValues = useAllVariableValues(variablesInString);\n if (!str) return undefined;\n return replaceVariables(str, variableValues);\n}\n"],"names":["createContext","useContext","useMemo","immerable","parseVariables","replaceVariables","useBuiltinVariableValues","VariableStoreStateMap","DEFAULT_LOCAL_SOURCE_NAME","_state","get","key","_sourceStatesOrEmpty","source","name","set","value","sourceName","_sourceName","has","undefined","delete","result","sourceStates","Object","keys","length","VariableContext","useVariableContext","ctx","Error","useVariableValues","names","state","values","forEach","s","useAllVariableValues","variableValues","builtinVariableValues","replaceVariablesInString","text","extraVariables","vars","entries","loading","useReplaceVariablesInString","str","variablesInString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,aAAa,EAAEC,UAAU,EAAEC,OAAO,QAAQ,QAAQ;AAE3D,SAASC,SAAS,QAAQ,QAAQ;AAElC,SAASC,cAAc,EAAEC,gBAAgB,QAAQ,WAAW;AAC5D,SAASC,wBAAwB,QAAQ,sBAAsB;AAmC/D;;CAEC,GACD,OAAO,MAAMC;IACX;;;GAGC,GACD,CAACJ,UAAU,GAAG,KAAK;IAEFK,4BAA4B,GAAG;IAC/BC,SAAwD,CAAC,EAAE;IAE5E;;;GAGC,GACDC,IAAIC,GAAqB,EAA6B;QACpD,OAAO,IAAI,CAACC,oBAAoB,CAACD,IAAIE,MAAM,CAAC,CAACF,IAAIG,IAAI,CAAC;IACxD;IAEA;;;;GAIC,GACDC,IAAIJ,GAAqB,EAAEK,KAAoB,EAA6B;QAC1E,MAAMC,aAAa,IAAI,CAACC,WAAW,CAACP,IAAIE,MAAM;QAC9C,IAAI,CAAC,IAAI,CAACJ,MAAM,CAACQ,WAAW,EAAE;YAC5B,IAAI,CAACR,MAAM,CAACQ,WAAW,GAAG,CAAC;QAC7B;QACA,IAAI,CAACL,oBAAoB,CAACD,IAAIE,MAAM,CAAC,CAACF,IAAIG,IAAI,CAAC,GAAGE;QAClD,OAAOA;IACT;IAEA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AEjB,IAAIA,UAAUZ,WAAW;QACvB,OAAOa;IACT;IAEA,OAAOC;AACT;AAEA,4EAA4E;AAC5E,OAAO,SAASG,qBAAqBL,KAAgB;IACnD,MAAMM,iBAAiBP,kBAAkBC;IACzC,MAAMO,wBAAwBjC,yBAAyB0B;IAEvD,OAAO9B,QAAQ;QACb,OAAO;YAAE,GAAGoC,cAAc;YAAE,GAAGC,qBAAqB;QAAC;IACvD,GAAG;QAACD;QAAgBC;KAAsB;AAC5C;AAEA,oFAAoF;AACpF,OAAO,SAASC,yBACdC,IAAY,EACZH,cAAgC,EAChCI,cAAuC;IAEvC,MAAMC,OAAO;QAAE,GAAGL,cAAc;IAAC,GAAG,uDAAuD;IAC3F,KAAK,MAAM,CAAC3B,KAAKK,MAAM,IAAIQ,OAAOoB,OAAO,CAACF,kBAAkB,CAAC,GAAI;QAC/DC,IAAI,CAAChC,IAAI,GAAG;YAAEK;YAAO6B,SAAS;QAAM;IACtC;IACA,OAAOxC,iBAAiBoC,MAAME;AAChC;AAEA,uDAAuD;AACvD,OAAO,SAASG,4BAA4BC,GAAuB;IACjE,MAAMC,oBAAoBD,MAAM3C,eAAe2C,OAAO,EAAE;IACxD,MAAMT,iBAAiBD,qBAAqBW;IAC5C,IAAI,CAACD,KAAK,OAAO3B;IACjB,OAAOf,iBAAiB0C,KAAKT;AAC/B"}
|
package/dist/test/mock-data.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ProfileData, TimeSeriesData, TraceData } from '@perses-dev/core';
|
|
1
|
+
import { LogData, ProfileData, TimeSeriesData, TraceData } from '@perses-dev/core';
|
|
2
2
|
export declare const MOCK_TIME_SERIES_DATA: TimeSeriesData;
|
|
3
3
|
export declare const MOCK_TRACE_DATA: TraceData;
|
|
4
|
+
export declare const MOCK_LOG_DATA: LogData;
|
|
4
5
|
export declare const MOCK_PROFILE_DATA: ProfileData;
|
|
5
6
|
//# sourceMappingURL=mock-data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mock-data.d.ts","sourceRoot":"","sources":["../../src/test/mock-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"mock-data.d.ts","sourceRoot":"","sources":["../../src/test/mock-data.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAEnF,eAAO,MAAM,qBAAqB,EAAE,cAsBnC,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,SAmC7B,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,OAoB3B,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,WAmB/B,CAAC"}
|
package/dist/test/mock-data.js
CHANGED
|
@@ -81,6 +81,27 @@ export const MOCK_TRACE_DATA = {
|
|
|
81
81
|
executedQueryString: '{ duration > 1000ms }'
|
|
82
82
|
}
|
|
83
83
|
};
|
|
84
|
+
export const MOCK_LOG_DATA = {
|
|
85
|
+
totalCount: 2,
|
|
86
|
+
entries: [
|
|
87
|
+
{
|
|
88
|
+
timestamp: 1666479357903,
|
|
89
|
+
line: 'Error: Something went wrong',
|
|
90
|
+
labels: {
|
|
91
|
+
level: 'error',
|
|
92
|
+
service: 'backend'
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
timestamp: 1666479382282,
|
|
97
|
+
line: 'Info: Request processed successfully',
|
|
98
|
+
labels: {
|
|
99
|
+
level: 'info',
|
|
100
|
+
service: 'frontend'
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
]
|
|
104
|
+
};
|
|
84
105
|
export const MOCK_PROFILE_DATA = {
|
|
85
106
|
profile: {
|
|
86
107
|
stackTrace: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/test/mock-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { ProfileData, TimeSeriesData, TraceData } from '@perses-dev/core';\n\nexport const MOCK_TIME_SERIES_DATA: TimeSeriesData = {\n timeRange: {\n start: new Date(1666625490000),\n end: new Date(1666625535000),\n },\n stepMs: 24379,\n series: [\n {\n name: 'device=\"/dev/vda1\", env=\"demo\", fstype=\"ext4\", instance=\"demo.do.prometheus.io:9100\", job=\"node\", mountpoint=\"/\"',\n values: [\n [1666479357903, 0.27700745551584494],\n [1666479382282, 0.27701284657366565],\n ],\n },\n {\n name: 'device=\"/dev/vda15\", env=\"demo\", fstype=\"vfat\", instance=\"demo.do.prometheus.io:9100\", job=\"node\", mountpoint=\"/boot/efi\"',\n values: [\n [1666479357903, 0.08486496097624885],\n [1666479382282, 0.08486496097624885],\n ],\n },\n ],\n};\n\nexport const MOCK_TRACE_DATA: TraceData = {\n searchResult: [\n {\n durationMs: 1120,\n serviceStats: {\n 'shop-backend': {\n spanCount: 4,\n errorCount: 0,\n },\n 'cart-service': {\n spanCount: 2,\n errorCount: 0,\n },\n 'article-service': {\n spanCount: 2,\n errorCount: 0,\n },\n 'auth-service': {\n spanCount: 1,\n errorCount: 0,\n },\n postgres: {\n spanCount: 1,\n errorCount: 0,\n },\n },\n startTimeUnixMs: 1699916103945861,\n traceId: '95ba9202315c29c801b5aa41452aa775',\n rootServiceName: 'shop-backend',\n rootTraceName: 'article-to-cart',\n },\n ],\n metadata: {\n executedQueryString: '{ duration > 1000ms }',\n },\n};\n\nexport const MOCK_PROFILE_DATA: ProfileData = {\n profile: {\n stackTrace: {\n id: 0,\n name: 'root',\n level: 0,\n start: 1699916103945861,\n end: 1699916105065861,\n total: 1000,\n self: 500,\n children: [],\n },\n },\n metadata: {\n spyName: '',\n sampleRate: 1000000000,\n units: 'samples',\n name: 'cpu',\n },\n};\n"],"names":["MOCK_TIME_SERIES_DATA","timeRange","start","Date","end","stepMs","series","name","values","MOCK_TRACE_DATA","searchResult","durationMs","serviceStats","spanCount","errorCount","postgres","startTimeUnixMs","traceId","rootServiceName","rootTraceName","metadata","executedQueryString","MOCK_PROFILE_DATA","profile","stackTrace","id","
|
|
1
|
+
{"version":3,"sources":["../../src/test/mock-data.ts"],"sourcesContent":["// Copyright 2023 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { LogData, ProfileData, TimeSeriesData, TraceData } from '@perses-dev/core';\n\nexport const MOCK_TIME_SERIES_DATA: TimeSeriesData = {\n timeRange: {\n start: new Date(1666625490000),\n end: new Date(1666625535000),\n },\n stepMs: 24379,\n series: [\n {\n name: 'device=\"/dev/vda1\", env=\"demo\", fstype=\"ext4\", instance=\"demo.do.prometheus.io:9100\", job=\"node\", mountpoint=\"/\"',\n values: [\n [1666479357903, 0.27700745551584494],\n [1666479382282, 0.27701284657366565],\n ],\n },\n {\n name: 'device=\"/dev/vda15\", env=\"demo\", fstype=\"vfat\", instance=\"demo.do.prometheus.io:9100\", job=\"node\", mountpoint=\"/boot/efi\"',\n values: [\n [1666479357903, 0.08486496097624885],\n [1666479382282, 0.08486496097624885],\n ],\n },\n ],\n};\n\nexport const MOCK_TRACE_DATA: TraceData = {\n searchResult: [\n {\n durationMs: 1120,\n serviceStats: {\n 'shop-backend': {\n spanCount: 4,\n errorCount: 0,\n },\n 'cart-service': {\n spanCount: 2,\n errorCount: 0,\n },\n 'article-service': {\n spanCount: 2,\n errorCount: 0,\n },\n 'auth-service': {\n spanCount: 1,\n errorCount: 0,\n },\n postgres: {\n spanCount: 1,\n errorCount: 0,\n },\n },\n startTimeUnixMs: 1699916103945861,\n traceId: '95ba9202315c29c801b5aa41452aa775',\n rootServiceName: 'shop-backend',\n rootTraceName: 'article-to-cart',\n },\n ],\n metadata: {\n executedQueryString: '{ duration > 1000ms }',\n },\n};\n\nexport const MOCK_LOG_DATA: LogData = {\n totalCount: 2,\n entries: [\n {\n timestamp: 1666479357903,\n line: 'Error: Something went wrong',\n labels: {\n level: 'error',\n service: 'backend',\n },\n },\n {\n timestamp: 1666479382282,\n line: 'Info: Request processed successfully',\n labels: {\n level: 'info',\n service: 'frontend',\n },\n },\n ],\n};\n\nexport const MOCK_PROFILE_DATA: ProfileData = {\n profile: {\n stackTrace: {\n id: 0,\n name: 'root',\n level: 0,\n start: 1699916103945861,\n end: 1699916105065861,\n total: 1000,\n self: 500,\n children: [],\n },\n },\n metadata: {\n spyName: '',\n sampleRate: 1000000000,\n units: 'samples',\n name: 'cpu',\n },\n};\n"],"names":["MOCK_TIME_SERIES_DATA","timeRange","start","Date","end","stepMs","series","name","values","MOCK_TRACE_DATA","searchResult","durationMs","serviceStats","spanCount","errorCount","postgres","startTimeUnixMs","traceId","rootServiceName","rootTraceName","metadata","executedQueryString","MOCK_LOG_DATA","totalCount","entries","timestamp","line","labels","level","service","MOCK_PROFILE_DATA","profile","stackTrace","id","total","self","children","spyName","sampleRate","units"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAIjC,OAAO,MAAMA,wBAAwC;IACnDC,WAAW;QACTC,OAAO,IAAIC,KAAK;QAChBC,KAAK,IAAID,KAAK;IAChB;IACAE,QAAQ;IACRC,QAAQ;QACN;YACEC,MAAM;YACNC,QAAQ;gBACN;oBAAC;oBAAe;iBAAoB;gBACpC;oBAAC;oBAAe;iBAAoB;aACrC;QACH;QACA;YACED,MAAM;YACNC,QAAQ;gBACN;oBAAC;oBAAe;iBAAoB;gBACpC;oBAAC;oBAAe;iBAAoB;aACrC;QACH;KACD;AACH,EAAE;AAEF,OAAO,MAAMC,kBAA6B;IACxCC,cAAc;QACZ;YACEC,YAAY;YACZC,cAAc;gBACZ,gBAAgB;oBACdC,WAAW;oBACXC,YAAY;gBACd;gBACA,gBAAgB;oBACdD,WAAW;oBACXC,YAAY;gBACd;gBACA,mBAAmB;oBACjBD,WAAW;oBACXC,YAAY;gBACd;gBACA,gBAAgB;oBACdD,WAAW;oBACXC,YAAY;gBACd;gBACAC,UAAU;oBACRF,WAAW;oBACXC,YAAY;gBACd;YACF;YACAE,iBAAiB;YACjBC,SAAS;YACTC,iBAAiB;YACjBC,eAAe;QACjB;KACD;IACDC,UAAU;QACRC,qBAAqB;IACvB;AACF,EAAE;AAEF,OAAO,MAAMC,gBAAyB;IACpCC,YAAY;IACZC,SAAS;QACP;YACEC,WAAW;YACXC,MAAM;YACNC,QAAQ;gBACNC,OAAO;gBACPC,SAAS;YACX;QACF;QACA;YACEJ,WAAW;YACXC,MAAM;YACNC,QAAQ;gBACNC,OAAO;gBACPC,SAAS;YACX;QACF;KACD;AACH,EAAE;AAEF,OAAO,MAAMC,oBAAiC;IAC5CC,SAAS;QACPC,YAAY;YACVC,IAAI;YACJ1B,MAAM;YACNqB,OAAO;YACP1B,OAAO;YACPE,KAAK;YACL8B,OAAO;YACPC,MAAM;YACNC,UAAU,EAAE;QACd;IACF;IACAhB,UAAU;QACRiB,SAAS;QACTC,YAAY;QACZC,OAAO;QACPhC,MAAM;IACR;AACF,EAAE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@perses-dev/plugin-system",
|
|
3
|
-
"version": "0.52.0-beta.
|
|
3
|
+
"version": "0.52.0-beta.4",
|
|
4
4
|
"description": "The plugin feature in Pereses",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"homepage": "https://github.com/perses/perses/blob/main/README.md",
|
|
@@ -29,8 +29,8 @@
|
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"@module-federation/enhanced": "^0.18.0",
|
|
32
|
-
"@perses-dev/components": "0.52.0-beta.
|
|
33
|
-
"@perses-dev/core": "0.52.0-beta.
|
|
32
|
+
"@perses-dev/components": "0.52.0-beta.4",
|
|
33
|
+
"@perses-dev/core": "0.52.0-beta.4",
|
|
34
34
|
"date-fns": "^4.1.0",
|
|
35
35
|
"date-fns-tz": "^3.2.0",
|
|
36
36
|
"immer": "^10.1.1",
|