@perses-dev/prometheus-plugin 0.57.0 → 0.58.0-beta.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/__mf/css/async/3829.85c2cbf6.css +1 -0
- package/__mf/font/inter-cyrillic-300-normal.432f2b21.woff +0 -0
- package/__mf/font/inter-cyrillic-300-normal.9da91009.woff2 +0 -0
- package/__mf/font/inter-cyrillic-400-normal.372704ff.woff2 +0 -0
- package/__mf/font/inter-cyrillic-400-normal.a6b6ef6f.woff +0 -0
- package/__mf/font/inter-cyrillic-500-normal.7c15bba8.woff2 +0 -0
- package/__mf/font/inter-cyrillic-500-normal.b9f8c929.woff +0 -0
- package/__mf/font/inter-cyrillic-600-normal.2f42892a.woff2 +0 -0
- package/__mf/font/inter-cyrillic-600-normal.c3987adc.woff +0 -0
- package/__mf/font/inter-cyrillic-700-normal.93eba3c3.woff +0 -0
- package/__mf/font/inter-cyrillic-700-normal.e9e5b2dc.woff2 +0 -0
- package/__mf/font/inter-cyrillic-900-normal.f285bd7a.woff2 +0 -0
- package/__mf/font/inter-cyrillic-900-normal.ffbd8a3a.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-300-normal.95bb9038.woff2 +0 -0
- package/__mf/font/inter-cyrillic-ext-300-normal.cfc143a9.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-400-normal.2a31c04b.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-400-normal.f572b170.woff2 +0 -0
- package/__mf/font/inter-cyrillic-ext-500-normal.5a6bb1da.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-500-normal.fe0d9b14.woff2 +0 -0
- package/__mf/font/inter-cyrillic-ext-600-normal.ecbdecad.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-600-normal.f7b3c15b.woff2 +0 -0
- package/__mf/font/inter-cyrillic-ext-700-normal.4b4022a6.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-700-normal.74b516d2.woff2 +0 -0
- package/__mf/font/inter-cyrillic-ext-900-normal.9970ddb5.woff +0 -0
- package/__mf/font/inter-cyrillic-ext-900-normal.a0d59adc.woff2 +0 -0
- package/__mf/font/inter-greek-300-normal.0d7be683.woff2 +0 -0
- package/__mf/font/inter-greek-300-normal.8f0b988e.woff +0 -0
- package/__mf/font/inter-greek-400-normal.cc58c11b.woff +0 -0
- package/__mf/font/inter-greek-400-normal.d7020e3c.woff2 +0 -0
- package/__mf/font/inter-greek-500-normal.d9a33207.woff +0 -0
- package/__mf/font/inter-greek-500-normal.f41f43db.woff2 +0 -0
- package/__mf/font/inter-greek-600-normal.4ec0c1c1.woff +0 -0
- package/__mf/font/inter-greek-600-normal.cc532937.woff2 +0 -0
- package/__mf/font/inter-greek-700-normal.5ec6c758.woff +0 -0
- package/__mf/font/inter-greek-700-normal.97f0eeeb.woff2 +0 -0
- package/__mf/font/inter-greek-900-normal.46b66369.woff2 +0 -0
- package/__mf/font/inter-greek-900-normal.9ae3a3c5.woff +0 -0
- package/__mf/font/inter-greek-ext-300-normal.10247a66.woff2 +0 -0
- package/__mf/font/inter-greek-ext-300-normal.4668e5cb.woff +0 -0
- package/__mf/font/inter-greek-ext-400-normal.4ce1df5d.woff2 +0 -0
- package/__mf/font/inter-greek-ext-400-normal.88ede1ea.woff +0 -0
- package/__mf/font/inter-greek-ext-500-normal.7a4aa726.woff +0 -0
- package/__mf/font/inter-greek-ext-500-normal.cbd51e2d.woff2 +0 -0
- package/__mf/font/inter-greek-ext-600-normal.089a95ee.woff +0 -0
- package/__mf/font/inter-greek-ext-600-normal.1f33d317.woff2 +0 -0
- package/__mf/font/inter-greek-ext-700-normal.31f1075d.woff +0 -0
- package/__mf/font/inter-greek-ext-700-normal.827cd618.woff2 +0 -0
- package/__mf/font/inter-greek-ext-900-normal.531bcee7.woff +0 -0
- package/__mf/font/inter-greek-ext-900-normal.8a9b36b9.woff2 +0 -0
- package/__mf/font/inter-latin-300-normal.15fb600d.woff2 +0 -0
- package/__mf/font/inter-latin-300-normal.6f95f590.woff +0 -0
- package/__mf/font/inter-latin-400-normal.2c7a775c.woff +0 -0
- package/__mf/font/inter-latin-400-normal.ef6d3f52.woff2 +0 -0
- package/__mf/font/inter-latin-500-normal.b7b43ace.woff2 +0 -0
- package/__mf/font/inter-latin-500-normal.cb4c8ceb.woff +0 -0
- package/__mf/font/inter-latin-600-normal.8fb1a964.woff2 +0 -0
- package/__mf/font/inter-latin-600-normal.ce0f5f43.woff +0 -0
- package/__mf/font/inter-latin-700-normal.953b7aa5.woff2 +0 -0
- package/__mf/font/inter-latin-700-normal.9c21d4dc.woff +0 -0
- package/__mf/font/inter-latin-900-normal.2a8028ec.woff2 +0 -0
- package/__mf/font/inter-latin-900-normal.fa252135.woff +0 -0
- package/__mf/font/inter-latin-ext-300-normal.167cc8c9.woff2 +0 -0
- package/__mf/font/inter-latin-ext-300-normal.f695be66.woff +0 -0
- package/__mf/font/inter-latin-ext-400-normal.32a25442.woff2 +0 -0
- package/__mf/font/inter-latin-ext-400-normal.4edcaace.woff +0 -0
- package/__mf/font/inter-latin-ext-500-normal.a19a84a6.woff +0 -0
- package/__mf/font/inter-latin-ext-500-normal.d9b491de.woff2 +0 -0
- package/__mf/font/inter-latin-ext-600-normal.38b075d8.woff2 +0 -0
- package/__mf/font/inter-latin-ext-600-normal.49faa47a.woff +0 -0
- package/__mf/font/inter-latin-ext-700-normal.93534b50.woff +0 -0
- package/__mf/font/inter-latin-ext-700-normal.b63daa1a.woff2 +0 -0
- package/__mf/font/inter-latin-ext-900-normal.0efdb307.woff +0 -0
- package/__mf/font/inter-latin-ext-900-normal.9c0fc2c7.woff2 +0 -0
- package/__mf/font/inter-vietnamese-300-normal.aad496d8.woff +0 -0
- package/__mf/font/inter-vietnamese-300-normal.ad9ef503.woff2 +0 -0
- package/__mf/font/inter-vietnamese-400-normal.a9dd2faf.woff +0 -0
- package/__mf/font/inter-vietnamese-400-normal.de4fc44f.woff2 +0 -0
- package/__mf/font/inter-vietnamese-500-normal.7c0a695f.woff2 +0 -0
- package/__mf/font/inter-vietnamese-500-normal.a3a73b95.woff +0 -0
- package/__mf/font/inter-vietnamese-600-normal.9d518599.woff2 +0 -0
- package/__mf/font/inter-vietnamese-600-normal.c5ce3fcb.woff +0 -0
- package/__mf/font/inter-vietnamese-700-normal.bc68b199.woff +0 -0
- package/__mf/font/inter-vietnamese-700-normal.faf12809.woff2 +0 -0
- package/__mf/font/inter-vietnamese-900-normal.2b782045.woff +0 -0
- package/__mf/font/inter-vietnamese-900-normal.e639b65a.woff2 +0 -0
- package/__mf/js/Prometheus.c5cd832d.js +7 -0
- package/__mf/js/async/1432.0bb0ef6b.js +1 -0
- package/__mf/js/async/1605.7c7a0998.js +110 -0
- package/__mf/js/async/{1605.dc180cb8.js.LICENSE.txt → 1605.7c7a0998.js.LICENSE.txt} +1 -1
- package/__mf/js/async/1616.ed429c53.js +1 -0
- package/__mf/js/async/1728.310a7d33.js +1 -0
- package/__mf/js/async/1969.a1e1979e.js +1 -0
- package/__mf/js/async/2043.c2948add.js +2 -0
- package/__mf/js/async/{2186.e58838a5.js → 2186.9a98bd8f.js} +2 -2
- package/__mf/js/async/2292.27a5ec4d.js +4 -0
- package/__mf/js/async/{9010.ca50fa9e.js.LICENSE.txt → 2292.27a5ec4d.js.LICENSE.txt} +1 -1
- package/__mf/js/async/2506.baf20a10.js +1 -0
- package/__mf/js/async/2814.fbf52858.js +1 -0
- package/__mf/js/async/3499.19c4bfa6.js +1 -0
- package/__mf/js/async/3829.f250b55a.js +7 -0
- package/__mf/js/async/{3652.6b591718.js.LICENSE.txt → 3829.f250b55a.js.LICENSE.txt} +19 -1
- package/__mf/js/async/392.233c0945.js +2 -0
- package/__mf/js/async/3963.81c8be7e.js +1 -0
- package/__mf/js/async/4121.9ed83f2a.js +2 -0
- package/__mf/js/async/4402.99ae853d.js +1 -0
- package/__mf/js/async/4626.e7ed0d7d.js +1 -0
- package/__mf/js/async/4800.cc42977e.js +22 -0
- package/__mf/js/async/4887.8af3673d.js +1 -0
- package/__mf/js/async/4987.f7360bdf.js +1 -0
- package/__mf/js/async/5002.bd952313.js +1 -0
- package/__mf/js/async/5071.5fcfd9a8.js +1 -0
- package/__mf/js/async/5440.52ec91ad.js +2 -0
- package/__mf/js/async/5587.e4d331db.js +1 -0
- package/__mf/js/async/5697.e17ba256.js +1 -0
- package/__mf/js/async/5763.ccf403b7.js +1 -0
- package/__mf/js/async/5922.ba33c996.js +1 -0
- package/__mf/js/async/6274.f04c9ecd.js +2 -0
- package/__mf/js/async/6438.b86a2aba.js +1 -0
- package/__mf/js/async/6507.71182781.js +1 -0
- package/__mf/js/async/7177.0ab860e0.js +1 -0
- package/__mf/js/async/7192.bbf62500.js +1 -0
- package/__mf/js/async/7462.e9a1c8bc.js +2 -0
- package/__mf/js/async/7647.82297501.js +1 -0
- package/__mf/js/async/7862.e13fbb9d.js +2 -0
- package/__mf/js/async/7894.9fe90396.js +1 -0
- package/__mf/js/async/7968.253f5f1d.js +1 -0
- package/__mf/js/async/7978.be30c741.js +1 -0
- package/__mf/js/async/8292.11dc2ca3.js +1 -0
- package/__mf/js/async/8356.e845a073.js +1 -0
- package/__mf/js/async/8470.84935087.js +2 -0
- package/__mf/js/async/{3996.69a9c1dc.js → 8634.e3cfb057.js} +1 -1
- package/__mf/js/async/873.6aafbb7b.js +1 -0
- package/__mf/js/async/8888.3a188176.js +1 -0
- package/__mf/js/async/9184.e6de21be.js +1 -0
- package/__mf/js/async/9235.85fb6b63.js +1 -0
- package/__mf/js/async/941.075ed563.js +2 -0
- package/__mf/js/async/9588.dfdaeff2.js +1 -0
- package/__mf/js/async/9745.0a6c90a2.js +1 -0
- package/__mf/js/async/9836.888f4ed2.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusDatasource.d4892cae.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusExplorer.681841d8.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.86c44577.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.ff683936.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.bac03b61.js +1 -0
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.9a495e56.js +1 -0
- package/__mf/js/main.afe2fc64.js +7 -0
- package/lib/cjs/model/prometheus-client.js +22 -17
- package/lib/cjs/plugins/PrometheusDatasourceEditor.js +10 -48
- package/lib/cjs/plugins/PrometheusLabelNamesVariable.js +3 -2
- package/lib/cjs/plugins/PrometheusLabelValuesVariable.js +3 -2
- package/lib/cjs/plugins/PrometheusPromQLVariable.js +3 -2
- package/lib/cjs/plugins/interpolation.js +54 -0
- package/lib/cjs/plugins/prometheus-datasource.js +15 -42
- package/lib/cjs/plugins/prometheus-time-series-query/get-time-series-data.js +10 -2
- package/lib/model/api-types.d.ts +1 -1
- package/lib/model/api-types.d.ts.map +1 -1
- package/lib/model/api-types.js.map +1 -1
- package/lib/model/prometheus-client.d.ts +16 -13
- package/lib/model/prometheus-client.d.ts.map +1 -1
- package/lib/model/prometheus-client.js +19 -16
- package/lib/model/prometheus-client.js.map +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.d.ts.map +1 -1
- package/lib/plugins/PrometheusDatasourceEditor.js +11 -8
- package/lib/plugins/PrometheusDatasourceEditor.js.map +1 -1
- package/lib/plugins/PrometheusLabelNamesVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusLabelNamesVariable.js +3 -2
- package/lib/plugins/PrometheusLabelNamesVariable.js.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusLabelValuesVariable.js +3 -2
- package/lib/plugins/PrometheusLabelValuesVariable.js.map +1 -1
- package/lib/plugins/PrometheusPromQLVariable.d.ts.map +1 -1
- package/lib/plugins/PrometheusPromQLVariable.js +3 -2
- package/lib/plugins/PrometheusPromQLVariable.js.map +1 -1
- package/lib/plugins/interpolation.d.ts +12 -0
- package/lib/plugins/interpolation.d.ts.map +1 -0
- package/lib/plugins/interpolation.js +38 -0
- package/lib/plugins/interpolation.js.map +1 -0
- package/lib/plugins/prometheus-datasource.d.ts.map +1 -1
- package/lib/plugins/prometheus-datasource.js +16 -43
- package/lib/plugins/prometheus-datasource.js.map +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.d.ts.map +1 -1
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.js +10 -2
- package/lib/plugins/prometheus-time-series-query/get-time-series-data.js.map +1 -1
- package/lib/plugins/types.d.ts +2 -1
- package/lib/plugins/types.d.ts.map +1 -1
- package/lib/plugins/types.js.map +1 -1
- package/mf-manifest.json +305 -293
- package/mf-stats.json +321 -293
- package/package.json +6 -6
- package/__mf/css/async/1233.d3010b86.css +0 -1
- package/__mf/css/async/1324.d3010b86.css +0 -1
- package/__mf/css/async/9518.d3010b86.css +0 -1
- 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/Prometheus.9877d89e.js +0 -6
- package/__mf/js/async/1233.0ab88b51.js +0 -1
- package/__mf/js/async/1324.ce01eced.js +0 -1
- package/__mf/js/async/1432.0c3e4ed0.js +0 -1
- package/__mf/js/async/1605.dc180cb8.js +0 -110
- package/__mf/js/async/1616.7587ce79.js +0 -1
- package/__mf/js/async/1728.531c96f9.js +0 -1
- package/__mf/js/async/1969.372d36b8.js +0 -1
- package/__mf/js/async/2043.d0fbb886.js +0 -2
- package/__mf/js/async/2506.1e336b3b.js +0 -1
- package/__mf/js/async/3184.6b4ad42e.js +0 -1
- package/__mf/js/async/3499.bef2e2e5.js +0 -1
- package/__mf/js/async/3652.6b591718.js +0 -7
- package/__mf/js/async/392.f1b4a590.js +0 -2
- package/__mf/js/async/3963.5fef6ffb.js +0 -1
- package/__mf/js/async/4121.828d661d.js +0 -2
- package/__mf/js/async/425.1ec8867f.js +0 -1
- package/__mf/js/async/4626.173e602a.js +0 -1
- package/__mf/js/async/4657.f0c3ccd6.js +0 -2
- package/__mf/js/async/4987.c12b89cb.js +0 -1
- package/__mf/js/async/5002.e4f54e8e.js +0 -1
- package/__mf/js/async/5071.e1c33fa7.js +0 -1
- package/__mf/js/async/529.2303b01b.js +0 -1
- package/__mf/js/async/54.e6002704.js +0 -22
- package/__mf/js/async/5440.8ced5513.js +0 -2
- package/__mf/js/async/5587.4d72fc35.js +0 -1
- package/__mf/js/async/5763.4ba478ff.js +0 -1
- package/__mf/js/async/5922.d1619ac1.js +0 -1
- package/__mf/js/async/6274.478a68f8.js +0 -2
- package/__mf/js/async/6283.181cb622.js +0 -2
- package/__mf/js/async/6969.b959b6f8.js +0 -1
- package/__mf/js/async/7177.205c9aaf.js +0 -1
- package/__mf/js/async/7192.d835931b.js +0 -1
- package/__mf/js/async/7894.9c5245d7.js +0 -1
- package/__mf/js/async/7968.6ac0ce96.js +0 -1
- package/__mf/js/async/7978.9532d5b8.js +0 -1
- package/__mf/js/async/8356.789e1dfb.js +0 -1
- package/__mf/js/async/8470.9b14a625.js +0 -2
- package/__mf/js/async/873.448eab23.js +0 -1
- package/__mf/js/async/8888.59eb50a2.js +0 -1
- package/__mf/js/async/9010.ca50fa9e.js +0 -2
- package/__mf/js/async/9020.ebc1cad3.js +0 -1
- package/__mf/js/async/9184.43a8d927.js +0 -1
- package/__mf/js/async/9235.36c3cd8c.js +0 -1
- package/__mf/js/async/9351.715f25c3.js +0 -1
- package/__mf/js/async/941.53b13124.js +0 -2
- package/__mf/js/async/9518.38e38a33.js +0 -1
- package/__mf/js/async/9588.9081c7de.js +0 -1
- package/__mf/js/async/9605.a92ec9c1.js +0 -1
- package/__mf/js/async/9836.00da6086.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusDatasource.b97f9012.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusExplorer.eba3b416.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelNamesVariable.bd38a89c.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusLabelValuesVariable.eb12e168.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusPromQLVariable.7ccb0601.js +0 -1
- package/__mf/js/async/__federation_expose_PrometheusTimeSeriesQuery.08f11ea9.js +0 -1
- package/__mf/js/main.78fc6444.js +0 -6
- /package/__mf/js/async/{2043.d0fbb886.js.LICENSE.txt → 2043.c2948add.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{392.f1b4a590.js.LICENSE.txt → 392.233c0945.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{4121.828d661d.js.LICENSE.txt → 4121.9ed83f2a.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{54.e6002704.js.LICENSE.txt → 4800.cc42977e.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{5440.8ced5513.js.LICENSE.txt → 5440.52ec91ad.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{6274.478a68f8.js.LICENSE.txt → 6274.f04c9ecd.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{4657.f0c3ccd6.js.LICENSE.txt → 7462.e9a1c8bc.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{6283.181cb622.js.LICENSE.txt → 7862.e13fbb9d.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{8470.9b14a625.js.LICENSE.txt → 8470.84935087.js.LICENSE.txt} +0 -0
- /package/__mf/js/async/{941.53b13124.js.LICENSE.txt → 941.075ed563.js.LICENSE.txt} +0 -0
|
@@ -22,6 +22,14 @@ Object.defineProperty(exports, "PrometheusDatasource", {
|
|
|
22
22
|
});
|
|
23
23
|
const _model = require("../model");
|
|
24
24
|
const _PrometheusDatasourceEditor = require("./PrometheusDatasourceEditor");
|
|
25
|
+
function wrapClientMethod(fn, datasourceUrl, specHeaders, specQueryParams) {
|
|
26
|
+
return (params, options)=>fn(params, {
|
|
27
|
+
datasourceUrl,
|
|
28
|
+
headers: options?.headers ?? specHeaders,
|
|
29
|
+
signal: options?.signal,
|
|
30
|
+
queryParams: (0, _model.mergeQueryParams)(specQueryParams, options?.queryParams)
|
|
31
|
+
});
|
|
32
|
+
}
|
|
25
33
|
/**
|
|
26
34
|
* Creates a PrometheusClient for a specific datasource spec.
|
|
27
35
|
*/ const createClient = (spec, options)=>{
|
|
@@ -43,48 +51,13 @@ const _PrometheusDatasourceEditor = require("./PrometheusDatasourceEditor");
|
|
|
43
51
|
headers: specHeaders,
|
|
44
52
|
queryParams
|
|
45
53
|
}),
|
|
46
|
-
instantQuery: (
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
datasourceUrl,
|
|
54
|
-
headers: headers ?? specHeaders,
|
|
55
|
-
abortSignal,
|
|
56
|
-
queryParams
|
|
57
|
-
}),
|
|
58
|
-
labelNames: (params, headers, abortSignal)=>(0, _model.labelNames)(params, {
|
|
59
|
-
datasourceUrl,
|
|
60
|
-
headers: headers ?? specHeaders,
|
|
61
|
-
abortSignal,
|
|
62
|
-
queryParams
|
|
63
|
-
}),
|
|
64
|
-
labelValues: (params, headers, abortSignal)=>(0, _model.labelValues)(params, {
|
|
65
|
-
datasourceUrl,
|
|
66
|
-
headers: headers ?? specHeaders,
|
|
67
|
-
abortSignal,
|
|
68
|
-
queryParams
|
|
69
|
-
}),
|
|
70
|
-
metricMetadata: (params, headers, abortSignal)=>(0, _model.metricMetadata)(params, {
|
|
71
|
-
datasourceUrl,
|
|
72
|
-
headers: headers ?? specHeaders,
|
|
73
|
-
abortSignal,
|
|
74
|
-
queryParams
|
|
75
|
-
}),
|
|
76
|
-
series: (params, headers, abortSignal)=>(0, _model.series)(params, {
|
|
77
|
-
datasourceUrl,
|
|
78
|
-
headers: headers ?? specHeaders,
|
|
79
|
-
abortSignal,
|
|
80
|
-
queryParams
|
|
81
|
-
}),
|
|
82
|
-
parseQuery: (params, headers, abortSignal)=>(0, _model.parseQuery)(params, {
|
|
83
|
-
datasourceUrl,
|
|
84
|
-
headers: headers ?? specHeaders,
|
|
85
|
-
abortSignal,
|
|
86
|
-
queryParams
|
|
87
|
-
})
|
|
54
|
+
instantQuery: wrapClientMethod(_model.instantQuery, datasourceUrl, specHeaders, queryParams),
|
|
55
|
+
rangeQuery: wrapClientMethod(_model.rangeQuery, datasourceUrl, specHeaders, queryParams),
|
|
56
|
+
labelNames: wrapClientMethod(_model.labelNames, datasourceUrl, specHeaders, queryParams),
|
|
57
|
+
labelValues: wrapClientMethod(_model.labelValues, datasourceUrl, specHeaders, queryParams),
|
|
58
|
+
metricMetadata: wrapClientMethod(_model.metricMetadata, datasourceUrl, specHeaders, queryParams),
|
|
59
|
+
series: wrapClientMethod(_model.series, datasourceUrl, specHeaders, queryParams),
|
|
60
|
+
parseQuery: wrapClientMethod(_model.parseQuery, datasourceUrl, specHeaders, queryParams)
|
|
88
61
|
};
|
|
89
62
|
};
|
|
90
63
|
const getBuiltinVariableDefinitions = ()=>{
|
|
@@ -25,6 +25,7 @@ const _pluginsystem = require("@perses-dev/plugin-system");
|
|
|
25
25
|
const _datefns = require("date-fns");
|
|
26
26
|
const _model = require("../../model");
|
|
27
27
|
const _utils = require("../../utils");
|
|
28
|
+
const _interpolation = require("../interpolation");
|
|
28
29
|
const _types = require("../types");
|
|
29
30
|
const _replaceprombuiltinvariables = require("./replace-prom-builtin-variables");
|
|
30
31
|
const getTimeSeriesData = async (spec, context, abortSignal)=>{
|
|
@@ -37,6 +38,7 @@ const getTimeSeriesData = async (spec, context, abortSignal)=>{
|
|
|
37
38
|
const listDatasourceSelectItems = await context.datasourceStore.listDatasourceSelectItems(_model.PROM_DATASOURCE_KIND);
|
|
38
39
|
const selectedDatasource = (0, _pluginsystem.datasourceSelectValueToSelector)(spec.datasource ?? _model.DEFAULT_PROM, context.variableState, listDatasourceSelectItems) ?? _model.DEFAULT_PROM;
|
|
39
40
|
const datasource = await context.datasourceStore.getDatasource(selectedDatasource);
|
|
41
|
+
const interpolatedOptions = (0, _interpolation.interpolateDatasourceProxyParams)(datasource, context.variableState);
|
|
40
42
|
const datasourceScrapeInterval = Math.trunc((0, _datefns.milliseconds)((0, _core.parseDurationString)(datasource.plugin.spec.scrapeInterval ?? _types.DEFAULT_SCRAPE_INTERVAL)) / 1000);
|
|
41
43
|
// Min step is the lower bound of the interval between data points
|
|
42
44
|
// If no value is provided for it, it should default to the scrape interval of the datasource
|
|
@@ -79,7 +81,10 @@ const getTimeSeriesData = async (spec, context, abortSignal)=>{
|
|
|
79
81
|
response = await client.instantQuery({
|
|
80
82
|
query,
|
|
81
83
|
time: end
|
|
82
|
-
},
|
|
84
|
+
}, {
|
|
85
|
+
...interpolatedOptions,
|
|
86
|
+
signal: abortSignal
|
|
87
|
+
});
|
|
83
88
|
break;
|
|
84
89
|
case 'range':
|
|
85
90
|
default:
|
|
@@ -88,7 +93,10 @@ const getTimeSeriesData = async (spec, context, abortSignal)=>{
|
|
|
88
93
|
start,
|
|
89
94
|
end,
|
|
90
95
|
step
|
|
91
|
-
},
|
|
96
|
+
}, {
|
|
97
|
+
...interpolatedOptions,
|
|
98
|
+
signal: abortSignal
|
|
99
|
+
});
|
|
92
100
|
break;
|
|
93
101
|
}
|
|
94
102
|
// TODO: What about error responses from Prom that have a response body?
|
package/lib/model/api-types.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api-types.d.ts","sourceRoot":"","sources":["../../../src/model/api-types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAG/C,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,CAAC,CAAC;IACR,
|
|
1
|
+
{"version":3,"file":"api-types.d.ts","sourceRoot":"","sources":["../../../src/model/api-types.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,OAAO,MAAM,0BAA0B,CAAC;AAG/C,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,MAAM,EAAE,SAAS,CAAC;IAClB,IAAI,EAAE,CAAC,CAAC;IACR,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;CAClB;AAED,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,IAAI,CAAC,EAAE,CAAC,CAAC;IACT,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,eAAe,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC;AAEnE,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC;AAErC,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAE1C,MAAM,MAAM,UAAU,GAAG,CAAC,eAAe,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;AAEtF,MAAM,MAAM,WAAW,GAAG,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,E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C;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED,MAAM,WAAW,+BAA+B;IAC9C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,MAAM,sBAAsB,GAAG,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC,CAAC,CAAC;AAGnF,MAAM,WAAW,2BAA2B;IAC1C,KAAK,EAAE,MAAM,CAAC;CACf;AAED,MAAM,MAAM,kBAAkB,GAAG,WAAW,CAAC,OAAO,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/api-types.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport ASTNode from '../components/promql/ast';\n\n// Just reuse dashboard model's type and re-export\nexport type { DurationString };\n\nexport interface SuccessResponse<T> {\n status: 'success';\n data: T;\n
|
|
1
|
+
{"version":3,"sources":["../../../src/model/api-types.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport ASTNode from '../components/promql/ast';\n\n// Just reuse dashboard model's type and re-export\nexport type { DurationString };\n\nexport interface SuccessResponse<T> {\n status: 'success';\n data: T;\n warnings?: string[];\n infos?: string[];\n}\n\nexport interface ErrorResponse<T> {\n status: 'error';\n data?: T;\n errorType: string;\n error: string;\n}\n\nexport type ApiResponse<T> = SuccessResponse<T> | ErrorResponse<T>;\n\nexport type DurationSeconds = number;\n\nexport type UnixTimestampSeconds = number;\n\nexport type ValueTuple = [unixTimeSeconds: UnixTimestampSeconds, sampleValue: string];\n\nexport type BucketTuple = [bucket: number, upperBound: string, lowerBound: string, count: string];\n\nexport type HistogramValue = { count: number; sum: string; buckets?: BucketTuple[] };\n\nexport type HistogramTuple = [unixTimeSeconds: UnixTimestampSeconds, value: HistogramValue];\n\nexport type Metric = Record<string, string>;\n\nexport interface VectorData {\n resultType: 'vector';\n result: Array<{\n metric: Metric;\n value: ValueTuple;\n histogram?: HistogramTuple;\n }>;\n}\n\nexport interface MatrixData {\n resultType: 'matrix';\n result: Array<{\n metric: Metric;\n values: ValueTuple[];\n histograms?: HistogramTuple[];\n }>;\n}\n\nexport interface ScalarData {\n resultType: 'scalar';\n result: ValueTuple;\n}\n\nexport interface StringData {\n resultType: 'string';\n result: ValueTuple;\n}\n\nexport interface InstantQueryRequestParameters {\n query: string;\n time?: UnixTimestampSeconds;\n timeout?: DurationString;\n}\n\nexport type InstantQueryResultType = MatrixData | VectorData | ScalarData | StringData;\n\n// Ref https://prometheus.io/docs/prometheus/latest/querying/api/#instant-queries\nexport type InstantQueryResponse = ApiResponse<InstantQueryResultType>;\n\nexport type MonitoredInstantQueryResponse = InstantQueryResponse & {\n responseTime: number;\n};\n\nexport interface RangeQueryRequestParameters {\n query: string;\n start: UnixTimestampSeconds;\n end: UnixTimestampSeconds;\n step: DurationSeconds;\n timeout?: DurationString;\n}\n\nexport type RangeQueryResponse = ApiResponse<MatrixData>;\n\nexport interface SeriesRequestParameters {\n 'match[]': string[];\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n limit?: number;\n}\n\nexport type SeriesResponse = ApiResponse<Metric[]>;\n\nexport interface LabelNamesRequestParameters {\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n limit?: number;\n}\n\nexport type LabelNamesResponse = ApiResponse<string[]>;\n\nexport interface LabelValuesRequestParameters {\n labelName: string;\n start?: UnixTimestampSeconds;\n end?: UnixTimestampSeconds;\n 'match[]'?: string[];\n limit?: number;\n}\n\nexport type LabelValuesResponse = ApiResponse<string[]>;\n\nexport interface MetricMetadata {\n type: string;\n help: string;\n unit?: string;\n}\n\nexport interface MetricMetadataRequestParameters {\n limit?: number;\n metric?: string;\n}\n\nexport type MetricMetadataResponse = ApiResponse<Record<string, MetricMetadata[]>>;\n\n// ref: https://prometheus.io/docs/prometheus/3.0/querying/api/#parsing-a-promql-expressions-into-a-abstract-syntax-tree-ast\nexport interface ParseQueryRequestParameters {\n query: string;\n}\n\nexport type ParseQueryResponse = ApiResponse<ASTNode>;\n"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAyIjC,WAAsD"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { QueryParamValues } from '@perses-dev/components';
|
|
1
2
|
import { RequestHeaders } from '@perses-dev/core';
|
|
2
3
|
import { DatasourceClient } from '@perses-dev/plugin-system';
|
|
3
4
|
import { InstantQueryRequestParameters, InstantQueryResponse, LabelNamesRequestParameters, LabelNamesResponse, LabelValuesRequestParameters, LabelValuesResponse, MetricMetadataRequestParameters, MetricMetadataResponse, ParseQueryRequestParameters, ParseQueryResponse, RangeQueryRequestParameters, RangeQueryResponse, SeriesRequestParameters, SeriesResponse } from './api-types';
|
|
@@ -5,22 +6,28 @@ interface PrometheusClientOptions {
|
|
|
5
6
|
datasourceUrl: string;
|
|
6
7
|
headers?: RequestHeaders;
|
|
7
8
|
}
|
|
9
|
+
export interface ClientRequestOptions {
|
|
10
|
+
headers?: RequestHeaders;
|
|
11
|
+
signal?: AbortSignal;
|
|
12
|
+
queryParams?: QueryParamValues;
|
|
13
|
+
}
|
|
8
14
|
export interface PrometheusClient extends DatasourceClient {
|
|
9
15
|
options: PrometheusClientOptions;
|
|
10
|
-
instantQuery(params: InstantQueryRequestParameters,
|
|
11
|
-
rangeQuery(params: RangeQueryRequestParameters,
|
|
12
|
-
labelNames(params: LabelNamesRequestParameters,
|
|
13
|
-
labelValues(params: LabelValuesRequestParameters,
|
|
14
|
-
metricMetadata(params: MetricMetadataRequestParameters,
|
|
15
|
-
series(params: SeriesRequestParameters,
|
|
16
|
-
parseQuery(params: ParseQueryRequestParameters,
|
|
16
|
+
instantQuery(params: InstantQueryRequestParameters, options?: ClientRequestOptions): Promise<InstantQueryResponse>;
|
|
17
|
+
rangeQuery(params: RangeQueryRequestParameters, options?: ClientRequestOptions): Promise<RangeQueryResponse>;
|
|
18
|
+
labelNames(params: LabelNamesRequestParameters, options?: ClientRequestOptions): Promise<LabelNamesResponse>;
|
|
19
|
+
labelValues(params: LabelValuesRequestParameters, options?: ClientRequestOptions): Promise<LabelValuesResponse>;
|
|
20
|
+
metricMetadata(params: MetricMetadataRequestParameters, options?: ClientRequestOptions): Promise<MetricMetadataResponse>;
|
|
21
|
+
series(params: SeriesRequestParameters, options?: ClientRequestOptions): Promise<SeriesResponse>;
|
|
22
|
+
parseQuery(params: ParseQueryRequestParameters, options?: ClientRequestOptions): Promise<ParseQueryResponse>;
|
|
17
23
|
}
|
|
18
24
|
export interface QueryOptions {
|
|
19
25
|
datasourceUrl: string;
|
|
20
26
|
headers?: RequestHeaders;
|
|
21
|
-
|
|
22
|
-
queryParams?:
|
|
27
|
+
signal?: AbortSignal;
|
|
28
|
+
queryParams?: QueryParamValues;
|
|
23
29
|
}
|
|
30
|
+
export declare function mergeQueryParams(defaults?: QueryParamValues, overrides?: QueryParamValues): QueryParamValues | undefined;
|
|
24
31
|
/**
|
|
25
32
|
* Calls the `/-/healthy` endpoint to check if the datasource is healthy.
|
|
26
33
|
*/
|
|
@@ -53,9 +60,5 @@ export declare function series(params: SeriesRequestParameters, queryOptions: Qu
|
|
|
53
60
|
* Calls the `/api/v1/parse_query` to parse the given promQL expresion into an abstract syntax tree (AST).
|
|
54
61
|
*/
|
|
55
62
|
export declare function parseQuery(params: ParseQueryRequestParameters, queryOptions: QueryOptions): Promise<ParseQueryResponse>;
|
|
56
|
-
/**
|
|
57
|
-
* Fetch JSON and parse warnings for query inspector
|
|
58
|
-
*/
|
|
59
|
-
export declare function fetchResults<T>(...args: Parameters<typeof global.fetch>): Promise<T>;
|
|
60
63
|
export {};
|
|
61
64
|
//# 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,EAAoB,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAC7D,OAAO,EACL,6BAA6B,EAC7B,oBAAoB,EACpB,2BAA2B,EAC3B,kBAAkB,EAClB,4BAA4B,EAC5B,mBAAmB,EACnB,+BAA+B,EAC/B,sBAAsB,EACtB,2BAA2B,EAC3B,kBAAkB,EAClB,2BAA2B,EAC3B,kBAAkB,EAClB,uBAAuB,EACvB,cAAc,EAEf,MAAM,aAAa,CAAC;AAErB,UAAU,uBAAuB;IAC/B,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,cAAc,CAAC;CAC1B;AAED,MAAM,WAAW,gBAAiB,SAAQ,gBAAgB;IACxD,OAAO,EAAE,uBAAuB,CAAC;IACjC,YAAY,
|
|
1
|
+
{"version":3,"file":"prometheus-client.d.ts","sourceRoot":"","sources":["../../../src/model/pr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AE,YAAY,GACzB,OAAO,CAAC,sBAAsB,CAAC,CAGjC;AAED;;GAEG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,uBAAuB,EAAE,YAAY,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC,CAG3G;AAED;;GAEG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,2BAA2B,EACnC,YAAY,EAAE,YAAY,GACzB,OAAO,CAAC,kBAAkB,CAAC,CAG7B"}
|
|
@@ -19,12 +19,24 @@ import { fetch, fetchJson } from '@perses-dev/core';
|
|
|
19
19
|
const urlParams = initialParams || new URLSearchParams();
|
|
20
20
|
if (queryParams) {
|
|
21
21
|
Object.entries(queryParams).forEach(([key, value])=>{
|
|
22
|
-
|
|
22
|
+
if (initialParams?.has(key)) return;
|
|
23
|
+
if (Array.isArray(value)) {
|
|
24
|
+
value.forEach((v)=>urlParams.append(key, v));
|
|
25
|
+
} else {
|
|
26
|
+
urlParams.set(key, value);
|
|
27
|
+
}
|
|
23
28
|
});
|
|
24
29
|
}
|
|
25
30
|
const queryString = urlParams.toString();
|
|
26
31
|
return queryString !== '' ? `?${queryString}` : '';
|
|
27
32
|
}
|
|
33
|
+
export function mergeQueryParams(defaults, overrides) {
|
|
34
|
+
if (!defaults && !overrides) return undefined;
|
|
35
|
+
return {
|
|
36
|
+
...defaults,
|
|
37
|
+
...overrides
|
|
38
|
+
};
|
|
39
|
+
}
|
|
28
40
|
/**
|
|
29
41
|
* Calls the `/-/healthy` endpoint to check if the datasource is healthy.
|
|
30
42
|
*/ export function healthCheck(queryOptions) {
|
|
@@ -33,7 +45,7 @@ import { fetch, fetchJson } from '@perses-dev/core';
|
|
|
33
45
|
try {
|
|
34
46
|
const resp = await fetch(url, {
|
|
35
47
|
headers: queryOptions.headers,
|
|
36
|
-
signal: queryOptions.
|
|
48
|
+
signal: queryOptions.signal
|
|
37
49
|
});
|
|
38
50
|
return resp.status === 200;
|
|
39
51
|
} catch {
|
|
@@ -91,15 +103,16 @@ import { fetch, fetchJson } from '@perses-dev/core';
|
|
|
91
103
|
return fetchWithPost(apiURI, params, queryOptions);
|
|
92
104
|
}
|
|
93
105
|
function fetchWithGet(apiURI, params, queryOptions) {
|
|
94
|
-
const { datasourceUrl, headers, queryParams } = queryOptions;
|
|
106
|
+
const { datasourceUrl, headers, queryParams, signal } = queryOptions;
|
|
95
107
|
const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams, createSearchParams(params))}`;
|
|
96
108
|
return fetchJson(url, {
|
|
97
109
|
method: 'GET',
|
|
98
|
-
headers
|
|
110
|
+
headers,
|
|
111
|
+
signal
|
|
99
112
|
});
|
|
100
113
|
}
|
|
101
114
|
function fetchWithPost(apiURI, params, queryOptions) {
|
|
102
|
-
const { datasourceUrl, headers,
|
|
115
|
+
const { datasourceUrl, headers, signal, queryParams } = queryOptions;
|
|
103
116
|
const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams)}`;
|
|
104
117
|
const init = {
|
|
105
118
|
method: 'POST',
|
|
@@ -110,7 +123,7 @@ function fetchWithPost(apiURI, params, queryOptions) {
|
|
|
110
123
|
signal,
|
|
111
124
|
body: createSearchParams(params)
|
|
112
125
|
};
|
|
113
|
-
return
|
|
126
|
+
return fetchJson(url, init);
|
|
114
127
|
}
|
|
115
128
|
/**
|
|
116
129
|
* Creates URLSearchParams from a request params object.
|
|
@@ -133,15 +146,5 @@ function fetchWithPost(apiURI, params, queryOptions) {
|
|
|
133
146
|
}
|
|
134
147
|
return searchParams;
|
|
135
148
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Fetch JSON and parse warnings for query inspector
|
|
138
|
-
*/ export async function fetchResults(...args) {
|
|
139
|
-
const response = await fetch(...args);
|
|
140
|
-
const json = await response.json();
|
|
141
|
-
return {
|
|
142
|
-
...json,
|
|
143
|
-
rawResponse: response
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
149
|
|
|
147
150
|
//# sourceMappingURL=prometheus-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/model/prometheus-client.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { fetch, fetchJson, RequestHeaders } from '@perses-dev/core';\nimport { DatasourceClient } from '@perses-dev/plugin-system';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n ParseQueryRequestParameters,\n ParseQueryResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n SeriesRequestParameters,\n SeriesResponse,\n SuccessResponse,\n} from './api-types';\n\ninterface PrometheusClientOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\nexport interface PrometheusClient extends DatasourceClient {\n options: PrometheusClientOptions;\n instantQuery(\n params: InstantQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<InstantQueryResponse>;\n rangeQuery(\n params: RangeQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<RangeQueryResponse>;\n labelNames(\n params: LabelNamesRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<LabelNamesResponse>;\n labelValues(\n params: LabelValuesRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<LabelValuesResponse>;\n metricMetadata(\n params: MetricMetadataRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<MetricMetadataResponse>;\n series(params: SeriesRequestParameters, headers?: RequestHeaders, signal?: AbortSignal): Promise<SeriesResponse>;\n parseQuery(\n params: ParseQueryRequestParameters,\n headers?: RequestHeaders,\n signal?: AbortSignal\n ): Promise<ParseQueryResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n abortSignal?: AbortSignal;\n queryParams?: Record<string, string>;\n}\n\n/**\n * Builds a query string from datasource-level query parameters.\n * Optionally merges with existing URLSearchParams.\n * Returns empty string if no parameters, otherwise returns query string with leading '?'.\n */\nfunction buildQueryString(queryParams?: Record<string, string>, initialParams?: URLSearchParams): string {\n const urlParams = initialParams || new URLSearchParams();\n\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n urlParams.set(key, value);\n });\n }\n\n const queryString = urlParams.toString();\n return queryString !== '' ? `?${queryString}` : '';\n}\n\n/**\n * Calls the `/-/healthy` endpoint to check if the datasource is healthy.\n */\nexport function healthCheck(queryOptions: QueryOptions) {\n return async (): Promise<boolean> => {\n const url = `${queryOptions.datasourceUrl}/-/healthy${buildQueryString(queryOptions.queryParams)}`;\n\n try {\n const resp = await fetch(url, { headers: queryOptions.headers, signal: queryOptions.abortSignal });\n return resp.status === 200;\n } catch {\n return false;\n }\n };\n}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(\n params: InstantQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<InstantQueryResponse> {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(\n params: RangeQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<RangeQueryResponse> {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(\n params: LabelNamesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelNamesResponse> {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(\n params: LabelValuesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelValuesResponse> {\n const { labelName, ...searchParams } = params;\n\n // In case label name is empty, we'll receive a 404, so we can replace it by an empty list, which is less confusing.\n // Note that an empty list is the prometheus result if the label does not exist.\n if (labelName.length === 0) {\n return new Promise((resolve) => {\n resolve({ data: [] as string[] } as SuccessResponse<string[]>);\n });\n }\n\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function metricMetadata(\n params: MetricMetadataRequestParameters,\n queryOptions: QueryOptions\n): Promise<MetricMetadataResponse> {\n const apiURI = `/api/v1/metadata`;\n return fetchWithGet<MetricMetadataRequestParameters, MetricMetadataResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/series` endpoint to finding series by label matchers.\n */\nexport function series(params: SeriesRequestParameters, queryOptions: QueryOptions): Promise<SeriesResponse> {\n const apiURI = `/api/v1/series`;\n return fetchWithPost<SeriesRequestParameters, SeriesResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/parse_query` to parse the given promQL expresion into an abstract syntax tree (AST).\n */\nexport function parseQuery(\n params: ParseQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<ParseQueryResponse> {\n const apiURI = `/api/v1/parse_query`;\n return fetchWithPost<ParseQueryRequestParameters, ParseQueryResponse>(apiURI, params, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, queryParams } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams, createSearchParams(params))}`;\n return fetchJson<TResponse>(url, { method: 'GET', headers });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, abortSignal: signal, queryParams } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams)}`;\n\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n ...headers,\n },\n signal,\n body: createSearchParams(params),\n };\n return fetchResults<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T): URLSearchParams {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n\n/**\n * Fetch JSON and parse warnings for query inspector\n */\nexport async function fetchResults<T>(...args: Parameters<typeof global.fetch>): Promise<T> {\n const response = await fetch(...args);\n const json: T = await response.json();\n return { ...json, rawResponse: response };\n}\n"],"names":["fetch","fetchJson","buildQueryString","queryParams","initialParams","urlParams","URLSearchParams","Object","entries","forEach","key","value","set","queryString","toString","healthCheck","queryOptions","url","datasourceUrl","resp","headers","signal","abortSignal","status","instantQuery","params","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","length","Promise","resolve","data","apiURI","encodeURIComponent","fetchWithGet","metricMetadata","series","parseQuery","createSearchParams","method","init","body","fetchResults","undefined","append","val","args","response","json","rawResponse"],"mappings":"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vE,MAAMyC,OAAO;QACXD,QAAQ;QACRvB,SAAS;YACP,gBAAgB;YAChB,GAAGA,OAAO;QACZ;QACAC;QACAwB,MAAMH,mBAAmBjB;IAC3B;IACA,OAAOqB,aAAwB7B,KAAK2B;AACtC;AAWA;;CAEC,GACD,SAASF,mBAA+CjB,MAAS;IAC/D,MAAMM,eAAe,IAAIzB;IACzB,IAAK,MAAMI,OAAOe,OAAQ;QACxB,MAAMd,QAAoBc,MAAM,CAACf,IAAI;QACrC,IAAIC,UAAUoC,WAAW;QAEzB,IAAI,OAAOpC,UAAU,UAAU;YAC7BoB,aAAaiB,MAAM,CAACtC,KAAKC;YACzB;QACF;QAEA,IAAI,OAAOA,UAAU,UAAU;YAC7BoB,aAAaiB,MAAM,CAACtC,KAAKC,MAAMG,QAAQ;YACvC;QACF;QAEA,KAAK,MAAMmC,OAAOtC,MAAO;YACvBoB,aAAaiB,MAAM,CAACtC,KAAKuC;QAC3B;IACF;IACA,OAAOlB;AACT;AAEA;;CAEC,GACD,OAAO,eAAee,aAAgB,GAAGI,IAAqC;IAC5E,MAAMC,WAAW,MAAMnD,SAASkD;IAChC,MAAME,OAAU,MAAMD,SAASC,IAAI;IACnC,OAAO;QAAE,GAAGA,IAAI;QAAEC,aAAaF;IAAS;AAC1C"}
|
|
1
|
+
{"version":3,"sources":["../../../src/model/prometheus-client.ts"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { QueryParamValues } from '@perses-dev/components';\nimport { fetch, fetchJson, RequestHeaders } from '@perses-dev/core';\nimport { DatasourceClient } from '@perses-dev/plugin-system';\nimport {\n InstantQueryRequestParameters,\n InstantQueryResponse,\n LabelNamesRequestParameters,\n LabelNamesResponse,\n LabelValuesRequestParameters,\n LabelValuesResponse,\n MetricMetadataRequestParameters,\n MetricMetadataResponse,\n ParseQueryRequestParameters,\n ParseQueryResponse,\n RangeQueryRequestParameters,\n RangeQueryResponse,\n SeriesRequestParameters,\n SeriesResponse,\n SuccessResponse,\n} from './api-types';\n\ninterface PrometheusClientOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n}\n\nexport interface ClientRequestOptions {\n headers?: RequestHeaders;\n signal?: AbortSignal;\n queryParams?: QueryParamValues;\n}\n\nexport interface PrometheusClient extends DatasourceClient {\n options: PrometheusClientOptions;\n instantQuery(params: InstantQueryRequestParameters, options?: ClientRequestOptions): Promise<InstantQueryResponse>;\n rangeQuery(params: RangeQueryRequestParameters, options?: ClientRequestOptions): Promise<RangeQueryResponse>;\n labelNames(params: LabelNamesRequestParameters, options?: ClientRequestOptions): Promise<LabelNamesResponse>;\n labelValues(params: LabelValuesRequestParameters, options?: ClientRequestOptions): Promise<LabelValuesResponse>;\n metricMetadata(\n params: MetricMetadataRequestParameters,\n options?: ClientRequestOptions\n ): Promise<MetricMetadataResponse>;\n series(params: SeriesRequestParameters, options?: ClientRequestOptions): Promise<SeriesResponse>;\n parseQuery(params: ParseQueryRequestParameters, options?: ClientRequestOptions): Promise<ParseQueryResponse>;\n}\n\nexport interface QueryOptions {\n datasourceUrl: string;\n headers?: RequestHeaders;\n signal?: AbortSignal;\n queryParams?: QueryParamValues;\n}\n\n/**\n * Builds a query string from datasource-level query parameters.\n * Optionally merges with existing URLSearchParams.\n * Returns empty string if no parameters, otherwise returns query string with leading '?'.\n */\nfunction buildQueryString(queryParams?: QueryParamValues, initialParams?: URLSearchParams): string {\n const urlParams = initialParams || new URLSearchParams();\n\n if (queryParams) {\n Object.entries(queryParams).forEach(([key, value]) => {\n if (initialParams?.has(key)) return;\n\n if (Array.isArray(value)) {\n value.forEach((v) => urlParams.append(key, v));\n } else {\n urlParams.set(key, value);\n }\n });\n }\n\n const queryString = urlParams.toString();\n return queryString !== '' ? `?${queryString}` : '';\n}\n\nexport function mergeQueryParams(\n defaults?: QueryParamValues,\n overrides?: QueryParamValues\n): QueryParamValues | undefined {\n if (!defaults && !overrides) return undefined;\n return { ...defaults, ...overrides };\n}\n\n/**\n * Calls the `/-/healthy` endpoint to check if the datasource is healthy.\n */\nexport function healthCheck(queryOptions: QueryOptions) {\n return async (): Promise<boolean> => {\n const url = `${queryOptions.datasourceUrl}/-/healthy${buildQueryString(queryOptions.queryParams)}`;\n\n try {\n const resp = await fetch(url, { headers: queryOptions.headers, signal: queryOptions.signal });\n return resp.status === 200;\n } catch {\n return false;\n }\n };\n}\n\n/**\n * Calls the `/api/v1/query` endpoint to get metrics data.\n */\nexport function instantQuery(\n params: InstantQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<InstantQueryResponse> {\n return fetchWithPost<InstantQueryRequestParameters, InstantQueryResponse>('/api/v1/query', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/query_range` endpoint to get metrics data.\n */\nexport function rangeQuery(\n params: RangeQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<RangeQueryResponse> {\n return fetchWithPost<RangeQueryRequestParameters, RangeQueryResponse>('/api/v1/query_range', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/labels` endpoint to get a list of label names.\n */\nexport function labelNames(\n params: LabelNamesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelNamesResponse> {\n return fetchWithPost<LabelNamesRequestParameters, LabelNamesResponse>('/api/v1/labels', params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function labelValues(\n params: LabelValuesRequestParameters,\n queryOptions: QueryOptions\n): Promise<LabelValuesResponse> {\n const { labelName, ...searchParams } = params;\n\n // In case label name is empty, we'll receive a 404, so we can replace it by an empty list, which is less confusing.\n // Note that an empty list is the prometheus result if the label does not exist.\n if (labelName.length === 0) {\n return new Promise((resolve) => {\n resolve({ data: [] as string[] } as SuccessResponse<string[]>);\n });\n }\n\n const apiURI = `/api/v1/label/${encodeURIComponent(labelName)}/values`;\n return fetchWithGet<typeof searchParams, LabelValuesResponse>(apiURI, searchParams, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/label/{labelName}/values` endpoint to get a list of values for a label.\n */\nexport function metricMetadata(\n params: MetricMetadataRequestParameters,\n queryOptions: QueryOptions\n): Promise<MetricMetadataResponse> {\n const apiURI = `/api/v1/metadata`;\n return fetchWithGet<MetricMetadataRequestParameters, MetricMetadataResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/series` endpoint to finding series by label matchers.\n */\nexport function series(params: SeriesRequestParameters, queryOptions: QueryOptions): Promise<SeriesResponse> {\n const apiURI = `/api/v1/series`;\n return fetchWithPost<SeriesRequestParameters, SeriesResponse>(apiURI, params, queryOptions);\n}\n\n/**\n * Calls the `/api/v1/parse_query` to parse the given promQL expresion into an abstract syntax tree (AST).\n */\nexport function parseQuery(\n params: ParseQueryRequestParameters,\n queryOptions: QueryOptions\n): Promise<ParseQueryResponse> {\n const apiURI = `/api/v1/parse_query`;\n return fetchWithPost<ParseQueryRequestParameters, ParseQueryResponse>(apiURI, params, queryOptions);\n}\n\nfunction fetchWithGet<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, queryParams, signal } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams, createSearchParams(params))}`;\n return fetchJson<TResponse>(url, { method: 'GET', headers, signal });\n}\n\nfunction fetchWithPost<T extends RequestParams<T>, TResponse>(\n apiURI: string,\n params: T,\n queryOptions: QueryOptions\n): Promise<TResponse> {\n const { datasourceUrl, headers, signal, queryParams } = queryOptions;\n const url = `${datasourceUrl}${apiURI}${buildQueryString(queryParams)}`;\n\n const init = {\n method: 'POST',\n headers: {\n 'Content-Type': 'application/x-www-form-urlencoded',\n ...headers,\n },\n signal,\n body: createSearchParams(params),\n };\n return fetchJson<TResponse>(url, init);\n}\n\n// Request parameter values we know how to serialize\ntype ParamValue = string | string[] | number | undefined;\n\n// Used to constrain the types that can be passed to createSearchParams to\n// just the ones we know how to serialize\ntype RequestParams<T> = {\n [K in keyof T]: ParamValue;\n};\n\n/**\n * Creates URLSearchParams from a request params object.\n */\nfunction createSearchParams<T extends RequestParams<T>>(params: T): URLSearchParams {\n const searchParams = new URLSearchParams();\n for (const key in params) {\n const value: ParamValue = params[key];\n if (value === undefined) continue;\n\n if (typeof value === 'string') {\n searchParams.append(key, value);\n continue;\n }\n\n if (typeof value === 'number') {\n searchParams.append(key, value.toString());\n continue;\n }\n\n for (const val of value) {\n searchParams.append(key, val);\n }\n }\n return searchParams;\n}\n"],"names":["fetch","fetchJson","buildQueryString","queryParams","initialParams","urlParams","URLSearchParams","Object","entries","forEach","key","value","has","Array","isArray","v","append","set","queryString","toString","mergeQueryParams","defaults","overrides","undefined","healthCheck","queryOptions","url","datasourceUrl","resp","headers","signal","status","instantQuery","params","fetchWithPost","rangeQuery","labelNames","labelValues","labelName","searchParams","length","Promise","resolve","data","apiURI","encodeURIComponent","fetchWithGet","metricMetadata","series","parseQuery","createSearchParams","method","init","body","val"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAGjC,SAASA,KAAK,EAAEC,SAAS,QAAwB,mBAAmB;AAoDpE;;;;CAIC,GACD,SAASC,iBAAiBC,WAA8B,EAAEC,aAA+B;IACvF,MAAMC,YAAYD,iBAAiB,IAAIE;IAEvC,IAAIH,aAAa;QACfI,OAAOC,OAAO,CAACL,aAAaM,OAAO,CAAC,CAAC,CAACC,KAAKC,MAAM;YAC/C,IAA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Z;QACAC;QACAuB,MAAMH,mBAAmBjB;IAC3B;IACA,OAAOhC,UAAqByB,KAAK0B;AACnC;AAWA;;CAEC,GACD,SAASF,mBAA+CjB,MAAS;IAC/D,MAAMM,eAAe,IAAIjC;IACzB,IAAK,MAAMI,OAAOuB,OAAQ;QACxB,MAAMtB,QAAoBsB,MAAM,CAACvB,IAAI;QACrC,IAAIC,UAAUY,WAAW;QAEzB,IAAI,OAAOZ,UAAU,UAAU;YAC7B4B,aAAavB,MAAM,CAACN,KAAKC;YACzB;QACF;QAEA,IAAI,OAAOA,UAAU,UAAU;YAC7B4B,aAAavB,MAAM,CAACN,KAAKC,MAAMQ,QAAQ;YACvC;QACF;QAEA,KAAK,MAAMmC,OAAO3C,MAAO;YACvB4B,aAAavB,MAAM,CAACN,KAAK4C;QAC3B;IACF;IACA,OAAOf;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusDatasourceEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusDatasourceEditor.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrometheusDatasourceEditor.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusDatasourceEditor.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAAE,YAAY,EAAoB,MAAM,OAAO,CAAC;AACvD,OAAO,EAA2B,wBAAwB,EAAE,MAAM,SAAS,CAAC;AAS5E,MAAM,WAAW,+BAA+B;IAC9C,KAAK,EAAE,wBAAwB,CAAC;IAChC,QAAQ,EAAE,CAAC,IAAI,EAAE,wBAAwB,KAAK,IAAI,CAAC;IACnD,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB;AAED,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,+BAA+B,GAAG,YAAY,CAgM/F"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
1
2
|
// Copyright The Perses Authors
|
|
2
3
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
3
4
|
// you may not use this file except in compliance with the License.
|
|
@@ -10,12 +11,11 @@
|
|
|
10
11
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
11
12
|
// See the License for the specific language governing permissions and
|
|
12
13
|
// limitations under the License.
|
|
13
|
-
import {
|
|
14
|
+
import { Box, IconButton, TextField, Typography } from '@mui/material';
|
|
14
15
|
import { HTTPSettingsEditor } from '@perses-dev/plugin-system';
|
|
15
|
-
import { Box, TextField, Typography, IconButton } from '@mui/material';
|
|
16
|
-
import PlusIcon from 'mdi-material-ui/Plus';
|
|
17
16
|
import MinusIcon from 'mdi-material-ui/Minus';
|
|
18
|
-
import
|
|
17
|
+
import PlusIcon from 'mdi-material-ui/Plus';
|
|
18
|
+
import { useRef, useState } from 'react';
|
|
19
19
|
import { DEFAULT_SCRAPE_INTERVAL } from './types';
|
|
20
20
|
export function PrometheusDatasourceEditor(props) {
|
|
21
21
|
const { value, onChange, isReadonly } = props;
|
|
@@ -25,10 +25,10 @@ export function PrometheusDatasourceEditor(props) {
|
|
|
25
25
|
// manipulating a map directly which causes weird UX.
|
|
26
26
|
const [entries, setEntries] = useState(()=>{
|
|
27
27
|
const queryParams = value.queryParams ?? {};
|
|
28
|
-
return Object.entries(queryParams).map(([key,
|
|
28
|
+
return Object.entries(queryParams).map(([key, val])=>({
|
|
29
29
|
id: String(nextIdRef.current++),
|
|
30
30
|
key,
|
|
31
|
-
value
|
|
31
|
+
value: Array.isArray(val) ? val.join(',') : val
|
|
32
32
|
}));
|
|
33
33
|
});
|
|
34
34
|
// Check for duplicate keys
|
|
@@ -44,12 +44,15 @@ export function PrometheusDatasourceEditor(props) {
|
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
const hasDuplicates = duplicateKeys.size > 0;
|
|
47
|
-
// Convert entries array to object and trigger onChange
|
|
47
|
+
// Convert entries array to object and trigger onChange.
|
|
48
|
+
// Values containing commas are stored as arrays to preserve the round-trip
|
|
49
|
+
// with the load-time join(',') in useState above.
|
|
48
50
|
const syncToParent = (newEntries)=>{
|
|
49
51
|
const newParams = {};
|
|
50
52
|
newEntries.forEach(({ key, value })=>{
|
|
51
53
|
if (key !== '') {
|
|
52
|
-
|
|
54
|
+
const parts = value.split(',');
|
|
55
|
+
newParams[key] = parts.length > 1 ? parts : value;
|
|
53
56
|
}
|
|
54
57
|
});
|
|
55
58
|
onChange({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/PrometheusDatasourceEditor.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { DurationString } from '@perses-dev/core';\nimport { HTTPSettingsEditor } from '@perses-dev/plugin-system';\nimport { Box, TextField, Typography, IconButton } from '@mui/material';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport React, { ReactElement, useState, useRef } from 'react';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from './types';\n\ninterface QueryParamEntry {\n // Unique identifier for the entry, added to avoid using array index as key\n id: string;\n key: string;\n value: string;\n}\n\nexport interface PrometheusDatasourceEditorProps {\n value: PrometheusDatasourceSpec;\n onChange: (next: PrometheusDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function PrometheusDatasourceEditor(props: PrometheusDatasourceEditorProps): ReactElement {\n const { value, onChange, isReadonly } = props;\n\n // Counter for generating unique IDs\n const nextIdRef = useRef(0);\n\n // Use local state to maintain an array of entries during editing, instead of\n // manipulating a map directly which causes weird UX.\n const [entries, setEntries] = useState<QueryParamEntry[]>(() => {\n const queryParams = value.queryParams ?? {};\n return Object.entries(queryParams).map(([key, value]) => ({\n id: String(nextIdRef.current++),\n key,\n value,\n }));\n });\n\n // Check for duplicate keys\n const keyMap = new Map<string, number>();\n const duplicateKeys = new Set<string>();\n entries.forEach(({ key }) => {\n if (key !== '') {\n const count = (keyMap.get(key) || 0) + 1;\n keyMap.set(key, count);\n if (count > 1) {\n duplicateKeys.add(key);\n }\n }\n });\n const hasDuplicates = duplicateKeys.size > 0;\n\n // Convert entries array to object and trigger onChange\n const syncToParent = (newEntries: QueryParamEntry[]) => {\n const newParams: Record<string, string> = {};\n newEntries.forEach(({ key, value }) => {\n if (key !== '') {\n newParams[key] = value;\n }\n });\n\n onChange({\n ...value,\n queryParams: Object.keys(newParams).length > 0 ? newParams : undefined,\n });\n };\n\n const handleQueryParamChange = (id: string, field: 'key' | 'value', newValue: string) => {\n const newEntries = entries.map((entry) => {\n if (entry.id !== id) return entry;\n return field === 'key' ? { ...entry, key: newValue } : { ...entry, value: newValue };\n });\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const addQueryParam = () => {\n const newEntries = [...entries, { id: String(nextIdRef.current++), key: '', value: '' }];\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const removeQueryParam = (id: string) => {\n const newEntries = entries.filter((entry) => entry.id !== id);\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const initialSpecDirect: PrometheusDatasourceSpec = {\n directUrl: '',\n };\n\n const initialSpecProxy: PrometheusDatasourceSpec = {\n proxy: {\n kind: 'HTTPProxy',\n spec: {\n allowedEndpoints: [\n // list of standard endpoints suggested by default\n {\n endpointPattern: '/api/v1/labels',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/series',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/metadata',\n method: 'GET',\n },\n {\n endpointPattern: '/api/v1/query',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/query_range',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',\n method: 'GET',\n },\n {\n endpointPattern: '/api/v1/parse_query',\n method: 'POST',\n },\n ],\n url: '',\n },\n },\n };\n\n return (\n <>\n <Typography variant=\"h4\" mb={2}>\n General Settings\n </Typography>\n <TextField\n size=\"small\"\n fullWidth\n label=\"Scrape Interval\"\n value={value.scrapeInterval || ''}\n placeholder={`Default: ${DEFAULT_SCRAPE_INTERVAL}`}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => onChange({ ...value, scrapeInterval: e.target.value as DurationString })}\n helperText=\"Set it to match the typical scrape interval used in your Prometheus instance.\"\n />\n <HTTPSettingsEditor\n value={value}\n onChange={onChange}\n isReadonly={isReadonly}\n initialSpecDirect={initialSpecDirect}\n initialSpecProxy={initialSpecProxy}\n />\n <Typography variant=\"h5\" mt={2} mb={1}>\n Query Parameters\n </Typography>\n {entries.length > 0 && (\n <>\n {entries.map((entry) => (\n <Box key={entry.id} display=\"flex\" alignItems=\"center\" gap={2} mb={1}>\n <TextField\n size=\"small\"\n label=\"Key\"\n value={entry.key}\n placeholder=\"Parameter name\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'key', e.target.value)}\n error={duplicateKeys.has(entry.key)}\n sx={{ minWidth: 150 }}\n />\n <TextField\n size=\"small\"\n label=\"Value\"\n value={entry.value}\n placeholder=\"Parameter value\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'value', e.target.value)}\n sx={{ minWidth: 150, flexGrow: 1 }}\n />\n {!isReadonly && (\n <IconButton onClick={() => removeQueryParam(entry.id)}>\n <MinusIcon />\n </IconButton>\n )}\n </Box>\n ))}\n </>\n )}\n {hasDuplicates && (\n <Typography variant=\"body2\" color=\"error\" mb={1}>\n Duplicate parameter keys detected. Each key must be unique.\n </Typography>\n )}\n {entries.length === 0 && (\n <Typography variant=\"body2\" color=\"textSecondary\">\n No query parameters configured. Use query parameters to pass additional options to Prometheus (e.g.,\n dedup=false for Thanos).\n </Typography>\n )}\n {!isReadonly && (\n <IconButton onClick={addQueryParam}>\n <PlusIcon />\n </IconButton>\n )}\n </>\n );\n}\n"],"names":["HTTPSettingsEditor","Box","TextField","Typography","IconButton","PlusIcon","MinusIcon","React","useState","useRef","DEFAULT_SCRAPE_INTERVAL","PrometheusDatasourceEditor","props","value","onChange","isReadonly","nextIdRef","entries","setEntries","queryParams","Object","map","key","id","String","current","keyMap","Map","duplicateKeys","Set","forEach","count","get","set","add","hasDuplicates","size","syncToParent","newEntries","newParams","keys","length","undefined","handleQueryParamChange","field","newValue","entry","addQueryParam","removeQueryParam","filter","initialSpecDirect","directUrl","initialSpecProxy","proxy","kind","spec","allowedEndpoints","endpointPattern","method","url","variant","mb","fullWidth","label","scrapeInterval","placeholder","InputProps","readOnly","InputLabelProps","shrink","e","target","helperText","mt","display","alignItems","gap","disabled","error","has","sx","minWidth","flexGrow","onClick","color"],"mappings":"AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAGjC,SAASA,kBAAkB,QAAQ,4BAA4B;AAC/D,SAASC,GAAG,EAAEC,SAAS,EAAEC,UAAU,EAAEC,UAAU,QAAQ,gBAAgB;AACvE,OAAOC,cAAc,uBAAuB;AAC5C,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,SAAuBC,QAAQ,EAAEC,MAAM,QAAQ,QAAQ;AAC9D,SAASC,uBAAuB,QAAkC,UAAU;AAe5E,OAAO,SAASC,2BAA2BC,KAAsC;IAC/E,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,UAAU,EAAE,GAAGH;IAExC,oCAAoC;IACpC,MAAMI,YAAYP,OAAO;IAEzB,6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+
{"version":3,"sources":["../../../src/plugins/PrometheusDatasourceEditor.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { Box, IconButton, TextField, Typography } from '@mui/material';\nimport { QueryParamValues } from '@perses-dev/components';\nimport { DurationString } from '@perses-dev/core';\nimport { HTTPSettingsEditor } from '@perses-dev/plugin-system';\nimport MinusIcon from 'mdi-material-ui/Minus';\nimport PlusIcon from 'mdi-material-ui/Plus';\nimport { ReactElement, useRef, useState } from 'react';\nimport { DEFAULT_SCRAPE_INTERVAL, PrometheusDatasourceSpec } from './types';\n\ninterface QueryParamEntry {\n // Unique identifier for the entry, added to avoid using array index as key\n id: string;\n key: string;\n value: string;\n}\n\nexport interface PrometheusDatasourceEditorProps {\n value: PrometheusDatasourceSpec;\n onChange: (next: PrometheusDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function PrometheusDatasourceEditor(props: PrometheusDatasourceEditorProps): ReactElement {\n const { value, onChange, isReadonly } = props;\n\n // Counter for generating unique IDs\n const nextIdRef = useRef(0);\n\n // Use local state to maintain an array of entries during editing, instead of\n // manipulating a map directly which causes weird UX.\n const [entries, setEntries] = useState<QueryParamEntry[]>(() => {\n const queryParams: QueryParamValues = value.queryParams ?? {};\n return Object.entries(queryParams).map(([key, val]) => ({\n id: String(nextIdRef.current++),\n key,\n value: Array.isArray(val) ? val.join(',') : val,\n }));\n });\n\n // Check for duplicate keys\n const keyMap = new Map<string, number>();\n const duplicateKeys = new Set<string>();\n entries.forEach(({ key }) => {\n if (key !== '') {\n const count = (keyMap.get(key) || 0) + 1;\n keyMap.set(key, count);\n if (count > 1) {\n duplicateKeys.add(key);\n }\n }\n });\n const hasDuplicates = duplicateKeys.size > 0;\n\n // Convert entries array to object and trigger onChange.\n // Values containing commas are stored as arrays to preserve the round-trip\n // with the load-time join(',') in useState above.\n const syncToParent = (newEntries: QueryParamEntry[]): void => {\n const newParams: Record<string, string | string[]> = {};\n newEntries.forEach(({ key, value }) => {\n if (key !== '') {\n const parts = value.split(',');\n newParams[key] = parts.length > 1 ? parts : value;\n }\n });\n\n onChange({\n ...value,\n queryParams: Object.keys(newParams).length > 0 ? newParams : undefined,\n });\n };\n\n const handleQueryParamChange = (id: string, field: 'key' | 'value', newValue: string): void => {\n const newEntries = entries.map((entry) => {\n if (entry.id !== id) return entry;\n return field === 'key' ? { ...entry, key: newValue } : { ...entry, value: newValue };\n });\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const addQueryParam = (): void => {\n const newEntries = [...entries, { id: String(nextIdRef.current++), key: '', value: '' }];\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const removeQueryParam = (id: string): void => {\n const newEntries = entries.filter((entry) => entry.id !== id);\n setEntries(newEntries);\n syncToParent(newEntries);\n };\n\n const initialSpecDirect: PrometheusDatasourceSpec = {\n directUrl: '',\n };\n\n const initialSpecProxy: PrometheusDatasourceSpec = {\n proxy: {\n kind: 'HTTPProxy',\n spec: {\n allowedEndpoints: [\n // list of standard endpoints suggested by default\n {\n endpointPattern: '/api/v1/labels',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/series',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/metadata',\n method: 'GET',\n },\n {\n endpointPattern: '/api/v1/query',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/query_range',\n method: 'POST',\n },\n {\n endpointPattern: '/api/v1/label/([a-zA-Z0-9_-]+)/values',\n method: 'GET',\n },\n {\n endpointPattern: '/api/v1/parse_query',\n method: 'POST',\n },\n ],\n url: '',\n },\n },\n };\n\n return (\n <>\n <Typography variant=\"h4\" mb={2}>\n General Settings\n </Typography>\n <TextField\n size=\"small\"\n fullWidth\n label=\"Scrape Interval\"\n value={value.scrapeInterval || ''}\n placeholder={`Default: ${DEFAULT_SCRAPE_INTERVAL}`}\n InputProps={{\n readOnly: isReadonly,\n }}\n InputLabelProps={{ shrink: isReadonly ? true : undefined }}\n onChange={(e) => onChange({ ...value, scrapeInterval: e.target.value as DurationString })}\n helperText=\"Set it to match the typical scrape interval used in your Prometheus instance.\"\n />\n <HTTPSettingsEditor\n value={value}\n onChange={onChange}\n isReadonly={isReadonly}\n initialSpecDirect={initialSpecDirect}\n initialSpecProxy={initialSpecProxy}\n />\n <Typography variant=\"h5\" mt={2} mb={1}>\n Query Parameters\n </Typography>\n {entries.length > 0 && (\n <>\n {entries.map((entry) => (\n <Box key={entry.id} display=\"flex\" alignItems=\"center\" gap={2} mb={1}>\n <TextField\n size=\"small\"\n label=\"Key\"\n value={entry.key}\n placeholder=\"Parameter name\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'key', e.target.value)}\n error={duplicateKeys.has(entry.key)}\n sx={{ minWidth: 150 }}\n />\n <TextField\n size=\"small\"\n label=\"Value\"\n value={entry.value}\n placeholder=\"Parameter value\"\n disabled={isReadonly}\n onChange={(e) => handleQueryParamChange(entry.id, 'value', e.target.value)}\n sx={{ minWidth: 150, flexGrow: 1 }}\n />\n {!isReadonly && (\n <IconButton onClick={() => removeQueryParam(entry.id)}>\n <MinusIcon />\n </IconButton>\n )}\n </Box>\n ))}\n </>\n )}\n {hasDuplicates && (\n <Typography variant=\"body2\" color=\"error\" mb={1}>\n Duplicate parameter keys detected. Each key must be unique.\n </Typography>\n )}\n {entries.length === 0 && (\n <Typography variant=\"body2\" color=\"textSecondary\">\n No query parameters configured. Use query parameters to pass additional options to Prometheus (e.g.,\n dedup=false for Thanos).\n </Typography>\n )}\n {!isReadonly && (\n <IconButton onClick={addQueryParam}>\n <PlusIcon />\n </IconButton>\n )}\n </>\n );\n}\n"],"names":["Box","IconButton","TextField","Typography","HTTPSettingsEditor","MinusIcon","PlusIcon","useRef","useState","DEFAULT_SCRAPE_INTERVAL","PrometheusDatasourceEditor","props","value","onChange","isReadonly","nextIdRef","entries","setEntries","queryParams","Object","map","key","val","id","String","current","Array","isArray","join","keyMap","Map","duplicateKeys","Set","forEach","count","get","set","add","hasDuplicates","size","syncToParent","newEntries","newParams","parts","split","length","keys","undefined","handleQueryParamChange","field","newValue","entry","addQueryParam","removeQueryParam","filter","initialSpecDirect","directUrl","initialSpecProxy","proxy","kind","spec","allowedEndpoints","endpointPattern","method","url","variant","mb","fullWidth","label","scrapeInterval","placeholder","InputProps","readOnly","InputLabelProps","shrink","e","target","helperText","mt","display","alignItems","gap","disabled","error","has","sx","minWidth","flexGrow","onClick","color"],"mappings":";AAAA,+BAA+B;AAC/B,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,GAAG,EAAEC,UAAU,EAAEC,SAAS,EAAEC,UAAU,QAAQ,gBAAgB;AAGvE,SAASC,kBAAkB,QAAQ,4BAA4B;AAC/D,OAAOC,eAAe,wBAAwB;AAC9C,OAAOC,cAAc,uBAAuB;AAC5C,SAAuBC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AACvD,SAASC,uBAAuB,QAAkC,UAAU;AAe5E,OAAO,SAASC,2BAA2BC,KAAsC;IAC/E,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,UAAU,EAAE,GAAGH;IAExC,oCAAoC;IACpC,MAAMI,YAAYR,OAAO;IAEzB,6EAA6E;IAC7E,qDAAqD;IACrD,MAAM,CAACS,SAASC,WAAW,GAAGT,SAA4B;QACxD,MAAMU,cAAgCN,MAAMM,WAAW,IAAI,CAAC;QAC5D,OAAOC,OAAOH,OAAO,CAACE,aAAaE,GAAG,C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,KAAC9C;;;;AAKX"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusLabelNamesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,EAMf,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"PrometheusLabelNamesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,EAMf,MAAM,2BAA2B,CAAC;AAInC,OAAO,EAAE,mCAAmC,EAAE,MAAM,SAAS,CAAC;AAE9D,eAAO,MAAM,4BAA4B,EAAE,cAAc,CAAC,mCAAmC,CA6B5F,CAAC"}
|
|
@@ -13,16 +13,17 @@
|
|
|
13
13
|
import { replaceVariables, parseVariables, datasourceSelectValueToSelector, isVariableDatasource } from '@perses-dev/plugin-system';
|
|
14
14
|
import { DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';
|
|
15
15
|
import { stringArrayToVariableOptions, PrometheusLabelNamesVariableEditor } from './prometheus-variables';
|
|
16
|
+
import { resolvePrometheusDatasource } from './interpolation';
|
|
16
17
|
export const PrometheusLabelNamesVariable = {
|
|
17
18
|
getVariableOptions: async (spec, ctx)=>{
|
|
18
19
|
const datasourceSelector = datasourceSelectValueToSelector(spec.datasource ?? DEFAULT_PROM, ctx.variables, await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)) ?? DEFAULT_PROM;
|
|
19
|
-
const client = await ctx.datasourceStore.
|
|
20
|
+
const { client, requestOptions } = await resolvePrometheusDatasource(ctx.datasourceStore, datasourceSelector, ctx.variables);
|
|
20
21
|
const match = spec.matchers ? spec.matchers.map((m)=>replaceVariables(m, ctx.variables)) : undefined;
|
|
21
22
|
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
22
23
|
const { data: options } = await client.labelNames({
|
|
23
24
|
'match[]': match,
|
|
24
25
|
...timeRange
|
|
25
|
-
});
|
|
26
|
+
}, requestOptions);
|
|
26
27
|
return {
|
|
27
28
|
data: stringArrayToVariableOptions(options)
|
|
28
29
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \\\"License\\\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \\\"AS IS\\\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n VariablePlugin,\n GetVariableOptionsContext,\n replaceVariables,\n parseVariables,\n datasourceSelectValueToSelector,\n isVariableDatasource,\n} from '@perses-dev/plugin-system';\nimport {
|
|
1
|
+
{"version":3,"sources":["../../../src/plugins/PrometheusLabelNamesVariable.tsx"],"sourcesContent":["// Copyright The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \\\"License\\\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \\\"AS IS\\\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n VariablePlugin,\n GetVariableOptionsContext,\n replaceVariables,\n parseVariables,\n datasourceSelectValueToSelector,\n isVariableDatasource,\n} from '@perses-dev/plugin-system';\nimport { DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';\nimport { stringArrayToVariableOptions, PrometheusLabelNamesVariableEditor } from './prometheus-variables';\nimport { resolvePrometheusDatasource } from './interpolation';\nimport { PrometheusLabelNamesVariableOptions } from './types';\n\nexport const PrometheusLabelNamesVariable: VariablePlugin<PrometheusLabelNamesVariableOptions> = {\n getVariableOptions: async (spec: PrometheusLabelNamesVariableOptions, ctx: GetVariableOptionsContext) => {\n const datasourceSelector =\n datasourceSelectValueToSelector(\n spec.datasource ?? DEFAULT_PROM,\n ctx.variables,\n await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)\n ) ?? DEFAULT_PROM;\n const { client, requestOptions } = await resolvePrometheusDatasource(\n ctx.datasourceStore,\n datasourceSelector,\n ctx.variables\n );\n const match = spec.matchers ? spec.matchers.map((m) => replaceVariables(m, ctx.variables)) : undefined;\n const timeRange = getPrometheusTimeRange(ctx.timeRange);\n\n const { data: options } = await client.labelNames({ 'match[]': match, ...timeRange }, requestOptions);\n return {\n data: stringArrayToVariableOptions(options),\n };\n },\n dependsOn: (spec: PrometheusLabelNamesVariableOptions) => {\n const matcherVariables = spec.matchers?.map((m) => parseVariables(m)).flat() || [];\n const datasourceVariables =\n spec.datasource && isVariableDatasource(spec.datasource) ? parseVariables(spec.datasource) : [];\n return { variables: [...matcherVariables, ...datasourceVariables] };\n },\n OptionsEditorComponent: PrometheusLabelNamesVariableEditor,\n createInitialOptions: () => ({}),\n};\n"],"names":["replaceVariables","parseVariables","datasourceSelectValueToSelector","isVariableDatasource","DEFAULT_PROM","getPrometheusTimeRange","PROM_DATASOURCE_KIND","stringArrayToVariableOptions","PrometheusLabelNamesVariableEditor","resolvePrometheusDatasource","PrometheusLabelNamesVariable","getVariableOptions","spec","ctx","datasourceSelector","datasource","variables","datasourceStore","listDatasourceSelectItems","client","requestOptions","match","matchers","map","m","undefined","timeRange","data","options","labelNames","dependsOn","matcherVariables","flat","datasourceVariables","OptionsEditorComponent","createInitialOptions"],"mappings":"AAAA,+BAA+B;AAC/B,oEAAoE;AACpE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE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AAsB,IAAO,CAAA,CAAC,CAAA;AAChC,EAAE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrometheusLabelValuesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,EAMf,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"PrometheusLabelValuesVariable.d.ts","sourceRoot":"","sources":["../../../src/plugins/PrometheusLabelValuesVariable.tsx"],"names":[],"mappings":"AAaA,OAAO,EACL,cAAc,EAMf,MAAM,2BAA2B,CAAC;AAInC,OAAO,EAAE,oCAAoC,EAAE,MAAM,SAAS,CAAC;AAE/D,eAAO,MAAM,6BAA6B,EAAE,cAAc,CAAC,oCAAoC,CAyC9F,CAAC"}
|
|
@@ -13,18 +13,19 @@
|
|
|
13
13
|
import { replaceVariables, parseVariables, datasourceSelectValueToSelector, isVariableDatasource } from '@perses-dev/plugin-system';
|
|
14
14
|
import { DEFAULT_PROM, getPrometheusTimeRange, PROM_DATASOURCE_KIND } from '../model';
|
|
15
15
|
import { stringArrayToVariableOptions, PrometheusLabelValuesVariableEditor } from './prometheus-variables';
|
|
16
|
+
import { resolvePrometheusDatasource } from './interpolation';
|
|
16
17
|
export const PrometheusLabelValuesVariable = {
|
|
17
18
|
getVariableOptions: async (spec, ctx)=>{
|
|
18
19
|
const pluginDef = spec;
|
|
19
20
|
const datasourceSelector = datasourceSelectValueToSelector(spec.datasource ?? DEFAULT_PROM, ctx.variables, await ctx.datasourceStore.listDatasourceSelectItems(PROM_DATASOURCE_KIND)) ?? DEFAULT_PROM;
|
|
20
|
-
const client = await ctx.datasourceStore.
|
|
21
|
+
const { client, requestOptions } = await resolvePrometheusDatasource(ctx.datasourceStore, datasourceSelector, ctx.variables);
|
|
21
22
|
const match = pluginDef.matchers ? pluginDef.matchers.map((m)=>replaceVariables(m, ctx.variables)) : undefined;
|
|
22
23
|
const timeRange = getPrometheusTimeRange(ctx.timeRange);
|
|
23
24
|
const { data: options } = await client.labelValues({
|
|
24
25
|
labelName: replaceVariables(pluginDef.labelName, ctx.variables),
|
|
25
26
|
'match[]': match,
|
|
26
27
|
...timeRange
|
|
27
|
-
});
|
|
28
|
+
}, requestOptions);
|
|
28
29
|
return {
|
|
29
30
|
data: stringArrayToVariableOptions(options)
|
|
30
31
|
};
|