@perses-dev/victorialogs-plugin 0.1.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/LICENSE +201 -0
- package/README.md +41 -0
- package/__mf/css/async/1580.d3010b86.css +1 -0
- package/__mf/css/async/2341.d3010b86.css +1 -0
- package/__mf/font/lato-all-300-normal.322bdf14.woff +0 -0
- package/__mf/font/lato-all-400-normal.63513b00.woff +0 -0
- package/__mf/font/lato-all-700-normal.bb27db94.woff +0 -0
- package/__mf/font/lato-all-900-normal.a27049a3.woff +0 -0
- package/__mf/font/lato-latin-300-normal.c5195215.woff2 +0 -0
- package/__mf/font/lato-latin-400-normal.b7ffde23.woff2 +0 -0
- package/__mf/font/lato-latin-700-normal.d5eb20bc.woff2 +0 -0
- package/__mf/font/lato-latin-900-normal.d884a71c.woff2 +0 -0
- package/__mf/font/lato-latin-ext-300-normal.abcc64a9.woff2 +0 -0
- package/__mf/font/lato-latin-ext-400-normal.6ebed106.woff2 +0 -0
- package/__mf/font/lato-latin-ext-700-normal.8697d1d5.woff2 +0 -0
- package/__mf/font/lato-latin-ext-900-normal.20a2b415.woff2 +0 -0
- package/__mf/js/VictoriaLogs.9a08c902.js +5 -0
- package/__mf/js/async/158.c35084cf.js +10 -0
- package/__mf/js/async/158.c35084cf.js.LICENSE.txt +17 -0
- package/__mf/js/async/1580.ace454a9.js +2 -0
- package/__mf/js/async/1580.ace454a9.js.LICENSE.txt +9 -0
- package/__mf/js/async/1964.6d84f735.js +2 -0
- package/__mf/js/async/1964.6d84f735.js.LICENSE.txt +9 -0
- package/__mf/js/async/2178.d1785908.js +2 -0
- package/__mf/js/async/2178.d1785908.js.LICENSE.txt +15 -0
- package/__mf/js/async/2292.0696771a.js +2 -0
- package/__mf/js/async/2292.0696771a.js.LICENSE.txt +24 -0
- package/__mf/js/async/2472.3c37aa71.js +22 -0
- package/__mf/js/async/2472.3c37aa71.js.LICENSE.txt +19 -0
- package/__mf/js/async/2558.beff8442.js +101 -0
- package/__mf/js/async/2708.c79893a7.js +1 -0
- package/__mf/js/async/3224.858fb6d6.js +1 -0
- package/__mf/js/async/3431.358ac817.js +1 -0
- package/__mf/js/async/3863.66f8659b.js +2 -0
- package/__mf/js/async/3863.66f8659b.js.LICENSE.txt +9 -0
- package/__mf/js/async/3960.bbacac1d.js +2 -0
- package/__mf/js/async/3960.bbacac1d.js.LICENSE.txt +8 -0
- package/__mf/js/async/3980.03396afa.js +2 -0
- package/__mf/js/async/3980.03396afa.js.LICENSE.txt +9 -0
- package/__mf/js/async/4075.8aae8af4.js +1 -0
- package/__mf/js/async/4238.cd5e3d1f.js +1 -0
- package/__mf/js/async/4269.f9191848.js +2 -0
- package/__mf/js/async/4269.f9191848.js.LICENSE.txt +9 -0
- package/__mf/js/async/4310.b6c0f250.js +7 -0
- package/__mf/js/async/4310.b6c0f250.js.LICENSE.txt +21 -0
- package/__mf/js/async/4421.c442f6d9.js +1 -0
- package/__mf/js/async/5214.bcb7530e.js +1 -0
- package/__mf/js/async/5348.aa77f629.js +2 -0
- package/__mf/js/async/5348.aa77f629.js.LICENSE.txt +9 -0
- package/__mf/js/async/5388.92f525c5.js +1 -0
- package/__mf/js/async/5409.5d25f1db.js +1 -0
- package/__mf/js/async/5628.f229b9f6.js +1 -0
- package/__mf/js/async/5682.a317ee96.js +1 -0
- package/__mf/js/async/5790.f7a41a40.js +1 -0
- package/__mf/js/async/5981.e54ec80b.js +2 -0
- package/__mf/js/async/5981.e54ec80b.js.LICENSE.txt +8 -0
- package/__mf/js/async/6134.6f58094d.js +38 -0
- package/__mf/js/async/6292.fda8a9af.js +1 -0
- package/__mf/js/async/6333.031c68b4.js +2 -0
- package/__mf/js/async/6333.031c68b4.js.LICENSE.txt +9 -0
- package/__mf/js/async/6374.e9650306.js +1 -0
- package/__mf/js/async/6377.e48abaa5.js +2 -0
- package/__mf/js/async/6377.e48abaa5.js.LICENSE.txt +32 -0
- package/__mf/js/async/6620.4f2fc96e.js +2 -0
- package/__mf/js/async/6620.4f2fc96e.js.LICENSE.txt +21 -0
- package/__mf/js/async/6770.5c90a318.js +1 -0
- package/__mf/js/async/694.663f3faf.js +1 -0
- package/__mf/js/async/7376.91743064.js +1 -0
- package/__mf/js/async/738.b4e8c361.js +1 -0
- package/__mf/js/async/7740.82b38509.js +1 -0
- package/__mf/js/async/8216.3417496f.js +1 -0
- package/__mf/js/async/8488.9eb8e6dc.js +1 -0
- package/__mf/js/async/8537.a7ed2e24.js +1 -0
- package/__mf/js/async/8727.e54ca5fd.js +1 -0
- package/__mf/js/async/8930.fa15926d.js +1 -0
- package/__mf/js/async/9173.d784dd69.js +2 -0
- package/__mf/js/async/9173.d784dd69.js.LICENSE.txt +19 -0
- package/__mf/js/async/9563.b88ff7ff.js +2 -0
- package/__mf/js/async/9563.b88ff7ff.js.LICENSE.txt +9 -0
- package/__mf/js/async/__federation_expose_VictoriaLogsDatasource.807e09ec.js +2 -0
- package/__mf/js/async/__federation_expose_VictoriaLogsDatasource.807e09ec.js.LICENSE.txt +9 -0
- package/__mf/js/async/__federation_expose_VictoriaLogsFieldNamesVariable.94ae15a7.js +2 -0
- package/__mf/js/async/__federation_expose_VictoriaLogsFieldNamesVariable.94ae15a7.js.LICENSE.txt +9 -0
- package/__mf/js/async/__federation_expose_VictoriaLogsFieldValuesVariable.eabc284b.js +2 -0
- package/__mf/js/async/__federation_expose_VictoriaLogsFieldValuesVariable.eabc284b.js.LICENSE.txt +9 -0
- package/__mf/js/async/__federation_expose_VictoriaLogsLogQuery.8122cbeb.js +1 -0
- package/__mf/js/async/__federation_expose_VictoriaLogsTimeSeriesQuery.56dd4cab.js +1 -0
- package/__mf/js/main.9f62e593.js +5 -0
- package/lib/bootstrap.d.ts +2 -0
- package/lib/bootstrap.d.ts.map +1 -0
- package/lib/bootstrap.js +7 -0
- package/lib/bootstrap.js.map +1 -0
- package/lib/cjs/bootstrap.js +14 -0
- package/lib/cjs/components/index.js +23 -0
- package/lib/cjs/components/logsql-editor.js +110 -0
- package/lib/cjs/components/logsql-extension.js +55 -0
- package/lib/cjs/components/logsql-highlight.js +40 -0
- package/lib/cjs/datasources/index.js +30 -0
- package/lib/cjs/datasources/victorialogs-datasource/VictoriaLogsDatasource.js +61 -0
- package/lib/cjs/datasources/victorialogs-datasource/VictoriaLogsDatasourceEditor.js +95 -0
- package/lib/cjs/datasources/victorialogs-datasource/index.js +32 -0
- package/lib/cjs/datasources/victorialogs-datasource/types.js +16 -0
- package/lib/cjs/env.d.js +2 -0
- package/lib/cjs/getPluginModule.js +27 -0
- package/lib/cjs/index-federation.js +43 -0
- package/lib/cjs/index.js +27 -0
- package/lib/cjs/model/client.js +156 -0
- package/lib/cjs/model/index.js +32 -0
- package/lib/cjs/model/selectors.js +47 -0
- package/lib/cjs/model/types.js +16 -0
- package/lib/cjs/queries/constants.js +22 -0
- package/lib/cjs/queries/index.js +31 -0
- package/lib/cjs/queries/victorialogs-log-query/VictoriaLogsLogQuery.js +31 -0
- package/lib/cjs/queries/victorialogs-log-query/VictoriaLogsLogQueryEditor.js +118 -0
- package/lib/cjs/queries/victorialogs-log-query/index.js +21 -0
- package/lib/cjs/queries/victorialogs-log-query/interface.js +4 -0
- package/lib/cjs/queries/victorialogs-log-query/query.js +61 -0
- package/lib/cjs/queries/victorialogs-log-query/types.js +4 -0
- package/lib/cjs/queries/victorialogs-time-series-query/VictoriaLogsTimeSeriesQuery.js +43 -0
- package/lib/cjs/queries/victorialogs-time-series-query/VictoriaLogsTimeSeriesQueryEditor.js +116 -0
- package/lib/cjs/queries/victorialogs-time-series-query/index.js +33 -0
- package/lib/cjs/queries/victorialogs-time-series-query/query.js +122 -0
- package/lib/cjs/queries/victorialogs-time-series-query/types.js +16 -0
- package/lib/cjs/setup-tests.js +7 -0
- package/lib/cjs/variables/index.js +31 -0
- package/lib/cjs/variables/types.js +4 -0
- package/lib/cjs/variables/utils.js +85 -0
- package/lib/cjs/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariable.js +45 -0
- package/lib/cjs/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariableEditor.js +89 -0
- package/lib/cjs/variables/victorialogs-field-names/index.js +30 -0
- package/lib/cjs/variables/victorialogs-field-values/VictoriaLogsFieldValuesVariable.js +49 -0
- package/lib/cjs/variables/victorialogs-field-values/VictoriaLogsFieldValuesVariableEditor.js +130 -0
- package/lib/cjs/variables/victorialogs-field-values/index.js +30 -0
- package/lib/components/index.d.ts +3 -0
- package/lib/components/index.d.ts.map +1 -0
- package/lib/components/index.js +15 -0
- package/lib/components/index.js.map +1 -0
- package/lib/components/logsql-editor.d.ts +5 -0
- package/lib/components/logsql-editor.d.ts.map +1 -0
- package/lib/components/logsql-editor.js +61 -0
- package/lib/components/logsql-editor.js.map +1 -0
- package/lib/components/logsql-extension.d.ts +4 -0
- package/lib/components/logsql-extension.d.ts.map +1 -0
- package/lib/components/logsql-extension.js +47 -0
- package/lib/components/logsql-extension.js.map +1 -0
- package/lib/components/logsql-highlight.d.ts +2 -0
- package/lib/components/logsql-highlight.d.ts.map +1 -0
- package/lib/components/logsql-highlight.js +32 -0
- package/lib/components/logsql-highlight.js.map +1 -0
- package/lib/datasources/index.d.ts +2 -0
- package/lib/datasources/index.d.ts.map +1 -0
- package/lib/datasources/index.js +15 -0
- package/lib/datasources/index.js.map +1 -0
- package/lib/datasources/victorialogs-datasource/VictoriaLogsDatasource.d.ts +5 -0
- package/lib/datasources/victorialogs-datasource/VictoriaLogsDatasource.d.ts.map +1 -0
- package/lib/datasources/victorialogs-datasource/VictoriaLogsDatasource.js +53 -0
- package/lib/datasources/victorialogs-datasource/VictoriaLogsDatasource.js.map +1 -0
- package/lib/datasources/victorialogs-datasource/VictoriaLogsDatasourceEditor.d.ts +9 -0
- package/lib/datasources/victorialogs-datasource/VictoriaLogsDatasourceEditor.d.ts.map +1 -0
- package/lib/datasources/victorialogs-datasource/VictoriaLogsDatasourceEditor.js +87 -0
- package/lib/datasources/victorialogs-datasource/VictoriaLogsDatasourceEditor.js.map +1 -0
- package/lib/datasources/victorialogs-datasource/index.d.ts +4 -0
- package/lib/datasources/victorialogs-datasource/index.d.ts.map +1 -0
- package/lib/datasources/victorialogs-datasource/index.js +17 -0
- package/lib/datasources/victorialogs-datasource/index.js.map +1 -0
- package/lib/datasources/victorialogs-datasource/types.d.ts +6 -0
- package/lib/datasources/victorialogs-datasource/types.d.ts.map +1 -0
- package/lib/datasources/victorialogs-datasource/types.js +15 -0
- package/lib/datasources/victorialogs-datasource/types.js.map +1 -0
- package/lib/env.d.js +3 -0
- package/lib/env.d.js.map +1 -0
- package/lib/getPluginModule.d.ts +6 -0
- package/lib/getPluginModule.d.ts.map +1 -0
- package/lib/getPluginModule.js +16 -0
- package/lib/getPluginModule.js.map +1 -0
- package/lib/index-federation.d.ts +1 -0
- package/lib/index-federation.d.ts.map +1 -0
- package/lib/index-federation.js +3 -0
- package/lib/index-federation.js.map +1 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +6 -0
- package/lib/index.js.map +1 -0
- package/lib/model/client.d.ts +39 -0
- package/lib/model/client.d.ts.map +1 -0
- package/lib/model/client.js +134 -0
- package/lib/model/client.js.map +1 -0
- package/lib/model/index.d.ts +4 -0
- package/lib/model/index.d.ts.map +1 -0
- package/lib/model/index.js +17 -0
- package/lib/model/index.js.map +1 -0
- package/lib/model/selectors.d.ts +10 -0
- package/lib/model/selectors.d.ts.map +1 -0
- package/lib/model/selectors.js +25 -0
- package/lib/model/selectors.js.map +1 -0
- package/lib/model/types.d.ts +44 -0
- package/lib/model/types.d.ts.map +1 -0
- package/lib/model/types.js +15 -0
- package/lib/model/types.js.map +1 -0
- package/lib/queries/constants.d.ts +5 -0
- package/lib/queries/constants.d.ts.map +1 -0
- package/lib/queries/constants.js +6 -0
- package/lib/queries/constants.js.map +1 -0
- package/lib/queries/index.d.ts +3 -0
- package/lib/queries/index.d.ts.map +1 -0
- package/lib/queries/index.js +16 -0
- package/lib/queries/index.js.map +1 -0
- package/lib/queries/victorialogs-log-query/VictoriaLogsLogQuery.d.ts +4 -0
- package/lib/queries/victorialogs-log-query/VictoriaLogsLogQuery.d.ts.map +1 -0
- package/lib/queries/victorialogs-log-query/VictoriaLogsLogQuery.js +23 -0
- package/lib/queries/victorialogs-log-query/VictoriaLogsLogQuery.js.map +1 -0
- package/lib/queries/victorialogs-log-query/VictoriaLogsLogQueryEditor.d.ts +7 -0
- package/lib/queries/victorialogs-log-query/VictoriaLogsLogQueryEditor.d.ts.map +1 -0
- package/lib/queries/victorialogs-log-query/VictoriaLogsLogQueryEditor.js +110 -0
- package/lib/queries/victorialogs-log-query/VictoriaLogsLogQueryEditor.js.map +1 -0
- package/lib/queries/victorialogs-log-query/index.d.ts +5 -0
- package/lib/queries/victorialogs-log-query/index.d.ts.map +1 -0
- package/lib/queries/victorialogs-log-query/index.js +6 -0
- package/lib/queries/victorialogs-log-query/index.js.map +1 -0
- package/lib/queries/victorialogs-log-query/interface.d.ts +24 -0
- package/lib/queries/victorialogs-log-query/interface.d.ts.map +1 -0
- package/lib/queries/victorialogs-log-query/interface.js +3 -0
- package/lib/queries/victorialogs-log-query/interface.js.map +1 -0
- package/lib/queries/victorialogs-log-query/query.d.ts +4 -0
- package/lib/queries/victorialogs-log-query/query.d.ts.map +1 -0
- package/lib/queries/victorialogs-log-query/query.js +53 -0
- package/lib/queries/victorialogs-log-query/query.js.map +1 -0
- package/lib/queries/victorialogs-log-query/types.d.ts +6 -0
- package/lib/queries/victorialogs-log-query/types.d.ts.map +1 -0
- package/lib/queries/victorialogs-log-query/types.js +3 -0
- package/lib/queries/victorialogs-log-query/types.js.map +1 -0
- package/lib/queries/victorialogs-time-series-query/VictoriaLogsTimeSeriesQuery.d.ts +4 -0
- package/lib/queries/victorialogs-time-series-query/VictoriaLogsTimeSeriesQuery.d.ts.map +1 -0
- package/lib/queries/victorialogs-time-series-query/VictoriaLogsTimeSeriesQuery.js +35 -0
- package/lib/queries/victorialogs-time-series-query/VictoriaLogsTimeSeriesQuery.js.map +1 -0
- package/lib/queries/victorialogs-time-series-query/VictoriaLogsTimeSeriesQueryEditor.d.ts +7 -0
- package/lib/queries/victorialogs-time-series-query/VictoriaLogsTimeSeriesQueryEditor.d.ts.map +1 -0
- package/lib/queries/victorialogs-time-series-query/VictoriaLogsTimeSeriesQueryEditor.js +108 -0
- package/lib/queries/victorialogs-time-series-query/VictoriaLogsTimeSeriesQueryEditor.js.map +1 -0
- package/lib/queries/victorialogs-time-series-query/index.d.ts +5 -0
- package/lib/queries/victorialogs-time-series-query/index.d.ts.map +1 -0
- package/lib/queries/victorialogs-time-series-query/index.js +18 -0
- package/lib/queries/victorialogs-time-series-query/index.js.map +1 -0
- package/lib/queries/victorialogs-time-series-query/query.d.ts +12 -0
- package/lib/queries/victorialogs-time-series-query/query.d.ts.map +1 -0
- package/lib/queries/victorialogs-time-series-query/query.js +114 -0
- package/lib/queries/victorialogs-time-series-query/query.js.map +1 -0
- package/lib/queries/victorialogs-time-series-query/types.d.ts +7 -0
- package/lib/queries/victorialogs-time-series-query/types.d.ts.map +1 -0
- package/lib/queries/victorialogs-time-series-query/types.js +15 -0
- package/lib/queries/victorialogs-time-series-query/types.js.map +1 -0
- package/lib/setup-tests.d.ts +2 -0
- package/lib/setup-tests.d.ts.map +1 -0
- package/lib/setup-tests.js +5 -0
- package/lib/setup-tests.js.map +1 -0
- package/lib/variables/index.d.ts +3 -0
- package/lib/variables/index.d.ts.map +1 -0
- package/lib/variables/index.js +16 -0
- package/lib/variables/index.js.map +1 -0
- package/lib/variables/types.d.ts +13 -0
- package/lib/variables/types.d.ts.map +1 -0
- package/lib/variables/types.js +3 -0
- package/lib/variables/types.js.map +1 -0
- package/lib/variables/utils.d.ts +12 -0
- package/lib/variables/utils.d.ts.map +1 -0
- package/lib/variables/utils.js +63 -0
- package/lib/variables/utils.js.map +1 -0
- package/lib/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariable.d.ts +4 -0
- package/lib/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariable.d.ts.map +1 -0
- package/lib/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariable.js +37 -0
- package/lib/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariable.js.map +1 -0
- package/lib/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariableEditor.d.ts +5 -0
- package/lib/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariableEditor.d.ts.map +1 -0
- package/lib/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariableEditor.js +81 -0
- package/lib/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariableEditor.js.map +1 -0
- package/lib/variables/victorialogs-field-names/index.d.ts +2 -0
- package/lib/variables/victorialogs-field-names/index.d.ts.map +1 -0
- package/lib/variables/victorialogs-field-names/index.js +15 -0
- package/lib/variables/victorialogs-field-names/index.js.map +1 -0
- package/lib/variables/victorialogs-field-values/VictoriaLogsFieldValuesVariable.d.ts +4 -0
- package/lib/variables/victorialogs-field-values/VictoriaLogsFieldValuesVariable.d.ts.map +1 -0
- package/lib/variables/victorialogs-field-values/VictoriaLogsFieldValuesVariable.js +41 -0
- package/lib/variables/victorialogs-field-values/VictoriaLogsFieldValuesVariable.js.map +1 -0
- package/lib/variables/victorialogs-field-values/VictoriaLogsFieldValuesVariableEditor.d.ts +5 -0
- package/lib/variables/victorialogs-field-values/VictoriaLogsFieldValuesVariableEditor.d.ts.map +1 -0
- package/lib/variables/victorialogs-field-values/VictoriaLogsFieldValuesVariableEditor.js +122 -0
- package/lib/variables/victorialogs-field-values/VictoriaLogsFieldValuesVariableEditor.js.map +1 -0
- package/lib/variables/victorialogs-field-values/index.d.ts +2 -0
- package/lib/variables/victorialogs-field-values/index.d.ts.map +1 -0
- package/lib/variables/victorialogs-field-values/index.js +15 -0
- package/lib/variables/victorialogs-field-values/index.js.map +1 -0
- package/mf-manifest.json +556 -0
- package/mf-stats.json +614 -0
- package/package.json +97 -0
|
@@ -0,0 +1,108 @@
|
|
|
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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
import { DatasourceSelect, isVariableDatasource, useDatasourceSelectValueToSelector } from '@perses-dev/plugin-system';
|
|
15
|
+
import { InputLabel, Stack } from '@mui/material';
|
|
16
|
+
import { useCallback, useState, useEffect } from 'react';
|
|
17
|
+
import { LogsQLEditor } from '../../components/logsql-editor';
|
|
18
|
+
import { VICTORIALOGS_DATASOURCE_KIND } from '../../model';
|
|
19
|
+
import { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';
|
|
20
|
+
export function VictoriaLogsQueryEditor(props) {
|
|
21
|
+
const { onChange, value } = props;
|
|
22
|
+
const { datasource } = value;
|
|
23
|
+
const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;
|
|
24
|
+
const selectedDatasource = useDatasourceSelectValueToSelector(datasourceSelectValue, VICTORIALOGS_DATASOURCE_KIND);
|
|
25
|
+
// Local state for editor value to prevent query_range calls on every keystroke
|
|
26
|
+
const [localQuery, setLocalQuery] = useState(value.query);
|
|
27
|
+
// Update local state when prop changes
|
|
28
|
+
useEffect(()=>{
|
|
29
|
+
setLocalQuery(value.query);
|
|
30
|
+
}, [
|
|
31
|
+
value.query
|
|
32
|
+
]);
|
|
33
|
+
const handleDatasourceChange = (newDatasourceSelection)=>{
|
|
34
|
+
if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {
|
|
35
|
+
onChange({
|
|
36
|
+
...value,
|
|
37
|
+
datasource: newDatasourceSelection
|
|
38
|
+
});
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
throw new Error('Got unexpected non VictoriaLogsQuery datasource selection');
|
|
42
|
+
};
|
|
43
|
+
// Debounced query change handler to prevent excessive query_range calls
|
|
44
|
+
const handleQueryChange = useCallback((newQuery)=>{
|
|
45
|
+
setLocalQuery(newQuery);
|
|
46
|
+
}, []);
|
|
47
|
+
// Immediate query execution on Enter or blur
|
|
48
|
+
const handleQueryExecute = useCallback((query)=>{
|
|
49
|
+
onChange({
|
|
50
|
+
...value,
|
|
51
|
+
query
|
|
52
|
+
});
|
|
53
|
+
}, [
|
|
54
|
+
onChange,
|
|
55
|
+
value
|
|
56
|
+
]);
|
|
57
|
+
return /*#__PURE__*/ _jsxs(Stack, {
|
|
58
|
+
spacing: 1.5,
|
|
59
|
+
paddingBottom: 1,
|
|
60
|
+
children: [
|
|
61
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
62
|
+
children: [
|
|
63
|
+
/*#__PURE__*/ _jsx(InputLabel, {
|
|
64
|
+
sx: {
|
|
65
|
+
display: 'block',
|
|
66
|
+
marginBottom: '4px',
|
|
67
|
+
fontWeight: 500
|
|
68
|
+
},
|
|
69
|
+
children: "Datasource"
|
|
70
|
+
}),
|
|
71
|
+
/*#__PURE__*/ _jsx(DatasourceSelect, {
|
|
72
|
+
datasourcePluginKind: DATASOURCE_KIND,
|
|
73
|
+
value: selectedDatasource,
|
|
74
|
+
onChange: handleDatasourceChange,
|
|
75
|
+
label: "VictoriaLogs Datasource",
|
|
76
|
+
notched: true
|
|
77
|
+
})
|
|
78
|
+
]
|
|
79
|
+
}),
|
|
80
|
+
/*#__PURE__*/ _jsxs("div", {
|
|
81
|
+
children: [
|
|
82
|
+
/*#__PURE__*/ _jsx(InputLabel, {
|
|
83
|
+
sx: {
|
|
84
|
+
display: 'block',
|
|
85
|
+
marginBottom: '4px',
|
|
86
|
+
fontWeight: 500
|
|
87
|
+
},
|
|
88
|
+
children: "LogsQL Query"
|
|
89
|
+
}),
|
|
90
|
+
/*#__PURE__*/ _jsx(LogsQLEditor, {
|
|
91
|
+
value: localQuery,
|
|
92
|
+
onChange: handleQueryChange,
|
|
93
|
+
onBlur: ()=>handleQueryExecute(localQuery),
|
|
94
|
+
onKeyDown: (event)=>{
|
|
95
|
+
if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
|
|
96
|
+
event.preventDefault();
|
|
97
|
+
handleQueryExecute(localQuery);
|
|
98
|
+
}
|
|
99
|
+
},
|
|
100
|
+
placeholder: 'Enter LogsQL query (e.g. {job="mysql"} |= "error")'
|
|
101
|
+
})
|
|
102
|
+
]
|
|
103
|
+
})
|
|
104
|
+
]
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
//# sourceMappingURL=VictoriaLogsTimeSeriesQueryEditor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/queries/victorialogs-time-series-query/VictoriaLogsTimeSeriesQueryEditor.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 {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { InputLabel, Stack } from '@mui/material';\nimport { ReactElement, useCallback, useState, useEffect } from 'react';\nimport { LogsQLEditor } from '../../components/logsql-editor';\nimport { VICTORIALOGS_DATASOURCE_KIND, VictoriaLogsDatasourceSelector } from '../../model';\nimport { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';\nimport { VictoriaLogsTimeSeriesQuerySpec } from './types';\n\ntype VictoriaLogsQueryEditorProps = OptionsEditorProps<VictoriaLogsTimeSeriesQuerySpec>;\n\nexport function VictoriaLogsQueryEditor(props: VictoriaLogsQueryEditorProps): ReactElement {\n const { onChange, value } = props;\n const { datasource } = value;\n const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n VICTORIALOGS_DATASOURCE_KIND\n ) as VictoriaLogsDatasourceSelector;\n\n // Local state for editor value to prevent query_range calls on every keystroke\n const [localQuery, setLocalQuery] = useState(value.query);\n\n // Update local state when prop changes\n useEffect(() => {\n setLocalQuery(value.query);\n }, [value.query]);\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (newDatasourceSelection) => {\n if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {\n onChange({ ...value, datasource: newDatasourceSelection });\n return;\n }\n\n throw new Error('Got unexpected non VictoriaLogsQuery datasource selection');\n };\n\n // Debounced query change handler to prevent excessive query_range calls\n const handleQueryChange = useCallback((newQuery: string) => {\n setLocalQuery(newQuery);\n }, []);\n\n // Immediate query execution on Enter or blur\n const handleQueryExecute = useCallback(\n (query: string) => {\n onChange({ ...value, query });\n },\n [onChange, value]\n );\n\n return (\n <Stack spacing={1.5} paddingBottom={1}>\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n Datasource\n </InputLabel>\n <DatasourceSelect\n datasourcePluginKind={DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n label=\"VictoriaLogs Datasource\"\n notched\n />\n </div>\n\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n LogsQL Query\n </InputLabel>\n <LogsQLEditor\n value={localQuery}\n onChange={handleQueryChange}\n onBlur={() => handleQueryExecute(localQuery)}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n handleQueryExecute(localQuery);\n }\n }}\n placeholder='Enter LogsQL query (e.g. {job=\"mysql\"} |= \"error\")'\n // height=\"120px\"\n />\n </div>\n </Stack>\n );\n}\n"],"names":["DatasourceSelect","isVariableDatasource","useDatasourceSelectValueToSelector","InputLabel","Stack","useCallback","useState","useEffect","LogsQLEditor","VICTORIALOGS_DATASOURCE_KIND","DATASOURCE_KIND","DEFAULT_DATASOURCE","VictoriaLogsQueryEditor","props","onChange","value","datasource","datasourceSelectValue","selectedDatasource","localQuery","setLocalQuery","query","handleDatasourceChange","newDatasourceSelection","kind","Error","handleQueryChange","newQuery","handleQueryExecute","spacing","paddingBottom","div","sx","display","marginBottom","fontWeight","datasourcePluginKind","label","notched","onBlur","onKeyDown","event","key","ctrlKey","metaKey","preventDefault","placeholder"],"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,SACEA,gBAAgB,EAEhBC,oBAAoB,EAEpBC,kCAAkC,QAC7B,4BAA4B;AACnC,SAASC,UAAU,EAAEC,KAAK,QAAQ,gBAAgB;AAClD,SAAuBC,WAAW,EAAEC,QAAQ,EAAEC,SAAS,QAAQ,QAAQ;AACvE,SAASC,YAAY,QAAQ,iCAAiC;AAC9D,SAASC,4BAA4B,QAAwC,cAAc;AAC3F,SAASC,eAAe,EAAEC,kBAAkB,QAAQ,eAAe;AAKnE,OAAO,SAASC,wBAAwBC,KAAmC;IACzE,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAE,GAAGF;IAC5B,MAAM,EAAEG,UAAU,EAAE,GAAGD;IACvB,MAAME,wBAAwBD,cAAcL;IAC5C,MAAMO,qBAAqBhB,mCACzBe,uBACAR;IAGF,+EAA+E;IAC/E,MAAM,CAACU,YAAYC,cAAc,GAAGd,SAASS,MAAMM,KAAK;IAExD,uCAAuC;IACvCd,UAAU;QACRa,cAAcL,MAAMM,KAAK;IAC3B,GAAG;QAACN,MAAMM,KAAK;KAAC;IAEhB,MAAMC,yBAA4D,CAACC;QACjE,IAAI,CAACtB,qBAAqBsB,2BAA2BA,uBAAuBC,IAAI,KAAKd,iBAAiB;YACpGI,SAAS;gBAAE,GAAGC,KAAK;gBAAEC,YAAYO;YAAuB;YACxD;QACF;QAEA,MAAM,IAAIE,MAAM;IAClB;IAEA,wEAAwE;IACxE,MAAMC,oBAAoBrB,YAAY,CAACsB;QACrCP,cAAcO;IAChB,GAAG,EAAE;IAEL,6CAA6C;IAC7C,MAAMC,qBAAqBvB,YACzB,CAACgB;QACCP,SAAS;YAAE,GAAGC,KAAK;YAAEM;QAAM;IAC7B,GACA;QAACP;QAAUC;KAAM;IAGnB,qBACE,MAACX;QAAMyB,SAAS;QAAKC,eAAe;;0BAClC,MAACC;;kCACC,KAAC5B;wBACC6B,IAAI;4BACFC,SAAS;4BACTC,cAAc;4BACdC,YAAY;wBACd;kCACD;;kCAGD,KAACnC;wBACCoC,sBAAsB1B;wBACtBK,OAAOG;wBACPJ,UAAUQ;wBACVe,OAAM;wBACNC,OAAO;;;;0BAIX,MAACP;;kCACC,KAAC5B;wBACC6B,IAAI;4BACFC,SAAS;4BACTC,cAAc;4BACdC,YAAY;wBACd;kCACD;;kCAGD,KAAC3B;wBACCO,OAAOI;wBACPL,UAAUY;wBACVa,QAAQ,IAAMX,mBAAmBT;wBACjCqB,WAAW,CAACC;4BACV,IAAIA,MAAMC,GAAG,KAAK,WAAYD,CAAAA,MAAME,OAAO,IAAIF,MAAMG,OAAO,AAAD,GAAI;gCAC7DH,MAAMI,cAAc;gCACpBjB,mBAAmBT;4BACrB;wBACF;wBACA2B,aAAY;;;;;;AAMtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/queries/victorialogs-time-series-query/index.ts"],"names":[],"mappings":"AAaA,cAAc,SAAS,CAAC;AACxB,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
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
|
+
export * from './query';
|
|
14
|
+
export * from './VictoriaLogsTimeSeriesQuery';
|
|
15
|
+
export * from './VictoriaLogsTimeSeriesQueryEditor';
|
|
16
|
+
export * from './types';
|
|
17
|
+
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/queries/victorialogs-time-series-query/index.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\nexport * from './query';\nexport * from './VictoriaLogsTimeSeriesQuery';\nexport * from './VictoriaLogsTimeSeriesQueryEditor';\nexport * from './types';\n"],"names":[],"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,cAAc,UAAU;AACxB,cAAc,gCAAgC;AAC9C,cAAc,sCAAsC;AACpD,cAAc,UAAU"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';
|
|
2
|
+
import { VictoriaLogsTimeSeriesQuerySpec } from './types';
|
|
3
|
+
export type VictoriaLogsMatrixResult = {
|
|
4
|
+
metric: Record<string, string>;
|
|
5
|
+
values: Array<[number, string]>;
|
|
6
|
+
};
|
|
7
|
+
export type VictoriaLogsMatrixResponse = {
|
|
8
|
+
resultType: 'matrix';
|
|
9
|
+
result: VictoriaLogsMatrixResult[];
|
|
10
|
+
};
|
|
11
|
+
export declare const getVictoriaLogsTimeSeriesData: TimeSeriesQueryPlugin<VictoriaLogsTimeSeriesQuerySpec>['getTimeSeriesData'];
|
|
12
|
+
//# sourceMappingURL=query.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../../../src/queries/victorialogs-time-series-query/query.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,qBAAqB,EAAoB,MAAM,2BAA2B,CAAC;AAKpF,OAAO,EAAE,+BAA+B,EAAE,MAAM,SAAS,CAAC;AAE1D,MAAM,MAAM,wBAAwB,GAAG;IACrC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,UAAU,EAAE,QAAQ,CAAC;IACrB,MAAM,EAAE,wBAAwB,EAAE,CAAC;CACpC,CAAC;AA4EF,eAAO,MAAM,6BAA6B,EAAE,qBAAqB,CAAC,+BAA+B,CAAC,CAAC,mBAAmB,CA+CrH,CAAC"}
|
|
@@ -0,0 +1,114 @@
|
|
|
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 { parseDurationString } from '@perses-dev/core';
|
|
14
|
+
import { replaceVariables } from '@perses-dev/plugin-system';
|
|
15
|
+
import { milliseconds } from 'date-fns';
|
|
16
|
+
import { DEFAULT_DATASOURCE } from '../constants';
|
|
17
|
+
// Constants for VictoriaLogs step calculation
|
|
18
|
+
const MAX_VICTORIALOGS_DATA_POINTS = 10000; // Similar to Prometheus
|
|
19
|
+
const DEFAULT_MIN_STEP_SECONDS = 15; // 15 seconds default minimum
|
|
20
|
+
/**
|
|
21
|
+
* Converts a duration string (like "15s", "1m") to seconds
|
|
22
|
+
*/ function getDurationStringSeconds(durationString) {
|
|
23
|
+
if (!durationString) return undefined;
|
|
24
|
+
const duration = parseDurationString(durationString);
|
|
25
|
+
const ms = milliseconds(duration);
|
|
26
|
+
return Math.floor(ms / 1000);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Calculates appropriate step for VictoriaLogs range queries
|
|
30
|
+
*/ function getVictoriaLogsRangeStep(startMs, endMs, minStepSeconds = DEFAULT_MIN_STEP_SECONDS, suggestedStepMs = 0) {
|
|
31
|
+
const suggestedStepSeconds = suggestedStepMs / 1000;
|
|
32
|
+
const querySeconds = (endMs - startMs) / 1000;
|
|
33
|
+
let safeStep = querySeconds / MAX_VICTORIALOGS_DATA_POINTS;
|
|
34
|
+
if (safeStep > 1) {
|
|
35
|
+
safeStep = Math.ceil(safeStep);
|
|
36
|
+
}
|
|
37
|
+
return Math.max(suggestedStepSeconds, minStepSeconds, safeStep);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Formats step in seconds as a duration string for VictoriaLogs API
|
|
41
|
+
*/ function formatStepForVictoriaLogs(stepSeconds) {
|
|
42
|
+
if (stepSeconds < 60) {
|
|
43
|
+
return `${Math.round(stepSeconds)}s`;
|
|
44
|
+
} else if (stepSeconds < 3600) {
|
|
45
|
+
return `${Math.round(stepSeconds / 60)}m`;
|
|
46
|
+
} else {
|
|
47
|
+
return `${Math.round(stepSeconds / 3600)}h`;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function convertMatrixToTimeSeries(matrix) {
|
|
51
|
+
return matrix.map((series)=>{
|
|
52
|
+
const { _stream, ...labels } = series.metric;
|
|
53
|
+
if (_stream) {
|
|
54
|
+
const match = _stream.match(/{([^}]+)}/);
|
|
55
|
+
if (match && match[1]) {
|
|
56
|
+
const labelsStr = match[1].split(',').forEach((labelPair)=>{
|
|
57
|
+
const [key, val] = labelPair.split('=').map((s)=>s.trim().replace(/^"|"$/g, ''));
|
|
58
|
+
if (key && val) labels[key] = val;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const name = Object.entries(labels).map(([k, v])=>`${k}=${v}`).join(', ');
|
|
63
|
+
return {
|
|
64
|
+
name: name,
|
|
65
|
+
values: series.values.map(([timestamp, value])=>[
|
|
66
|
+
Number(timestamp) * 1000,
|
|
67
|
+
Number(value)
|
|
68
|
+
]),
|
|
69
|
+
labels
|
|
70
|
+
};
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
export const getVictoriaLogsTimeSeriesData = async (spec, context)=>{
|
|
74
|
+
if (!spec.query) {
|
|
75
|
+
return {
|
|
76
|
+
series: [],
|
|
77
|
+
timeRange: {
|
|
78
|
+
start: context.timeRange.start,
|
|
79
|
+
end: context.timeRange.end
|
|
80
|
+
},
|
|
81
|
+
stepMs: DEFAULT_MIN_STEP_SECONDS * 1000
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
const query = replaceVariables(spec.query, context.variableState);
|
|
85
|
+
const client = await context.datasourceStore.getDatasourceClient(spec.datasource ?? DEFAULT_DATASOURCE);
|
|
86
|
+
const { start, end } = context.timeRange;
|
|
87
|
+
const minStepSeconds = spec.step ? getDurationStringSeconds(spec.step) ?? DEFAULT_MIN_STEP_SECONDS : DEFAULT_MIN_STEP_SECONDS;
|
|
88
|
+
const stepSeconds = getVictoriaLogsRangeStep(start.getTime(), end.getTime(), minStepSeconds, context.suggestedStepMs);
|
|
89
|
+
const stepString = formatStepForVictoriaLogs(stepSeconds);
|
|
90
|
+
const stepMs = stepSeconds * 1000;
|
|
91
|
+
const response = await client.statsQueryRange({
|
|
92
|
+
query,
|
|
93
|
+
step: stepString,
|
|
94
|
+
start: start.toISOString(),
|
|
95
|
+
end: end.toISOString()
|
|
96
|
+
});
|
|
97
|
+
if (response.status === 'error') {
|
|
98
|
+
throw new Error(response.error);
|
|
99
|
+
}
|
|
100
|
+
const series = convertMatrixToTimeSeries(response.data.result);
|
|
101
|
+
return {
|
|
102
|
+
series: series,
|
|
103
|
+
timeRange: {
|
|
104
|
+
start,
|
|
105
|
+
end
|
|
106
|
+
},
|
|
107
|
+
stepMs,
|
|
108
|
+
metadata: {
|
|
109
|
+
executedQueryString: query
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
//# sourceMappingURL=query.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/queries/victorialogs-time-series-query/query.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 { TimeSeries, DurationString, parseDurationString } from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceVariables } from '@perses-dev/plugin-system';\nimport { milliseconds } from 'date-fns';\nimport { VictoriaLogsClient } from '../../model/client';\nimport { VictoriaLogsStatsQueryRangeResponse } from '../../model/types';\nimport { DEFAULT_DATASOURCE } from '../constants';\nimport { VictoriaLogsTimeSeriesQuerySpec } from './types';\n\nexport type VictoriaLogsMatrixResult = {\n metric: Record<string, string>;\n values: Array<[number, string]>;\n};\n\nexport type VictoriaLogsMatrixResponse = {\n resultType: 'matrix';\n result: VictoriaLogsMatrixResult[];\n};\n\n// Constants for VictoriaLogs step calculation\nconst MAX_VICTORIALOGS_DATA_POINTS = 10000; // Similar to Prometheus\nconst DEFAULT_MIN_STEP_SECONDS = 15; // 15 seconds default minimum\n\n/**\n * Converts a duration string (like \"15s\", \"1m\") to seconds\n */\nfunction getDurationStringSeconds(durationString?: DurationString): number | undefined {\n if (!durationString) return undefined;\n\n const duration = parseDurationString(durationString);\n const ms = milliseconds(duration);\n return Math.floor(ms / 1000);\n}\n\n/**\n * Calculates appropriate step for VictoriaLogs range queries\n */\nfunction getVictoriaLogsRangeStep(\n startMs: number,\n endMs: number,\n minStepSeconds = DEFAULT_MIN_STEP_SECONDS,\n suggestedStepMs = 0\n): number {\n const suggestedStepSeconds = suggestedStepMs / 1000;\n const querySeconds = (endMs - startMs) / 1000;\n\n let safeStep = querySeconds / MAX_VICTORIALOGS_DATA_POINTS;\n if (safeStep > 1) {\n safeStep = Math.ceil(safeStep);\n }\n\n return Math.max(suggestedStepSeconds, minStepSeconds, safeStep);\n}\n\n/**\n * Formats step in seconds as a duration string for VictoriaLogs API\n */\nfunction formatStepForVictoriaLogs(stepSeconds: number): string {\n if (stepSeconds < 60) {\n return `${Math.round(stepSeconds)}s`;\n } else if (stepSeconds < 3600) {\n return `${Math.round(stepSeconds / 60)}m`;\n } else {\n return `${Math.round(stepSeconds / 3600)}h`;\n }\n}\n\nfunction convertMatrixToTimeSeries(matrix: VictoriaLogsMatrixResult[]): TimeSeries[] {\n return matrix.map((series) => {\n const { _stream, ...labels } = series.metric;\n if (_stream) {\n const match = _stream.match(/{([^}]+)}/);\n if (match && match[1]) {\n const labelsStr = match[1].split(',').forEach(labelPair => {\n const [key, val] = labelPair.split('=').map(s => s.trim().replace(/^\"|\"$/g, ''));\n if (key && val) labels[key] = val;\n });\n }\n }\n const name = Object.entries(labels)\n .map(([k, v]) => `${k}=${v}`)\n .join(', ');\n return {\n name: name,\n values: series.values.map(([timestamp, value]) => [\n Number(timestamp) * 1000, // Convert seconds to milliseconds\n Number(value),\n ]),\n labels,\n };\n });\n}\n\nexport const getVictoriaLogsTimeSeriesData: TimeSeriesQueryPlugin<VictoriaLogsTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (!spec.query) {\n return {\n series: [],\n timeRange: { start: context.timeRange.start, end: context.timeRange.end },\n stepMs: DEFAULT_MIN_STEP_SECONDS * 1000,\n };\n }\n\n const query = replaceVariables(spec.query, context.variableState);\n const client = (await context.datasourceStore.getDatasourceClient<VictoriaLogsClient>(\n spec.datasource ?? DEFAULT_DATASOURCE\n )) as VictoriaLogsClient;\n\n const { start, end } = context.timeRange;\n\n const minStepSeconds = spec.step\n ? (getDurationStringSeconds(spec.step as DurationString) ?? DEFAULT_MIN_STEP_SECONDS)\n : DEFAULT_MIN_STEP_SECONDS;\n const stepSeconds = getVictoriaLogsRangeStep(start.getTime(), end.getTime(), minStepSeconds, context.suggestedStepMs);\n const stepString = formatStepForVictoriaLogs(stepSeconds);\n const stepMs = stepSeconds * 1000;\n\n const response: VictoriaLogsStatsQueryRangeResponse = await client.statsQueryRange({\n query,\n step: stepString,\n start: start.toISOString(),\n end: end.toISOString(),\n });\n\n if (response.status === 'error') {\n throw new Error(response.error)\n }\n\n const series = convertMatrixToTimeSeries(response.data.result as VictoriaLogsMatrixResult[]);\n\n return {\n series: series,\n timeRange: { start, end },\n stepMs,\n metadata: {\n executedQueryString: query,\n },\n };\n};\n"],"names":["parseDurationString","replaceVariables","milliseconds","DEFAULT_DATASOURCE","MAX_VICTORIALOGS_DATA_POINTS","DEFAULT_MIN_STEP_SECONDS","getDurationStringSeconds","durationString","undefined","duration","ms","Math","floor","getVictoriaLogsRangeStep","startMs","endMs","minStepSeconds","suggestedStepMs","suggestedStepSeconds","querySeconds","safeStep","ceil","max","formatStepForVictoriaLogs","stepSeconds","round","convertMatrixToTimeSeries","matrix","map","series","_stream","labels","metric","match","labelsStr","split","forEach","labelPair","key","val","s","trim","replace","name","Object","entries","k","v","join","values","timestamp","value","Number","getVictoriaLogsTimeSeriesData","spec","context","query","timeRange","start","end","stepMs","variableState","client","datasourceStore","getDatasourceClient","datasource","step","getTime","stepString","response","statsQueryRange","toISOString","status","Error","error","data","result","metadata","executedQueryString"],"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,SAAqCA,mBAAmB,QAAQ,mBAAmB;AACnF,SAAgCC,gBAAgB,QAAQ,4BAA4B;AACpF,SAASC,YAAY,QAAQ,WAAW;AAGxC,SAASC,kBAAkB,QAAQ,eAAe;AAalD,8CAA8C;AAC9C,MAAMC,+BAA+B,OAAO,wBAAwB;AACpE,MAAMC,2BAA2B,IAAI,6BAA6B;AAElE;;CAEC,GACD,SAASC,yBAAyBC,cAA+B;IAC/D,IAAI,CAACA,gBAAgB,OAAOC;IAE5B,MAAMC,WAAWT,oBAAoBO;IACrC,MAAMG,KAAKR,aAAaO;IACxB,OAAOE,KAAKC,KAAK,CAACF,KAAK;AACzB;AAEA;;CAEC,GACD,SAASG,yBACPC,OAAe,EACfC,KAAa,EACbC,iBAAiBX,wBAAwB,EACzCY,kBAAkB,CAAC;IAEnB,MAAMC,uBAAuBD,kBAAkB;IAC/C,MAAME,eAAe,AAACJ,CAAAA,QAAQD,OAAM,IAAK;IAEzC,IAAIM,WAAWD,eAAef;IAC9B,IAAIgB,WAAW,GAAG;QAChBA,WAAWT,KAAKU,IAAI,CAACD;IACvB;IAEA,OAAOT,KAAKW,GAAG,CAACJ,sBAAsBF,gBAAgBI;AACxD;AAEA;;CAEC,GACD,SAASG,0BAA0BC,WAAmB;IACpD,IAAIA,cAAc,IAAI;QACpB,OAAO,GAAGb,KAAKc,KAAK,CAACD,aAAa,CAAC,CAAC;IACtC,OAAO,IAAIA,cAAc,MAAM;QAC7B,OAAO,GAAGb,KAAKc,KAAK,CAACD,cAAc,IAAI,CAAC,CAAC;IAC3C,OAAO;QACL,OAAO,GAAGb,KAAKc,KAAK,CAACD,cAAc,MAAM,CAAC,CAAC;IAC7C;AACF;AAEA,SAASE,0BAA0BC,MAAkC;IACnE,OAAOA,OAAOC,GAAG,CAAC,CAACC;QACjB,MAAM,EAAEC,OAAO,EAAE,GAAGC,QAAQ,GAAGF,OAAOG,MAAM;QAC5C,IAAIF,SAAS;YACX,MAAMG,QAAQH,QAAQG,KAAK,CAAC;YAC5B,IAAIA,SAASA,KAAK,CAAC,EAAE,EAAE;gBACrB,MAAMC,YAAYD,KAAK,CAAC,EAAE,CAACE,KAAK,CAAC,KAAKC,OAAO,CAACC,CAAAA;oBAC5C,MAAM,CAACC,KAAKC,IAAI,GAAGF,UAAUF,KAAK,CAAC,KAAKP,GAAG,CAACY,CAAAA,IAAKA,EAAEC,IAAI,GAAGC,OAAO,CAAC,UAAU;oBAC5E,IAAIJ,OAAOC,KAAKR,MAAM,CAACO,IAAI,GAAGC;gBAChC;YACF;QACF;QACA,MAAMI,OAAOC,OAAOC,OAAO,CAACd,QACzBH,GAAG,CAAC,CAAC,CAACkB,GAAGC,EAAE,GAAK,GAAGD,EAAE,CAAC,EAAEC,GAAG,EAC3BC,IAAI,CAAC;QACR,OAAO;YACLL,MAAMA;YACNM,QAAQpB,OAAOoB,MAAM,CAACrB,GAAG,CAAC,CAAC,CAACsB,WAAWC,MAAM,GAAK;oBAChDC,OAAOF,aAAa;oBACpBE,OAAOD;iBACR;YACDpB;QACF;IACF;AACF;AAEA,OAAO,MAAMsB,gCAA6G,OACxHC,MACAC;IAEA,IAAI,CAACD,KAAKE,KAAK,EAAE;QACf,OAAO;YACL3B,QAAQ,EAAE;YACV4B,WAAW;gBAAEC,OAAOH,QAAQE,SAAS,CAACC,KAAK;gBAAEC,KAAKJ,QAAQE,SAAS,CAACE,GAAG;YAAC;YACxEC,QAAQvD,2BAA2B;QACrC;IACF;IAEA,MAAMmD,QAAQvD,iBAAiBqD,KAAKE,KAAK,EAAED,QAAQM,aAAa;IAChE,MAAMC,SAAU,MAAMP,QAAQQ,eAAe,CAACC,mBAAmB,CAC/DV,KAAKW,UAAU,IAAI9D;IAGrB,MAAM,EAAEuD,KAAK,EAAEC,GAAG,EAAE,GAAGJ,QAAQE,SAAS;IAExC,MAAMzC,iBAAiBsC,KAAKY,IAAI,GAC3B5D,yBAAyBgD,KAAKY,IAAI,KAAuB7D,2BAC1DA;IACJ,MAAMmB,cAAcX,yBAAyB6C,MAAMS,OAAO,IAAIR,IAAIQ,OAAO,IAAInD,gBAAgBuC,QAAQtC,eAAe;IACpH,MAAMmD,aAAa7C,0BAA0BC;IAC7C,MAAMoC,SAASpC,cAAc;IAE7B,MAAM6C,WAAgD,MAAMP,OAAOQ,eAAe,CAAC;QACjFd;QACAU,MAAME;QACNV,OAAOA,MAAMa,WAAW;QACxBZ,KAAKA,IAAIY,WAAW;IACtB;IAEA,IAAIF,SAASG,MAAM,KAAK,SAAS;QAC/B,MAAM,IAAIC,MAAMJ,SAASK,KAAK;IAChC;IAEA,MAAM7C,SAASH,0BAA0B2C,SAASM,IAAI,CAACC,MAAM;IAE7D,OAAO;QACL/C,QAAQA;QACR4B,WAAW;YAAEC;YAAOC;QAAI;QACxBC;QACAiB,UAAU;YACRC,qBAAqBtB;QACvB;IACF;AACF,EAAE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/queries/victorialogs-time-series-query/types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAEtD,MAAM,WAAW,+BAA+B;IAC9C,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,kBAAkB,CAAC;IAChC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf"}
|
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
export { };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/queries/victorialogs-time-series-query/types.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 { DatasourceSelector } from '@perses-dev/core';\n\nexport interface VictoriaLogsTimeSeriesQuerySpec {\n query: string;\n datasource?: DatasourceSelector;\n step?: string;\n}\n"],"names":[],"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,WAIC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-tests.d.ts","sourceRoot":"","sources":["../../src/setup-tests.ts"],"names":[],"mappings":"AAAA,OAAO,2BAA2B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/setup-tests.ts"],"sourcesContent":["import '@testing-library/jest-dom';\n\n// Always mock e-charts during tests since we don't have a proper canvas in jsdom\njest.mock('echarts/core');\n"],"names":["jest","mock"],"mappings":"AAAA,OAAO,4BAA4B;AAEnC,iFAAiF;AACjFA,KAAKC,IAAI,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/variables/index.ts"],"names":[],"mappings":"AAaA,cAAc,4BAA4B,CAAC;AAC3C,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
export * from './victorialogs-field-names';
|
|
14
|
+
export * from './victorialogs-field-values';
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/variables/index.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\nexport * from './victorialogs-field-names';\nexport * from './victorialogs-field-values';\n"],"names":[],"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,cAAc,6BAA6B;AAC3C,cAAc,8BAA8B"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { DatasourceSelectValue } from '@perses-dev/plugin-system';
|
|
2
|
+
import { VictoriaLogsDatasourceSelector } from "../model";
|
|
3
|
+
export interface VictoriaLogsVariableOptionsBase {
|
|
4
|
+
datasource?: DatasourceSelectValue<VictoriaLogsDatasourceSelector>;
|
|
5
|
+
}
|
|
6
|
+
export type VictoriaLogsFieldNamesVariableOptions = VictoriaLogsVariableOptionsBase & {
|
|
7
|
+
query: string;
|
|
8
|
+
};
|
|
9
|
+
export type VictoriaLogsFieldValuesVariableOptions = VictoriaLogsVariableOptionsBase & {
|
|
10
|
+
field: string;
|
|
11
|
+
query: string;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/variables/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAClE,OAAO,EAAE,8BAA8B,EAAE,MAAM,UAAU,CAAC;AAE1D,MAAM,WAAW,+BAA+B;IAC9C,UAAU,CAAC,EAAE,qBAAqB,CAAC,8BAA8B,CAAC,CAAC;CACpE;AAED,MAAM,MAAM,qCAAqC,GAAG,+BAA+B,GAAG;IACpF,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,sCAAsC,GAAG,+BAA+B,GAAG;IACrF,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/variables/types.ts"],"sourcesContent":["import { DatasourceSelectValue } from '@perses-dev/plugin-system';\nimport { VictoriaLogsDatasourceSelector } from \"../model\";\n\nexport interface VictoriaLogsVariableOptionsBase {\n datasource?: DatasourceSelectValue<VictoriaLogsDatasourceSelector>;\n}\n\nexport type VictoriaLogsFieldNamesVariableOptions = VictoriaLogsVariableOptionsBase & {\n query: string;\n};\n\nexport type VictoriaLogsFieldValuesVariableOptions = VictoriaLogsVariableOptionsBase & {\n field: string;\n query: string;\n};\n"],"names":[],"mappings":"AAWA,WAGE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VictoriaLogsFieldItem, VictoriaLogsFieldNamesResponse, VictoriaLogsFieldValuesResponse } from '../model';
|
|
2
|
+
import { VariableOption } from '@perses-dev/plugin-system';
|
|
3
|
+
import { AbsoluteTimeRange, DatasourceSelector, StatusError } from '@perses-dev/core';
|
|
4
|
+
import { UseQueryResult } from '@tanstack/react-query';
|
|
5
|
+
export declare const fieldItemsToVariableOptions: (values?: VictoriaLogsFieldItem[]) => VariableOption[];
|
|
6
|
+
export declare function getVictoriaLogsTimeRange(timeRange: AbsoluteTimeRange): {
|
|
7
|
+
start: string;
|
|
8
|
+
end: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function useFieldNames(query: string, datasource: DatasourceSelector): UseQueryResult<VictoriaLogsFieldNamesResponse, StatusError>;
|
|
11
|
+
export declare function useFieldValues(field: string, query: string, datasource: DatasourceSelector): UseQueryResult<VictoriaLogsFieldValuesResponse, StatusError>;
|
|
12
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/variables/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,qBAAqB,EAAE,8BAA8B,EAAE,+BAA+B,EAAE,MAAM,UAAU,CAAC;AACtI,OAAO,EAAE,cAAc,EAAqC,MAAM,2BAA2B,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACrF,OAAO,EAAY,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAEjE,eAAO,MAAM,2BAA2B,GAAI,SAAS,qBAAqB,EAAE,KAAG,cAAc,EAM5F,CAAC;AAEF,wBAAgB,wBAAwB,CAAC,SAAS,EAAE,iBAAiB,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAMrG;AAED,wBAAgB,aAAa,CAC3B,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,kBAAkB,GAC7B,cAAc,CAAC,8BAA8B,EAAE,WAAW,CAAC,CAkB7D;AAED,wBAAgB,cAAc,CAC5B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,UAAU,EAAE,kBAAkB,GAC7B,cAAc,CAAC,+BAA+B,EAAE,WAAW,CAAC,CAmB9D"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { useDatasourceClient, useTimeRange } from '@perses-dev/plugin-system';
|
|
2
|
+
import { useQuery } from '@tanstack/react-query';
|
|
3
|
+
export const fieldItemsToVariableOptions = (values)=>{
|
|
4
|
+
if (!values) return [];
|
|
5
|
+
return values.map((value)=>({
|
|
6
|
+
value: value.value,
|
|
7
|
+
label: value.value
|
|
8
|
+
}));
|
|
9
|
+
};
|
|
10
|
+
export function getVictoriaLogsTimeRange(timeRange) {
|
|
11
|
+
const { start, end } = timeRange;
|
|
12
|
+
return {
|
|
13
|
+
start: start.toISOString(),
|
|
14
|
+
end: end.toISOString()
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export function useFieldNames(query, datasource) {
|
|
18
|
+
const { absoluteTimeRange: { start, end } } = useTimeRange();
|
|
19
|
+
const { data: client } = useDatasourceClient(datasource);
|
|
20
|
+
const enabled = !!client && !!query;
|
|
21
|
+
return useQuery({
|
|
22
|
+
enabled: enabled,
|
|
23
|
+
queryKey: [
|
|
24
|
+
'datasource',
|
|
25
|
+
datasource.name,
|
|
26
|
+
'query',
|
|
27
|
+
query
|
|
28
|
+
],
|
|
29
|
+
queryFn: async ()=>{
|
|
30
|
+
return await client.fieldNames({
|
|
31
|
+
start: start.toISOString(),
|
|
32
|
+
end: end.toISOString(),
|
|
33
|
+
query: query
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export function useFieldValues(field, query, datasource) {
|
|
39
|
+
const { absoluteTimeRange: { start, end } } = useTimeRange();
|
|
40
|
+
const { data: client } = useDatasourceClient(datasource);
|
|
41
|
+
const enabled = !!client && !!query;
|
|
42
|
+
return useQuery({
|
|
43
|
+
enabled: enabled,
|
|
44
|
+
queryKey: [
|
|
45
|
+
'field',
|
|
46
|
+
field,
|
|
47
|
+
'datasource',
|
|
48
|
+
datasource.name,
|
|
49
|
+
'query',
|
|
50
|
+
query
|
|
51
|
+
],
|
|
52
|
+
queryFn: async ()=>{
|
|
53
|
+
return await client.fieldValues({
|
|
54
|
+
query: query,
|
|
55
|
+
field: field,
|
|
56
|
+
start: start.toISOString(),
|
|
57
|
+
end: end.toISOString()
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/variables/utils.ts"],"sourcesContent":["import { VictoriaLogsClient, VictoriaLogsFieldItem, VictoriaLogsFieldNamesResponse, VictoriaLogsFieldValuesResponse } from '../model';\nimport { VariableOption, useDatasourceClient, useTimeRange } from '@perses-dev/plugin-system';\nimport { AbsoluteTimeRange, DatasourceSelector, StatusError } from '@perses-dev/core'\nimport { useQuery, UseQueryResult } from '@tanstack/react-query';\n\nexport const fieldItemsToVariableOptions = (values?: VictoriaLogsFieldItem[]): VariableOption[] => {\n if (!values) return [];\n return values.map((value) => ({\n value: value.value,\n label: value.value,\n }));\n};\n\nexport function getVictoriaLogsTimeRange(timeRange: AbsoluteTimeRange): { start: string; end: string } {\n const { start, end } = timeRange;\n return {\n start: start.toISOString(),\n end: end.toISOString(),\n };\n}\n\nexport function useFieldNames(\n query: string,\n datasource: DatasourceSelector\n): UseQueryResult<VictoriaLogsFieldNamesResponse, StatusError> {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<VictoriaLogsClient>(datasource);\n const enabled = !!client && !!query;\n\n return useQuery<VictoriaLogsFieldNamesResponse, StatusError>({\n enabled: enabled,\n queryKey: ['datasource', datasource.name, 'query', query],\n queryFn: async () => {\n return await client!.fieldNames({\n start: start.toISOString(),\n end: end.toISOString(),\n query: query,\n });\n },\n });\n}\n\nexport function useFieldValues(\n field: string,\n query: string,\n datasource: DatasourceSelector\n): UseQueryResult<VictoriaLogsFieldValuesResponse, StatusError> {\n const {\n absoluteTimeRange: { start, end },\n } = useTimeRange();\n const { data: client } = useDatasourceClient<VictoriaLogsClient>(datasource);\n const enabled = !!client && !!query;\n\n return useQuery<VictoriaLogsFieldValuesResponse, StatusError>({\n enabled: enabled,\n queryKey: ['field', field, 'datasource', datasource.name, 'query', query],\n queryFn: async () => {\n return await client!.fieldValues({\n query: query,\n field: field,\n start: start.toISOString(),\n end: end.toISOString(),\n });\n },\n });\n}\n"],"names":["useDatasourceClient","useTimeRange","useQuery","fieldItemsToVariableOptions","values","map","value","label","getVictoriaLogsTimeRange","timeRange","start","end","toISOString","useFieldNames","query","datasource","absoluteTimeRange","data","client","enabled","queryKey","name","queryFn","fieldNames","useFieldValues","field","fieldValues"],"mappings":"AACA,SAAyBA,mBAAmB,EAAEC,YAAY,QAAQ,4BAA4B;AAE9F,SAASC,QAAQ,QAAwB,wBAAwB;AAEjE,OAAO,MAAMC,8BAA8B,CAACC;IAC1C,IAAI,CAACA,QAAQ,OAAO,EAAE;IACtB,OAAOA,OAAOC,GAAG,CAAC,CAACC,QAAW,CAAA;YAC5BA,OAAOA,MAAMA,KAAK;YAClBC,OAAOD,MAAMA,KAAK;QACpB,CAAA;AACF,EAAE;AAEF,OAAO,SAASE,yBAAyBC,SAA4B;IACnE,MAAM,EAAEC,KAAK,EAAEC,GAAG,EAAE,GAAGF;IACvB,OAAO;QACLC,OAAOA,MAAME,WAAW;QACxBD,KAAKA,IAAIC,WAAW;IACtB;AACF;AAEA,OAAO,SAASC,cACdC,KAAa,EACbC,UAA8B;IAE9B,MAAM,EACJC,mBAAmB,EAAEN,KAAK,EAAEC,GAAG,EAAE,EAClC,GAAGV;IACJ,MAAM,EAAEgB,MAAMC,MAAM,EAAE,GAAGlB,oBAAwCe;IACjE,MAAMI,UAAU,CAAC,CAACD,UAAU,CAAC,CAACJ;IAE9B,OAAOZ,SAAsD;QAC3DiB,SAASA;QACTC,UAAU;YAAC;YAAcL,WAAWM,IAAI;YAAE;YAASP;SAAM;QACzDQ,SAAS;YACP,OAAO,MAAMJ,OAAQK,UAAU,CAAC;gBAC9Bb,OAAOA,MAAME,WAAW;gBACxBD,KAAKA,IAAIC,WAAW;gBACpBE,OAAOA;YACT;QACF;IACF;AACF;AAEA,OAAO,SAASU,eACdC,KAAa,EACbX,KAAa,EACbC,UAA8B;IAE9B,MAAM,EACJC,mBAAmB,EAAEN,KAAK,EAAEC,GAAG,EAAE,EAClC,GAAGV;IACJ,MAAM,EAAEgB,MAAMC,MAAM,EAAE,GAAGlB,oBAAwCe;IACjE,MAAMI,UAAU,CAAC,CAACD,UAAU,CAAC,CAACJ;IAE9B,OAAOZ,SAAuD;QAC5DiB,SAASA;QACTC,UAAU;YAAC;YAASK;YAAO;YAAcV,WAAWM,IAAI;YAAE;YAASP;SAAM;QACzEQ,SAAS;YACP,OAAO,MAAMJ,OAAQQ,WAAW,CAAC;gBAC/BZ,OAAOA;gBACPW,OAAOA;gBACPf,OAAOA,MAAME,WAAW;gBACxBD,KAAKA,IAAIC,WAAW;YACtB;QACF;IACF;AACF"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { VariablePlugin } from '@perses-dev/plugin-system';
|
|
2
|
+
import { VictoriaLogsFieldNamesVariableOptions } from '../types';
|
|
3
|
+
export declare const VictoriaLogsFieldNamesVariable: VariablePlugin<VictoriaLogsFieldNamesVariableOptions>;
|
|
4
|
+
//# sourceMappingURL=VictoriaLogsFieldNamesVariable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VictoriaLogsFieldNamesVariable.d.ts","sourceRoot":"","sources":["../../../../src/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariable.tsx"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EAMf,MAAM,2BAA2B,CAAC;AAInC,OAAO,EAAE,qCAAqC,EAAE,MAAM,UAAU,CAAC;AAEjE,eAAO,MAAM,8BAA8B,EAAE,cAAc,CAAC,qCAAqC,CAwBhG,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { replaceVariables, parseVariables, datasourceSelectValueToSelector, isVariableDatasource } from '@perses-dev/plugin-system';
|
|
2
|
+
import { DEFAULT_VICTORIALOGS, VICTORIALOGS_DATASOURCE_KIND } from '../../model';
|
|
3
|
+
import { VictoriaLogsFieldNamesVariableEditor } from './VictoriaLogsFieldNamesVariableEditor';
|
|
4
|
+
import { fieldItemsToVariableOptions, getVictoriaLogsTimeRange } from '../utils';
|
|
5
|
+
export const VictoriaLogsFieldNamesVariable = {
|
|
6
|
+
getVariableOptions: async (spec, ctx)=>{
|
|
7
|
+
const datasourceSelector = datasourceSelectValueToSelector(spec.datasource ?? DEFAULT_VICTORIALOGS, ctx.variables, await ctx.datasourceStore.listDatasourceSelectItems(VICTORIALOGS_DATASOURCE_KIND)) ?? DEFAULT_VICTORIALOGS;
|
|
8
|
+
const client = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);
|
|
9
|
+
const timeRange = getVictoriaLogsTimeRange(ctx.timeRange);
|
|
10
|
+
const query = replaceVariables(spec.query, ctx.variables);
|
|
11
|
+
const { values } = query ? await client.fieldNames({
|
|
12
|
+
query: query,
|
|
13
|
+
...timeRange
|
|
14
|
+
}) : {
|
|
15
|
+
values: []
|
|
16
|
+
};
|
|
17
|
+
return {
|
|
18
|
+
data: fieldItemsToVariableOptions(values)
|
|
19
|
+
};
|
|
20
|
+
},
|
|
21
|
+
dependsOn: (spec)=>{
|
|
22
|
+
const queryVariables = parseVariables(spec.query);
|
|
23
|
+
const datasourceVariables = spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];
|
|
24
|
+
return {
|
|
25
|
+
variables: [
|
|
26
|
+
...queryVariables,
|
|
27
|
+
...datasourceVariables
|
|
28
|
+
]
|
|
29
|
+
};
|
|
30
|
+
},
|
|
31
|
+
OptionsEditorComponent: VictoriaLogsFieldNamesVariableEditor,
|
|
32
|
+
createInitialOptions: ()=>({
|
|
33
|
+
query: ''
|
|
34
|
+
})
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
//# sourceMappingURL=VictoriaLogsFieldNamesVariable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariable.tsx"],"sourcesContent":["import {\n VariablePlugin,\n GetVariableOptionsContext,\n replaceVariables,\n parseVariables,\n datasourceSelectValueToSelector,\n isVariableDatasource,\n} from '@perses-dev/plugin-system';\nimport { VictoriaLogsClient, DEFAULT_VICTORIALOGS, VICTORIALOGS_DATASOURCE_KIND } from '../../model';\nimport { VictoriaLogsFieldNamesVariableEditor } from './VictoriaLogsFieldNamesVariableEditor';\nimport { fieldItemsToVariableOptions, getVictoriaLogsTimeRange } from '../utils';\nimport { VictoriaLogsFieldNamesVariableOptions } from '../types';\n\nexport const VictoriaLogsFieldNamesVariable: VariablePlugin<VictoriaLogsFieldNamesVariableOptions> = {\n getVariableOptions: async (spec: VictoriaLogsFieldNamesVariableOptions, ctx: GetVariableOptionsContext) => {\n const datasourceSelector = datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_VICTORIALOGS,\n ctx.variables,\n await ctx.datasourceStore.listDatasourceSelectItems(VICTORIALOGS_DATASOURCE_KIND)\n ) ?? DEFAULT_VICTORIALOGS;\n const client: VictoriaLogsClient = await ctx.datasourceStore.getDatasourceClient(datasourceSelector);\n const timeRange = getVictoriaLogsTimeRange(ctx.timeRange);\n const query = replaceVariables(spec.query, ctx.variables);\n\n const { values } = query ? await client.fieldNames({ query: query, ...timeRange }) : { values: [] };\n return {\n data: fieldItemsToVariableOptions(values),\n };\n },\n dependsOn: (spec: VictoriaLogsFieldNamesVariableOptions) => {\n const queryVariables = parseVariables(spec.query);\n const datasourceVariables =\n spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];\n return { variables: [...queryVariables, ...datasourceVariables] };\n },\n OptionsEditorComponent: VictoriaLogsFieldNamesVariableEditor,\n createInitialOptions: () => ({ query: '' }),\n};\n"],"names":["replaceVariables","parseVariables","datasourceSelectValueToSelector","isVariableDatasource","DEFAULT_VICTORIALOGS","VICTORIALOGS_DATASOURCE_KIND","VictoriaLogsFieldNamesVariableEditor","fieldItemsToVariableOptions","getVictoriaLogsTimeRange","VictoriaLogsFieldNamesVariable","getVariableOptions","spec","ctx","datasourceSelector","datasource","variables","datasourceStore","listDatasourceSelectItems","client","getDatasourceClient","timeRange","query","values","fieldNames","data","dependsOn","queryVariables","datasourceVariables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,SAGEA,gBAAgB,EAChBC,cAAc,EACdC,+BAA+B,EAC/BC,oBAAoB,QACf,4BAA4B;AACnC,SAA6BC,oBAAoB,EAAEC,4BAA4B,QAAQ,cAAc;AACrG,SAASC,oCAAoC,QAAQ,yCAAyC;AAC9F,SAASC,2BAA2B,EAAEC,wBAAwB,QAAQ,WAAW;AAGjF,OAAO,MAAMC,iCAAwF;IACnGC,oBAAoB,OAAOC,MAA6CC;QACtE,MAAMC,qBAAqBX,gCACzBS,KAAKG,UAAU,IAAIV,sBACnBQ,IAAIG,SAAS,EACb,MAAMH,IAAII,eAAe,CAACC,yBAAyB,CAACZ,kCACjDD;QACL,MAAMc,SAA6B,MAAMN,IAAII,eAAe,CAACG,mBAAmB,CAACN;QACjF,MAAMO,YAAYZ,yBAAyBI,IAAIQ,SAAS;QACxD,MAAMC,QAAQrB,iBAAiBW,KAAKU,KAAK,EAAET,IAAIG,SAAS;QAExD,MAAM,EAAEO,MAAM,EAAE,GAAGD,QAAQ,MAAMH,OAAOK,UAAU,CAAC;YAAEF,OAAOA;YAAO,GAAGD,SAAS;QAAC,KAAK;YAAEE,QAAQ,EAAE;QAAC;QAClG,OAAO;YACLE,MAAMjB,4BAA4Be;QACpC;IACF;IACAG,WAAW,CAACd;QACV,MAAMe,iBAAiBzB,eAAeU,KAAKU,KAAK;QAChD,MAAMM,sBACJhB,KAAKG,UAAU,IAAIX,qBAAqBQ,KAAKG,UAAU,IAAIb,eAAeU,KAAKG,UAAU,IAAI,EAAE;QACjG,OAAO;YAAEC,WAAW;mBAAIW;mBAAmBC;aAAoB;QAAC;IAClE;IACAC,wBAAwBtB;IACxBuB,sBAAsB,IAAO,CAAA;YAAER,OAAO;QAAG,CAAA;AAC3C,EAAE"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { OptionsEditorProps } from '@perses-dev/plugin-system';
|
|
2
|
+
import { ReactElement } from 'react';
|
|
3
|
+
import { VictoriaLogsFieldNamesVariableOptions } from '../types';
|
|
4
|
+
export declare function VictoriaLogsFieldNamesVariableEditor(props: OptionsEditorProps<VictoriaLogsFieldNamesVariableOptions>): ReactElement;
|
|
5
|
+
//# sourceMappingURL=VictoriaLogsFieldNamesVariableEditor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"VictoriaLogsFieldNamesVariableEditor.d.ts","sourceRoot":"","sources":["../../../../src/variables/victorialogs-field-names/VictoriaLogsFieldNamesVariableEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAGL,kBAAkB,EAGnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAyB,MAAM,OAAO,CAAC;AAS5D,OAAO,EACL,qCAAqC,EACtC,MAAM,UAAU,CAAC;AAElB,wBAAgB,oCAAoC,CAClD,KAAK,EAAE,kBAAkB,CAAC,qCAAqC,CAAC,GAC/D,YAAY,CAoEd"}
|