metrics.tsx 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import type {Client, ResponseMeta} from 'sentry/api';
  2. import {getInterval} from 'sentry/components/charts/utils';
  3. import {normalizeDateTimeParams} from 'sentry/components/organizations/pageFilters/parse';
  4. import type {DateString} from 'sentry/types/core';
  5. import type {MetricsApiResponse} from 'sentry/types/metrics';
  6. import type {Organization} from 'sentry/types/organization';
  7. import {defined} from 'sentry/utils';
  8. export type DoReleaseHealthRequestOptions = {
  9. field: string[];
  10. orgSlug: Organization['slug'];
  11. cursor?: string;
  12. end?: DateString;
  13. environment?: Readonly<string[]>;
  14. groupBy?: string[];
  15. includeAllArgs?: boolean;
  16. includeSeries?: number;
  17. includeTotals?: number;
  18. interval?: string;
  19. limit?: number;
  20. orderBy?: string;
  21. project?: Readonly<number[]>;
  22. query?: string;
  23. start?: DateString;
  24. statsPeriod?: string | null;
  25. statsPeriodEnd?: string;
  26. statsPeriodStart?: string;
  27. };
  28. export const doReleaseHealthRequest = (
  29. api: Client,
  30. {
  31. field,
  32. orgSlug,
  33. cursor,
  34. environment,
  35. groupBy,
  36. includeSeries,
  37. includeTotals,
  38. interval,
  39. limit,
  40. orderBy,
  41. project,
  42. query,
  43. includeAllArgs = false,
  44. statsPeriodStart,
  45. statsPeriodEnd,
  46. ...dateTime
  47. }: DoReleaseHealthRequestOptions
  48. ): Promise<MetricsApiResponse | [MetricsApiResponse, string, ResponseMeta]> => {
  49. const {start, end, statsPeriod} = normalizeDateTimeParams(dateTime, {
  50. allowEmptyPeriod: true,
  51. });
  52. const urlQuery = Object.fromEntries(
  53. Object.entries({
  54. field: field.filter(f => !!f),
  55. cursor,
  56. end,
  57. environment,
  58. groupBy: groupBy?.filter(g => !!g),
  59. includeSeries,
  60. includeTotals,
  61. interval: interval || getInterval({start, end, period: statsPeriod}),
  62. query: query || undefined,
  63. per_page: limit,
  64. project,
  65. orderBy,
  66. start,
  67. statsPeriod,
  68. statsPeriodStart,
  69. statsPeriodEnd,
  70. }).filter(([, value]) => defined(value) && value !== '')
  71. );
  72. const pathname = `/organizations/${orgSlug}/metrics/data/`;
  73. return api.requestPromise(pathname, {includeAllArgs, query: urlQuery});
  74. };