serverSideSampling.tsx 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. }: {
  11. api: Client;
  12. orgSlug: Organization['slug'];
  13. }): Promise<SamplingSdkVersion[]> {
  14. const {samplingDistribution} = ServerSideSamplingStore.getState();
  15. const projectIds = samplingDistribution.project_breakdown?.map(
  16. projectBreakdown => projectBreakdown.project_id
  17. );
  18. const promise = api.requestPromise(
  19. `/organizations/${orgSlug}/dynamic-sampling/sdk-versions/`,
  20. {
  21. query: {
  22. project: projectIds,
  23. statsPeriod: '24h',
  24. },
  25. }
  26. );
  27. promise.then(ServerSideSamplingStore.loadSamplingSdkVersionsSuccess).catch(response => {
  28. const errorMessage = t('Unable to fetch sampling sdk versions');
  29. handleXhrErrorResponse(errorMessage)(response);
  30. });
  31. return promise;
  32. }
  33. export function fetchSamplingDistribution({
  34. api,
  35. orgSlug,
  36. projSlug,
  37. }: {
  38. api: Client;
  39. orgSlug: Organization['slug'];
  40. projSlug: Project['slug'];
  41. }): Promise<SamplingDistribution> {
  42. ServerSideSamplingStore.reset();
  43. const promise = api.requestPromise(
  44. `/projects/${orgSlug}/${projSlug}/dynamic-sampling/distribution/`,
  45. {
  46. query: {
  47. statsPeriod: '24h',
  48. },
  49. }
  50. );
  51. promise
  52. .then(ServerSideSamplingStore.loadSamplingDistributionSuccess)
  53. .catch(response => {
  54. const errorMessage = t('Unable to fetch sampling distribution');
  55. handleXhrErrorResponse(errorMessage)(response);
  56. });
  57. return promise;
  58. }