@perses-dev/prometheus-plugin 0.1.0 → 0.2.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 ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of the copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import { PluginSetupFunction } from '@perses-dev/core';
1
+ import { PluginSetupFunction } from '@perses-dev/plugin-system';
2
2
  export declare const setup: PluginSetupFunction;
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAMvD,eAAO,MAAM,KAAK,EAAE,mBAiCnB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAMhE,eAAO,MAAM,KAAK,EAAE,mBAiCnB,CAAC"}
package/dist/index.js CHANGED
@@ -1,50 +1 @@
1
- // Copyright 2021 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 { PrometheusGraphQueryKind, usePrometheusGraphQuery } from './plugins/graph-query';
14
- import { IntervalKind, useIntervalValues } from './plugins/interval-variable';
15
- import { PrometheusLabelNamesKind, usePrometheusLabelNames } from './plugins/label-names-variable';
16
- import { PrometheusLabelValuesKind, usePrometheusLabelValues } from './plugins/label-values-variable';
17
- export const setup = (registerPlugin) => {
18
- registerPlugin({
19
- pluginType: 'Variable',
20
- kind: PrometheusLabelNamesKind,
21
- validate: undefined,
22
- plugin: {
23
- useVariableOptions: usePrometheusLabelNames,
24
- },
25
- });
26
- registerPlugin({
27
- pluginType: 'Variable',
28
- kind: PrometheusLabelValuesKind,
29
- validate: undefined,
30
- plugin: {
31
- useVariableOptions: usePrometheusLabelValues,
32
- },
33
- });
34
- registerPlugin({
35
- pluginType: 'Variable',
36
- kind: IntervalKind,
37
- validate: undefined,
38
- plugin: {
39
- useVariableOptions: useIntervalValues,
40
- },
41
- });
42
- registerPlugin({
43
- pluginType: 'GraphQuery',
44
- kind: PrometheusGraphQueryKind,
45
- validate: undefined,
46
- plugin: {
47
- useGraphQuery: usePrometheusGraphQuery,
48
- },
49
- });
50
- };
1
+ import{PrometheusGraphQueryKind,usePrometheusGraphQuery}from"./plugins/graph-query";import{IntervalKind,useIntervalValues}from"./plugins/interval-variable";import{PrometheusLabelNamesKind,usePrometheusLabelNames}from"./plugins/label-names-variable";import{PrometheusLabelValuesKind,usePrometheusLabelValues}from"./plugins/label-values-variable";export const setup=e=>{e({pluginType:"Variable",kind:PrometheusLabelNamesKind,validate:void 0,plugin:{useVariableOptions:usePrometheusLabelNames}}),e({pluginType:"Variable",kind:PrometheusLabelValuesKind,validate:void 0,plugin:{useVariableOptions:usePrometheusLabelValues}}),e({pluginType:"Variable",kind:IntervalKind,validate:void 0,plugin:{useVariableOptions:useIntervalValues}}),e({pluginType:"GraphQuery",kind:PrometheusGraphQueryKind,validate:void 0,plugin:{useGraphQuery:usePrometheusGraphQuery}})};
@@ -49,7 +49,7 @@ export interface RangeQueryRequestParameters {
49
49
  }
50
50
  export declare type RangeQueryResponse = ApiResponse<MatrixData>;
51
51
  export interface SeriesRequestParameters {
52
- match: string[];
52
+ 'match[]': string[];
53
53
  start: UnixTimestampSeconds;
54
54
  end: UnixTimestampSeconds;
55
55
  }
@@ -57,14 +57,14 @@ export declare type SeriesResponse = ApiResponse<Metric[]>;
57
57
  export interface LabelNamesRequestParameters {
58
58
  start?: UnixTimestampSeconds;
59
59
  end?: UnixTimestampSeconds;
60
- match?: string[];
60
+ 'match[]'?: string[];
61
61
  }
62
62
  export declare type LabelNamesResponse = ApiResponse<string[]>;
63
63
  export interface LabelValuesRequestParameters {
64
64
  labelName: string;
65
65
  start?: UnixTimestampSeconds;
66
66
  end?: UnixTimestampSeconds;
67
- match?: string[];
67
+ 'match[]'?: string[];
68
68
  }
69
69
  export declare type LabelValuesResponse = ApiResponse<string[]>;
