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
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ function DetectorResolve({detector}: {detector: MetricDetector}) {
const mainCondition = conditions.find(
condition => condition.conditionResult !== DetectorPriorityLevel.OK
);

// Get the OK condition (resolution condition)
const okCondition = conditions.find(
condition => condition.conditionResult === DetectorPriorityLevel.OK
);

const thresholdSuffix = getMetricDetectorSuffix(
detector.config?.detectionType || 'static',
detector.dataSources[0].queryObj?.snubaQuery?.aggregate || 'count()'
Expand All @@ -102,6 +108,8 @@ function DetectorResolve({detector}: {detector: MetricDetector}) {
typeof mainCondition?.comparison === 'number'
? mainCondition.comparison
: undefined,
resolutionThreshold:
typeof okCondition?.comparison === 'number' ? okCondition.comparison : undefined,
comparisonDelta: (detector.config as any)?.comparison_delta,
thresholdSuffix,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ export function ResolveSection() {
const highThreshold = useMetricDetectorFormField(
METRIC_DETECTOR_FORM_FIELDS.highThreshold
);
const mediumThreshold = useMetricDetectorFormField(
METRIC_DETECTOR_FORM_FIELDS.mediumThreshold
);
const conditionType = useMetricDetectorFormField(
METRIC_DETECTOR_FORM_FIELDS.conditionType
);
Expand All @@ -81,12 +84,17 @@ export function ResolveSection() {

const thresholdSuffix = getStaticDetectorThresholdSuffix(aggregate);

// Compute the automatic resolution threshold: medium if present, otherwise high
const resolutionThreshold =
mediumThreshold && mediumThreshold !== '' ? mediumThreshold : highThreshold || 0;

const descriptionContent = getResolutionDescription(
detectionType === 'percent'
? {
detectionType: 'percent',
conditionType,
highThreshold: highThreshold || 0,
resolutionThreshold,
comparisonDelta: conditionComparisonAgo ?? 3600, // Default to 1 hour if not set
thresholdSuffix,
}
Expand All @@ -95,6 +103,7 @@ export function ResolveSection() {
detectionType: 'static',
conditionType,
highThreshold: highThreshold || 0,
resolutionThreshold,
thresholdSuffix,
}
: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('getDetectorResolutionDescription', () => {
detectionType: 'static',
conditionType: DataConditionType.GREATER,
highThreshold: 100,
resolutionThreshold: undefined,
thresholdSuffix: '%',
});

Expand All @@ -34,6 +35,7 @@ describe('getDetectorResolutionDescription', () => {
detectionType: 'static',
conditionType: DataConditionType.LESS,
highThreshold: 50,
resolutionThreshold: undefined,
thresholdSuffix: 'ms',
});

Expand All @@ -47,13 +49,42 @@ describe('getDetectorResolutionDescription', () => {
detectionType: 'static',
conditionType: DataConditionType.GREATER,
highThreshold: 100,
resolutionThreshold: undefined,
thresholdSuffix: '',
});

expect(result).toBe(
'Issue will be resolved when the query value is less than 100.'
);
});

it('uses resolutionThreshold instead of highThreshold when provided for GREATER condition', () => {
const result = getResolutionDescription({
detectionType: 'static',
conditionType: DataConditionType.GREATER,
highThreshold: 100,
resolutionThreshold: 75,
thresholdSuffix: '%',
});

expect(result).toBe(
'Issue will be resolved when the query value is less than 75%.'
);
});

it('uses resolutionThreshold instead of highThreshold when provided for LESS condition', () => {
const result = getResolutionDescription({
detectionType: 'static',
conditionType: DataConditionType.LESS,
highThreshold: 50,
resolutionThreshold: 80,
thresholdSuffix: 'ms',
});

expect(result).toBe(
'Issue will be resolved when the query value is more than 80ms.'
);
});
});

describe('percent detection type', () => {
Expand All @@ -62,6 +93,7 @@ describe('getDetectorResolutionDescription', () => {
detectionType: 'percent',
conditionType: DataConditionType.GREATER,
highThreshold: 25,
resolutionThreshold: undefined,
comparisonDelta: 3600, // 1 hour
thresholdSuffix: '%',
});
Expand All @@ -76,6 +108,7 @@ describe('getDetectorResolutionDescription', () => {
detectionType: 'percent',
conditionType: undefined,
highThreshold: 25,
resolutionThreshold: undefined,
comparisonDelta: 3600,
thresholdSuffix: '%',
});
Expand All @@ -88,6 +121,7 @@ describe('getDetectorResolutionDescription', () => {
detectionType: 'percent',
conditionType: DataConditionType.GREATER,
highThreshold: undefined,
resolutionThreshold: undefined,
comparisonDelta: 3600,
thresholdSuffix: '%',
});
Expand All @@ -100,6 +134,7 @@ describe('getDetectorResolutionDescription', () => {
detectionType: 'percent',
conditionType: DataConditionType.LESS,
highThreshold: 15,
resolutionThreshold: undefined,
comparisonDelta: 7200, // 2 hours
thresholdSuffix: '%',
});
Expand All @@ -114,6 +149,7 @@ describe('getDetectorResolutionDescription', () => {
detectionType: 'percent',
conditionType: DataConditionType.GREATER,
highThreshold: 20,
resolutionThreshold: undefined,
comparisonDelta: 300, // 5 minutes
thresholdSuffix: '%',
});
Expand All @@ -122,5 +158,20 @@ describe('getDetectorResolutionDescription', () => {
'Issue will be resolved when the query value is less than 20% higher than the previous 5 minutes.'
);
});

it('uses resolutionThreshold instead of highThreshold when provided', () => {
const result = getResolutionDescription({
detectionType: 'percent',
conditionType: DataConditionType.GREATER,
highThreshold: 25,
resolutionThreshold: 15,
comparisonDelta: 3600,
thresholdSuffix: '%',
});

expect(result).toBe(
'Issue will be resolved when the query value is less than 15% higher than the previous 1 hour.'
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ interface PercentDetectionParams extends BaseDetectionParams {
conditionType: DataConditionType | undefined;
detectionType: 'percent';
highThreshold: string | number | undefined;
resolutionThreshold: string | number | undefined;
}

interface StaticDetectionParams extends BaseDetectionParams {
conditionType: DataConditionType | undefined;
detectionType: 'static';
highThreshold: string | number | undefined;
resolutionThreshold: string | number | undefined;
}

interface DynamicDetectionParams extends BaseDetectionParams {
Expand All @@ -45,21 +47,27 @@ export function getResolutionDescription(params: ResolutionDescriptionParams): s
);
}

if (!params.conditionType || params.highThreshold === undefined) {
// Use resolutionThreshold if provided, otherwise fall back to highThreshold
const threshold =
params.resolutionThreshold === undefined
? params.highThreshold
: params.resolutionThreshold;

if (!params.conditionType || threshold === undefined) {
return t('Resolution conditions not configured');
}

if (params.detectionType === 'static') {
if (params.conditionType === DataConditionType.GREATER) {
return t(
'Issue will be resolved when the query value is less than %s%s.',
params.highThreshold,
threshold,
suffix
);
}
return t(
'Issue will be resolved when the query value is more than %s%s.',
params.highThreshold,
threshold,
suffix
);
}
Expand All @@ -69,13 +77,13 @@ export function getResolutionDescription(params: ResolutionDescriptionParams): s
if (params.conditionType === DataConditionType.GREATER) {
return t(
'Issue will be resolved when the query value is less than %s%% higher than the previous %s.',
params.highThreshold,
threshold,
getDuration(delta)
);
}
return t(
'Issue will be resolved when the query value is less than %s%% lower than the previous %s.',
params.highThreshold,
threshold,
getDuration(delta)
);
}
Expand Down
Loading