Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(stats): Display subseries in tooltip #73774

Merged
merged 7 commits into from
Jul 5, 2024
Merged
Changes from 1 commit
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
85 changes: 70 additions & 15 deletions static/app/views/organizationStats/usageStatsOrg.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import type {WithRouterProps} from 'react-router';
import styled from '@emotion/styled';
import * as Sentry from '@sentry/react';
import isEqual from 'lodash/isEqual';
import startCase from 'lodash/startCase';
import moment from 'moment';

import {navigateTo} from 'sentry/actionCreators/navigation';
import type {TooltipSubLabel} from 'sentry/components/charts/components/tooltip';
import OptionSelector from 'sentry/components/charts/optionSelector';
import {InlineContainer, SectionHeading} from 'sentry/components/charts/styles';
import type {DateTimeObject} from 'sentry/components/charts/utils';
Expand Down Expand Up @@ -115,7 +117,7 @@ class UsageStatsOrganization<
return {
...queryDatetime,
interval: getSeriesApiInterval(dataDatetime),
groupBy: ['category', 'outcome'],
groupBy: ['category', 'outcome', 'reason'],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this need to be behind a feature flag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I recall correctly, no, but let me check again to confirm.

project: projectIds,
field: ['sum(quantity)'],
};
Expand All @@ -136,6 +138,7 @@ class UsageStatsOrganization<
chartDateTimezoneDisplay: string;
chartDateUtc: boolean;
chartStats: ChartStats;
chartSubLabels: TooltipSubLabel[];
chartTransform: ChartDataTransform;
dataError?: Error;
} {
Expand Down Expand Up @@ -232,6 +235,7 @@ class UsageStatsOrganization<
chartDateEnd,
chartDateUtc,
chartTransform,
chartSubLabels,
} = this.chartData;

const hasError = error || !!dataError;
Expand All @@ -249,6 +253,9 @@ class UsageStatsOrganization<
usageDateShowUtc: chartDateUtc,
usageDateInterval: chartDateInterval,
usageStats: chartStats,
chartTooltip: {
subLabels: chartSubLabels,
},
} as UsageChartProps;

return chartProps;
Expand Down Expand Up @@ -318,6 +325,7 @@ class UsageStatsOrganization<
total?: string;
};
chartStats: ChartStats;
chartSubLabels: TooltipSubLabel[];
dataError?: Error;
} {
const cardStats = {
Expand All @@ -332,9 +340,10 @@ class UsageStatsOrganization<
projected: [],
filtered: [],
};
const chartSubLabels: TooltipSubLabel[] = [];

if (!orgStats) {
return {cardStats, chartStats};
return {cardStats, chartStats, chartSubLabels};
}

try {
Expand Down Expand Up @@ -383,20 +392,64 @@ class UsageStatsOrganization<
count[outcome] += group.totals['sum(quantity)'];

group.series['sum(quantity)'].forEach((stat, i) => {
switch (outcome) {
case Outcome.ACCEPTED:
case Outcome.FILTERED:
usageStats[i][outcome] += stat;
return;
case Outcome.DROPPED:
case Outcome.RATE_LIMITED:
case Outcome.CARDINALITY_LIMITED:
case Outcome.INVALID:
usageStats[i].dropped.total += stat;
// TODO: add client discards to dropped?
return;
default:
const dataObject = {
name: orgStats.intervals[i],
value: stat,
};

const reason = String(group.by.reason ?? '');
const label = startCase(reason.replace(/-|_/g, ' '));
const existingSubLabel = chartSubLabels.find(
subLabel => subLabel.label === label
);

if (outcome === Outcome.FILTERED) {
usageStats[i][outcome] += stat;

if (group.by.outcome === Outcome.FILTERED) {
if (existingSubLabel) {
existingSubLabel.data.push({
...dataObject,
value: dataObject.value,
});
return;
}

chartSubLabels.push({
parentLabel: t('Filtered'),
label,
data: [dataObject],
});
}
return;
}

if (outcome === Outcome.ACCEPTED) {
usageStats[i][outcome] += stat;
return;
}

if (
outcome === Outcome.DROPPED ||
outcome === Outcome.RATE_LIMITED ||
outcome === Outcome.CARDINALITY_LIMITED ||
outcome === Outcome.INVALID
) {
usageStats[i].dropped.total += stat;

if (existingSubLabel) {
existingSubLabel.data.push({
...dataObject,
value: dataObject.value,
});
return;
}

chartSubLabels.push({
parentLabel: t('Dropped'),
label,
data: [dataObject],
});
}
});
});
Expand Down Expand Up @@ -441,6 +494,7 @@ class UsageStatsOrganization<
),
},
chartStats,
chartSubLabels,
};
} catch (err) {
Sentry.withScope(scope => {
Expand All @@ -452,6 +506,7 @@ class UsageStatsOrganization<
return {
cardStats,
chartStats,
chartSubLabels,
dataError: new Error('Failed to parse stats data'),
};
}
Expand Down
Loading