70
70
  export interface MetricMetadata {
@@ -1 +1 @@
1
- {"version":3,"file":"api-types.d.ts","sourceRoot":"","sources":["../../src/model/api-types.ts"],"names":[],"mappings":"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"}
1
+ {"version":3,"file":"api-types.d.ts","sourceRoot":"","sources":["../../src/model/api-types.ts"],"names":[],"mappings":"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"}
@@ -1,13 +1 @@
1
- // Copyright 2021 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 {};
1
+ export{};
@@ -3,5 +3,9 @@ export interface PrometheusSpecDatasource extends DatasourceSpecDefinition {
3
3
  kind: 'Prometheus';
4
4
  http: HTTPConfig;
5
5
  }
6
- export declare function usePrometheusConfig(selector: DatasourceSelector): PrometheusSpecDatasource;
6
+ export declare function usePrometheusConfig(selector?: DatasourceSelector): {
7
+ spec: PrometheusSpecDatasource;
8
+ kind: "GlobalDatasource";
9
+ metadata: import("@perses-dev/core").Metadata;
10
+ };
7
11
  //# sourceMappingURL=datasource.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/model/datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,kBAAkB,EAClB,wBAAwB,EACxB,UAAU,EAEX,MAAM,kBAAkB,CAAC;AAE1B,MAAM,WAAW,wBAAyB,SAAQ,wBAAwB;IACxE,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,UAAU,CAAC;CAClB;AAMD,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,kBAAkB,4BAE/D"}
1
+ {"version":3,"file":"datasource.d.ts","sourceRoot":"","sources":["../../src/model/datasource.ts"],"names":[],"mappings":"AAaA,OAAO,EAEL,kBAAkB,EAClB,wBAAwB,EACxB,UAAU,EACX,MAAM,kBAAkB,CAAC;AAG1B,MAAM,WAAW,wBAAyB,SAAQ,wBAAwB;IACxE,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,EAAE,UAAU,CAAC;CAClB;AAMD,wBAAgB,mBAAmB,CAAC,QAAQ,CAAC,EAAE,kBAAkB;;;;EAmBhE"}
@@ -1,19 +1 @@
1
- // Copyright 2021 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 { useDataSourceConfig, } from '@perses-dev/core';
14
- function isPrometheusDatasource(def) {
15
- return def.kind === 'Prometheus';
16
- }
17
- export function usePrometheusConfig(selector) {
18
- return useDataSourceConfig(selector, isPrometheusDatasource);
19
- }
1
+ import{useDatasources}from"@perses-dev/plugin-system";function isPrometheusDatasource(e){return"Prometheus"===e.kind}export function usePrometheusConfig(e){const o=useDatasources(),r=void 0===e?[o.defaultDatasource]:o.getDatasources(e);if(r.length>1)throw new Error("More than one Datasource found");const t=r[0];if(void 0===t)throw new Error("Datasource not found");const s=t.spec;if(isPrometheusDatasource(s))return{...t,spec:s};throw new Error("Datasource is not a valid Prometheus Datasource")}
@@ -1,39 +1 @@
1
- // Copyright 2021 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
- /**
14
- * Parse a ValueTuple from a PromServer response into the a millisecond-based
15
- * unix time and a numeric sample value.
16
- */
17
- export function parseValueTuple(data) {
18
- const [unixTimeSeconds, sampleValue] = data;
19
- // Prom returns unix time in seconds, so convert to ms
20
- return [unixTimeSeconds * 1000, parseSampleValue(sampleValue)];
21
- }
22
- /**
23
- * Parses a string sample value from Prometheus, usually included as the
24
- * second member of a ValueTuple.
25
- */
26
- export function parseSampleValue(sampleValue) {
27
- // Account for Prometheus' representation of +/- infinity, otherwise just
28
- // parse the sample value as a float
29
- let value;
30
- switch (sampleValue) {
31
- case '+Inf':
32
- value = Number.POSITIVE_INFINITY;
33
- case '-Inf':
34
- value = Number.NEGATIVE_INFINITY;
35
- default:
36
- value = parseFloat(sampleValue);
37
- }
38
- return value;
39
- }
1
+ export function parseValueTuple(e){const[a,r]=e;return[1e3*a,parseSampleValue(r)]}export function parseSampleValue(e){let a;switch(e){case"+Inf":a=Number.POSITIVE_INFINITY;case"-Inf":a=Number.NEGATIVE_INFINITY;default:a=parseFloat(e)}return a}
@@ -1,22 +1,24 @@
1
1
  import { UseQueryOptions } from 'react-query';
2
2
  import { DatasourceSelector } from '@perses-dev/core';
3
3
  import { InstantQueryRequestParameters, InstantQueryResponse, LabelNamesRequestParameters, LabelNamesResponse, LabelValuesRequestParameters, LabelValuesResponse, RangeQueryRequestParameters, RangeQueryResponse } from './api-types';
4
- export declare type QueryOptions = Pick<UseQueryOptions, 'enabled'>;
4
+ export declare type QueryOptions = Pick<UseQueryOptions, 'enabled'> & {
5
+ datasource?: DatasourceSelector;
6
+ };
5
7
  /**
6
8
  * Calls the `/api/v1/query` endpoint to get metrics data.
7
9
  */
8
- export declare function useInstantQuery(datasource: DatasourceSelector, params: InstantQueryRequestParameters, queryOptions?: QueryOptions): import("react-query").UseQueryResult<InstantQueryResponse, Error>;
10
+ export declare function useInstantQuery(params: InstantQueryRequestParameters, queryOptions?: QueryOptions): import("react-query").UseQueryResult<InstantQueryResponse, Error>;
9
11
  /**
10
12
  * Calls the `/api/v1/query_range` endpoint to get metrics data.
11
13
  */
12
- export declare function useRangeQuery(datasource: DatasourceSelector, params: RangeQueryRequestParameters, queryOptions?: QueryOptions): import("react-query").UseQueryResult<RangeQueryResponse, Error>;
14
+ export declare function useRangeQuery(params: RangeQueryRequestParameters, queryOptions?: QueryOptions): import("react-query").UseQueryResult<RangeQueryResponse, Error>;
13
15
  /**
14
16
  * Calls the `/api/v1/labels` endpoint to get a list of label names.
15
17
  */
16
- export declare function useLabelNames(datasource: DatasourceSelector, params: LabelNamesRequestParameters, queryOptions?: QueryOptions): import("react-query").UseQueryResult<LabelNamesResponse, Error>;
18
+ export declare function useLabelNames(params: LabelNamesRequestParameters, queryOptions?: QueryOptions): import("react-query").UseQueryResult<LabelNamesResponse, Error>;
17
19
  /**
18
20
  * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of
19
21
  * values for a label.
20
22
  */
21
- export declare function useLabelValues(datasource: DatasourceSelector, params: LabelValuesRequestParameters, queryOptions?: QueryOptions): import("react-query").UseQueryResult<LabelValuesResponse, Error>;
23
+ export declare function useLabelValues(params: LabelValuesRequestParameters, queryOptions?: QueryOptions): import("react-query").UseQueryResult<LabelValuesResponse, Error>;
22
24
  //# sourceMappingURL=prometheus-client.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAY,eAAe,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAsB,kBAAkB,EAAa,MAAM,kBAAkB,CAAC;AACrF,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAGrB,oBAAY,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC;AAE5D;;GAEG;AACH,wBAAgB,eAAe,CAC7B,UAAU,EAAE,kBAAkB,EAC9B,MAAM,EAAE,6BAA6B,EACrC,YAAY,CAAC,EAAE,YAAY,qEAS5B;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,kBAAkB,EAC9B,MAAM,EAAE,2BAA2B,EACnC,YAAY,CAAC,EAAE,YAAY,mEAS5B;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,kBAAkB,EAC9B,MAAM,EAAE,2BAA2B,EACnC,YAAY,CAAC,EAAE,YAAY,mEAS5B;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAC5B,UAAU,EAAE,kBAAkB,EAC9B,MAAM,EAAE,4BAA4B,EACpC,YAAY,CAAC,EAAE,YAAY,oEAW5B"}
1
+ {"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../src/model/prometheus-client.ts"],"names":[],"mappings":"AAaA,OAAO,EAAY,eAAe,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAsB,kBAAkB,EAAa,MAAM,kBAAkB,CAAC;AACrF,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EACnB,MAAM,aAAa,CAAC;AAGrB,oBAAY,YAAY,GAAG,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,GAAG;IAC5D,UAAU,CAAC,EAAE,kBAAkB,CAAC;CACjC,CAAC;AAEF;;GAEG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,6BAA6B,EAAE,YAAY,CAAC,EAAE,YAAY,qEAEjG;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,CAAC,EAAE,YAAY,mEAE7F;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,2BAA2B,EAAE,YAAY,CAAC,EAAE,YAAY,mEAE7F;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,4BAA4B,EAAE,YAAY,CAAC,EAAE,YAAY,oEAI/F"}
@@ -1,97 +1 @@
1
- // Copyright 2021 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 { useQuery } from 'react-query';
14
- import { buildDatasourceURL, fetchJson } from '@perses-dev/core';
15
- import { usePrometheusConfig } from './datasource';
16
- /**
17
- * Calls the `/api/v1/query` endpoint to get metrics data.
18
- */
19
- export function useInstantQuery(datasource, params, queryOptions) {
20
- return useQueryWithPost(datasource, '/api/v1/query', params, undefined, queryOptions);
21
- }
22
- /**
23
- * Calls the `/api/v1/query_range` endpoint to get metrics data.
24
- */
25
- export function useRangeQuery(datasource, params, queryOptions) {
26
- return useQueryWithPost(datasource, '/api/v1/query_range', params, undefined, queryOptions);
27
- }
28
- /**
29
- * Calls the `/api/v1/labels` endpoint to get a list of label names.
30
- */
31
- export function useLabelNames(datasource, params, queryOptions) {
32
- return useQueryWithPost(datasource, '/api/v1/labels', params, { match: 'match[]' }, queryOptions);
33
- }
34
- /**
35
- * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of
36
- * values for a label.
37
- */
38
- export function useLabelValues(datasource, params, queryOptions) {
39
- const { labelName, ...searchParams } = params;
40
- const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;
41
- return useQueryWithGet(datasource, apiURI, searchParams, { match: 'match[]' }, queryOptions);
42
- }
43
- function useQueryWithGet(datasourceSelector, apiURI, params, rename, queryOptions) {
44
- const httpConfig = usePrometheusConfig(datasourceSelector).http;
45
- const datasourceURL = buildDatasourceURL(datasourceSelector.name, httpConfig);
46
- const key = [datasourceURL, apiURI, params];
47
- return useQuery(key, () => {
48
- let url = `${datasourceURL}${apiURI}`;
49
- const urlParams = createSearchParams(params, rename).toString();
50
- if (urlParams !== '') {
51
- url += `?${urlParams}`;
52
- }
53
- return fetchJson(url, { method: 'GET' });
54
- }, queryOptions);
55
- }
56
- function useQueryWithPost(datasourceSelector, apiURI, params, rename, queryOptions) {
57
- const httpConfig = usePrometheusConfig(datasourceSelector).http;
58
- const datasourceURL = buildDatasourceURL(datasourceSelector.name, httpConfig);
59
- const key = [datasourceURL, apiURI, params];
60
- return useQuery(key, () => {
61
- const url = `${datasourceURL}${apiURI}`;
62
- const init = {
63
- method: 'POST',
64
- headers: {
65
- 'Content-Type': 'application/x-www-form-urlencoded',
66
- },
67
- body: createSearchParams(params, rename),
68
- };
69
- return fetchJson(url, init);
70
- }, queryOptions);
71
- }
72
- /**
73
- * Creates URLSearchParams from a request params object.
74
- */
75
- function createSearchParams(params, rename) {
76
- const searchParams = new URLSearchParams();
77
- for (const key in params) {
78
- const value = params[key];
79
- if (value === undefined)
80
- continue;
81
- // Allow keys to be renamed when mapping to parameters
82
- const renamed = rename === null || rename === void 0 ? void 0 : rename[key];
83
- const name = renamed !== undefined ? renamed : key;
84
- if (typeof value === 'string') {
85
- searchParams.append(name, value);
86
- continue;
87
- }
88
- if (typeof value === 'number') {
89
- searchParams.append(name, value.toString());
90
- continue;
91
- }
92
- for (const val of value) {
93
- searchParams.append(name, val);
94
- }
95
- }
96
- return searchParams;
97
- }
1
+ import{useQuery}from"react-query";import{buildDatasourceURL,fetchJson}from"@perses-dev/core";import{usePrometheusConfig}from"./datasource";export function useInstantQuery(e,t){return useQueryWithPost("/api/v1/query",e,t)}export function useRangeQuery(e,t){return useQueryWithPost("/api/v1/query_range",e,t)}export function useLabelNames(e,t){return useQueryWithPost("/api/v1/labels",e,t)}export function useLabelValues(e,t){const{labelName:r,...o}=e;return useQueryWithGet(`/api/v1/label/${encodeURIComponent(r)}/values`,o,t)}function useQueryWithGet(e,t,r){const o=usePrometheusConfig(null==r?void 0:r.datasource),u=buildDatasourceURL(o.metadata.name,o.spec.http);return useQuery([u,e,t],(()=>{let r=`${u}${e}`;const o=createSearchParams(t).toString();return""!==o&&(r+=`?${o}`),fetchJson(r,{method:"GET"})}),r)}function useQueryWithPost(e,t,r){const o=usePrometheusConfig(null==r?void 0:r.datasource),u=buildDatasourceURL(o.metadata.name,o.spec.http);return useQuery([u,e,t],(()=>{const r=`${u}${e}`,o={method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:createSearchParams(t)};return fetchJson(r,o)}),r)}function createSearchParams(e){const t=new URLSearchParams;for(const r in e){const o=e[r];if(void 0!==o)if("string"!=typeof o)if("number"!=typeof o)for(const e of o)t.append(r,e);else t.append(r,o.toString());else t.append(r,o)}return t}
@@ -1 +1 @@
1
- {"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../src/model/templating.ts"],"names":[],"mappings":"AAkBA;;GAEG;AACH,oBAAY,cAAc,GAAG,MAAM,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,eAAe,CAAC,EAAE,cAAc,EAAE;;;EAkB3E;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc;;;EAWvE"}
1
+ {"version":3,"file":"templating.d.ts","sourceRoot":"","sources":["../../src/model/templating.ts"],"names":[],"mappings":"AAmBA;;GAEG;AACH,oBAAY,cAAc,GAAG,MAAM,CAAC;AAEpC;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,eAAe,CAAC,EAAE,cAAc,EAAE;;;EAkB3E;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc;;;EAWvE"}
@@ -1,116 +1 @@
1
- // Copyright 2021 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 { Duration, parser, StringLiteral } from 'lezer-promql';
14
- import { DEFAULT_ALL_VALUE, useMemoized, useDashboardVariables } from '@perses-dev/core';
15
- const REPLACE_IN_NODE_TYPES = new Set([StringLiteral, Duration]);
16
- /**
17
- * Replaces template variable placeholders with variable values from the current
18
- * dashbboard in multiple template strings. Since template strings are often
19
- * used as request parameters, the results are memoized and only recalculated
20
- * if the templateStrings or variable values change.
21
- */
22
- export function useReplaceTemplateStrings(templateStrings) {
23
- const variablesState = useDashboardVariables();
24
- // Replace template string placeholders with variable values
25
- return useMemoized(() => {
26
- const result = [];
27
- const needsVariableValuesFor = new Set();
28
- for (const templateString of templateStrings !== null && templateStrings !== void 0 ? templateStrings : []) {
29
- const replaced = replaceTemplateVariables(templateString, variablesState);
30
- result.push(replaced.result);
31
- for (const varName of replaced.needsVariableValuesFor) {
32
- needsVariableValuesFor.add(varName);
33
- }
34
- }
35
- return { result, needsVariableValuesFor };
36
- }, [templateStrings, variablesState]);
37
- }
38
- /**
39
- * Replaces template variable placeholders with variable values from the current
40
- * dashboard in a single template string. Since template strings are often
41
- * used as request parameters, the results are memoized and only recalculated
42
- * if the templateString or variable values change.
43
- */
44
- export function useReplaceTemplateString(templateString) {
45
- const variablesState = useDashboardVariables();
46
- // Replace template string placeholders with variable values
47
- return useMemoized(() => {
48
- if (templateString === undefined) {
49
- return { result: '', needsVariableValuesFor: new Set() };
50
- }
51
- return replaceTemplateVariables(templateString, variablesState);
52
- }, [templateString, variablesState]);
53
- }
54
- /**
55
- * Replace template variable placeholders with variable values.
56
- */
57
- function replaceTemplateVariables(templateString, variablesState) {
58
- const needsVariableValuesFor = new Set();
59
- let indexAdjustment = 0;
60
- const tree = parser.parse(templateString);
61
- const cursor = tree.cursor();
62
- do {
63
- // Only replace variables in string literals for now
64
- if (REPLACE_IN_NODE_TYPES.has(cursor.node.type.id))
65
- continue;
66
- let { from, to } = cursor.node;
67
- from += indexAdjustment;
68
- to += indexAdjustment;
69
- let nodeText = templateString.substring(from, to);
70
- nodeText = nodeText.replaceAll(/\$([a-zA-Z0-9_-]+)/g, (match, variableName) => {
71
- const state = variablesState[variableName];
72
- if (state === undefined) {
73
- throw new Error(`Unknown variable '${variableName}'`);
74
- }
75
- const { value, options } = state;
76
- let replacement;
77
- if (Array.isArray(value)) {
78
- let selectedValues = value;
79
- // Is the default ALL value?
80
- if (value.length === 1 && value[0] === DEFAULT_ALL_VALUE) {
81
- // For the default ALL value, we want to use all options as the
82
- // selected values
83
- if (options === undefined) {
84
- // Wait until options are loaded before we do replacement
85
- needsVariableValuesFor.add(variableName);
86
- return match;
87
- }
88
- selectedValues = options;
89
- }
90
- // TODO: Escape v for regex
91
- replacement = selectedValues.map((v) => v).join('|');
92
- }
93
- else {
94
- replacement = escapeVariableValue(value);
95
- }
96
- return replacement;
97
- });
98
- // Replace the string literal with the new one and since that may change the
99
- // overall length of the string, keep track of an "index adjustment" so we
100
- // can shift positions in the tree accordingly
101
- const oldLength = to - from;
102
- indexAdjustment += nodeText.length - oldLength;
103
- templateString = templateString.substring(0, from) + nodeText + templateString.substring(from + oldLength);
104
- } while (cursor.next());
105
- return {
106
- result: templateString,
107
- needsVariableValuesFor,
108
- };
109
- }
110
- const SINGLE_BACKSLASH = '\\';
111
- const DOUBLE_BACKSLASH = '\\\\';
112
- function escapeVariableValue(value) {
113
- // TODO: What about ["'`]? Do we need to know what kind of quotes the
114
- // string literal is using?
115
- return value.replaceAll(SINGLE_BACKSLASH, DOUBLE_BACKSLASH);
116
- }
1
+ import{Duration,parser,StringLiteral}from"lezer-promql";import{useMemoized,DEFAULT_ALL_VALUE}from"@perses-dev/core";import{useTemplateVariables}from"@perses-dev/plugin-system";const REPLACE_IN_NODE_TYPES=new Set([StringLiteral,Duration]);export function useReplaceTemplateStrings(e){const{variables:r}=useTemplateVariables();return useMemoized((()=>{const t=[],a=new Set;for(const s of null!=e?e:[]){const e=replaceTemplateVariables(s,r);t.push(e.result);for(const r of e.needsVariableValuesFor)a.add(r)}return{result:t,needsVariableValuesFor:a}}),[e,r])}export function useReplaceTemplateString(e){const{variables:r}=useTemplateVariables();return useMemoized((()=>void 0===e?{result:"",needsVariableValuesFor:new Set}:replaceTemplateVariables(e,r)),[e,r])}function replaceTemplateVariables(e,r){const t=new Set;let a=0;const s=parser.parse(e).cursor();do{if(REPLACE_IN_NODE_TYPES.has(s.node.type.id))continue;let{from:l,to:n}=s.node;l+=a,n+=a;let o=e.substring(l,n);o=o.replaceAll(/\$([a-zA-Z0-9_-]+)/g,((e,a)=>{const s=r[a];if(void 0===s)throw new Error(`Unknown variable '${a}'`);const{value:l,options:n}=s;let o;if(Array.isArray(l)){let r=l;if(1===l.length&&l[0]===DEFAULT_ALL_VALUE){if(void 0===n)return t.add(a),e;r=n}o=r.map((e=>e)).join("|")}else o=escapeVariableValue(l);return o}));const i=n-l;a+=o.length-i,e=e.substring(0,l)+o+e.substring(l+i)}while(s.next());return{result:e,needsVariableValuesFor:t}}const SINGLE_BACKSLASH="\\",DOUBLE_BACKSLASH="\\\\";function escapeVariableValue(e){return e.replaceAll("\\","\\\\")}
@@ -17,7 +17,7 @@ export declare function useDashboardPrometheusTimeRange(): {
17
17
  * a "safe" step based on the max data points we want to allow returning from
18
18
  * a Prom query.
19
19
  */
20
- export declare function usePanelRangeStep(timeRange: PrometheusTimeRange, minStepSeconds?: number, resolution?: number): number;
20
+ export declare function usePanelRangeStep(timeRange: PrometheusTimeRange, minStepSeconds?: number, resolution?: number, suggestedStepMs?: number): number;
21
21
  /**
22
22
  * Converts a DurationString to seconds, rounding down.
23
23
  */
@@ -1 +1 @@
1
- {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/model/time.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,EAKf,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,oBAAoB,CAAC;IAC5B,GAAG,EAAE,oBAAoB,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,+BAA+B;;;EAU9C;AAMD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,mBAAmB,EAAE,cAAc,SAAK,EAAE,UAAU,SAAI,UAwBpG;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc,sBAMvE"}
1
+ {"version":3,"file":"time.d.ts","sourceRoot":"","sources":["../../src/model/time.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAoC,MAAM,kBAAkB,CAAC;AAIpF,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAC;AAEnD,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,oBAAoB,CAAC;IAC5B,GAAG,EAAE,oBAAoB,CAAC;CAC3B;AAED;;GAEG;AACH,wBAAgB,+BAA+B;;;EAY9C;AAMD;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAC/B,SAAS,EAAE,mBAAmB,EAC9B,cAAc,SAAK,EACnB,UAAU,SAAI,EACd,eAAe,SAAI,UAiBpB;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,cAAc,CAAC,EAAE,cAAc,sBAMvE"}
@@ -1,68 +1 @@
1
- // Copyright 2021 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, useMemoized, usePanelState, useDashboardTimeRange, } from '@perses-dev/core';
14
- import { milliseconds, getUnixTime } from 'date-fns';
15
- import { useRef } from 'react';
16
- /**
17
- * Get the time range for the current dashboard, converted to Prometheus time.
18
- */
19
- export function useDashboardPrometheusTimeRange() {
20
- const { start, end } = useDashboardTimeRange();
21
- // Only recalculate the time range if the value on the dashboard changes
22
- return useMemoized(() => {
23
- return {
24
- start: Math.ceil(getUnixTime(start)),
25
- end: Math.ceil(getUnixTime(end)),
26
- };
27
- }, [start, end]);
28
- }
29
- // Max data points to allow returning from a Prom Query, used to calculate a
30
- // "safe" step for a range query
31
- const MAX_PROM_DATA_POINTS = 10000;
32
- /**
33
- * Gets the step to use for a Panel range query. Tries to take into account
34
- * the width of the panel, any minimum step/resolution set by the user, and
35
- * a "safe" step based on the max data points we want to allow returning from
36
- * a Prom query.
37
- */
38
- export function usePanelRangeStep(timeRange, minStepSeconds = 15, resolution = 1) {
39
- // Keep track of the latest panel width in a ref
40
- const { contentDimensions } = usePanelState();
41
- const panelWidth = useRef(contentDimensions === null || contentDimensions === void 0 ? void 0 : contentDimensions.width);
42
- panelWidth.current = contentDimensions === null || contentDimensions === void 0 ? void 0 : contentDimensions.width;
43
- // Whenever the time range changes, recalculate the appropriate step
44
- return useMemoized(() => {
45
- const queryRangeSeconds = timeRange.end - timeRange.start;
46
- // TODO: Should we try to suggest more "rounded" step values based around
47
- // time increments that make sense (e.g. 15s, 30s, 1m, 5m, etc.)
48
- let suggestedStep = 0;
49
- if (panelWidth.current !== undefined) {
50
- suggestedStep = Math.floor(queryRangeSeconds / panelWidth.current);
51
- }
52
- let safeStep = queryRangeSeconds / MAX_PROM_DATA_POINTS;
53
- if (safeStep > 1) {
54
- safeStep = Math.ceil(safeStep);
55
- }
56
- return Math.max(suggestedStep * resolution, minStepSeconds, safeStep);
57
- }, [timeRange, minStepSeconds, resolution]);
58
- }
59
- /**
60
- * Converts a DurationString to seconds, rounding down.
61
- */
62
- export function getDurationStringSeconds(durationString) {
63
- if (durationString === undefined)
64
- return undefined;
65
- const duration = parseDurationString(durationString);
66
- const ms = milliseconds(duration);
67
- return Math.floor(ms / 1000);
68
- }
1
+ import{parseDurationString,useMemoized}from"@perses-dev/core";import{useTimeRange}from"@perses-dev/plugin-system";import{milliseconds,getUnixTime}from"date-fns";import{useRef}from"react";export function useDashboardPrometheusTimeRange(){const{timeRange:{start:e,end:t}}=useTimeRange();return useMemoized((()=>({start:Math.ceil(getUnixTime(e)),end:Math.ceil(getUnixTime(t))})),[e,t])}const MAX_PROM_DATA_POINTS=1e4;export function usePanelRangeStep(e,t=15,r=1,n=0){const i=useRef(1e3*n);return i.current=1e3*n,useMemoized((()=>{let n=(e.end-e.start)/1e4;return n>1&&(n=Math.ceil(n)),Math.max(i.current*r,t,n)}),[e,t,r])}export function getDurationStringSeconds(e){if(void 0===e)return;const t=parseDurationString(e),r=milliseconds(t);return Math.floor(r/1e3)}
@@ -1,4 +1,5 @@
1
- import { DurationString, GraphQueryDefinition, JsonObject, UseGraphQueryHook } from '@perses-dev/core';
1
+ import { DurationString, JsonObject } from '@perses-dev/core';
2
+ import { GraphQueryDefinition, UseGraphQueryHook, UseGraphQueryHookOptions } from '@perses-dev/plugin-system';
2
3
  import { TemplateString } from '../model/templating';
3
4
  export declare const PrometheusGraphQueryKind: "PrometheusGraphQuery";
4
5
  declare type PrometheusGraphQuery = GraphQueryDefinition<GraphQueryOptions>;
@@ -7,6 +8,6 @@ interface GraphQueryOptions extends JsonObject {
7
8
  min_step?: DurationString;
8
9
  resolution?: number;
9
10
  }
10
- export declare function usePrometheusGraphQuery(definition: PrometheusGraphQuery): ReturnType<UseGraphQueryHook<GraphQueryOptions>>;
11
+ export declare function usePrometheusGraphQuery(definition: PrometheusGraphQuery, hookOptions?: UseGraphQueryHookOptions): ReturnType<UseGraphQueryHook<GraphQueryOptions>>;
11
12
  export {};
12
13
  //# sourceMappingURL=graph-query.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"graph-query.d.ts","sourceRoot":"","sources":["../../src/plugins/graph-query.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,EAEd,oBAAoB,EACpB,UAAU,EAEV,iBAAiB,EAElB,MAAM,kBAAkB,CAAC;AAM1B,OAAO,EAAE,cAAc,EAA4B,MAAM,qBAAqB,CAAC;AAG/E,eAAO,MAAM,wBAAwB,wBAAkC,CAAC;AAExE,aAAK,oBAAoB,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;AAEpE,UAAU,iBAAkB,SAAQ,UAAU;IAC5C,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,oBAAoB,GAC/B,UAAU,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC,CAsElD"}
1
+ {"version":3,"file":"graph-query.d.ts","sourceRoot":"","sources":["../../src/plugins/graph-query.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,UAAU,EAAe,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAEL,oBAAoB,EACpB,iBAAiB,EACjB,wBAAwB,EACzB,MAAM,2BAA2B,CAAC;AAMnC,OAAO,EAAE,cAAc,EAA4B,MAAM,qBAAqB,CAAC;AAG/E,eAAO,MAAM,wBAAwB,wBAAkC,CAAC;AAExE,aAAK,oBAAoB,GAAG,oBAAoB,CAAC,iBAAiB,CAAC,CAAC;AAEpE,UAAU,iBAAkB,SAAQ,UAAU;IAC5C,KAAK,EAAE,cAAc,CAAC;IACtB,QAAQ,CAAC,EAAE,cAAc,CAAC;IAC1B,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,oBAAoB,EAChC,WAAW,CAAC,EAAE,wBAAwB,GACrC,UAAU,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC,CAoElD"}
@@ -1,77 +1 @@
1
- // Copyright 2021 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 { useDashboardSpec, useMemoized, } from '@perses-dev/core';
14
- import { fromUnixTime } from 'date-fns';
15
- import { useMemo } from 'react';
16
- import { parseValueTuple } from '../model/parse-sample-values';
17
- import { useRangeQuery } from '../model/prometheus-client';
18
- import { useReplaceTemplateString } from '../model/templating';
19
- import { getDurationStringSeconds, useDashboardPrometheusTimeRange, usePanelRangeStep } from '../model/time';
20
- export const PrometheusGraphQueryKind = 'PrometheusGraphQuery';
21
- export function usePrometheusGraphQuery(definition) {
22
- const spec = useDashboardSpec();
23
- const minStep = getDurationStringSeconds(definition.options.min_step);
24
- const timeRange = useDashboardPrometheusTimeRange();
25
- const step = usePanelRangeStep(timeRange, minStep);
26
- // Align the time range so that it's a multiple of the step (TODO: we may
27
- // ultimately want to return this from the hook so that charts will know what
28
- // time range was actually used?)
29
- const { start, end } = useMemoized(() => {
30
- const { start, end } = timeRange;
31
- const utcOffsetSec = new Date().getTimezoneOffset() * 60;
32
- const alignedEnd = Math.floor((end + utcOffsetSec) / step) * step - utcOffsetSec;
33
- const alignedStart = Math.floor((start + utcOffsetSec) / step) * step - utcOffsetSec;
34
- return {
35
- start: alignedStart,
36
- end: alignedEnd,
37
- };
38
- }, [timeRange, step]);
39
- const { result: query, needsVariableValuesFor } = useReplaceTemplateString(definition.options.query);
40
- const request = {
41
- query,
42
- start,
43
- end,
44
- step,
45
- };
46
- const { data: response, isLoading: loading, error, } = useRangeQuery(spec.datasource, request, {
47
- enabled: needsVariableValuesFor.size === 0,
48
- });
49
- const data = useMemo(() => {
50
- if (response === undefined)
51
- return undefined;
52
- if (response.status === 'error')
53
- return undefined;
54
- // TODO: Maybe do a proper Iterable implementation that defers some of this
55
- // processing until its needed
56
- const chartData = {
57
- timeRange: { start: fromUnixTime(start), end: fromUnixTime(end) },
58
- stepMs: step * 1000,
59
- series: response.data.result.map((value) => {
60
- const { metric, values } = value;
61
- // Name the series after the metric labels or if no metric, just use the
62
- // overall query
63
- let name = Object.entries(metric)
64
- .map(([labelName, labelValue]) => `${labelName}="${labelValue}"`)
65
- .join(', ');
66
- if (name === '')
67
- name = query;
68
- return {
69
- name,
70
- values: values.map(parseValueTuple),
71
- };
72
- }),
73
- };
74
- return chartData;
75
- }, [response, start, end, step, query]);
76
- return { data, loading, error: error !== null && error !== void 0 ? error : undefined };
77
- }
1
+ import{useMemoized}from"@perses-dev/core";import{fromUnixTime}from"date-fns";import{useMemo}from"react";import{parseValueTuple}from"../model/parse-sample-values";import{useRangeQuery}from"../model/prometheus-client";import{useReplaceTemplateString}from"../model/templating";import{getDurationStringSeconds,useDashboardPrometheusTimeRange,usePanelRangeStep}from"../model/time";export const PrometheusGraphQueryKind="PrometheusGraphQuery";export function usePrometheusGraphQuery(e,r){const t=getDurationStringSeconds(e.options.min_step),o=useDashboardPrometheusTimeRange(),s=usePanelRangeStep(o,t,void 0,null==r?void 0:r.suggestedStepMs),{start:a,end:n}=useMemoized((()=>{const{start:e,end:r}=o,t=60*(new Date).getTimezoneOffset(),a=Math.floor((r+t)/s)*s-t;return{start:Math.floor((e+t)/s)*s-t,end:a}}),[o,s]),{result:m,needsVariableValuesFor:i}=useReplaceTemplateString(e.options.query),u={query:m,start:a,end:n,step:s},{data:p,isLoading:l,error:d}=useRangeQuery(u,{enabled:0===i.size});return{data:useMemo((()=>{if(void 0!==p&&"error"!==p.status)return{timeRange:{start:fromUnixTime(a),end:fromUnixTime(n)},stepMs:1e3*s,series:p.data.result.map((e=>{const{metric:r,values:t}=e;let o=Object.entries(r).map((([e,r])=>`${e}="${r}"`)).join(", ");return""===o&&(o=m),{name:o,values:t.map(parseValueTuple)}}))}}),[p,a,n,s,m]),loading:l,error:null!=d?d:void 0}}
@@ -1,4 +1,5 @@
1
- import { JsonObject, DurationString, UseVariableOptionsHook, VariableDefinition } from '@perses-dev/core';
1
+ import { JsonObject, DurationString, VariableDefinition } from '@perses-dev/core';
2
+ import { UseVariableOptionsHook } from '@perses-dev/plugin-system';
2
3
  export declare const IntervalKind: "Inverval";
3
4
  declare type IntervalVariable = VariableDefinition<IntervalOptions>;
4
5
  interface IntervalOptions extends JsonObject {
@@ -1 +1 @@
1
- {"version":3,"file":"interval-variable.d.ts","sourceRoot":"","sources":["../../src/plugins/interval-variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAE1G,eAAO,MAAM,YAAY,YAAsB,CAAC;AAEhD,aAAK,gBAAgB,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAAC;AAE5D,UAAU,eAAgB,SAAQ,UAAU;IAC1C,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE;QACL,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,cAAc,CAAC;KAC9B,CAAC;CACH;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,gBAAgB,GAAG,UAAU,CAAC,sBAAsB,CAAC,eAAe,CAAC,CAAC,CAMnH"}
1
+ {"version":3,"file":"interval-variable.d.ts","sourceRoot":"","sources":["../../src/plugins/interval-variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClF,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAEnE,eAAO,MAAM,YAAY,YAAsB,CAAC;AAEhD,aAAK,gBAAgB,GAAG,kBAAkB,CAAC,eAAe,CAAC,CAAC;AAE5D,UAAU,eAAgB,SAAQ,UAAU;IAC1C,MAAM,EAAE,cAAc,EAAE,CAAC;IACzB,IAAI,CAAC,EAAE;QACL,UAAU,EAAE,MAAM,CAAC;QACnB,YAAY,EAAE,cAAc,CAAC;KAC9B,CAAC;CACH;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,UAAU,EAAE,gBAAgB,GAAG,UAAU,CAAC,sBAAsB,CAAC,eAAe,CAAC,CAAC,CAMnH"}
@@ -1,22 +1 @@
1
- // Copyright 2021 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 const IntervalKind = 'Inverval';
14
- /**
15
- * Variable plugin for getting a list of variable options from a predefined
16
- * list of duration values.
17
- */
18
- export function useIntervalValues(definition) {
19
- // TODO: What about auto?
20
- const { options: { values }, } = definition;
21
- return { loading: false, error: undefined, data: values };
22
- }
1
+ export const IntervalKind="Inverval";export function useIntervalValues(n){const{options:{values:e}}=n;return{loading:!1,error:void 0,data:e}}
@@ -1,4 +1,5 @@
1
- import { JsonObject, UseVariableOptionsHook, VariableDefinition } from '@perses-dev/core';
1
+ import { JsonObject, VariableDefinition } from '@perses-dev/core';
2
+ import { UseVariableOptionsHook } from '@perses-dev/plugin-system';
2
3
  import { TemplateString } from '../model/templating';
3
4
  export declare const PrometheusLabelNamesKind: "PrometheusLabelNames";
4
5
  declare type PrometheusLabelNames = VariableDefinition<LabelNamesOptions>;
@@ -1 +1 @@
1
- {"version":3,"file":"label-names-variable.d.ts","sourceRoot":"","sources":["../../src/plugins/label-names-variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAoB,sBAAsB,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC5G,OAAO,EAAE,cAAc,EAA6B,MAAM,qBAAqB,CAAC;AAKhF,eAAO,MAAM,wBAAwB,wBAAkC,CAAC;AAExE,aAAK,oBAAoB,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;AAElE,UAAU,iBAAkB,SAAQ,UAAU;IAC5C,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,oBAAoB,GAC/B,UAAU,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,CAAC,CA2BvD"}
1
+ {"version":3,"file":"label-names-variable.d.ts","sourceRoot":"","sources":["../../src/plugins/label-names-variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAClE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AACnE,OAAO,EAAE,cAAc,EAA6B,MAAM,qBAAqB,CAAC;AAKhF,eAAO,MAAM,wBAAwB,wBAAkC,CAAC;AAExE,aAAK,oBAAoB,GAAG,kBAAkB,CAAC,iBAAiB,CAAC,CAAC;AAElE,UAAU,iBAAkB,SAAQ,UAAU;IAC5C,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,oBAAoB,GAC/B,UAAU,CAAC,sBAAsB,CAAC,iBAAiB,CAAC,CAAC,CAyBvD"}
@@ -1,42 +1 @@
1
- // Copyright 2021 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 { useDashboardSpec } from '@perses-dev/core';
14
- import { useReplaceTemplateStrings } from '../model/templating';
15
- import { useDashboardPrometheusTimeRange } from '../model/time';
16
- import { useLabelNames } from '../model/prometheus-client';
17
- export const PrometheusLabelNamesKind = 'PrometheusLabelNames';
18
- /**
19
- * Get variable option values by running a Prometheus label names query.
20
- */
21
- export function usePrometheusLabelNames(definition) {
22
- var _a;
23
- const spec = useDashboardSpec();
24
- const { start, end } = useDashboardPrometheusTimeRange();
25
- const { result: match, needsVariableValuesFor } = useReplaceTemplateStrings(definition.options.match);
26
- // Make the request, pausing any requests that are still waiting on variable
27
- // values to be filled in/selected
28
- const request = {
29
- match,
30
- start,
31
- end,
32
- };
33
- const { data: response, isLoading: loading, error, } = useLabelNames(spec.datasource, request, {
34
- enabled: needsVariableValuesFor.size === 0,
35
- });
36
- const data = (_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : [];
37
- return {
38
- data: data,
39
- loading: loading || needsVariableValuesFor.size > 0,
40
- error: error !== null && error !== void 0 ? error : undefined,
41
- };
42
- }
1
+ import{useReplaceTemplateStrings}from"../model/templating";import{useDashboardPrometheusTimeRange}from"../model/time";import{useLabelNames}from"../model/prometheus-client";export const PrometheusLabelNamesKind="PrometheusLabelNames";export function usePrometheusLabelNames(e){var a;const{start:t,end:s}=useDashboardPrometheusTimeRange(),{result:o,needsVariableValuesFor:r}=useReplaceTemplateStrings(e.options.match),m={"match[]":o,start:t,end:s},{data:l,isLoading:i,error:n}=useLabelNames(m,{enabled:0===r.size});return{data:null!==(a=null==l?void 0:l.data)&&void 0!==a?a:[],loading:i||r.size>0,error:null!=n?n:void 0}}
@@ -1,4 +1,5 @@
1
- import { JsonObject, UseVariableOptionsHook, VariableDefinition } from '@perses-dev/core';
1
+ import { JsonObject, VariableDefinition } from '@perses-dev/core';
2
+ import { UseVariableOptionsHook } from '@perses-dev/plugin-system';
2
3
  import { TemplateString } from '../model/templating';
3
4
  export declare const PrometheusLabelValuesKind: "PrometheusLabelValues";
4
5
  declare type PrometheusLabelValues = VariableDefinition<LabelValuesOptions>;
@@ -1 +1 @@
1
- {"version":3,"file":"label-values-variable.d.ts","sourceRoot":"","sources":["../../src/plugins/label-values-variable.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,UAAU,EAGV,sBAAsB,EACtB,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,cAAc,EAA6B,MAAM,qBAAqB,CAAC;AAGhF,eAAO,MAAM,yBAAyB,yBAAmC,CAAC;AAE1E,aAAK,qBAAqB,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;AAEpE,UAAU,kBAAmB,SAAQ,UAAU;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,qBAAqB,GAChC,UAAU,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC,CA4BxD"}
1
+ {"version":3,"file":"label-values-variable.d.ts","sourceRoot":"","sources":["../../src/plugins/label-values-variable.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAe,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,sBAAsB,EAAE,MAAM,2BAA2B,CAAC;AAGnE,OAAO,EAAE,cAAc,EAA6B,MAAM,qBAAqB,CAAC;AAGhF,eAAO,MAAM,yBAAyB,yBAAmC,CAAC;AAE1E,aAAK,qBAAqB,GAAG,kBAAkB,CAAC,kBAAkB,CAAC,CAAC;AAEpE,UAAU,kBAAmB,SAAQ,UAAU;IAC7C,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,cAAc,EAAE,CAAC;CAC1B;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,EAAE,qBAAqB,GAChC,UAAU,CAAC,sBAAsB,CAAC,kBAAkB,CAAC,CAAC,CA0BxD"}
@@ -1,42 +1 @@
1
- // Copyright 2021 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 { useDashboardSpec, useMemoized, } from '@perses-dev/core';
14
- import { useDashboardPrometheusTimeRange } from '../model/time';
15
- import { useReplaceTemplateStrings } from '../model/templating';
16
- import { useLabelValues } from '../model/prometheus-client';
17
- export const PrometheusLabelValuesKind = 'PrometheusLabelValues';
18
- /**
19
- * Get variable option values by running a Prometheus label values query.
20
- */
21
- export function usePrometheusLabelValues(definition) {
22
- const spec = useDashboardSpec();
23
- const { start, end } = useDashboardPrometheusTimeRange();
24
- const { result: match, needsVariableValuesFor } = useReplaceTemplateStrings(definition.options.match);
25
- // Make the request, pausing any requests that are still waiting on variable
26
- // values to be filled in/selected
27
- const request = {
28
- labelName: definition.options.label_name,
29
- match,
30
- start,
31
- end,
32
- };
33
- const { data: response, isLoading: loading, error, } = useLabelValues(spec.datasource, request, {
34
- enabled: needsVariableValuesFor.size === 0,
35
- });
36
- const data = useMemoized(() => { var _a; return (_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : []; }, [response]);
37
- return {
38
- data: data,
39
- loading: loading || needsVariableValuesFor.size > 0,
40
- error: error !== null && error !== void 0 ? error : undefined,
41
- };
42
- }
1
+ import{useMemoized}from"@perses-dev/core";import{useDashboardPrometheusTimeRange}from"../model/time";import{useReplaceTemplateStrings}from"../model/templating";import{useLabelValues}from"../model/prometheus-client";export const PrometheusLabelValuesKind="PrometheusLabelValues";export function usePrometheusLabelValues(e){const{start:a,end:o}=useDashboardPrometheusTimeRange(),{result:r,needsVariableValuesFor:s}=useReplaceTemplateStrings(e.options.match),t={labelName:e.options.label_name,"match[]":r,start:a,end:o},{data:l,isLoading:m,error:u}=useLabelValues(t,{enabled:0===s.size});return{data:useMemoized((()=>{var e;return null!==(e=null==l?void 0:l.data)&&void 0!==e?e:[]}),[l]),loading:m||s.size>0,error:null!=u?u:void 0}}
package/package.json CHANGED
@@ -1,7 +1,16 @@
1
1
  {
2
2
  "name": "@perses-dev/prometheus-plugin",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Prometheus plugin for Perses",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://github.com/perses/perses/blob/main/README.md",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/perses/perses.git"
10
+ },
11
+ "bugs": {
12
+ "url": "https://github.com/perses/perses/issues"
13
+ },
5
14
  "module": "dist/index.js",
6
15
  "types": "dist/index.d.ts",
7
16
  "scripts": {
@@ -12,12 +21,18 @@
12
21
  "lint:fix": "eslint --fix src --ext .ts,.tsx"
13
22
  },
14
23
  "dependencies": {
15
- "@perses-dev/core": "^0.1.0",
24
+ "@lezer/lr": "^0.15.8",
25
+ "@perses-dev/core": "^0.2.0",
26
+ "@perses-dev/plugin-system": "^0.2.0",
16
27
  "date-fns": "^2.28.0",
17
- "lezer": "^0.13.5",
18
- "lezer-promql": "^0.20.0",
19
- "react": "^17.0.2",
20
- "react-query": "^3.34.8"
28
+ "lezer-promql": "^0.22.0",
29
+ "react-query": "^3.34.16"
30
+ },
31
+ "devDependencies": {
32
+ "react": "^17.0.2"
33
+ },
34
+ "peerDependencies": {
35
+ "react": "^17.0.2"
21
36
  },
22
37
  "perses": {
23
38
  "kind": "Plugin",
@@ -36,6 +51,5 @@
36
51
  },
37
52
  "files": [
38
53
  "dist"
39
- ],
40
- "license": "Apache-2.0"
54
+ ]
41
55
  }