Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 70 additions & 0 deletions static/app/views/organizationStats/mapSeriesToChart.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,74 @@ describe('mapSeriesToChart func', function () {
{value: ['Jan 2 12:00 AM - 1:00 AM (+00:00)', 2]},
]);
});

it('should correctly sum up the profiles', function () {
const groups = [
{
by: {
outcome: 'invalid',
reason: 'bad',
category: 'profile',
},
totals: {
'sum(quantity)': 10,
},
series: {
'sum(quantity)': [1, 2],
},
},
{
by: {
outcome: 'accepted',
reason: 'good',
category: 'profile',
},
totals: {
'sum(quantity)': 10,
},
series: {
'sum(quantity)': [3, 4],
},
},
{
by: {
outcome: 'accepted',
reason: 'good',
category: 'profile_duration',
},
totals: {
'sum(quantity)': 10,
},
series: {
'sum(quantity)': [1, 2],
},
},
];

const mappedSeries = mapSeriesToChart({
orgStats: {
start: '2021-01-01T00:00:00Z',
end: '2021-01-07T00:00:00Z',
intervals: ['2021-01-01T00:00:00Z', '2021-01-02T00:00:00Z'],
groups,
},
chartDateInterval: '1h',
chartDateUtc: true,
dataCategory: 'profile_duration',
shouldEstimateDroppedProfiles: true,
endpointQuery: {},
});

// multiplies dropped profiles by 9000
expect(mappedSeries.chartStats.invalid).toEqual([
{value: ['Jan 1 12:00 AM - 1:00 AM (+00:00)', 9000]},
{value: ['Jan 2 12:00 AM - 1:00 AM (+00:00)', 18000]},
]);

// does not add accepted profiles to accepted profile duration
expect(mappedSeries.chartStats.accepted).toEqual([
{value: ['Jan 1 12:00 AM - 1:00 AM (+00:00)', 1]},
{value: ['Jan 2 12:00 AM - 1:00 AM (+00:00)', 2]},
]);
});
});
17 changes: 13 additions & 4 deletions static/app/views/organizationStats/mapSeriesToChart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,14 @@ import {formatUsageWithUnits, getFormatUsageOptions} from './utils';
// used for estimated dropped continuous profile hours and ui profile hours from profile chunks and profile chunks ui
export function droppedProfileChunkMultiplier(
category: number | string | undefined,
outcome: number | string | undefined
outcome: number | string | undefined,
shouldEstimateDroppedProfiles?: boolean
) {
if (category === 'profile_chunk' || category === 'profile_chunk_ui') {
if (
category === 'profile_chunk' ||
category === 'profile_chunk_ui' ||
(shouldEstimateDroppedProfiles && category === 'profile')
) {
if (outcome === Outcome.ACCEPTED) {
return 0;
}
Expand All @@ -33,12 +38,14 @@ export function mapSeriesToChart({
chartDateUtc,
endpointQuery,
chartDateInterval,
shouldEstimateDroppedProfiles = false,
}: {
chartDateInterval: IntervalPeriod;
chartDateUtc: boolean;
dataCategory: DataCategoryInfo['plural'];
endpointQuery: Record<string, unknown>;
orgStats?: UsageSeries;
shouldEstimateDroppedProfiles?: boolean;
}): {
cardStats: {
accepted?: string;
Expand Down Expand Up @@ -117,7 +124,7 @@ export function mapSeriesToChart({
} else {
const value =
group.totals['sum(quantity)']! *
droppedProfileChunkMultiplier(category, outcome);
droppedProfileChunkMultiplier(category, outcome, shouldEstimateDroppedProfiles);
if (outcome !== Outcome.CLIENT_DISCARD) {
count.total += value;
}
Expand All @@ -130,7 +137,9 @@ export function mapSeriesToChart({
}

group.series['sum(quantity)']!.forEach((stat, i) => {
stat = stat * droppedProfileChunkMultiplier(category, outcome);
stat =
stat *
droppedProfileChunkMultiplier(category, outcome, shouldEstimateDroppedProfiles);
const dataObject = {name: orgStats.intervals[i]!, value: stat};

const strigfiedReason = String(group.by.reason ?? '');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
import {Fragment} from 'react';
import styled from '@emotion/styled';

import type {TooltipSubLabel} from 'sentry/components/charts/components/tooltip';
import {getSeriesApiInterval} from 'sentry/components/charts/utils';
import type {CursorHandler} from 'sentry/components/pagination';
import Pagination from 'sentry/components/pagination';
import {DATA_CATEGORY_INFO} from 'sentry/constants';
import {tct} from 'sentry/locale';
import type {DataCategoryInfo} from 'sentry/types/core';
import type {DataCategoryInfo, IntervalPeriod} from 'sentry/types/core';
import type {Project} from 'sentry/types/project';
import {browserHistory} from 'sentry/utils/browserHistory';
import type {WithRouteAnalyticsProps} from 'sentry/utils/routeAnalytics/withRouteAnalytics';
import withRouteAnalytics from 'sentry/utils/routeAnalytics/withRouteAnalytics';
import withProjects from 'sentry/utils/withProjects';
// eslint-disable-next-line no-restricted-imports
import withSentryRouter from 'sentry/utils/withSentryRouter';
import {mapSeriesToChart} from 'sentry/views/organizationStats/mapSeriesToChart';
import type {
ChartDataTransform,
ChartStats,
} from 'sentry/views/organizationStats/usageChart';
import type {UsageStatsOrganizationProps} from 'sentry/views/organizationStats/usageStatsOrg';
import UsageStatsOrganization from 'sentry/views/organizationStats/usageStatsOrg';
import {
Expand All @@ -24,7 +30,7 @@ import {
} from 'sentry/views/organizationStats/utils';

import withSubscription from 'getsentry/components/withSubscription';
import type {Subscription} from 'getsentry/types';
import {PlanTier, type Subscription} from 'getsentry/types';
import {SPIKE_PROTECTION_OPTION_DISABLED} from 'getsentry/views/spikeProtection/constants';
import {SpikeProtectionRangeLimitation} from 'getsentry/views/spikeProtection/spikeProtectionCallouts';
import SpikeProtectionHistoryTable from 'getsentry/views/spikeProtection/spikeProtectionHistoryTable';
Expand Down Expand Up @@ -389,6 +395,59 @@ class EnhancedUsageStatsOrganization extends UsageStatsOrganization<
</Fragment>
);
}

get endpointQuery() {
const {dataCategoryApiName, subscription} = this.props;

const query = super.endpointQuery;

if (
dataCategoryApiName === 'profile_duration' &&
subscription.planTier !== PlanTier.AM2
) {
query.category.push('profile');
}

return query;
}

get chartData(): {
cardStats: {
accepted?: string;
accepted_stored?: string;
filtered?: string;
invalid?: string;
rateLimited?: string;
total?: string;
};
chartDateEnd: string;
chartDateEndDisplay: string;
chartDateInterval: IntervalPeriod;
chartDateStart: string;
chartDateStartDisplay: string;
chartDateTimezoneDisplay: string;
chartDateUtc: boolean;
chartStats: ChartStats;
chartSubLabels: TooltipSubLabel[];
chartTransform: ChartDataTransform;
dataError?: Error;
} {
const {dataCategoryApiName, subscription} = this.props;
return {
...mapSeriesToChart({
orgStats: this.state.orgStats,
chartDateInterval: this.chartDateRange.chartDateInterval,
chartDateUtc: this.chartDateRange.chartDateUtc,
dataCategory: this.props.dataCategory,
endpointQuery: this.endpointQuery,
shouldEstimateDroppedProfiles:
dataCategoryApiName === 'profile_duration' &&
subscription.planTier !== PlanTier.AM2,
}),
...this.chartDateRange,
...this.chartTransform,
};
}
}

const DroppedFromSpikesStat = styled('div')`
Expand Down
Loading