metrics.tsx 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. import type {DateString} from 'sentry/types/core';
  2. export type MetricAggregation =
  3. | 'sum'
  4. | 'count_unique'
  5. | 'avg'
  6. | 'count'
  7. | 'min'
  8. | 'max'
  9. | 'min'
  10. | 'p50'
  11. | 'p75'
  12. | 'p95'
  13. | 'p99';
  14. export type MetricType =
  15. | 'c'
  16. | 'd'
  17. | 'g'
  18. | 'e'
  19. | 's'
  20. // Virtual metrics combine multiple metrics into one, to hide the internal complexity
  21. // of span based metrics.
  22. // Created and used only in the frontend
  23. | 'v';
  24. export type UseCase = 'custom' | 'transactions' | 'sessions' | 'spans' | 'metric_stats';
  25. export type MRI = `${MetricType}:${UseCase}${string}@${string}`;
  26. export type ParsedMRI = {
  27. name: string;
  28. type: MetricType;
  29. unit: string;
  30. useCase: UseCase;
  31. };
  32. export type MetricsApiRequestMetric = {
  33. field: string;
  34. groupBy?: string[];
  35. orderBy?: string;
  36. query?: string;
  37. };
  38. export interface MetricsApiRequestQuery extends MetricsApiRequestMetric {
  39. interval: string;
  40. end?: DateString;
  41. environment?: string[];
  42. includeSeries?: number;
  43. includeTotals?: number;
  44. limit?: number;
  45. project?: number[];
  46. start?: DateString;
  47. statsPeriod?: string;
  48. }
  49. export type MetricsDataIntervalLadder = 'metrics' | 'bar' | 'dashboard';
  50. export type MetricsApiResponse = {
  51. end: string;
  52. groups: MetricsGroup[];
  53. intervals: string[];
  54. meta: MetricMeta[];
  55. query: string;
  56. start: string;
  57. };
  58. export interface MetricsQueryApiResponse {
  59. data: {
  60. by: Record<string, string>;
  61. series: Array<number | null>;
  62. totals: number;
  63. }[][];
  64. end: string;
  65. intervals: string[];
  66. meta: [
  67. ...{name: string; type: string}[],
  68. // The last entry in meta has a different shape
  69. MetricsQueryApiResponseLastMeta,
  70. ][];
  71. start: string;
  72. }
  73. export interface MetricsQueryApiResponseLastMeta {
  74. group_bys: string[];
  75. limit: number | null;
  76. order: string | null;
  77. has_more?: boolean;
  78. scaling_factor?: number | null;
  79. unit?: string | null;
  80. unit_family?: 'duration' | 'information' | null;
  81. }
  82. export type MetricsGroup = {
  83. by: Record<string, string>;
  84. series: Record<string, Array<number | null>>;
  85. totals: Record<string, number | null>;
  86. };
  87. export type MetricsTagCollection = Record<string, MetricsTag>;
  88. export type MetricsTag = {
  89. key: string;
  90. };
  91. export type MetricsTagValue = {
  92. key: string;
  93. value: string;
  94. };
  95. export type MetricMeta = {
  96. blockingStatus: BlockingStatus[];
  97. mri: MRI;
  98. // name: string; // returned by the API but should not be used, use parseMRI(mri).name instead
  99. operations: MetricAggregation[];
  100. projectIds: number[];
  101. type: MetricType;
  102. unit: string;
  103. };
  104. export type BlockingStatus = {
  105. blockedTags: string[];
  106. isBlocked: boolean;
  107. projectId: number;
  108. };
  109. export type MetricsMetaCollection = Record<string, MetricMeta>;
  110. export interface MetricsExtractionCondition {
  111. id: number;
  112. mris: MRI[];
  113. value: string;
  114. }
  115. export interface MetricsExtractionRule {
  116. aggregates: MetricAggregation[];
  117. conditions: MetricsExtractionCondition[];
  118. spanAttribute: string;
  119. tags: string[];
  120. unit: string;
  121. }