serverSideSampling.tsx 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. ServerSideSamplingStore.setFetching(true);
  28. promise
  29. .then(ServerSideSamplingStore.loadSamplingSdkVersionsSuccess)
  30. .catch(response => {
  31. const errorMessage = t('Unable to fetch sampling sdk versions');
  32. handleXhrErrorResponse(errorMessage)(response);
  33. })
  34. .finally(() => {
  35. ServerSideSamplingStore.setFetching(false);
  36. });
  37. return promise;
  38. }
  39. export function fetchSamplingDistribution({
  40. api,
  41. orgSlug,
  42. projSlug,
  43. }: {
  44. api: Client;
  45. orgSlug: Organization['slug'];
  46. projSlug: Project['slug'];
  47. }): Promise<SamplingDistribution> {
  48. ServerSideSamplingStore.reset();
  49. ServerSideSamplingStore.setFetching(true);
  50. const promise = api.requestPromise(
  51. `/projects/${orgSlug}/${projSlug}/dynamic-sampling/distribution/`,
  52. {
  53. query: {
  54. statsPeriod: '24h',
  55. },
  56. }
  57. );
  58. promise
  59. .then(ServerSideSamplingStore.loadSamplingDistributionSuccess)
  60. .catch(response => {
  61. const errorMessage = t('Unable to fetch sampling distribution');
  62. handleXhrErrorResponse(errorMessage)(response);
  63. })
  64. .finally(() => {
  65. ServerSideSamplingStore.setFetching(false);
  66. });
  67. return promise;
  68. }