1
1
import { MutableSearch } from 'sentry/utils/tokenizeSearch' ;
2
+ import { useLocation } from 'sentry/utils/useLocation' ;
3
+ import useOrganization from 'sentry/utils/useOrganization' ;
4
+ import usePageFilters from 'sentry/utils/usePageFilters' ;
5
+ import { Dataset } from 'sentry/views/alerts/rules/metric/types' ;
6
+ import { Mode } from 'sentry/views/explore/contexts/pageParamsContext/mode' ;
7
+ import { generateExploreCompareRoute } from 'sentry/views/explore/multiQueryMode/locationUtils' ;
8
+ import { ChartType } from 'sentry/views/insights/common/components/chart' ;
9
+ import { BaseChartActionDropdown } from 'sentry/views/insights/common/components/chartActionDropdown' ;
2
10
import { InsightsLineChartWidget } from 'sentry/views/insights/common/components/insightsLineChartWidget' ;
3
11
import { useHttpDomainSummaryChartFilter } from 'sentry/views/insights/common/components/widgets/hooks/useHttpDomainSummaryChartFilter' ;
4
12
import type { LoadableChartWidgetProps } from 'sentry/views/insights/common/components/widgets/types' ;
5
13
import { useSpanMetricsSeries } from 'sentry/views/insights/common/queries/useDiscoverSeries' ;
14
+ import { getAlertsUrl } from 'sentry/views/insights/common/utils/getAlertsUrl' ;
15
+ import { useAlertsProject } from 'sentry/views/insights/common/utils/useAlertsProject' ;
6
16
import { DataTitles } from 'sentry/views/insights/common/views/spans/types' ;
7
17
import { Referrer } from 'sentry/views/insights/http/referrers' ;
8
18
import { FIELD_ALIASES } from 'sentry/views/insights/http/settings' ;
9
19
10
20
export default function HttpDomainSummaryResponseCodesChartWidget (
11
21
props : LoadableChartWidgetProps
12
22
) {
23
+ const organization = useOrganization ( ) ;
24
+ const location = useLocation ( ) ;
25
+ const { selection} = usePageFilters ( ) ;
26
+
13
27
const chartFilters = useHttpDomainSummaryChartFilter ( ) ;
28
+ const project = useAlertsProject ( ) ;
29
+ const search = MutableSearch . fromQueryObject ( chartFilters ) ;
30
+ const referrer = Referrer . DOMAIN_SUMMARY_RESPONSE_CODE_CHART ;
31
+
14
32
const {
15
33
isPending : isResponseCodeDataLoading ,
16
34
data : responseCodeData ,
17
35
error : responseCodeError ,
18
36
} = useSpanMetricsSeries (
19
37
{
20
- search : MutableSearch . fromQueryObject ( chartFilters ) ,
38
+ search,
21
39
yAxis : [ 'http_response_rate(3)' , 'http_response_rate(4)' , 'http_response_rate(5)' ] ,
22
40
transformAliasToInputFormat : true ,
23
41
} ,
24
- Referrer . DOMAIN_SUMMARY_RESPONSE_CODE_CHART ,
42
+ referrer ,
25
43
props . pageFilters
26
44
) ;
27
45
46
+ const responseRateField = 'tags[http.response.status_code,number]' ;
47
+ const stringifiedSearch = search . formatString ( ) ;
48
+
49
+ const queries = [
50
+ {
51
+ yAxes : [ 'count()' ] ,
52
+ label : '3xx' ,
53
+ query : `${ stringifiedSearch } ${ responseRateField } :>300 ${ responseRateField } :<=399` ,
54
+ } ,
55
+ {
56
+ yAxes : [ 'count()' ] ,
57
+ label : '4xx' ,
58
+ query : `${ stringifiedSearch } ${ responseRateField } :>400 ${ responseRateField } :<=499` ,
59
+ } ,
60
+ {
61
+ yAxes : [ 'count()' ] ,
62
+ label : '5xx' ,
63
+ query : `${ stringifiedSearch } ${ responseRateField } :>500 ${ responseRateField } :<=599` ,
64
+ } ,
65
+ ] ;
66
+
67
+ const exploreUrl = generateExploreCompareRoute ( {
68
+ organization,
69
+ mode : Mode . AGGREGATE ,
70
+ location,
71
+ queries : queries . map ( query => ( {
72
+ ...query ,
73
+ chartType : ChartType . LINE ,
74
+ } ) ) ,
75
+ } ) ;
76
+
77
+ const extraActions = [
78
+ < BaseChartActionDropdown
79
+ key = "http response chart widget"
80
+ exploreUrl = { exploreUrl }
81
+ referrer = { referrer }
82
+ alertMenuOptions = { queries . map ( query => ( {
83
+ key : query . label ,
84
+ label : query . label ,
85
+ to : getAlertsUrl ( {
86
+ project,
87
+ aggregate : query . yAxes [ 0 ] ! ,
88
+ organization,
89
+ pageFilters : selection ,
90
+ dataset : Dataset . EVENTS_ANALYTICS_PLATFORM ,
91
+ query : query . query ,
92
+ } ) ,
93
+ } ) ) }
94
+ /> ,
95
+ ] ;
96
+
28
97
return (
29
98
< InsightsLineChartWidget
30
99
{ ...props }
@@ -35,6 +104,7 @@ export default function HttpDomainSummaryResponseCodesChartWidget(
35
104
responseCodeData [ `http_response_rate(4)` ] ,
36
105
responseCodeData [ `http_response_rate(5)` ] ,
37
106
] }
107
+ extraActions = { extraActions }
38
108
aliases = { FIELD_ALIASES }
39
109
isLoading = { isResponseCodeDataLoading }
40
110
error = { responseCodeError }
0 commit comments