metrics.tsx 2.7 KB

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