@perses-dev/loki-plugin 0.3.0 → 0.5.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.
Files changed (160) hide show
  1. package/__mf/js/Loki.b64c7408.js +6 -0
  2. package/__mf/js/async/1238.71fd7843.js +1 -0
  3. package/__mf/js/async/1490.0d8dcc42.js +22 -0
  4. package/__mf/js/async/1501.eefd56b9.js +1 -0
  5. package/__mf/js/async/1616.60c9a082.js +1 -0
  6. package/__mf/js/async/1728.21a8f690.js +1 -0
  7. package/__mf/js/async/1811.a291a38b.js +28 -0
  8. package/__mf/js/async/1825.5005b3af.js +1 -0
  9. package/__mf/js/async/1969.53d223ca.js +1 -0
  10. package/__mf/js/async/2043.eb7e1c61.js +2 -0
  11. package/__mf/js/async/2386.a3cfef97.js +2 -0
  12. package/__mf/js/async/3059.cb101ca2.js +1 -0
  13. package/__mf/js/async/3181.d2b90b95.js +2 -0
  14. package/__mf/js/async/3849.85df5535.js +7 -0
  15. package/__mf/js/async/392.c0f9d49a.js +2 -0
  16. package/__mf/js/async/{1964.7b2e7223.js → 4121.328a1e93.js} +2 -2
  17. package/__mf/js/async/4466.21ddc88c.js +74 -0
  18. package/__mf/js/async/{2651.ef335482.js → 5002.29685f8e.js} +1 -1
  19. package/__mf/js/async/5071.a03a64fd.js +1 -0
  20. package/__mf/js/async/5440.3fedd5ea.js +2 -0
  21. package/__mf/js/async/5501.01af8b43.js +2 -0
  22. package/__mf/js/async/{5214.fee648bb.js → 5587.55dbc663.js} +1 -1
  23. package/__mf/js/async/6100.e2898f9c.js +1 -0
  24. package/__mf/js/async/6274.293b47c4.js +2 -0
  25. package/__mf/js/async/6283.78af4bc8.js +2 -0
  26. package/__mf/js/async/6498.903f2a94.js +2 -0
  27. package/__mf/js/async/7177.b50a1c64.js +1 -0
  28. package/__mf/js/async/7192.4dea1fd0.js +1 -0
  29. package/__mf/js/async/7370.0ddd349a.js +2 -0
  30. package/__mf/js/async/7968.ec040694.js +1 -0
  31. package/__mf/js/async/7978.38078276.js +1 -0
  32. package/__mf/js/async/8035.8dab4893.js +38 -0
  33. package/__mf/js/async/8356.5635696c.js +1 -0
  34. package/__mf/js/async/8470.c67049a2.js +2 -0
  35. package/__mf/js/async/8482.07caae1a.js +1 -0
  36. package/__mf/js/async/873.02aa55af.js +1 -0
  37. package/__mf/js/async/8988.1c565f12.js +1 -0
  38. package/__mf/js/async/9071.ed72bdac.js +2 -0
  39. package/__mf/js/async/9235.f2e0e95c.js +1 -0
  40. package/__mf/js/async/9389.a8ea42a0.js +2 -0
  41. package/__mf/js/async/941.0bce16fe.js +2 -0
  42. package/__mf/js/async/9588.2d82f477.js +1 -0
  43. package/__mf/js/async/9754.5d7b21c2.js +10 -0
  44. package/__mf/js/async/9836.de786d07.js +1 -0
  45. package/__mf/js/async/__federation_expose_LokiDatasource.3da46ee2.js +2 -0
  46. package/__mf/js/async/__federation_expose_LokiLogQuery.c1be0273.js +1 -0
  47. package/__mf/js/async/__federation_expose_LokiTimeSeriesQuery.cf876f4b.js +1 -0
  48. package/__mf/js/main.de30f7e6.js +6 -0
  49. package/lib/bootstrap.js +3 -3
  50. package/lib/bootstrap.js.map +1 -1
  51. package/lib/cjs/bootstrap.js +1 -1
  52. package/lib/cjs/components/complete.js +258 -0
  53. package/lib/cjs/components/logql-editor.js +6 -3
  54. package/lib/cjs/components/logql-extension.js +15 -1
  55. package/lib/cjs/model/index.js +1 -0
  56. package/lib/cjs/model/loki-client.js +10 -10
  57. package/lib/cjs/model/loki-selectors.js +5 -5
  58. package/lib/cjs/queries/constants.js +3 -3
  59. package/lib/cjs/queries/loki-log-query/LokiLogQueryEditor.js +21 -17
  60. package/lib/cjs/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.js +5 -16
  61. package/lib/components/complete.d.ts +37 -0
  62. package/lib/components/complete.d.ts.map +1 -0
  63. package/lib/components/complete.js +249 -0
  64. package/lib/components/complete.js.map +1 -0
  65. package/lib/components/logql-editor.d.ts +4 -1
  66. package/lib/components/logql-editor.d.ts.map +1 -1
  67. package/lib/components/logql-editor.js +7 -4
  68. package/lib/components/logql-editor.js.map +1 -1
  69. package/lib/components/logql-extension.d.ts +9 -1
  70. package/lib/components/logql-extension.d.ts.map +1 -1
  71. package/lib/components/logql-extension.js +15 -1
  72. package/lib/components/logql-extension.js.map +1 -1
  73. package/lib/datasources/loki-datasource/LokiDatasourceEditor.js +1 -1
  74. package/lib/datasources/loki-datasource/LokiDatasourceEditor.js.map +1 -1
  75. package/lib/model/index.d.ts +1 -0
  76. package/lib/model/index.d.ts.map +1 -1
  77. package/lib/model/index.js +1 -0
  78. package/lib/model/index.js.map +1 -1
  79. package/lib/queries/loki-log-query/LokiLogQueryEditor.d.ts.map +1 -1
  80. package/lib/queries/loki-log-query/LokiLogQueryEditor.js +23 -19
  81. package/lib/queries/loki-log-query/LokiLogQueryEditor.js.map +1 -1
  82. package/lib/queries/loki-log-query/get-loki-log-data.js.map +1 -1
  83. package/lib/queries/loki-log-query/log-query-plugin-interface.d.ts +0 -1
  84. package/lib/queries/loki-log-query/log-query-plugin-interface.d.ts.map +1 -1
  85. package/lib/queries/loki-log-query/log-query-plugin-interface.js.map +1 -1
  86. package/lib/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.d.ts.map +1 -1
  87. package/lib/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.js +5 -16
  88. package/lib/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.js.map +1 -1
  89. package/lib/queries/loki-time-series-query/get-loki-time-series-data.d.ts +1 -4
  90. package/lib/queries/loki-time-series-query/get-loki-time-series-data.d.ts.map +1 -1
  91. package/lib/queries/loki-time-series-query/get-loki-time-series-data.js.map +1 -1
  92. package/mf-manifest.json +107 -102
  93. package/mf-stats.json +107 -102
  94. package/package.json +7 -6
  95. package/__mf/js/Loki.2f631825.js +0 -5
  96. package/__mf/js/async/1360.2348e2a7.js +0 -10
  97. package/__mf/js/async/1540.6b797827.js +0 -74
  98. package/__mf/js/async/1580.c7d3c3f1.js +0 -2
  99. package/__mf/js/async/2178.c22bac1c.js +0 -2
  100. package/__mf/js/async/2226.a056d1a3.js +0 -1
  101. package/__mf/js/async/2292.35c2eeec.js +0 -2
  102. package/__mf/js/async/2472.75bb97e0.js +0 -22
  103. package/__mf/js/async/2652.7b7038d2.js +0 -28
  104. package/__mf/js/async/2708.9651e2da.js +0 -1
  105. package/__mf/js/async/282.6c4c5a94.js +0 -1
  106. package/__mf/js/async/3224.b1170acc.js +0 -1
  107. package/__mf/js/async/3431.2270637c.js +0 -1
  108. package/__mf/js/async/3863.16343b76.js +0 -2
  109. package/__mf/js/async/3960.6091bb00.js +0 -2
  110. package/__mf/js/async/3980.08ab4aef.js +0 -2
  111. package/__mf/js/async/4075.19dee570.js +0 -1
  112. package/__mf/js/async/4238.155e3b8a.js +0 -1
  113. package/__mf/js/async/4269.b4d0f49d.js +0 -2
  114. package/__mf/js/async/4310.b96a5c66.js +0 -7
  115. package/__mf/js/async/4421.5adcbc2d.js +0 -1
  116. package/__mf/js/async/529.f12e49de.js +0 -2
  117. package/__mf/js/async/5409.ff95cf63.js +0 -1
  118. package/__mf/js/async/5780.d837c3cd.js +0 -1
  119. package/__mf/js/async/5981.a46c5157.js +0 -2
  120. package/__mf/js/async/6134.f7ee513c.js +0 -38
  121. package/__mf/js/async/6292.9997ca36.js +0 -1
  122. package/__mf/js/async/6329.9c3a3698.js +0 -2
  123. package/__mf/js/async/6333.01fb6457.js +0 -2
  124. package/__mf/js/async/6377.9f308c7f.js +0 -2
  125. package/__mf/js/async/6770.ba5a38f3.js +0 -1
  126. package/__mf/js/async/694.c25a1f84.js +0 -1
  127. package/__mf/js/async/7376.0459aaf7.js +0 -1
  128. package/__mf/js/async/738.a16c93b6.js +0 -1
  129. package/__mf/js/async/7740.6f193fac.js +0 -1
  130. package/__mf/js/async/8216.d9cc6234.js +0 -1
  131. package/__mf/js/async/8488.5b4b7170.js +0 -1
  132. package/__mf/js/async/8537.dc791586.js +0 -1
  133. package/__mf/js/async/9173.75bbe78a.js +0 -2
  134. package/__mf/js/async/9563.0375701c.js +0 -2
  135. package/__mf/js/async/__federation_expose_LokiDatasource.a9871645.js +0 -2
  136. package/__mf/js/async/__federation_expose_LokiLogQuery.9b430d01.js +0 -1
  137. package/__mf/js/async/__federation_expose_LokiTimeSeriesQuery.61feff51.js +0 -1
  138. package/__mf/js/main.174be1bc.js +0 -5
  139. /package/__mf/css/async/{1580.d3010b86.css → 3061.d3010b86.css} +0 -0
  140. /package/__mf/css/async/{2341.d3010b86.css → 5442.d3010b86.css} +0 -0
  141. /package/__mf/css/async/{6759.d3010b86.css → 7370.d3010b86.css} +0 -0
  142. /package/__mf/js/async/{2472.75bb97e0.js.LICENSE.txt → 1490.0d8dcc42.js.LICENSE.txt} +0 -0
  143. /package/__mf/js/async/{2292.35c2eeec.js.LICENSE.txt → 2043.eb7e1c61.js.LICENSE.txt} +0 -0
  144. /package/__mf/js/async/{1580.c7d3c3f1.js.LICENSE.txt → 2386.a3cfef97.js.LICENSE.txt} +0 -0
  145. /package/__mf/js/async/{3863.16343b76.js.LICENSE.txt → 3181.d2b90b95.js.LICENSE.txt} +0 -0
  146. /package/__mf/js/async/{4310.b96a5c66.js.LICENSE.txt → 3849.85df5535.js.LICENSE.txt} +0 -0
  147. /package/__mf/js/async/{5981.a46c5157.js.LICENSE.txt → 392.c0f9d49a.js.LICENSE.txt} +0 -0
  148. /package/__mf/js/async/{1964.7b2e7223.js.LICENSE.txt → 4121.328a1e93.js.LICENSE.txt} +0 -0
  149. /package/__mf/js/async/{6377.9f308c7f.js.LICENSE.txt → 5440.3fedd5ea.js.LICENSE.txt} +0 -0
  150. /package/__mf/js/async/{2178.c22bac1c.js.LICENSE.txt → 5501.01af8b43.js.LICENSE.txt} +0 -0
  151. /package/__mf/js/async/{3960.6091bb00.js.LICENSE.txt → 6274.293b47c4.js.LICENSE.txt} +0 -0
  152. /package/__mf/js/async/{3980.08ab4aef.js.LICENSE.txt → 6283.78af4bc8.js.LICENSE.txt} +0 -0
  153. /package/__mf/js/async/{529.f12e49de.js.LICENSE.txt → 6498.903f2a94.js.LICENSE.txt} +0 -0
  154. /package/__mf/js/async/{4269.b4d0f49d.js.LICENSE.txt → 7370.0ddd349a.js.LICENSE.txt} +0 -0
  155. /package/__mf/js/async/{9173.75bbe78a.js.LICENSE.txt → 8470.c67049a2.js.LICENSE.txt} +0 -0
  156. /package/__mf/js/async/{6329.9c3a3698.js.LICENSE.txt → 9071.ed72bdac.js.LICENSE.txt} +0 -0
  157. /package/__mf/js/async/{6333.01fb6457.js.LICENSE.txt → 9389.a8ea42a0.js.LICENSE.txt} +0 -0
  158. /package/__mf/js/async/{9563.0375701c.js.LICENSE.txt → 941.0bce16fe.js.LICENSE.txt} +0 -0
  159. /package/__mf/js/async/{1360.2348e2a7.js.LICENSE.txt → 9754.5d7b21c2.js.LICENSE.txt} +0 -0
  160. /package/__mf/js/async/{__federation_expose_LokiDatasource.a9871645.js.LICENSE.txt → __federation_expose_LokiDatasource.3da46ee2.js.LICENSE.txt} +0 -0
