PromQueryModeller.ts 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { FUNCTIONS } from '../promql';
  2. import { getAggregationOperations } from './aggregations';
  3. import { getOperationDefinitions } from './operations';
  4. import { LokiAndPromQueryModellerBase } from './shared/LokiAndPromQueryModellerBase';
  5. import { PromQueryPattern, PromVisualQueryOperationCategory } from './types';
  6. export class PromQueryModeller extends LokiAndPromQueryModellerBase {
  7. constructor() {
  8. super(() => {
  9. const allOperations = [...getOperationDefinitions(), ...getAggregationOperations()];
  10. for (const op of allOperations) {
  11. const func = FUNCTIONS.find((x) => x.insertText === op.id);
  12. if (func) {
  13. op.documentation = func.documentation;
  14. }
  15. }
  16. return allOperations;
  17. });
  18. this.setOperationCategories([
  19. PromVisualQueryOperationCategory.Aggregations,
  20. PromVisualQueryOperationCategory.RangeFunctions,
  21. PromVisualQueryOperationCategory.Functions,
  22. PromVisualQueryOperationCategory.BinaryOps,
  23. PromVisualQueryOperationCategory.Trigonometric,
  24. PromVisualQueryOperationCategory.Time,
  25. ]);
  26. }
  27. getQueryPatterns(): PromQueryPattern[] {
  28. return [
  29. {
  30. name: 'Rate then sum',
  31. operations: [
  32. { id: 'rate', params: ['$__rate_interval'] },
  33. { id: 'sum', params: [] },
  34. ],
  35. },
  36. {
  37. name: 'Rate then sum by(label) then avg',
  38. operations: [
  39. { id: 'rate', params: ['$__rate_interval'] },
  40. { id: '__sum_by', params: [''] },
  41. { id: 'avg', params: [] },
  42. ],
  43. },
  44. {
  45. name: 'Histogram quantile on rate',
  46. operations: [
  47. { id: 'rate', params: ['$__rate_interval'] },
  48. { id: '__sum_by', params: ['le'] },
  49. { id: 'histogram_quantile', params: [0.95] },
  50. ],
  51. },
  52. {
  53. name: 'Histogram quantile on increase ',
  54. operations: [
  55. { id: 'increase', params: ['$__rate_interval'] },
  56. { id: '__max_by', params: ['le'] },
  57. { id: 'histogram_quantile', params: [0.95] },
  58. ],
  59. },
  60. ];
  61. }
  62. }
  63. export const promQueryModeller = new PromQueryModeller();