@@ -8,7 +8,6 @@ import minBy from 'lodash/minBy';
88import { fetchTotalCount } from 'app/actionCreators/events' ;
99import { Client } from 'app/api' ;
1010import Feature from 'app/components/acl/feature' ;
11- import MarkLine from 'app/components/charts/components/markLine' ;
1211import EventsRequest from 'app/components/charts/eventsRequest' ;
1312import { LineChartSeries } from 'app/components/charts/lineChart' ;
1413import OptionSelector from 'app/components/charts/optionSelector' ;
@@ -25,21 +24,19 @@ import {t} from 'app/locale';
2524import space from 'app/styles/space' ;
2625import { Organization , Project } from 'app/types' ;
2726import { Series , SeriesDataUnit } from 'app/types/echarts' ;
28- import { MINUTE } from 'app/utils/formatters' ;
2927import {
3028 getCrashFreeRateSeries ,
3129 MINUTES_THRESHOLD_TO_DISPLAY_SECONDS ,
3230} from 'app/utils/sessions' ;
33- import theme from 'app/utils/theme' ;
3431import withApi from 'app/utils/withApi' ;
32+ import { getComparisonMarkLines } from 'app/views/alerts/changeAlerts/comparisonMarklines' ;
3533import { COMPARISON_DELTA_OPTIONS } from 'app/views/alerts/incidentRules/constants' ;
3634import { isSessionAggregate , SESSION_AGGREGATE_TO_FIELD } from 'app/views/alerts/utils' ;
3735import { AlertWizardAlertNames } from 'app/views/alerts/wizard/options' ;
3836import { getAlertTypeFromAggregateDataset } from 'app/views/alerts/wizard/utils' ;
3937
4038import {
4139 AlertRuleComparisonType ,
42- AlertRuleThresholdType ,
4340 Dataset ,
4441 IncidentRule ,
4542 SessionsAggregate ,
@@ -227,80 +224,6 @@ class TriggersChart extends React.PureComponent<Props, State> {
227224 ) ;
228225 }
229226
230- getComparisonMarkLines (
231- timeseriesData : Series [ ] = [ ] ,
232- comparisonTimeseriesData : Series [ ] = [ ]
233- ) : LineChartSeries [ ] {
234- const { timeWindow} = this . props ;
235- const changeStatuses : { name : number | string ; status : string } [ ] = [ ] ;
236-
237- if (
238- timeseriesData ?. [ 0 ] ?. data !== undefined &&
239- timeseriesData [ 0 ] . data . length > 1 &&
240- comparisonTimeseriesData ?. [ 0 ] ?. data !== undefined &&
241- comparisonTimeseriesData [ 0 ] . data . length > 1
242- ) {
243- const changeData = comparisonTimeseriesData [ 0 ] . data ;
244- const baseData = timeseriesData [ 0 ] . data ;
245-
246- if (
247- this . props . triggers . some ( ( { alertThreshold} ) => typeof alertThreshold === 'number' )
248- ) {
249- const lastPointLimit =
250- ( baseData [ changeData . length - 1 ] . name as number ) - timeWindow * MINUTE ;
251- changeData . forEach ( ( { name, value : comparisonValue } , idx ) => {
252- const baseValue = baseData [ idx ] . value ;
253- const comparisonPercentage =
254- comparisonValue === 0
255- ? baseValue === 0
256- ? 0
257- : Infinity
258- : ( ( baseValue - comparisonValue ) / comparisonValue ) * 100 ;
259- const status = this . checkChangeStatus ( comparisonPercentage ) ;
260- if (
261- idx === 0 ||
262- idx === changeData . length - 1 ||
263- status !== changeStatuses [ changeStatuses . length - 1 ] . status
264- ) {
265- changeStatuses . push ( { name, status} ) ;
266- }
267- } ) ;
268-
269- return changeStatuses . slice ( 0 , - 1 ) . map ( ( { name, status} , idx ) => ( {
270- seriesName : t ( 'status' ) ,
271- type : 'line' ,
272- markLine : MarkLine ( {
273- silent : true ,
274- lineStyle : {
275- color :
276- status === 'critical'
277- ? theme . red300
278- : status === 'warning'
279- ? theme . yellow300
280- : theme . green300 ,
281- type : 'solid' ,
282- width : 4 ,
283- } ,
284- data : [
285- [
286- { coord : [ name , 0 ] } ,
287- {
288- coord : [
289- Math . min ( changeStatuses [ idx + 1 ] . name as number , lastPointLimit ) ,
290- 0 ,
291- ] ,
292- } ,
293- ] as any ,
294- ] ,
295- } ) ,
296- data : [ ] ,
297- } ) ) ;
298- }
299- }
300-
301- return [ ] ;
302- }
303-
304227 async fetchTotalCount ( ) {
305228 const { api, organization, environment, projects, query} = this . props ;
306229 const statsPeriod = this . getStatsPeriod ( ) ;
@@ -318,55 +241,6 @@ class TriggersChart extends React.PureComponent<Props, State> {
318241 }
319242 }
320243
321- checkChangeStatus ( value : number ) : string {
322- const { thresholdType, triggers} = this . props ;
323- const criticalTrigger = triggers ?. find ( trig => trig . label === 'critical' ) ;
324- const warningTrigger = triggers ?. find ( trig => trig . label === 'warning' ) ;
325- const criticalTriggerAlertThreshold =
326- typeof criticalTrigger ?. alertThreshold === 'number'
327- ? criticalTrigger . alertThreshold
328- : undefined ;
329- const warningTriggerAlertThreshold =
330- typeof warningTrigger ?. alertThreshold === 'number'
331- ? warningTrigger . alertThreshold
332- : undefined ;
333-
334- // Need to catch the critical threshold cases before warning threshold cases
335- if (
336- thresholdType === AlertRuleThresholdType . ABOVE &&
337- criticalTriggerAlertThreshold &&
338- value >= criticalTriggerAlertThreshold
339- ) {
340- return 'critical' ;
341- }
342- if (
343- thresholdType === AlertRuleThresholdType . ABOVE &&
344- warningTriggerAlertThreshold &&
345- value >= warningTriggerAlertThreshold
346- ) {
347- return 'warning' ;
348- }
349- // When threshold is below(lower than in comparison alerts) the % diff value is negative
350- // It crosses the threshold if its abs value is greater than threshold
351- // -80% change crosses below 60% threshold -1 * (-80) > 60
352- if (
353- thresholdType === AlertRuleThresholdType . BELOW &&
354- criticalTriggerAlertThreshold &&
355- - 1 * value >= criticalTriggerAlertThreshold
356- ) {
357- return 'critical' ;
358- }
359- if (
360- thresholdType === AlertRuleThresholdType . BELOW &&
361- warningTriggerAlertThreshold &&
362- - 1 * value >= warningTriggerAlertThreshold
363- ) {
364- return 'warning' ;
365- }
366-
367- return '' ;
368- }
369-
370244 renderChart (
371245 timeseriesData : Series [ ] = [ ] ,
372246 isLoading : boolean ,
@@ -448,11 +322,14 @@ class TriggersChart extends React.PureComponent<Props, State> {
448322 aggregate,
449323 environment,
450324 comparisonDelta,
325+ triggers,
326+ thresholdType,
451327 } = this . props ;
452328
453329 const period = this . getStatsPeriod ( ) ;
454- const renderComparisonStats =
455- organization . features . includes ( 'change-alerts' ) && comparisonDelta ;
330+ const renderComparisonStats = Boolean (
331+ organization . features . includes ( 'change-alerts' ) && comparisonDelta
332+ ) ;
456333
457334 return isSessionAggregate ( aggregate ) ? (
458335 < SessionsRequest
@@ -513,9 +390,12 @@ class TriggersChart extends React.PureComponent<Props, State> {
513390 { ( { loading, reloading, timeseriesData, comparisonTimeseriesData} ) => {
514391 let comparisonMarkLines : LineChartSeries [ ] = [ ] ;
515392 if ( renderComparisonStats && comparisonTimeseriesData ) {
516- comparisonMarkLines = this . getComparisonMarkLines (
393+ comparisonMarkLines = getComparisonMarkLines (
517394 timeseriesData ,
518- comparisonTimeseriesData
395+ comparisonTimeseriesData ,
396+ timeWindow ,
397+ triggers ,
398+ thresholdType
519399 ) ;
520400 }
521401
0 commit comments