@@ -1,4 +1,12 @@
1
1
  import { LRLanguage } from '@codemirror/language';
2
2
  import { Extension } from '@uiw/react-codemirror';
3
- export declare function LogQLExtension(): Array<LRLanguage | Extension>;
3
+ import { AbsoluteTimeRange } from '@perses-dev/core';
4
+ import { LokiClient } from '../model';
5
+ export interface CompletionConfig {
6
+ /** a LokiClient instance, can be created with LokiDatasource.createClient() */
7
+ client?: LokiClient;
8
+ /** search for label values in a given time range */
9
+ timeRange?: AbsoluteTimeRange;
10
+ }
11
+ export declare function LogQLExtension(completionCfg?: CompletionConfig): Array<LRLanguage | Extension>;
4
12
  //# sourceMappingURL=logql-extension.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"logql-extension.d.ts","sourceRoot":"","sources":["../../../src/components/logql-extension.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAelD,wBAAgB,cAAc,IAAI,KAAK,CAAC,UAAU,GAAG,SAAS,CAAC,CAG9D"}
1
+ {"version":3,"file":"logql-extension.d.ts","sourceRoot":"","sources":["../../../src/components/logql-extension.ts"],"names":[],"mappings":"AAaA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAGlD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAgBtC,MAAM,WAAW,gBAAgB;IAC/B,+EAA+E;IAC/E,MAAM,CAAC,EAAE,UAAU,CAAC;IAEpB,oDAAoD;IACpD,SAAS,CAAC,EAAE,iBAAiB,CAAC;CAC/B;AAED,wBAAgB,cAAc,CAAC,aAAa,CAAC,EAAE,gBAAgB,GAAG,KAAK,CAAC,UAAU,GAAG,SAAS,CAAC,CAgB9F"}
@@ -13,6 +13,7 @@
13
13
  import { LRLanguage } from '@codemirror/language';
14
14
  import { parser } from '@grafana/lezer-logql';
15
15
  import { logqlHighlight } from './logql-highlight';
