123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- import {Client} from 'sentry/api';
- import {t} from 'sentry/locale';
- import {ServerSideSamplingStore} from 'sentry/stores/serverSideSamplingStore';
- import {Organization, Project} from 'sentry/types';
- import {SamplingDistribution, SamplingSdkVersion} from 'sentry/types/sampling';
- import handleXhrErrorResponse from 'sentry/utils/handleXhrErrorResponse';
- export function fetchSamplingSdkVersions({
- api,
- orgSlug,
- projectID,
- }: {
- api: Client;
- orgSlug: Organization['slug'];
- projectID: Project['id'];
- }): Promise<SamplingSdkVersion[]> {
- const {samplingDistribution} = ServerSideSamplingStore.getState();
- const {startTimestamp, endTimestamp, project_breakdown} = samplingDistribution;
- if (!startTimestamp || !endTimestamp) {
- ServerSideSamplingStore.setFetching(false);
- ServerSideSamplingStore.loadSamplingSdkVersionsSuccess([]);
- return new Promise(resolve => {
- resolve([]);
- });
- }
- const projectIds = [
- projectID,
- ...(project_breakdown?.map(projectBreakdown => projectBreakdown.project_id) ?? []),
- ];
- const promise = api.requestPromise(
- `/organizations/${orgSlug}/dynamic-sampling/sdk-versions/`,
- {
- query: {
- project: projectIds,
- start: startTimestamp,
- end: endTimestamp,
- },
- }
- );
- ServerSideSamplingStore.setFetching(true);
- promise
- .then(ServerSideSamplingStore.loadSamplingSdkVersionsSuccess)
- .catch(response => {
- const errorMessage = t('Unable to fetch sampling sdk versions');
- handleXhrErrorResponse(errorMessage)(response);
- })
- .finally(() => {
- ServerSideSamplingStore.setFetching(false);
- });
- return promise;
- }
- export function fetchSamplingDistribution({
- api,
- orgSlug,
- projSlug,
- }: {
- api: Client;
- orgSlug: Organization['slug'];
- projSlug: Project['slug'];
- }): Promise<SamplingDistribution> {
- ServerSideSamplingStore.reset();
- ServerSideSamplingStore.setFetching(true);
- const promise = api.requestPromise(
- `/projects/${orgSlug}/${projSlug}/dynamic-sampling/distribution/`
- );
- promise
- .then(ServerSideSamplingStore.loadSamplingDistributionSuccess)
- .catch(response => {
- const errorMessage = t('Unable to fetch sampling distribution');
- handleXhrErrorResponse(errorMessage)(response);
- })
- .finally(() => {
- ServerSideSamplingStore.setFetching(false);
- });
- return promise;
- }
|