Skip to content
Open
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 @@ -4,23 +4,28 @@ import {
AssertionSuggestionCard,
AssertionSuggestionCardPlaceholder,
} from 'sentry/views/alerts/rules/uptime/assertionSuggestionCard';
import type {AssertionSuggestion} from 'sentry/views/alerts/rules/uptime/types';
import {
AssertionType,
ComparisonType,
OpType,
type AssertionSuggestion,
} from 'sentry/views/alerts/rules/uptime/types';

function makeSuggestion(
overrides: Partial<AssertionSuggestion> = {}
): AssertionSuggestion {
return {
assertion_type: 'status_code',
comparison: 'equals',
assertion_type: AssertionType.STATUS_CODE,
comparison: ComparisonType.EQUALS,
expected_value: '200',
confidence: 0.9,
explanation: 'Checks for a healthy response',
json_path: null,
header_name: null,
assertion_json: {
op: 'status_code_check' as const,
op: OpType.STATUS_CODE_CHECK,
id: 'test-1',
operator: {cmp: 'equals' as const},
operator: {cmp: ComparisonType.EQUALS},
value: 200,
},
...overrides,
Expand All @@ -30,8 +35,8 @@ function makeSuggestion(
describe('AssertionSuggestionCard', () => {
it('renders status_code assertion label', () => {
const suggestion = makeSuggestion({
assertion_type: 'status_code',
comparison: 'equals',
assertion_type: AssertionType.STATUS_CODE,
comparison: ComparisonType.EQUALS,
expected_value: '200',
});

Expand All @@ -43,8 +48,8 @@ describe('AssertionSuggestionCard', () => {

it('renders json_path assertion label', () => {
const suggestion = makeSuggestion({
assertion_type: 'json_path',
comparison: 'equals',
assertion_type: AssertionType.JSON_PATH,
comparison: ComparisonType.EQUALS,
expected_value: 'active',
json_path: '$.status',
});
Expand All @@ -57,8 +62,8 @@ describe('AssertionSuggestionCard', () => {

it('renders json_path with always comparison as exists', () => {
const suggestion = makeSuggestion({
assertion_type: 'json_path',
comparison: 'always',
assertion_type: AssertionType.JSON_PATH,
comparison: ComparisonType.ALWAYS,
json_path: '$.data',
});

Expand All @@ -70,8 +75,8 @@ describe('AssertionSuggestionCard', () => {

it('renders header assertion label', () => {
const suggestion = makeSuggestion({
assertion_type: 'header',
comparison: 'equals',
assertion_type: AssertionType.HEADER,
comparison: ComparisonType.EQUALS,
expected_value: 'application/json',
header_name: 'Content-Type',
});
Expand All @@ -84,8 +89,8 @@ describe('AssertionSuggestionCard', () => {

it('renders header with always comparison as exists', () => {
const suggestion = makeSuggestion({
assertion_type: 'header',
comparison: 'always',
assertion_type: AssertionType.HEADER,
comparison: ComparisonType.ALWAYS,
header_name: 'X-Request-Id',
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {Tooltip} from '@sentry/scraps/tooltip';

import Placeholder from 'sentry/components/placeholder';
import {t, tct} from 'sentry/locale';
import type {AssertionSuggestion} from 'sentry/views/alerts/rules/uptime/types';
import {
AssertionType,
ComparisonType,
type AssertionSuggestion,
} from 'sentry/views/alerts/rules/uptime/types';

function getConfidenceBadgeVariant(confidence: number): 'success' | 'warning' | 'danger' {
if (confidence >= 0.8) {
Expand All @@ -29,13 +33,13 @@ export function AssertionSuggestionCard({
}: AssertionSuggestionCardProps) {
const getAssertionLabel = () => {
switch (suggestion.assertion_type) {
case 'status_code':
case AssertionType.STATUS_CODE:
return tct('Status code [comparison] [value]', {
comparison: suggestion.comparison.replace('_', ' '),
value: suggestion.expected_value,
});
case 'json_path':
if (suggestion.comparison === 'always') {
case AssertionType.JSON_PATH:
if (suggestion.comparison === ComparisonType.ALWAYS) {
return tct('[path] exists', {
path: suggestion.json_path,
});
Expand All @@ -45,8 +49,8 @@ export function AssertionSuggestionCard({
comparison: suggestion.comparison.replace('_', ' '),
value: `"${suggestion.expected_value}"`,
});
case 'header':
if (suggestion.comparison === 'always') {
case AssertionType.HEADER:
if (suggestion.comparison === ComparisonType.ALWAYS) {
return tct('Header [name] exists', {
name: suggestion.header_name,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import {IconSeer} from 'sentry/icons';
import {t} from 'sentry/locale';
import {uniqueId} from 'sentry/utils/guid';
import {AssertionSuggestionsDrawerContent} from 'sentry/views/alerts/rules/uptime/assertionSuggestionsDrawerContent';
import type {
AndOp,
Assertion,
AssertionSuggestion,
Op,
import {
OpType,
type AndOp,
type Assertion,
type AssertionSuggestion,
type Op,
} from 'sentry/views/alerts/rules/uptime/types';

/**
Expand All @@ -21,10 +22,10 @@ import type {
function addIdToOp(op: Op): Op {
const id = uniqueId();
switch (op.op) {
case 'and':
case 'or':
case OpType.AND:
case OpType.OR:
return {...op, id, children: op.children.map(addIdToOp)};
case 'not':
case OpType.NOT:
return {...op, id, operand: addIdToOp(op.operand)};
default:
return {...op, id};
Expand Down Expand Up @@ -81,7 +82,7 @@ export function AssertionSuggestionsButton({
children: [...current.root.children, newOp],
}
: {
op: 'and',
op: OpType.AND,
id: uniqueId(),
children: [newOp],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import {OrganizationFixture} from 'sentry-fixture/organization';
import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';

import {AssertionSuggestionsDrawerContent} from 'sentry/views/alerts/rules/uptime/assertionSuggestionsDrawerContent';
import type {PreviewCheckPayload} from 'sentry/views/alerts/rules/uptime/types';
import {
AssertionType,
ComparisonType,
OpType,
type PreviewCheckPayload,
} from 'sentry/views/alerts/rules/uptime/types';

describe('AssertionSuggestionsDrawerContent', () => {
const organization = OrganizationFixture();
Expand Down Expand Up @@ -41,23 +46,23 @@ describe('AssertionSuggestionsDrawerContent', () => {
suggested_assertion: null,
suggestions: [
{
assertion_type: 'status_code',
comparison: 'equals',
assertion_type: AssertionType.STATUS_CODE,
comparison: ComparisonType.EQUALS,
expected_value: '200',
confidence: 0.95,
explanation: 'HTTP 200 indicates a successful response',
json_path: null,
header_name: null,
assertion_json: {
op: 'status_code_check',
op: OpType.STATUS_CODE_CHECK,
id: 'sug-1',
operator: {cmp: 'equals'},
operator: {cmp: ComparisonType.EQUALS},
value: 200,
},
},
{
assertion_type: 'json_path',
comparison: 'equals',
assertion_type: AssertionType.JSON_PATH,
comparison: ComparisonType.EQUALS,
expected_value: 'ok',
confidence: 0.8,
explanation: 'The status field should be ok',
Expand All @@ -67,7 +72,7 @@ describe('AssertionSuggestionsDrawerContent', () => {
op: 'json_path_match',
id: 'sug-2',
path: '$.status',
operator: {cmp: 'equals'},
operator: {cmp: ComparisonType.EQUALS},
value: 'ok',
},
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import {render, screen, userEvent} from 'sentry-test/reactTestingLibrary';

import {ComparisonType, OpType} from 'sentry/views/alerts/rules/uptime/types';

import {AddOpButton} from './addOpButton';

describe('AddOpButton', () => {
Expand Down Expand Up @@ -61,8 +63,8 @@ describe('AddOpButton', () => {

expect(mockOnAddOp).toHaveBeenCalledWith({
id: expect.any(String),
op: 'status_code_check',
operator: {cmp: 'equals'},
op: OpType.STATUS_CODE_CHECK,
operator: {cmp: ComparisonType.EQUALS},
value: 200,
});
});
Expand All @@ -77,9 +79,9 @@ describe('AddOpButton', () => {

expect(mockOnAddOp).toHaveBeenCalledWith({
id: expect.any(String),
op: 'json_path',
op: OpType.JSON_PATH,
value: '',
operator: {cmp: 'equals'},
operator: {cmp: ComparisonType.EQUALS},
operand: {jsonpath_op: 'literal', value: ''},
});
});
Expand All @@ -92,10 +94,10 @@ describe('AddOpButton', () => {

expect(mockOnAddOp).toHaveBeenCalledWith({
id: expect.any(String),
op: 'header_check',
key_op: {cmp: 'equals'},
op: OpType.HEADER_CHECK,
key_op: {cmp: ComparisonType.EQUALS},
key_operand: {header_op: 'literal', value: ''},
value_op: {cmp: 'equals'},
value_op: {cmp: ComparisonType.EQUALS},
value_operand: {header_op: 'literal', value: ''},
});
});
Expand All @@ -110,7 +112,7 @@ describe('AddOpButton', () => {

expect(mockOnAddOp).toHaveBeenCalledWith({
id: expect.any(String),
op: 'and',
op: OpType.AND,
children: [],
});
});
Expand All @@ -126,8 +128,8 @@ describe('AddOpButton', () => {

expect(mockOnAddOp).toHaveBeenNthCalledWith(1, {
id: expect.any(String),
op: 'status_code_check',
operator: {cmp: 'equals'},
op: OpType.STATUS_CODE_CHECK,
operator: {cmp: ComparisonType.EQUALS},
value: 200,
});

Expand All @@ -141,8 +143,8 @@ describe('AddOpButton', () => {

expect(mockOnAddOp).toHaveBeenNthCalledWith(2, {
id: expect.any(String),
op: 'status_code_check',
operator: {cmp: 'equals'},
op: OpType.STATUS_CODE_CHECK,
operator: {cmp: ComparisonType.EQUALS},
value: 200,
});

Expand Down
30 changes: 16 additions & 14 deletions static/app/views/alerts/rules/uptime/assertions/addOpButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import {
} from 'sentry/components/dropdownMenu';
import {t} from 'sentry/locale';
import {uniqueId} from 'sentry/utils/guid';
import type {
AndOp,
HeaderCheckOp,
JsonPathOp,
Op,
StatusCodeOp,
import {
ComparisonType,
OpType,
type AndOp,
type HeaderCheckOp,
type JsonPathOp,
type Op,
type StatusCodeOp,
} from 'sentry/views/alerts/rules/uptime/types';

interface AddOpButtonProps extends Omit<DropdownMenuProps, 'items'> {
Expand All @@ -29,8 +31,8 @@ export function AddOpButton({onAddOp, ...dropdownProps}: AddOpButtonProps) {
onAction: () => {
const statusCodeOp: StatusCodeOp = {
id: uniqueId(),
op: 'status_code_check',
operator: {cmp: 'equals'},
op: OpType.STATUS_CODE_CHECK,
operator: {cmp: ComparisonType.EQUALS},
value: 200,
};
onAddOp(statusCodeOp);
Expand All @@ -43,9 +45,9 @@ export function AddOpButton({onAddOp, ...dropdownProps}: AddOpButtonProps) {
onAction: () => {
const jsonPathOp: JsonPathOp = {
id: uniqueId(),
op: 'json_path',
op: OpType.JSON_PATH,
value: '',
operator: {cmp: 'equals'},
operator: {cmp: ComparisonType.EQUALS},
operand: {jsonpath_op: 'literal', value: ''},
};
onAddOp(jsonPathOp);
Expand All @@ -58,10 +60,10 @@ export function AddOpButton({onAddOp, ...dropdownProps}: AddOpButtonProps) {
onAction: () => {
const headerOp: HeaderCheckOp = {
id: uniqueId(),
op: 'header_check',
key_op: {cmp: 'equals'},
op: OpType.HEADER_CHECK,
key_op: {cmp: ComparisonType.EQUALS},
key_operand: {header_op: 'literal', value: ''},
value_op: {cmp: 'equals'},
value_op: {cmp: ComparisonType.EQUALS},
value_operand: {header_op: 'literal', value: ''},
};
onAddOp(headerOp);
Expand All @@ -74,7 +76,7 @@ export function AddOpButton({onAddOp, ...dropdownProps}: AddOpButtonProps) {
onAction: () => {
const andOp: AndOp = {
id: uniqueId(),
op: 'and',
op: OpType.AND,
children: [],
};
onAddOp(andOp);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ import {
makeOrOp,
makeStatusCodeOp,
} from 'sentry/views/alerts/rules/uptime/assertions/testUtils';
import type {Assertion} from 'sentry/views/alerts/rules/uptime/types';
import {ComparisonType, type Assertion} from 'sentry/views/alerts/rules/uptime/types';

import {AssertionFailureTree} from './assertionFailureTree';

describe('AssertionFailureTree', () => {
it('renders rows in order for a simple assertion', () => {
const assertion: Assertion = {
root: makeAndOp({
children: [makeStatusCodeOp({operator: {cmp: 'equals'}, value: 500})],
children: [
makeStatusCodeOp({operator: {cmp: ComparisonType.EQUALS}, value: 500}),
],
}),
};

Expand All @@ -40,7 +42,7 @@ describe('AssertionFailureTree', () => {
children: [
makeJsonPathOp({
value: '$.status',
operator: {cmp: 'equals'},
operator: {cmp: ComparisonType.EQUALS},
operand: {jsonpath_op: 'literal', value: 'ok'},
}),
makeHeaderCheckOp({
Expand Down
Loading
Loading