16
+ import { complete } from './complete';
16
17
  function logqlLanguage() {
17
18
  return LRLanguage.define({
18
19
  parser: parser.configure({
@@ -37,8 +38,21 @@ function logqlLanguage() {
37
38
  }
38
39
  });
39
40
  }
40
- export function LogQLExtension() {
41
+ export function LogQLExtension(completionCfg) {
41
42
  const language = logqlLanguage();
43
+ // Only add autocomplete if config is provided
44
+ if (completionCfg) {
45
+ const completion = language.data.of({
46
+ autocomplete: (ctx)=>complete(completionCfg, ctx).catch((e)=>{
47
+ console.error('error during LogQL auto-complete', e);
48
+ return null;
49
+ })
50
+ });
51
+ return [
52
+ language,
53
+ completion
54
+ ];
55
+ }
42
56
  return [
43
57
  language
44
58
  ];
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/components/logql-extension.ts"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { LRLanguage } from '@codemirror/language';\nimport { parser } from '@grafana/lezer-logql';\nimport { Extension } from '@uiw/react-codemirror';\nimport { logqlHighlight } from './logql-highlight';\n\nfunction logqlLanguage(): LRLanguage {\n return LRLanguage.define({\n parser: parser.configure({\n props: [logqlHighlight],\n }),\n languageData: {\n closeBrackets: { brackets: ['(', '[', '{', \"'\", '\"', '`'] },\n commentTokens: { line: '#' },\n },\n });\n}\n\nexport function LogQLExtension(): Array<LRLanguage | Extension> {\n const language = logqlLanguage();\n return [language];\n}\n"],"names":["LRLanguage","parser","logqlHighlight","logqlLanguage","define","configure","props","languageData","closeBrackets","brackets","commentTokens","line","LogQLExtension","language"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,UAAU,QAAQ,uBAAuB;AAClD,SAASC,MAAM,QAAQ,uBAAuB;AAE9C,SAASC,cAAc,QAAQ,oBAAoB;AAEnD,SAASC;IACP,OAAOH,WAAWI,MAAM,CAAC;QACvBH,QAAQA,OAAOI,SAAS,CAAC;YACvBC,OAAO;gBAACJ;aAAe;QACzB;QACAK,cAAc;YACZC,eAAe;gBAAEC,UAAU;oBAAC;oBAAK;oBAAK;oBAAK;oBAAK;oBAAK;iBAAI;YAAC;YAC1DC,eAAe;gBAAEC,MAAM;YAAI;QAC7B;IACF;AACF;AAEA,OAAO,SAASC;IACd,MAAMC,WAAWV;IACjB,OAAO;QAACU;KAAS;AACnB"}
1
+ {"version":3,"sources":["../../../src/components/logql-extension.ts"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { LRLanguage } from '@codemirror/language';\nimport { parser } from '@grafana/lezer-logql';\nimport { CompletionContext } from '@codemirror/autocomplete';\nimport { Extension } from '@uiw/react-codemirror';\nimport { AbsoluteTimeRange } from '@perses-dev/core';\nimport { LokiClient } from '../model';\nimport { logqlHighlight } from './logql-highlight';\nimport { complete } from './complete';\n\nfunction logqlLanguage(): LRLanguage {\n return LRLanguage.define({\n parser: parser.configure({\n props: [logqlHighlight],\n }),\n languageData: {\n closeBrackets: { brackets: ['(', '[', '{', \"'\", '\"', '`'] },\n commentTokens: { line: '#' },\n },\n });\n}\n\nexport interface CompletionConfig {\n /** a LokiClient instance, can be created with LokiDatasource.createClient() */\n client?: LokiClient;\n\n /** search for label values in a given time range */\n timeRange?: AbsoluteTimeRange;\n}\n\nexport function LogQLExtension(completionCfg?: CompletionConfig): Array<LRLanguage | Extension> {\n const language = logqlLanguage();\n\n // Only add autocomplete if config is provided\n if (completionCfg) {\n const completion = language.data.of({\n autocomplete: (ctx: CompletionContext) =>\n complete(completionCfg, ctx).catch((e) => {\n console.error('error during LogQL auto-complete', e);\n return null;\n }),\n });\n return [language, completion];\n }\n\n return [language];\n}\n"],"names":["LRLanguage","parser","logqlHighlight","complete","logqlLanguage","define","configure","props","languageData","closeBrackets","brackets","commentTokens","line","LogQLExtension","completionCfg","language","completion","data","of","autocomplete","ctx","catch","e","console","error"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,UAAU,QAAQ,uBAAuB;AAClD,SAASC,MAAM,QAAQ,uBAAuB;AAK9C,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,QAAQ,QAAQ,aAAa;AAEtC,SAASC;IACP,OAAOJ,WAAWK,MAAM,CAAC;QACvBJ,QAAQA,OAAOK,SAAS,CAAC;YACvBC,OAAO;gBAACL;aAAe;QACzB;QACAM,cAAc;YACZC,eAAe;gBAAEC,UAAU;oBAAC;oBAAK;oBAAK;oBAAK;oBAAK;oBAAK;iBAAI;YAAC;YAC1DC,eAAe;gBAAEC,MAAM;YAAI;QAC7B;IACF;AACF;AAUA,OAAO,SAASC,eAAeC,aAAgC;IAC7D,MAAMC,WAAWX;IAEjB,8CAA8C;IAC9C,IAAIU,eAAe;QACjB,MAAME,aAAaD,SAASE,IAAI,CAACC,EAAE,CAAC;YAClCC,cAAc,CAACC,MACbjB,SAASW,eAAeM,KAAKC,KAAK,CAAC,CAACC;oBAClCC,QAAQC,KAAK,CAAC,oCAAoCF;oBAClD,OAAO;gBACT;QACJ;QACA,OAAO;YAACP;YAAUC;SAAW;IAC/B;IAEA,OAAO;QAACD;KAAS;AACnB"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
1
2
  // Copyright 2025 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,7 +11,6 @@
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 { jsx as _jsx } from "react/jsx-runtime";
14
14
  import { HTTPSettingsEditor } from '@perses-dev/plugin-system';
15
15
  export function LokiDatasourceEditor(props) {
16
16
  const { value, onChange, isReadonly } = props;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/datasources/loki-datasource/LokiDatasourceEditor.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { HTTPSettingsEditor } from '@perses-dev/plugin-system';\nimport { ReactElement } from 'react';\nimport { LokiDatasourceSpec } from './loki-datasource-types';\n\nexport interface LokiDatasourceEditorProps {\n value: LokiDatasourceSpec;\n onChange: (next: LokiDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function LokiDatasourceEditor(props: LokiDatasourceEditorProps): ReactElement {\n const { value, onChange, isReadonly } = props;\n\n const initialSpecDirect: LokiDatasourceSpec = {\n directUrl: '',\n };\n\n const initialSpecProxy: LokiDatasourceSpec = {\n proxy: {\n kind: 'HTTPProxy',\n spec: {\n allowedEndpoints: [\n {\n endpointPattern: '/loki/api/v1/query',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/query_range',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/labels',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/label/([a-zA-Z0-9_-]+)/values',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/series',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/index/volume',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/index/volume_range',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/index/stats',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/tail',\n method: 'GET',\n },\n ],\n url: '',\n },\n },\n };\n\n return (\n <HTTPSettingsEditor\n value={value}\n onChange={onChange}\n isReadonly={isReadonly}\n initialSpecDirect={initialSpecDirect}\n initialSpecProxy={initialSpecProxy}\n />\n );\n}\n"],"names":["HTTPSettingsEditor","LokiDatasourceEditor","props","value","onChange","isReadonly","initialSpecDirect","directUrl","initialSpecProxy","proxy","kind","spec","allowedEndpoints","endpointPattern","method","url"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SAASA,kBAAkB,QAAQ,4BAA4B;AAU/D,OAAO,SAASC,qBAAqBC,KAAgC;IACnE,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,UAAU,EAAE,GAAGH;IAExC,MAAMI,oBAAwC;QAC5CC,WAAW;IACb;IAEA,MAAMC,mBAAuC;QAC3CC,OAAO;YACLC,MAAM;YACNC,MAAM;gBACJC,kBAAkB;oBAChB;wBACEC,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;iBACD;gBACDC,KAAK;YACP;QACF;IACF;IAEA,qBACE,KAACf;QACCG,OAAOA;QACPC,UAAUA;QACVC,YAAYA;QACZC,mBAAmBA;QACnBE,kBAAkBA;;AAGxB"}
1
+ {"version":3,"sources":["../../../../src/datasources/loki-datasource/LokiDatasourceEditor.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { HTTPSettingsEditor } from '@perses-dev/plugin-system';\nimport { ReactElement } from 'react';\nimport { LokiDatasourceSpec } from './loki-datasource-types';\n\nexport interface LokiDatasourceEditorProps {\n value: LokiDatasourceSpec;\n onChange: (next: LokiDatasourceSpec) => void;\n isReadonly?: boolean;\n}\n\nexport function LokiDatasourceEditor(props: LokiDatasourceEditorProps): ReactElement {\n const { value, onChange, isReadonly } = props;\n\n const initialSpecDirect: LokiDatasourceSpec = {\n directUrl: '',\n };\n\n const initialSpecProxy: LokiDatasourceSpec = {\n proxy: {\n kind: 'HTTPProxy',\n spec: {\n allowedEndpoints: [\n {\n endpointPattern: '/loki/api/v1/query',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/query_range',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/labels',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/label/([a-zA-Z0-9_-]+)/values',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/series',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/index/volume',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/index/volume_range',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/index/stats',\n method: 'GET',\n },\n {\n endpointPattern: '/loki/api/v1/tail',\n method: 'GET',\n },\n ],\n url: '',\n },\n },\n };\n\n return (\n <HTTPSettingsEditor\n value={value}\n onChange={onChange}\n isReadonly={isReadonly}\n initialSpecDirect={initialSpecDirect}\n initialSpecProxy={initialSpecProxy}\n />\n );\n}\n"],"names":["HTTPSettingsEditor","LokiDatasourceEditor","props","value","onChange","isReadonly","initialSpecDirect","directUrl","initialSpecProxy","proxy","kind","spec","allowedEndpoints","endpointPattern","method","url"],"mappings":";AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAASA,kBAAkB,QAAQ,4BAA4B;AAU/D,OAAO,SAASC,qBAAqBC,KAAgC;IACnE,MAAM,EAAEC,KAAK,EAAEC,QAAQ,EAAEC,UAAU,EAAE,GAAGH;IAExC,MAAMI,oBAAwC;QAC5CC,WAAW;IACb;IAEA,MAAMC,mBAAuC;QAC3CC,OAAO;YACLC,MAAM;YACNC,MAAM;gBACJC,kBAAkB;oBAChB;wBACEC,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;oBACA;wBACED,iBAAiB;wBACjBC,QAAQ;oBACV;iBACD;gBACDC,KAAK;YACP;QACF;IACF;IAEA,qBACE,KAACf;QACCG,OAAOA;QACPC,UAAUA;QACVC,YAAYA;QACZC,mBAAmBA;QACnBE,kBAAkBA;;AAGxB"}
@@ -1,3 +1,4 @@
1
1
  export * from './loki-client';
2
+ export * from './loki-client-types';
2
3
  export * from './loki-selectors';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/model/index.ts"],"names":[],"mappings":"AAaA,cAAc,eAAe,CAAC;AAC9B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC"}
@@ -11,6 +11,7 @@
11
11
  // See the License for the specific language governing permissions and
12
12
  // limitations under the License.
13
13
  export * from './loki-client';
14
+ export * from './loki-client-types';
14
15
  export * from './loki-selectors';
15
16
 
16
17
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/model/index.ts"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './loki-client';\nexport * from './loki-selectors';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,gBAAgB;AAC9B,cAAc,mBAAmB"}
1
+ {"version":3,"sources":["../../../src/model/index.ts"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nexport * from './loki-client';\nexport * from './loki-client-types';\nexport * from './loki-selectors';\n"],"names":[],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,cAAc,gBAAgB;AAC9B,cAAc,sBAAsB;AACpC,cAAc,mBAAmB"}
@@ -1 +1 @@
1
- {"version":3,"file":"LokiLogQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-log-query/LokiLogQueryEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAEnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAoC,MAAM,OAAO,CAAC;AAMvE,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAG1D,KAAK,oBAAoB,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CA6H5E"}
1
+ {"version":3,"file":"LokiLogQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-log-query/LokiLogQueryEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAInB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAwB,MAAM,OAAO,CAAC;AAO3D,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAE1D,KAAK,oBAAoB,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;AAEjE,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CAkI5E"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  // Copyright 2025 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,22 +11,35 @@
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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
- import { DatasourceSelect, isVariableDatasource, useDatasourceSelectValueToSelector } from '@perses-dev/plugin-system';
14
+ import { DatasourceSelect, isVariableDatasource, useDatasourceSelectValueToSelector, useDatasourceClient, useTimeRange } from '@perses-dev/plugin-system';
15
15
  import { InputLabel, Stack, ToggleButton, ToggleButtonGroup } from '@mui/material';
16
- import { useCallback } from 'react';
16
+ import { useCallback, useMemo } from 'react';
17
17
  import { produce } from 'immer';
18
18
  import { OptionsEditorControl } from '@perses-dev/components';
19
- import { LogQLEditor } from '../../components/logql-editor';
19
+ import { LogQLEditor } from '../../components';
20
20
  import { isDefaultLokiSelector, LOKI_DATASOURCE_KIND } from '../../model';
21
21
  import { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';
22
22
  import { useQueryState } from '../query-editor-model';
23
23
  export function LokiLogQueryEditor(props) {
24
- const { onChange, value, queryHandlerSettings } = props;
24
+ const { onChange, value } = props;
25
25
  const { datasource } = value;
26
26
  const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;
27
27
  const selectedDatasource = useDatasourceSelectValueToSelector(datasourceSelectValue, LOKI_DATASOURCE_KIND);
28
28
  const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);
29
+ // Get client and time range for autocompletion
30
+ const { data: client } = useDatasourceClient(selectedDatasource);
31
+ const { absoluteTimeRange } = useTimeRange();
32
+ // Create completion config for autocompletion
33
+ const completionConfig = useMemo(()=>{
34
+ if (!client) return undefined;
35
+ return {
36
+ client,
37
+ timeRange: absoluteTimeRange
38
+ };
39
+ }, [
40
+ client,
41
+ absoluteTimeRange
42
+ ]);
29
43
  const handleDatasourceChange = (newDatasourceSelection)=>{
30
44
  if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {
31
45
  onChange(produce(value, (draft)=>{
@@ -33,10 +47,6 @@ export function LokiLogQueryEditor(props) {
33
47
  const nextDatasource = isDefaultLokiSelector(newDatasourceSelection) ? undefined : newDatasourceSelection;
34
48
  draft.datasource = nextDatasource;
35
49
  }));
36
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
37
- ...value,
38
- datasource: newDatasourceSelection
39
- });
40
50
  return;
41
51
  }
42
52
  throw new Error('Got unexpected non LokiQuery datasource selection');
@@ -46,21 +56,14 @@ export function LokiLogQueryEditor(props) {
46
56
  }));
47
57
  // Immediate query execution on Enter or blur
48
58
  const handleQueryExecute = (query)=>{
49
- if (queryHandlerSettings?.watchQueryChanges) {
50
- queryHandlerSettings.watchQueryChanges(query);
51
- }
52
59
  onChange(produce(value, (draft)=>{
53
60
  draft.query = query;
54
61
  }));
55
62
  };
56
63
  const handleLogsQueryChange = useCallback((e)=>{
57
64
  handleQueryChange(e);
58
- if (queryHandlerSettings?.watchQueryChanges) {
59
- queryHandlerSettings.watchQueryChanges(e);
60
- }
61
65
  }, [
62
- handleQueryChange,
63
- queryHandlerSettings
66
+ handleQueryChange
64
67
  ]);
65
68
  return /*#__PURE__*/ _jsxs(Stack, {
66
69
  spacing: 1.5,
@@ -98,14 +101,15 @@ export function LokiLogQueryEditor(props) {
98
101
  /*#__PURE__*/ _jsx(LogQLEditor, {
99
102
  value: query,
100
103
  onChange: handleLogsQueryChange,
101
- onBlur: queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined,
104
+ onBlur: handleQueryBlur,
102
105
  onKeyDown: (event)=>{
103
106
  if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
104
107
  event.preventDefault();
105
108
  handleQueryExecute(query);
106
109
  }
107
110
  },
108
- placeholder: 'Enter LogQL query (e.g. {job="mysql"} |= "error")'
111
+ placeholder: 'Enter LogQL query (e.g. {job="mysql"} |= "error")',
112
+ completionConfig: completionConfig
109
113
  })
110
114
  ]
111
115
  }),
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/queries/loki-log-query/LokiLogQueryEditor.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { InputLabel, Stack, ToggleButton, ToggleButtonGroup } from '@mui/material';\nimport { ReactElement, useCallback, useState, useEffect } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorControl } from '@perses-dev/components';\nimport { LogQLEditor } from '../../components/logql-editor';\nimport { isDefaultLokiSelector, LOKI_DATASOURCE_KIND, LokiDatasourceSelector } from '../../model';\nimport { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';\nimport { LokiLogQuerySpec } from './loki-log-query-types';\nimport { useQueryState } from '../query-editor-model';\n\ntype LokiQueryEditorProps = OptionsEditorProps<LokiLogQuerySpec>;\n\nexport function LokiLogQueryEditor(props: LokiQueryEditorProps): ReactElement {\n const { onChange, value, queryHandlerSettings } = props;\n const { datasource } = value;\n const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n LOKI_DATASOURCE_KIND\n ) as LokiDatasourceSelector;\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (newDatasourceSelection) => {\n if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultLokiSelector(newDatasourceSelection) ? undefined : newDatasourceSelection;\n draft.datasource = nextDatasource;\n })\n );\n\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, datasource: newDatasourceSelection });\n return;\n }\n\n throw new Error('Got unexpected non LokiQuery datasource selection');\n };\n\n const handleLogsDirection = (_: React.MouseEvent, v: 'backward' | 'forward') =>\n onChange(\n produce(value, (draft: LokiLogQuerySpec) => {\n draft.direction = v;\n })\n );\n\n // Immediate query execution on Enter or blur\n const handleQueryExecute = (query: string) => {\n if (queryHandlerSettings?.watchQueryChanges) {\n queryHandlerSettings.watchQueryChanges(query);\n }\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n const handleLogsQueryChange = useCallback(\n (e: string) => {\n handleQueryChange(e);\n if (queryHandlerSettings?.watchQueryChanges) {\n queryHandlerSettings.watchQueryChanges(e);\n }\n },\n [handleQueryChange, queryHandlerSettings]\n );\n\n return (\n <Stack spacing={1.5} paddingBottom={1}>\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n Datasource\n </InputLabel>\n <DatasourceSelect\n datasourcePluginKind={DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n label=\"Loki Datasource\"\n notched\n />\n </div>\n\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n LogQL Query\n </InputLabel>\n <LogQLEditor\n value={query}\n onChange={handleLogsQueryChange}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n handleQueryExecute(query);\n }\n }}\n placeholder='Enter LogQL query (e.g. {job=\"mysql\"} |= \"error\")'\n // height=\"120px\"\n />\n </div>\n <div>\n <OptionsEditorControl\n label=\"Order\"\n // description=\"Percentage means thresholds relative to min & max\"\n control={\n <ToggleButtonGroup\n exclusive\n value={value?.direction ?? 'backward'}\n onChange={handleLogsDirection}\n sx={{ height: '36px', marginLeft: '10px', width: 'max-content' }}\n >\n <ToggleButton aria-label=\"backward\" value=\"backward\" sx={{ fontWeight: 500 }}>\n Newest first\n </ToggleButton>\n <ToggleButton aria-label=\"forward\" value=\"forward\" sx={{ fontWeight: 500 }}>\n Oldest first\n </ToggleButton>\n </ToggleButtonGroup>\n }\n />\n </div>\n </Stack>\n );\n}\n"],"names":["DatasourceSelect","isVariableDatasource","useDatasourceSelectValueToSelector","InputLabel","Stack","ToggleButton","ToggleButtonGroup","useCallback","produce","OptionsEditorControl","LogQLEditor","isDefaultLokiSelector","LOKI_DATASOURCE_KIND","DATASOURCE_KIND","DEFAULT_DATASOURCE","useQueryState","LokiLogQueryEditor","props","onChange","value","queryHandlerSettings","datasource","datasourceSelectValue","selectedDatasource","query","handleQueryChange","handleQueryBlur","handleDatasourceChange","newDatasourceSelection","kind","draft","nextDatasource","undefined","setWatchOtherSpecs","Error","handleLogsDirection","_","v","direction","handleQueryExecute","watchQueryChanges","handleLogsQueryChange","e","spacing","paddingBottom","div","sx","display","marginBottom","fontWeight","datasourcePluginKind","label","notched","onBlur","runWithOnBlur","onKeyDown","event","key","ctrlKey","metaKey","preventDefault","placeholder","control","exclusive","height","marginLeft","width","aria-label"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAA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hD,OAAM;gCAAW2B,IAAI;oCAAEG,YAAY;gCAAI;0CAAG;;0CAG9E,KAAC5C;gCAAa8D,cAAW;gCAAUhD,OAAM;gCAAU2B,IAAI;oCAAEG,YAAY;gCAAI;0CAAG;;;;;;;;AAS1F"}
1
+ {"version":3,"sources":["../../../../src/queries/loki-log-query/LokiLogQueryEditor.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceSelectValueToSelector,\n useDatasourceClient,\n useTimeRange,\n} from '@perses-dev/plugin-system';\nimport { InputLabel, Stack, ToggleButton, ToggleButtonGroup } from '@mui/material';\nimport { ReactElement, useCallback, useMemo } from 'react';\nimport { produce } from 'immer';\nimport { OptionsEditorControl } from '@perses-dev/components';\nimport { LogQLEditor } from '../../components';\nimport { isDefaultLokiSelector, LOKI_DATASOURCE_KIND, LokiDatasourceSelector, LokiClient } from '../../model';\nimport { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';\nimport { useQueryState } from '../query-editor-model';\nimport { LokiLogQuerySpec } from './loki-log-query-types';\n\ntype LokiQueryEditorProps = OptionsEditorProps<LokiLogQuerySpec>;\n\nexport function LokiLogQueryEditor(props: LokiQueryEditorProps): ReactElement {\n const { onChange, value } = props;\n const { datasource } = value;\n const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n LOKI_DATASOURCE_KIND\n ) as LokiDatasourceSelector;\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n\n // Get client and time range for autocompletion\n const { data: client } = useDatasourceClient<LokiClient>(selectedDatasource);\n const { absoluteTimeRange } = useTimeRange();\n\n // Create completion config for autocompletion\n const completionConfig = useMemo(() => {\n if (!client) return undefined;\n return {\n client,\n timeRange: absoluteTimeRange,\n };\n }, [client, absoluteTimeRange]);\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (newDatasourceSelection) => {\n if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {\n onChange(\n produce(value, (draft) => {\n // If they're using the default, just omit the datasource prop (i.e. set to undefined)\n const nextDatasource = isDefaultLokiSelector(newDatasourceSelection) ? undefined : newDatasourceSelection;\n draft.datasource = nextDatasource;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non LokiQuery datasource selection');\n };\n\n const handleLogsDirection = (_: React.MouseEvent, v: 'backward' | 'forward') =>\n onChange(\n produce(value, (draft: LokiLogQuerySpec) => {\n draft.direction = v;\n })\n );\n\n // Immediate query execution on Enter or blur\n const handleQueryExecute = (query: string) => {\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n const handleLogsQueryChange = useCallback(\n (e: string) => {\n handleQueryChange(e);\n },\n [handleQueryChange]\n );\n\n return (\n <Stack spacing={1.5} paddingBottom={1}>\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n Datasource\n </InputLabel>\n <DatasourceSelect\n datasourcePluginKind={DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n label=\"Loki Datasource\"\n notched\n />\n </div>\n\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n LogQL Query\n </InputLabel>\n <LogQLEditor\n value={query}\n onChange={handleLogsQueryChange}\n onBlur={handleQueryBlur}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n handleQueryExecute(query);\n }\n }}\n placeholder='Enter LogQL query (e.g. {job=\"mysql\"} |= \"error\")'\n completionConfig={completionConfig}\n // height=\"120px\"\n />\n </div>\n <div>\n <OptionsEditorControl\n label=\"Order\"\n // description=\"Percentage means thresholds relative to min & max\"\n control={\n <ToggleButtonGroup\n exclusive\n value={value?.direction ?? 'backward'}\n onChange={handleLogsDirection}\n sx={{ height: '36px', marginLeft: '10px', width: 'max-content' }}\n >\n <ToggleButton aria-label=\"backward\" value=\"backward\" sx={{ fontWeight: 500 }}>\n Newest first\n </ToggleButton>\n <ToggleButton aria-label=\"forward\" value=\"forward\" sx={{ fontWeight: 500 }}>\n Oldest first\n </ToggleButton>\n </ToggleButtonGroup>\n }\n />\n </div>\n </Stack>\n );\n}\n"],"names":["DatasourceSelect","isVariableDatasource","useDatasourceSelectValueToSelector","useDatasourceClient","useTimeRange","InputLabel","Stack","ToggleButton","ToggleButtonGroup","useCallback","useMemo","produce","OptionsEditorControl","LogQLEditor","isDefaultLokiSelector","LOKI_DATASOURCE_KIND","DATASOURCE_KIND","DEFAULT_DATASOURCE","useQueryState","LokiLogQueryEditor","props","onChange","value","datasource","datasourceSelectValue","selectedDatasource","query","handleQueryChange","handleQueryBlur","data","client","absoluteTimeRange","completionConfig","undefined","timeRange","handleDatasourceChange","newDatasourceSelection","kind","draft","nextDatasource","Error","handleLogsDirection","_","v","direction","handleQueryExecute","handleLogsQueryChange","e","spacing","paddingBottom","div","sx","display","marginBottom","fontWeight","datasourcePluginKind","label","notched","onBlur","onKeyDown","event","key","ctrlKey","metaKey","preventDefault","placeholder","control","exclusive","height","marginLeft","width","aria-label"],"mappings":";AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SACEA,gBAAgB,EA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CAAI;0CAAG;;0CAG9E,KAAC/C;gCAAagE,cAAW;gCAAUjD,OAAM;gCAAU6B,IAAI;oCAAEG,YAAY;gCAAI;0CAAG;;;;;;;;AAS1F"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/queries/loki-log-query/get-loki-log-data.ts"],"sourcesContent":["import { replaceVariables } from '@perses-dev/plugin-system';\nimport { LokiStreamResult } from '../../model/loki-client-types';\nimport { LokiClient } from '../../model/loki-client';\nimport { LogEntry, LogData } from '@perses-dev/core';\nimport { DEFAULT_DATASOURCE } from '../constants';\nimport { LokiLogQuerySpec, LokiLogQueryResponse } from './loki-log-query-types';\nimport { LogQueryPlugin, LogQueryContext } from './log-query-plugin-interface';\n\nfunction convertStreamsToLogs(streams: LokiStreamResult[]): LogData {\n const entries: LogEntry[] = [];\n\n streams.forEach((stream) => {\n stream.values.forEach(([timestamp, logLine]: [string, string]) => {\n entries.push({\n timestamp: Number(timestamp) / 1000000000,\n line: logLine,\n labels: stream.stream,\n });\n });\n });\n\n return {\n entries,\n totalCount: entries.length,\n };\n}\n\nexport const getLokiLogData: LogQueryPlugin<LokiLogQuerySpec>['getLogData'] = async (\n spec: LokiLogQuerySpec,\n context: LogQueryContext\n) => {\n if (!spec.query) {\n return {\n logs: { entries: [], totalCount: 0 },\n timeRange: { start: context.timeRange.start, end: context.timeRange.end },\n };\n }\n\n const query = replaceVariables(spec.query, context.variableState);\n const client = (await context.datasourceStore.getDatasourceClient<LokiClient>(\n spec.datasource ?? DEFAULT_DATASOURCE\n )) as LokiClient;\n\n const { start, end } = context.timeRange;\n\n const response: LokiLogQueryResponse = await client.queryRange({\n query,\n start: start.getTime().toString(),\n end: end.getTime().toString(),\n direction: spec.direction,\n });\n\n if (response.data.resultType === 'streams') {\n const logs = convertStreamsToLogs(response.data.result);\n return {\n logs,\n timeRange: { start, end },\n metadata: {\n executedQueryString: query,\n },\n };\n }\n\n return {\n logs: { entries: [], totalCount: 0 },\n timeRange: { start, end },\n };\n};\n"],"names":["replaceVariables","DEFAULT_DATASOURCE","convertStreamsToLogs","streams","entries","forEach","stream","values","timestamp","logLine","push","Number","line","labels","totalCount","length","getLokiLogData","spec","context","query","logs","timeRange","start","end","variableState","client","datasourceStore","getDatasourceClient","datasource","response","queryRange","getTime","toString","direction","data","resultType","result","metadata","executedQueryString"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,4BAA4B;AAI7D,SAASC,kBAAkB,QAAQ,eAAe;AAIlD,SAASC,qBAAqBC,OAA2B;IACvD,MAAMC,UAAsB,EAAE;IAE9BD,QAAQE,OAAO,CAAC,CAACC;QACfA,OAAOC,MAAM,CAACF,OAAO,CAAC,CAAC,CAACG,WAAWC,QAA0B;YAC3DL,QAAQM,IAAI,CAAC;gBACXF,WAAWG,OAAOH,aAAa;gBAC/BI,MAAMH;gBACNI,QAAQP,OAAOA,MAAM;YACvB;QACF;IACF;IAEA,OAAO;QACLF;QACAU,YAAYV,QAAQW,MAAM;IAC5B;AACF;AAEA,OAAO,MAAMC,iBAAiE,OAC5EC,MACAC;IAEA,IAAI,CAACD,KAAKE,KAAK,EAAE;QACf,OAAO;YACLC,MAAM;gBAAEhB,SAAS,EAAE;gBAAEU,YAAY;YAAE;YACnCO,WAAW;gBAAEC,OAAOJ,QAAQG,SAAS,CAACC,KAAK;gBAAEC,KAAKL,QAAQG,SAAS,CAACE,GAAG;YAAC;QAC1E;IACF;IAEA,MAAMJ,QAAQnB,iBAAiBiB,KAAKE,KAAK,EAAED,QAAQM,aAAa;IAChE,MAAMC,SAAU,MAAMP,QAAQQ,eAAe,CAACC,mBAAmB,CAC/DV,KAAKW,UAAU,IAAI3B;IAGrB,MAAM,EAAEqB,KAAK,EAAEC,GAAG,EAAE,GAAGL,QAAQG,SAAS;IAExC,MAAMQ,WAAiC,MAAMJ,OAAOK,UAAU,CAAC;QAC7DX;QACAG,OAAOA,MAAMS,OAAO,GAAGC,QAAQ;QAC/BT,KAAKA,IAAIQ,OAAO,GAAGC,QAAQ;QAC3BC,WAAWhB,KAAKgB,SAAS;IAC3B;IAEA,IAAIJ,SAASK,IAAI,CAACC,UAAU,KAAK,WAAW;QAC1C,MAAMf,OAAOlB,qBAAqB2B,SAASK,IAAI,CAACE,MAAM;QACtD,OAAO;YACLhB;YACAC,WAAW;gBAAEC;gBAAOC;YAAI;YACxBc,UAAU;gBACRC,qBAAqBnB;YACvB;QACF;IACF;IAEA,OAAO;QACLC,MAAM;YAAEhB,SAAS,EAAE;YAAEU,YAAY;QAAE;QACnCO,WAAW;YAAEC;YAAOC;QAAI;IAC1B;AACF,EAAE"}
1
+ {"version":3,"sources":["../../../../src/queries/loki-log-query/get-loki-log-data.ts"],"sourcesContent":["import { replaceVariables } from '@perses-dev/plugin-system';\nimport { LogEntry, LogData } from '@perses-dev/core';\nimport { LokiStreamResult } from '../../model/loki-client-types';\nimport { LokiClient } from '../../model/loki-client';\nimport { DEFAULT_DATASOURCE } from '../constants';\nimport { LokiLogQuerySpec, LokiLogQueryResponse } from './loki-log-query-types';\nimport { LogQueryPlugin, LogQueryContext } from './log-query-plugin-interface';\n\nfunction convertStreamsToLogs(streams: LokiStreamResult[]): LogData {\n const entries: LogEntry[] = [];\n\n streams.forEach((stream) => {\n stream.values.forEach(([timestamp, logLine]: [string, string]) => {\n entries.push({\n timestamp: Number(timestamp) / 1000000000,\n line: logLine,\n labels: stream.stream,\n });\n });\n });\n\n return {\n entries,\n totalCount: entries.length,\n };\n}\n\nexport const getLokiLogData: LogQueryPlugin<LokiLogQuerySpec>['getLogData'] = async (\n spec: LokiLogQuerySpec,\n context: LogQueryContext\n) => {\n if (!spec.query) {\n return {\n logs: { entries: [], totalCount: 0 },\n timeRange: { start: context.timeRange.start, end: context.timeRange.end },\n };\n }\n\n const query = replaceVariables(spec.query, context.variableState);\n const client = (await context.datasourceStore.getDatasourceClient<LokiClient>(\n spec.datasource ?? DEFAULT_DATASOURCE\n )) as LokiClient;\n\n const { start, end } = context.timeRange;\n\n const response: LokiLogQueryResponse = await client.queryRange({\n query,\n start: start.getTime().toString(),\n end: end.getTime().toString(),\n direction: spec.direction,\n });\n\n if (response.data.resultType === 'streams') {\n const logs = convertStreamsToLogs(response.data.result);\n return {\n logs,\n timeRange: { start, end },\n metadata: {\n executedQueryString: query,\n },\n };\n }\n\n return {\n logs: { entries: [], totalCount: 0 },\n timeRange: { start, end },\n };\n};\n"],"names":["replaceVariables","DEFAULT_DATASOURCE","convertStreamsToLogs","streams","entries","forEach","stream","values","timestamp","logLine","push","Number","line","labels","totalCount","length","getLokiLogData","spec","context","query","logs","timeRange","start","end","variableState","client","datasourceStore","getDatasourceClient","datasource","response","queryRange","getTime","toString","direction","data","resultType","result","metadata","executedQueryString"],"mappings":"AAAA,SAASA,gBAAgB,QAAQ,4BAA4B;AAI7D,SAASC,kBAAkB,QAAQ,eAAe;AAIlD,SAASC,qBAAqBC,OAA2B;IACvD,MAAMC,UAAsB,EAAE;IAE9BD,QAAQE,OAAO,CAAC,CAACC;QACfA,OAAOC,MAAM,CAACF,OAAO,CAAC,CAAC,CAACG,WAAWC,QAA0B;YAC3DL,QAAQM,IAAI,CAAC;gBACXF,WAAWG,OAAOH,aAAa;gBAC/BI,MAAMH;gBACNI,QAAQP,OAAOA,MAAM;YACvB;QACF;IACF;IAEA,OAAO;QACLF;QACAU,YAAYV,QAAQW,MAAM;IAC5B;AACF;AAEA,OAAO,MAAMC,iBAAiE,OAC5EC,MACAC;IAEA,IAAI,CAACD,KAAKE,KAAK,EAAE;QACf,OAAO;YACLC,MAAM;gBAAEhB,SAAS,EAAE;gBAAEU,YAAY;YAAE;YACnCO,WAAW;gBAAEC,OAAOJ,QAAQG,SAAS,CAACC,KAAK;gBAAEC,KAAKL,QAAQG,SAAS,CAACE,GAAG;YAAC;QAC1E;IACF;IAEA,MAAMJ,QAAQnB,iBAAiBiB,KAAKE,KAAK,EAAED,QAAQM,aAAa;IAChE,MAAMC,SAAU,MAAMP,QAAQQ,eAAe,CAACC,mBAAmB,CAC/DV,KAAKW,UAAU,IAAI3B;IAGrB,MAAM,EAAEqB,KAAK,EAAEC,GAAG,EAAE,GAAGL,QAAQG,SAAS;IAExC,MAAMQ,WAAiC,MAAMJ,OAAOK,UAAU,CAAC;QAC7DX;QACAG,OAAOA,MAAMS,OAAO,GAAGC,QAAQ;QAC/BT,KAAKA,IAAIQ,OAAO,GAAGC,QAAQ;QAC3BC,WAAWhB,KAAKgB,SAAS;IAC3B;IAEA,IAAIJ,SAASK,IAAI,CAACC,UAAU,KAAK,WAAW;QAC1C,MAAMf,OAAOlB,qBAAqB2B,SAASK,IAAI,CAACE,MAAM;QACtD,OAAO;YACLhB;YACAC,WAAW;gBAAEC;gBAAOC;YAAI;YACxBc,UAAU;gBACRC,qBAAqBnB;YACvB;QACF;IACF;IAEA,OAAO;QACLC,MAAM;YAAEhB,SAAS,EAAE;YAAEU,YAAY;QAAE;QACnCO,WAAW;YAAEC;YAAOC;QAAI;IAC1B;AACF,EAAE"}
@@ -11,7 +11,6 @@ export interface LogQueryContext {
11
11
  timeRange: AbsoluteTimeRange;
12
12
  variableState: VariableStateMap;
13
13
  datasourceStore: DatasourceStore;
14
- refreshKey: string;
15
14
  }
16
15
  type LogQueryPluginDependencies = {
17
16
  variables?: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"log-query-plugin-interface.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-log-query/log-query-plugin-interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAEtF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,CAAC,EAAE;QACT,mBAAmB,EAAE,MAAM,CAAC;KAC7B,CAAC;CACH;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,aAAa,EAAE,gBAAgB,CAAC;IAChC,eAAe,EAAE,eAAe,CAAC;IACjC,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,KAAK,0BAA0B,GAAG;IAChC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,WAAW,cAAc,CAAC,IAAI,GAAG,WAAW,CAAE,SAAQ,MAAM,CAAC,IAAI,CAAC;IACtE,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1E,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,KAAK,0BAA0B,CAAC;CAC9E"}
1
+ {"version":3,"file":"log-query-plugin-interface.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-log-query/log-query-plugin-interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAEtF,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,iBAAiB,CAAC;IAC7B,QAAQ,CAAC,EAAE;QACT,mBAAmB,EAAE,MAAM,CAAC;KAC7B,CAAC;CACH;AAED,MAAM,WAAW,eAAe;IAC9B,SAAS,EAAE,iBAAiB,CAAC;IAC7B,aAAa,EAAE,gBAAgB,CAAC;IAChC,eAAe,EAAE,eAAe,CAAC;CAClC;AAED,KAAK,0BAA0B,GAAG;IAChC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;CACtB,CAAC;AAEF,MAAM,WAAW,cAAc,CAAC,IAAI,GAAG,WAAW,CAAE,SAAQ,MAAM,CAAC,IAAI,CAAC;IACtE,UAAU,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,KAAK,OAAO,CAAC,cAAc,CAAC,CAAC;IAC1E,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,eAAe,KAAK,0BAA0B,CAAC;CAC9E"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/queries/loki-log-query/log-query-plugin-interface.ts"],"sourcesContent":["import { LogData, AbsoluteTimeRange, UnknownSpec } from '@perses-dev/core';\nimport { DatasourceStore, Plugin, VariableStateMap } from '@perses-dev/plugin-system';\n\nexport interface LogQueryResult {\n logs: LogData;\n timeRange: AbsoluteTimeRange;\n metadata?: {\n executedQueryString: string;\n };\n}\n\nexport interface LogQueryContext {\n timeRange: AbsoluteTimeRange;\n variableState: VariableStateMap;\n datasourceStore: DatasourceStore;\n refreshKey: string;\n}\n\ntype LogQueryPluginDependencies = {\n variables?: string[];\n};\n\nexport interface LogQueryPlugin<Spec = UnknownSpec> extends Plugin<Spec> {\n getLogData: (spec: Spec, ctx: LogQueryContext) => Promise<LogQueryResult>;\n dependsOn?: (spec: Spec, ctx: LogQueryContext) => LogQueryPluginDependencies;\n}\n"],"names":[],"mappings":"AAsBA,WAGC"}
1
+ {"version":3,"sources":["../../../../src/queries/loki-log-query/log-query-plugin-interface.ts"],"sourcesContent":["import { LogData, AbsoluteTimeRange, UnknownSpec } from '@perses-dev/core';\nimport { DatasourceStore, Plugin, VariableStateMap } from '@perses-dev/plugin-system';\n\nexport interface LogQueryResult {\n logs: LogData;\n timeRange: AbsoluteTimeRange;\n metadata?: {\n executedQueryString: string;\n };\n}\n\nexport interface LogQueryContext {\n timeRange: AbsoluteTimeRange;\n variableState: VariableStateMap;\n datasourceStore: DatasourceStore;\n}\n\ntype LogQueryPluginDependencies = {\n variables?: string[];\n};\n\nexport interface LogQueryPlugin<Spec = UnknownSpec> extends Plugin<Spec> {\n getLogData: (spec: Spec, ctx: LogQueryContext) => Promise<LogQueryResult>;\n dependsOn?: (spec: Spec, ctx: LogQueryContext) => LogQueryPluginDependencies;\n}\n"],"names":[],"mappings":"AAqBA,WAGC"}
@@ -1 +1 @@
1
- {"version":3,"file":"LokiTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAEnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAe,MAAM,OAAO,CAAC;AAKlD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAGzE,KAAK,oBAAoB,GAAG,kBAAkB,CAAC,uBAAuB,CAAC,CAAC;AAExE,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CA+FzE"}
1
+ {"version":3,"file":"LokiTimeSeriesQueryEditor.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.tsx"],"names":[],"mappings":"AAaA,OAAO,EAIL,kBAAkB,EAEnB,MAAM,2BAA2B,CAAC;AAEnC,OAAO,EAAE,YAAY,EAAe,MAAM,OAAO,CAAC;AAMlD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gCAAgC,CAAC;AAEzE,KAAK,oBAAoB,GAAG,kBAAkB,CAAC,uBAAuB,CAAC,CAAC;AAExE,wBAAgB,eAAe,CAAC,KAAK,EAAE,oBAAoB,GAAG,YAAY,CAsFzE"}
@@ -1,3 +1,4 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
2
  // Copyright 2025 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,17 +11,16 @@
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 { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
14
14
  import { DatasourceSelect, isVariableDatasource, useDatasourceSelectValueToSelector } from '@perses-dev/plugin-system';
15
15
  import { InputLabel, Stack } from '@mui/material';
16
16
  import { useCallback } from 'react';
17
17
  import { produce } from 'immer';
18
- import { LogQLEditor } from '../../components/logql-editor';
18
+ import { LogQLEditor } from '../../components';
19
19
  import { LOKI_DATASOURCE_KIND } from '../../model';
20
20
  import { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';
21
21
  import { useQueryState } from '../query-editor-model';
22
22
  export function LokiQueryEditor(props) {
23
- const { onChange, value, queryHandlerSettings } = props;
23
+ const { onChange, value } = props;
24
24
  const { datasource } = value;
25
25
  const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;
26
26
  const selectedDatasource = useDatasourceSelectValueToSelector(datasourceSelectValue, LOKI_DATASOURCE_KIND);
@@ -30,31 +30,20 @@ export function LokiQueryEditor(props) {
30
30
  onChange(produce(value, (draft)=>{
31
31
  draft.datasource = newDatasourceSelection;
32
32
  }));
33
- if (queryHandlerSettings?.setWatchOtherSpecs) queryHandlerSettings.setWatchOtherSpecs({
34
- ...value,
35
- datasource: newDatasourceSelection
36
- });
37
33
  return;
38
34
  }
39
35
  throw new Error('Got unexpected non LokiQuery datasource selection');
40
36
  };
41
37
  // Immediate query execution on Enter or blur
42
38
  const handleQueryExecute = (query)=>{
43
- if (queryHandlerSettings?.watchQueryChanges) {
44
- queryHandlerSettings.watchQueryChanges(query);
45
- }
46
39
  onChange(produce(value, (draft)=>{
47
40
  draft.query = query;
48
41
  }));
49
42
  };
50
43
  const handleLogsQueryChange = useCallback((e)=>{
51
44
  handleQueryChange(e);
52
- if (queryHandlerSettings?.watchQueryChanges) {
53
- queryHandlerSettings.watchQueryChanges(e);
54
- }
55
45
  }, [
56
- handleQueryChange,
57
- queryHandlerSettings
46
+ handleQueryChange
58
47
  ]);
59
48
  return /*#__PURE__*/ _jsxs(Stack, {
60
49
  spacing: 1.5,
@@ -92,7 +81,7 @@ export function LokiQueryEditor(props) {
92
81
  /*#__PURE__*/ _jsx(LogQLEditor, {
93
82
  value: query,
94
83
  onChange: handleLogsQueryChange,
95
- onBlur: queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined,
84
+ onBlur: handleQueryBlur,
96
85
  onKeyDown: (event)=>{
97
86
  if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {
98
87
  event.preventDefault();
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { InputLabel, Stack } from '@mui/material';\nimport { ReactElement, useCallback } from 'react';\nimport { produce } from 'immer';\nimport { LogQLEditor } from '../../components/logql-editor';\nimport { LOKI_DATASOURCE_KIND, LokiDatasourceSelector } from '../../model';\nimport { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';\nimport { LokiTimeSeriesQuerySpec } from './loki-time-series-query-types';\nimport { useQueryState } from '../query-editor-model';\n\ntype LokiQueryEditorProps = OptionsEditorProps<LokiTimeSeriesQuerySpec>;\n\nexport function LokiQueryEditor(props: LokiQueryEditorProps): ReactElement {\n const { onChange, value, queryHandlerSettings } = props;\n const { datasource } = value;\n const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n LOKI_DATASOURCE_KIND\n ) as LokiDatasourceSelector;\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (newDatasourceSelection) => {\n if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {\n onChange(\n produce(value, (draft) => {\n draft.datasource = newDatasourceSelection;\n })\n );\n\n if (queryHandlerSettings?.setWatchOtherSpecs)\n queryHandlerSettings.setWatchOtherSpecs({ ...value, datasource: newDatasourceSelection });\n return;\n }\n\n throw new Error('Got unexpected non LokiQuery datasource selection');\n };\n\n // Immediate query execution on Enter or blur\n const handleQueryExecute = (query: string) => {\n if (queryHandlerSettings?.watchQueryChanges) {\n queryHandlerSettings.watchQueryChanges(query);\n }\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n const handleLogsQueryChange = useCallback(\n (e: string) => {\n handleQueryChange(e);\n if (queryHandlerSettings?.watchQueryChanges) {\n queryHandlerSettings.watchQueryChanges(e);\n }\n },\n [handleQueryChange, queryHandlerSettings]\n );\n\n return (\n <Stack spacing={1.5} paddingBottom={1}>\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n Datasource\n </InputLabel>\n <DatasourceSelect\n datasourcePluginKind={DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n label=\"Loki Datasource\"\n notched\n />\n </div>\n\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n LogQL Query\n </InputLabel>\n <LogQLEditor\n value={query}\n onChange={handleLogsQueryChange}\n onBlur={queryHandlerSettings?.runWithOnBlur ? handleQueryBlur : undefined}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n handleQueryExecute(query);\n }\n }}\n placeholder='Enter LogQL query (e.g. {job=\"mysql\"} |= \"error\")'\n // height=\"120px\"\n />\n </div>\n </Stack>\n );\n}\n"],"names":["DatasourceSelect","isVariableDatasource","useDatasourceSelectValueToSelector","InputLabel","Stack","useCallback","produce","LogQLEditor","LOKI_DATASOURCE_KIND","DATASOURCE_KIND","DEFAULT_DATASOURCE","useQueryState","LokiQueryEditor","props","onChange","value","queryHandlerSettings","datasource","datasourceSelectValue","selectedDatasource","query","handleQueryChange","handleQueryBlur","handleDatasourceChange","newDatasourceSelection","kind","draft","setWatchOtherSpecs","Error","handleQueryExecute","watchQueryChanges","handleLogsQueryChange","e","spacing","paddingBottom","div","sx","display","marginBottom","fontWeight","datasourcePluginKind","label","notched","onBlur","runWithOnBlur","undefined","onKeyDown","event","key","ctrlKey","metaKey","preventDefault","placeholder"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;;AAEjC,SACEA,gBAAgB,EAEhBC,oBAAoB,EAEpBC,kCAAkC,QAC7B,4BAA4B;AACnC,SAASC,UAAU,EAAEC,KAAK,QAAQ,gBAAgB;AAClD,SAAuBC,WAAW,QAAQ,QAAQ;AAClD,SAASC,OAAO,QAAQ,QAAQ;AAChC,SAASC,WAAW,QAAQ,gCAAgC;AAC5D,SAASC,oBAAoB,QAAgC,cAAc;AAC3E,SAASC,eAAe,EAAEC,kBAAkB,QAAQ,eAAe;AAEnE,SAASC,aAAa,QAAQ,wBAAwB;AAItD,OAAO,SAASC,gBAAgBC,KAA2B;IACzD,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,oBAAoB,EAAE,GAAGH;IAClD,MAAM,EAAEI,UAAU,EAAE,GAAGF;IACvB,MAAMG,wBAAwBD,cAAcP;IAC5C,MAAMS,qBAAqBjB,mCACzBgB,uBACAV;IAEF,MAAM,EAAEY,KAAK,EAAEC,iBAAiB,EAAEC,eAAe,EAAE,GAAGX,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,mBAAmBT;4BACrB;wBACF;wBACAgC,aAAY;;;;;;AAMtB"}
1
+ {"version":3,"sources":["../../../../src/queries/loki-time-series-query/LokiTimeSeriesQueryEditor.tsx"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport {\n DatasourceSelect,\n DatasourceSelectProps,\n isVariableDatasource,\n OptionsEditorProps,\n useDatasourceSelectValueToSelector,\n} from '@perses-dev/plugin-system';\nimport { InputLabel, Stack } from '@mui/material';\nimport { ReactElement, useCallback } from 'react';\nimport { produce } from 'immer';\nimport { LogQLEditor } from '../../components';\nimport { LOKI_DATASOURCE_KIND, LokiDatasourceSelector } from '../../model';\nimport { DATASOURCE_KIND, DEFAULT_DATASOURCE } from '../constants';\nimport { useQueryState } from '../query-editor-model';\nimport { LokiTimeSeriesQuerySpec } from './loki-time-series-query-types';\n\ntype LokiQueryEditorProps = OptionsEditorProps<LokiTimeSeriesQuerySpec>;\n\nexport function LokiQueryEditor(props: LokiQueryEditorProps): ReactElement {\n const { onChange, value } = props;\n const { datasource } = value;\n const datasourceSelectValue = datasource ?? DEFAULT_DATASOURCE;\n const selectedDatasource = useDatasourceSelectValueToSelector(\n datasourceSelectValue,\n LOKI_DATASOURCE_KIND\n ) as LokiDatasourceSelector;\n const { query, handleQueryChange, handleQueryBlur } = useQueryState(props);\n\n const handleDatasourceChange: DatasourceSelectProps['onChange'] = (newDatasourceSelection) => {\n if (!isVariableDatasource(newDatasourceSelection) && newDatasourceSelection.kind === DATASOURCE_KIND) {\n onChange(\n produce(value, (draft) => {\n draft.datasource = newDatasourceSelection;\n })\n );\n return;\n }\n\n throw new Error('Got unexpected non LokiQuery datasource selection');\n };\n\n // Immediate query execution on Enter or blur\n const handleQueryExecute = (query: string) => {\n onChange(\n produce(value, (draft) => {\n draft.query = query;\n })\n );\n };\n\n const handleLogsQueryChange = useCallback(\n (e: string) => {\n handleQueryChange(e);\n },\n [handleQueryChange]\n );\n\n return (\n <Stack spacing={1.5} paddingBottom={1}>\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n Datasource\n </InputLabel>\n <DatasourceSelect\n datasourcePluginKind={DATASOURCE_KIND}\n value={selectedDatasource}\n onChange={handleDatasourceChange}\n label=\"Loki Datasource\"\n notched\n />\n </div>\n\n <div>\n <InputLabel\n sx={{\n display: 'block',\n marginBottom: '4px',\n fontWeight: 500,\n }}\n >\n LogQL Query\n </InputLabel>\n <LogQLEditor\n value={query}\n onChange={handleLogsQueryChange}\n onBlur={handleQueryBlur}\n onKeyDown={(event) => {\n if (event.key === 'Enter' && (event.ctrlKey || event.metaKey)) {\n event.preventDefault();\n handleQueryExecute(query);\n }\n }}\n placeholder='Enter LogQL query (e.g. {job=\"mysql\"} |= \"error\")'\n // height=\"120px\"\n />\n </div>\n </Stack>\n );\n}\n"],"names":["DatasourceSelect","isVariableDatasource","useDatasourceSelectValueToSelector","InputLabel","Stack","useCallback","produce","LogQLEditor","LOKI_DATASOURCE_KIND","DATASOURCE_KIND","DEFAULT_DATASOURCE","useQueryState","LokiQueryEditor","props","onChange","value","datasource","datasourceSelectValue","selectedDatasource","query","handleQueryChange","handleQueryBlur","handleDatasourceChange","newDatasourceSelection","kind","draft","Error","handleQueryExecute","handleLogsQueryChange","e","spacing","paddingBottom","div","sx","display","marginBottom","fontWeight","datasourcePluginKind","label","notched","onBlur","onKeyDown","event","key","ctrlKey","metaKey","preventDefault","placeholder"],"mappings":";AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6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BACd;kCACD;;kCAGD,KAACpC;wBACCqC,sBAAsB5B;wBACtBM,OAAOG;wBACPJ,UAAUQ;wBACVgB,OAAM;wBACNC,OAAO;;;;0BAIX,MAACP;;kCACC,KAAC7B;wBACC8B,IAAI;4BACFC,SAAS;4BACTC,cAAc;4BACdC,YAAY;wBACd;kCACD;;kCAGD,KAAC7B;wBACCQ,OAAOI;wBACPL,UAAUc;wBACVY,QAAQnB;wBACRoB,WAAW,CAACC;4BACV,IAAIA,MAAMC,GAAG,KAAK,WAAYD,CAAAA,MAAME,OAAO,IAAIF,MAAMG,OAAO,AAAD,GAAI;gCAC7DH,MAAMI,cAAc;gCACpBnB,mBAAmBR;4BACrB;wBACF;wBACA4B,aAAY;;;;;;AAMtB"}
@@ -1,9 +1,6 @@
1
1
  import { TimeSeriesQueryPlugin } from '@perses-dev/plugin-system';
2
+ import { LokiMatrixResult } from '../../model/loki-client-types';
2
3
  import { LokiTimeSeriesQuerySpec } from './loki-time-series-query-types';
3
- export type LokiMatrixResult = {
4
- metric: Record<string, string>;
5
- values: Array<[number, string]>;
6
- };
7
4
  export type LokiMatrixResponse = {
8
5
  resultType: 'matrix';
9
6
  result: LokiMatrixResult[];
@@ -1 +1 @@
1
- {"version":3,"file":"get-loki-time-series-data.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-time-series-query/get-loki-time-series-data.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,qBAAqB,EAAoB,MAAM,2BAA2B,CAAC;AAIpF,OAAO,EAAE,uBAAuB,EAA+B,MAAM,gCAAgC,CAAC;AAEtG,MAAM,MAAM,gBAAgB,GAAG;IAC7B,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC/B,MAAM,EAAE,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACjC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,QAAQ,CAAC;IACrB,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAkEF,eAAO,MAAM,qBAAqB,EAAE,qBAAqB,CAAC,uBAAuB,CAAC,CAAC,mBAAmB,CAoDrG,CAAC"}
1
+ {"version":3,"file":"get-loki-time-series-data.d.ts","sourceRoot":"","sources":["../../../../src/queries/loki-time-series-query/get-loki-time-series-data.ts"],"names":[],"mappings":"AAcA,OAAO,EAAE,qBAAqB,EAAoB,MAAM,2BAA2B,CAAC;AAGpF,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAEjE,OAAO,EAAE,uBAAuB,EAA+B,MAAM,gCAAgC,CAAC;AAEtG,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE,QAAQ,CAAC;IACrB,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAkEF,eAAO,MAAM,qBAAqB,EAAE,qBAAqB,CAAC,uBAAuB,CAAC,CAAC,mBAAmB,CAoDrG,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../src/queries/loki-time-series-query/get-loki-time-series-data.ts"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeries, DurationString, parseDurationString } from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceVariables } from '@perses-dev/plugin-system';\nimport { milliseconds } from 'date-fns';\nimport { LokiClient } from '../../model/loki-client';\nimport { DEFAULT_DATASOURCE } from '../constants';\nimport { LokiTimeSeriesQuerySpec, LokiTimeSeriesQueryResponse } from './loki-time-series-query-types';\n\nexport type LokiMatrixResult = {\n metric: Record<string, string>;\n values: Array<[number, string]>;\n};\n\nexport type LokiMatrixResponse = {\n resultType: 'matrix';\n result: LokiMatrixResult[];\n};\n\n// Constants for Loki step calculation\nconst MAX_LOKI_DATA_POINTS = 10000; // Similar to Prometheus\nconst DEFAULT_MIN_STEP_SECONDS = 15; // 15 seconds default minimum\n\n/**\n * Converts a duration string (like \"15s\", \"1m\") to seconds\n */\nfunction getDurationStringSeconds(durationString?: DurationString): number | undefined {\n if (!durationString) return undefined;\n\n const duration = parseDurationString(durationString);\n const ms = milliseconds(duration);\n return Math.floor(ms / 1000);\n}\n\n/**\n * Calculates appropriate step for Loki range queries\n */\nfunction getLokiRangeStep(\n startMs: number,\n endMs: number,\n minStepSeconds = DEFAULT_MIN_STEP_SECONDS,\n suggestedStepMs = 0\n): number {\n const suggestedStepSeconds = suggestedStepMs / 1000;\n const queryRangeSeconds = (endMs - startMs) / 1000;\n\n let safeStep = queryRangeSeconds / MAX_LOKI_DATA_POINTS;\n if (safeStep > 1) {\n safeStep = Math.ceil(safeStep);\n }\n\n return Math.max(suggestedStepSeconds, minStepSeconds, safeStep);\n}\n\n/**\n * Formats step in seconds as a duration string for Loki API\n */\nfunction formatStepForLoki(stepSeconds: number): string {\n if (stepSeconds < 60) {\n return `${Math.round(stepSeconds)}s`;\n } else if (stepSeconds < 3600) {\n return `${Math.round(stepSeconds / 60)}m`;\n } else {\n return `${Math.round(stepSeconds / 3600)}h`;\n }\n}\n\nfunction convertMatrixToTimeSeries(matrix: LokiMatrixResult[]): TimeSeries[] {\n return matrix.map((series) => {\n const name = Object.entries(series.metric)\n .map(([k, v]) => `${k}=${v}`)\n .join(', ');\n return {\n name,\n values: series.values.map(([timestamp, value]) => [\n Number(timestamp) * 1000, // Convert seconds to milliseconds\n Number(value),\n ]),\n labels: series.metric,\n };\n });\n}\n\nexport const getLokiTimeSeriesData: TimeSeriesQueryPlugin<LokiTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (!spec.query) {\n return {\n series: [],\n timeRange: { start: context.timeRange.start, end: context.timeRange.end },\n stepMs: DEFAULT_MIN_STEP_SECONDS * 1000,\n };\n }\n\n const query = replaceVariables(spec.query, context.variableState);\n const client = (await context.datasourceStore.getDatasourceClient<LokiClient>(\n spec.datasource ?? DEFAULT_DATASOURCE\n )) as LokiClient;\n\n const { start, end } = context.timeRange;\n\n // Calculate proper step using similar logic to Prometheus\n const minStepSeconds = spec.step\n ? (getDurationStringSeconds(spec.step as DurationString) ?? DEFAULT_MIN_STEP_SECONDS)\n : DEFAULT_MIN_STEP_SECONDS;\n const stepSeconds = getLokiRangeStep(start.getTime(), end.getTime(), minStepSeconds, context.suggestedStepMs);\n const stepString = formatStepForLoki(stepSeconds);\n const stepMs = stepSeconds * 1000;\n\n const response: LokiTimeSeriesQueryResponse = await client.queryRange({\n query,\n start: start.getTime().toString(),\n end: end.getTime().toString(),\n step: stepString,\n });\n\n if (response.data.resultType === 'matrix') {\n const convertedSeries = convertMatrixToTimeSeries(response.data.result as LokiMatrixResult[]);\n\n return {\n series: convertedSeries,\n timeRange: { start, end },\n stepMs,\n metadata: {\n executedQueryString: query,\n },\n };\n }\n\n return {\n series: [],\n timeRange: { start, end },\n stepMs,\n };\n};\n"],"names":["parseDurationString","replaceVariables","milliseconds","DEFAULT_DATASOURCE","MAX_LOKI_DATA_POINTS","DEFAULT_MIN_STEP_SECONDS","getDurationStringSeconds","durationString","undefined","duration","ms","Math","floor","getLokiRangeStep","startMs","endMs","minStepSeconds","suggestedStepMs","suggestedStepSeconds","queryRangeSeconds","safeStep","ceil","max","formatStepForLoki","stepSeconds","round","convertMatrixToTimeSeries","matrix","map","series","name","Object","entries","metric","k","v","join","values","timestamp","value","Number","labels","getLokiTimeSeriesData","spec","context","query","timeRange","start","end","stepMs","variableState","client","datasourceStore","getDatasourceClient","datasource","step","getTime","stepString","response","queryRange","toString","data","resultType","convertedSeries","result","metadata","executedQueryString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE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AAGI,QAAQ;QAC3BL,MAAME;IACR;IAEA,IAAIC,SAASG,IAAI,CAACC,UAAU,KAAK,UAAU;QACzC,MAAMC,kBAAkBrC,0BAA0BgC,SAASG,IAAI,CAACG,MAAM;QAEtE,OAAO;YACLnC,QAAQkC;YACRjB,WAAW;gBAAEC;gBAAOC;YAAI;YACxBC;YACAgB,UAAU;gBACRC,qBAAqBrB;YACvB;QACF;IACF;IAEA,OAAO;QACLhB,QAAQ,EAAE;QACViB,WAAW;YAAEC;YAAOC;QAAI;QACxBC;IACF;AACF,EAAE"}
1
+ {"version":3,"sources":["../../../../src/queries/loki-time-series-query/get-loki-time-series-data.ts"],"sourcesContent":["// Copyright 2025 The Perses Authors\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\nimport { TimeSeries, DurationString, parseDurationString } from '@perses-dev/core';\nimport { TimeSeriesQueryPlugin, replaceVariables } from '@perses-dev/plugin-system';\nimport { milliseconds } from 'date-fns';\nimport { LokiClient } from '../../model/loki-client';\nimport { LokiMatrixResult } from '../../model/loki-client-types';\nimport { DEFAULT_DATASOURCE } from '../constants';\nimport { LokiTimeSeriesQuerySpec, LokiTimeSeriesQueryResponse } from './loki-time-series-query-types';\n\nexport type LokiMatrixResponse = {\n resultType: 'matrix';\n result: LokiMatrixResult[];\n};\n\n// Constants for Loki step calculation\nconst MAX_LOKI_DATA_POINTS = 10000; // Similar to Prometheus\nconst DEFAULT_MIN_STEP_SECONDS = 15; // 15 seconds default minimum\n\n/**\n * Converts a duration string (like \"15s\", \"1m\") to seconds\n */\nfunction getDurationStringSeconds(durationString?: DurationString): number | undefined {\n if (!durationString) return undefined;\n\n const duration = parseDurationString(durationString);\n const ms = milliseconds(duration);\n return Math.floor(ms / 1000);\n}\n\n/**\n * Calculates appropriate step for Loki range queries\n */\nfunction getLokiRangeStep(\n startMs: number,\n endMs: number,\n minStepSeconds = DEFAULT_MIN_STEP_SECONDS,\n suggestedStepMs = 0\n): number {\n const suggestedStepSeconds = suggestedStepMs / 1000;\n const queryRangeSeconds = (endMs - startMs) / 1000;\n\n let safeStep = queryRangeSeconds / MAX_LOKI_DATA_POINTS;\n if (safeStep > 1) {\n safeStep = Math.ceil(safeStep);\n }\n\n return Math.max(suggestedStepSeconds, minStepSeconds, safeStep);\n}\n\n/**\n * Formats step in seconds as a duration string for Loki API\n */\nfunction formatStepForLoki(stepSeconds: number): string {\n if (stepSeconds < 60) {\n return `${Math.round(stepSeconds)}s`;\n } else if (stepSeconds < 3600) {\n return `${Math.round(stepSeconds / 60)}m`;\n } else {\n return `${Math.round(stepSeconds / 3600)}h`;\n }\n}\n\nfunction convertMatrixToTimeSeries(matrix: LokiMatrixResult[]): TimeSeries[] {\n return matrix.map((series) => {\n const name = Object.entries(series.metric)\n .map(([k, v]) => `${k}=${v}`)\n .join(', ');\n return {\n name,\n values: series.values.map(([timestamp, value]) => [\n Number(timestamp) * 1000, // Convert seconds to milliseconds\n Number(value),\n ]),\n labels: series.metric,\n };\n });\n}\n\nexport const getLokiTimeSeriesData: TimeSeriesQueryPlugin<LokiTimeSeriesQuerySpec>['getTimeSeriesData'] = async (\n spec,\n context\n) => {\n if (!spec.query) {\n return {\n series: [],\n timeRange: { start: context.timeRange.start, end: context.timeRange.end },\n stepMs: DEFAULT_MIN_STEP_SECONDS * 1000,\n };\n }\n\n const query = replaceVariables(spec.query, context.variableState);\n const client = (await context.datasourceStore.getDatasourceClient<LokiClient>(\n spec.datasource ?? DEFAULT_DATASOURCE\n )) as LokiClient;\n\n const { start, end } = context.timeRange;\n\n // Calculate proper step using similar logic to Prometheus\n const minStepSeconds = spec.step\n ? (getDurationStringSeconds(spec.step as DurationString) ?? DEFAULT_MIN_STEP_SECONDS)\n : DEFAULT_MIN_STEP_SECONDS;\n const stepSeconds = getLokiRangeStep(start.getTime(), end.getTime(), minStepSeconds, context.suggestedStepMs);\n const stepString = formatStepForLoki(stepSeconds);\n const stepMs = stepSeconds * 1000;\n\n const response: LokiTimeSeriesQueryResponse = await client.queryRange({\n query,\n start: start.getTime().toString(),\n end: end.getTime().toString(),\n step: stepString,\n });\n\n if (response.data.resultType === 'matrix') {\n const convertedSeries = convertMatrixToTimeSeries(response.data.result as LokiMatrixResult[]);\n\n return {\n series: convertedSeries,\n timeRange: { start, end },\n stepMs,\n metadata: {\n executedQueryString: query,\n },\n };\n }\n\n return {\n series: [],\n timeRange: { start, end },\n stepMs,\n };\n};\n"],"names":["parseDurationString","replaceVariables","milliseconds","DEFAULT_DATASOURCE","MAX_LOKI_DATA_POINTS","DEFAULT_MIN_STEP_SECONDS","getDurationStringSeconds","durationString","undefined","duration","ms","Math","floor","getLokiRangeStep","startMs","endMs","minStepSeconds","suggestedStepMs","suggestedStepSeconds","queryRangeSeconds","safeStep","ceil","max","formatStepForLoki","stepSeconds","round","convertMatrixToTimeSeries","matrix","map","series","name","Object","entries","metric","k","v","join","values","timestamp","value","Number","labels","getLokiTimeSeriesData","spec","context","query","timeRange","start","end","stepMs","variableState","client","datasourceStore","getDatasourceClient","datasource","step","getTime","stepString","response","queryRange","toString","data","resultType","convertedSeries","result","metadata","executedQueryString"],"mappings":"AAAA,oCAAoC;AACpC,kEAAkE;AAClE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,6CAA6C;AAC7C,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AAEjC,SAAqCA,mBAAmB,QAAQ,mBAAmB;AACnF,SAAgCC,gBAAgB,QAAQ,4BAA4B;AACpF,SAASC,YAAY,QAAQ,WAAW;AAGxC,SAASC,kBAAkB,QAAQ,eAAe;AAQlD,sCAAsC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