serverSideSampling.tsx 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import {Client} from 'sentry/api';
  2. import {t} from 'sentry/locale';
  3. import {ServerSideSamplingStore} from 'sentry/stores/serverSideSamplingStore';
  4. import {Organization, Project} from 'sentry/types';
  5. import {SamplingDistribution, SamplingSdkVersion} from 'sentry/types/sampling';
  6. import handleXhrErrorResponse from 'sentry/utils/handleXhrErrorResponse';
  7. export function fetchSamplingSdkVersions({
  8. api,
  9. orgSlug,
  10. projectID,
  11. }: {
  12. api: Client;
  13. orgSlug: Organization['slug'];
  14. projectID: Project['id'];
  15. }): Promise<SamplingSdkVersion[]> {
  16. const {samplingDistribution} = ServerSideSamplingStore.getState();
  17. const projectIds = [
  18. projectID,
  19. ...(samplingDistribution.project_breakdown?.map(
  20. projectBreakdown => projectBreakdown.project_id
  21. ) ?? []),
  22. ];
  23. const promise = api.requestPromise(
  24. `/organizations/${orgSlug}/dynamic-sampling/sdk-versions/`,
  25. {
  26. query: {
  27. project: projectIds,
  28. statsPeriod: '24h',
  29. },
  30. }
  31. );
  32. ServerSideSamplingStore.setFetching(true);
  33. promise
  34. .then(ServerSideSamplingStore.loadSamplingSdkVersionsSuccess)
  35. .catch(response => {
  36. const errorMessage = t('Unable to fetch sampling sdk versions');
  37. handleXhrErrorResponse(errorMessage)(response);
  38. })
  39. .finally(() => {
  40. ServerSideSamplingStore.setFetching(false);
  41. });
  42. return promise;
  43. }
  44. export function fetchSamplingDistribution({
  45. api,
  46. orgSlug,
  47. projSlug,
  48. }: {
  49. api: Client;
  50. orgSlug: Organization['slug'];
  51. projSlug: Project['slug'];
  52. }): Promise<SamplingDistribution> {
  53. ServerSideSamplingStore.reset();
  54. ServerSideSamplingStore.setFetching(true);
  55. const promise = api.requestPromise(
  56. `/projects/${orgSlug}/${projSlug}/dynamic-sampling/distribution/`,
  57. {
  58. query: {
  59. statsPeriod: '24h',
  60. },
  61. }
  62. );
  63. promise
  64. .then(ServerSideSamplingStore.loadSamplingDistributionSuccess)
  65. .catch(response => {
  66. const errorMessage = t('Unable to fetch sampling distribution');
  67. handleXhrErrorResponse(errorMessage)(response);
  68. })
  69. .finally(() => {
  70. ServerSideSamplingStore.setFetching(false);
  71. });
  72. return promise;
  73. }