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
1 change: 1 addition & 0 deletions src/sentry/charts/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ class ChartType(Enum):
SLACK_DISCOVER_TOTAL_PERIOD = "slack:discover.totalPeriod"
SLACK_DISCOVER_TOTAL_DAILY = "slack:discover.totalDaily"
SLACK_DISCOVER_TOP5_PERIOD = "slack:discover.top5Period"
SLACK_DISCOVER_TOP5_PERIOD_LINE = "slack:discover.top5PeriodLine"
SLACK_DISCOVER_TOP5_DAILY = "slack:discover.top5Daily"
SLACK_DISCOVER_PREVIOUS_PERIOD = "slack:discover.previousPeriod"
30 changes: 30 additions & 0 deletions src/sentry/integrations/slack/unfurl/discover.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,29 @@
"default": ChartType.SLACK_DISCOVER_TOTAL_PERIOD,
"daily": ChartType.SLACK_DISCOVER_TOTAL_DAILY,
"top5": ChartType.SLACK_DISCOVER_TOP5_PERIOD,
"top5line": ChartType.SLACK_DISCOVER_TOP5_PERIOD_LINE,
"dailytop5": ChartType.SLACK_DISCOVER_TOP5_DAILY,
"previous": ChartType.SLACK_DISCOVER_PREVIOUS_PERIOD,
}

# All `multiPlotType: line` fields in /static/app/utils/discover/fields.tsx
Copy link
Member

Choose a reason for hiding this comment

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

Should we add a corresponding comment in the fields.tsx file so we know to update both?

line_plot_fields = {
"count_unique",
"failure_count",
"min",
"max",
"p50",
"p75",
"p95",
"p99",
"p100",
"percentile",
"avg",
"apdex",
"user_misery",
"failure_rate",
}

TOP_N = 5
MAX_PERIOD_DAYS_INCLUDE_PREVIOUS = 45
DEFAULT_PERIOD = "14d"
Expand All @@ -48,6 +67,13 @@ def get_double_period(period: str) -> str:
return f"{value * 2}{unit}"


def get_top5_display_mode(field: str) -> str:
if is_equation(field):
return "top5line"

return "top5line" if field.split("(")[0] in line_plot_fields else "top5"


def is_aggregate(field: str) -> bool:
field_match = re.match(AGGREGATE_PATTERN, field)
if field_match:
Expand Down Expand Up @@ -141,6 +167,10 @@ def unfurl_discover(
)
else:
params.setlist("topEvents", [f"{TOP_N}"])

y_axis = params.getlist("yAxis")[0]
display_mode = get_top5_display_mode(y_axis)

else:
# topEvents param persists in the URL in some cases, we want to discard
# it if it's not a top n display type.
Expand Down
2 changes: 2 additions & 0 deletions src/sentry/web/frontend/debug/debug_chart_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,8 @@ def get(self, request):
charts.append(generate_chart(ChartType.SLACK_DISCOVER_TOTAL_DAILY, discover_empty))
charts.append(generate_chart(ChartType.SLACK_DISCOVER_TOP5_PERIOD, discover_top5))
charts.append(generate_chart(ChartType.SLACK_DISCOVER_TOP5_PERIOD, discover_empty))
charts.append(generate_chart(ChartType.SLACK_DISCOVER_TOP5_PERIOD_LINE, discover_top5))
charts.append(generate_chart(ChartType.SLACK_DISCOVER_TOP5_PERIOD_LINE, discover_empty))
charts.append(generate_chart(ChartType.SLACK_DISCOVER_TOP5_DAILY, discover_top5))
charts.append(generate_chart(ChartType.SLACK_DISCOVER_TOP5_DAILY, discover_empty))
charts.append(
Expand Down
56 changes: 56 additions & 0 deletions static/app/chartcuterie/discover.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,62 @@ discoverCharts.push({
...slackChartSize,
});

discoverCharts.push({
key: ChartType.SLACK_DISCOVER_TOP5_PERIOD_LINE,
getOption: (
data: {stats: Record<string, EventsStats>} | {seriesName?: string; stats: EventsStats}
) => {
if (isArray(data.stats.data)) {
const color = theme.charts.getColorPalette(data.stats.data.length - 2);

const lineSeries = LineSeries({
data: data.stats.data.map(([timestamp, countsForTimestamp]) => [
timestamp * 1000,
countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
]),
lineStyle: {color: color?.[0], opacity: 1},
itemStyle: {color: color?.[0]},
});

return {
...slackChartDefaults,
useUTC: true,
color,
series: [lineSeries],
};
}

const stats = Object.values(data.stats);
const hasOther = Object.keys(data.stats).includes('Other');
const color = theme.charts.getColorPalette(stats.length - 2 - (hasOther ? 1 : 0));
if (hasOther) {
color.push(theme.chartOther);
}

const series = stats
.sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
.map((topSeries, i) =>
LineSeries({
data: topSeries.data.map(([timestamp, countsForTimestamp]) => [
timestamp * 1000,
countsForTimestamp.reduce((acc, {count}) => acc + count, 0),
]),
lineStyle: {color: color?.[i], opacity: 1},
itemStyle: {color: color?.[i]},
})
);

return {
...slackChartDefaults,
xAxis: discoverxAxis,
useUTC: true,
color,
series,
};
},
...slackChartSize,
});

discoverCharts.push({
key: ChartType.SLACK_DISCOVER_TOP5_DAILY,
getOption: (
Expand Down
1 change: 1 addition & 0 deletions static/app/chartcuterie/types.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export enum ChartType {
SLACK_DISCOVER_TOTAL_PERIOD = 'slack:discover.totalPeriod',
SLACK_DISCOVER_TOTAL_DAILY = 'slack:discover.totalDaily',
SLACK_DISCOVER_TOP5_PERIOD = 'slack:discover.top5Period',
SLACK_DISCOVER_TOP5_PERIOD_LINE = 'slack:discover.top5PeriodLine',
SLACK_DISCOVER_TOP5_DAILY = 'slack:discover.top5Daily',
SLACK_DISCOVER_PREVIOUS_PERIOD = 'slack:discover.previousPeriod',
}
Expand Down
2 changes: 1 addition & 1 deletion static/app/utils/discover/fields.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ export const AGGREGATIONS = {
],
outputType: 'number',
isSortable: true,
multiPlotType: 'area',
multiPlotType: 'line',
},
failure_rate: {
parameters: [],
Expand Down
3 changes: 2 additions & 1 deletion tests/sentry/integrations/slack/test_unfurl.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ def test_unfurl_discover_short_url(self, mock_generate_chart):
)
assert len(mock_generate_chart.mock_calls) == 1

assert mock_generate_chart.call_args[0][0] == ChartType.SLACK_DISCOVER_TOP5_PERIOD
# Line chart expected since yAxis is count_unique(user)
assert mock_generate_chart.call_args[0][0] == ChartType.SLACK_DISCOVER_TOP5_PERIOD_LINE
chart_data = mock_generate_chart.call_args[0][1]
assert chart_data["seriesName"] == "count_unique(user)"
# 2 + 1 cause of Other
Expand Down