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
9 changes: 6 additions & 3 deletions static/app/types/workflowEngine/detectors.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ import type {
EventTypes,
ExtrapolationMode,
} from 'sentry/views/alerts/rules/metric/types';
import type {Assertion, UptimeMonitorMode} from 'sentry/views/alerts/rules/uptime/types';
import type {
UptimeAssertion,
UptimeMonitorMode,
} from 'sentry/views/alerts/rules/uptime/types';
import type {Monitor, MonitorConfig} from 'sentry/views/insights/crons/types';

/**
Expand Down Expand Up @@ -59,7 +62,7 @@ export interface UptimeSubscriptionDataSource extends BaseDataSource {
* See UptimeSubscriptionSerializer
*/
queryObj: {
assertion: Assertion | null;
assertion: UptimeAssertion | null;
body: string | null;
headers: Array<[string, string]>;
intervalSeconds: number;
Expand Down Expand Up @@ -191,7 +194,7 @@ interface UpdateUptimeDataSourcePayload {
timeoutMs: number;
traceSampling: boolean;
url: string;
assertion?: Assertion | null;
assertion?: UptimeAssertion | null;
body?: string | null;
headers?: Array<[string, string]>;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,27 @@ import {
AssertionSuggestionCardPlaceholder,
} from 'sentry/views/alerts/rules/uptime/assertionSuggestionCard';
import {
AssertionType,
ComparisonType,
OpType,
type AssertionSuggestion,
UptimeAssertionType,
UptimeComparisonType,
UptimeOpType,
type UptimeAssertionSuggestion,
} from 'sentry/views/alerts/rules/uptime/types';

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

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

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

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

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import {Tooltip} from '@sentry/scraps/tooltip';
import Placeholder from 'sentry/components/placeholder';
import {t, tct} from 'sentry/locale';
import {
AssertionType,
ComparisonType,
type AssertionSuggestion,
UptimeAssertionType,
UptimeComparisonType,
type UptimeAssertionSuggestion,
} from 'sentry/views/alerts/rules/uptime/types';

function getConfidenceBadgeVariant(confidence: number): 'success' | 'warning' | 'danger' {
Expand All @@ -24,7 +24,7 @@ function getConfidenceBadgeVariant(confidence: number): 'success' | 'warning' |

interface AssertionSuggestionCardProps {
onApply: () => void;
suggestion: AssertionSuggestion;
suggestion: UptimeAssertionSuggestion;
}

export function AssertionSuggestionCard({
Expand All @@ -33,13 +33,13 @@ export function AssertionSuggestionCard({
}: AssertionSuggestionCardProps) {
const getAssertionLabel = () => {
switch (suggestion.assertion_type) {
case AssertionType.STATUS_CODE:
case UptimeAssertionType.STATUS_CODE:
return tct('Status code [comparison] [value]', {
comparison: suggestion.comparison.replace('_', ' '),
value: suggestion.expected_value,
});
case AssertionType.JSON_PATH:
if (suggestion.comparison === ComparisonType.ALWAYS) {
case UptimeAssertionType.JSON_PATH:
if (suggestion.comparison === UptimeComparisonType.ALWAYS) {
return tct('[path] exists', {
path: suggestion.json_path,
});
Expand All @@ -49,8 +49,8 @@ export function AssertionSuggestionCard({
comparison: suggestion.comparison.replace('_', ' '),
value: `"${suggestion.expected_value}"`,
});
case AssertionType.HEADER:
if (suggestion.comparison === ComparisonType.ALWAYS) {
case UptimeAssertionType.HEADER:
if (suggestion.comparison === UptimeComparisonType.ALWAYS) {
return tct('Header [name] exists', {
name: suggestion.header_name,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import {t} from 'sentry/locale';
import {uniqueId} from 'sentry/utils/guid';
import {AssertionSuggestionsDrawerContent} from 'sentry/views/alerts/rules/uptime/assertionSuggestionsDrawerContent';
import {
OpType,
type AndOp,
type Assertion,
type AssertionSuggestion,
type Op,
UptimeOpType,
type UptimeAndOp,
type UptimeAssertion,
type UptimeAssertionSuggestion,
type UptimeOp,
} from 'sentry/views/alerts/rules/uptime/types';

/**
* Adds an `id` field to an assertion Op for the frontend
*/
function addIdToOp(op: Op): Op {
function addIdToOp(op: UptimeOp): UptimeOp {
const id = uniqueId();
switch (op.op) {
case OpType.AND:
case OpType.OR:
case UptimeOpType.AND:
case UptimeOpType.OR:
return {...op, id, children: op.children.map(addIdToOp)};
case OpType.NOT:
case UptimeOpType.NOT:
return {...op, id, operand: addIdToOp(op.operand)};
default:
return {...op, id};
Expand All @@ -36,7 +36,7 @@ interface AssertionSuggestionsButtonProps {
/**
* Returns the current assertion value from the form at call time.
*/
getCurrentAssertion: () => Assertion | null;
getCurrentAssertion: () => UptimeAssertion | null;
/**
* Callback to get the current form data for the test request.
*/
Expand All @@ -50,7 +50,7 @@ interface AssertionSuggestionsButtonProps {
/**
* Callback when user applies a suggestion
*/
onApplySuggestion: (updatedAssertion: Assertion) => void;
onApplySuggestion: (updatedAssertion: UptimeAssertion) => void;
/**
* Button size
*/
Expand All @@ -70,19 +70,19 @@ export function AssertionSuggestionsButton({
const {openDrawer, isDrawerOpen} = useDrawer();

const handleApplySuggestion = useCallback(
(suggestion: AssertionSuggestion) => {
(suggestion: UptimeAssertionSuggestion) => {
const newOp = addIdToOp(suggestion.assertion_json);
// Read the current assertion at apply time so we always merge with
// the latest form state, preserving any existing assertions.
const current = getCurrentAssertion();

const newRoot: AndOp = current?.root
const newRoot: UptimeAndOp = current?.root
? {
...current.root,
children: [...current.root.children, newOp],
}
: {
op: OpType.AND,
op: UptimeOpType.AND,
id: uniqueId(),
children: [newOp],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import {render, screen, waitFor} from 'sentry-test/reactTestingLibrary';

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

Expand Down Expand Up @@ -46,23 +46,23 @@ describe('AssertionSuggestionsDrawerContent', () => {
suggested_assertion: null,
suggestions: [
{
assertion_type: AssertionType.STATUS_CODE,
comparison: ComparisonType.EQUALS,
assertion_type: UptimeAssertionType.STATUS_CODE,
comparison: UptimeComparisonType.EQUALS,
expected_value: '200',
confidence: 0.95,
explanation: 'HTTP 200 indicates a successful response',
json_path: null,
header_name: null,
assertion_json: {
op: OpType.STATUS_CODE_CHECK,
op: UptimeOpType.STATUS_CODE_CHECK,
id: 'sug-1',
operator: {cmp: ComparisonType.EQUALS},
operator: {cmp: UptimeComparisonType.EQUALS},
value: 200,
},
},
{
assertion_type: AssertionType.JSON_PATH,
comparison: ComparisonType.EQUALS,
assertion_type: UptimeAssertionType.JSON_PATH,
comparison: UptimeComparisonType.EQUALS,
expected_value: 'ok',
confidence: 0.8,
explanation: 'The status field should be ok',
Expand All @@ -72,7 +72,7 @@ describe('AssertionSuggestionsDrawerContent', () => {
op: 'json_path_match',
id: 'sug-2',
path: '$.status',
operator: {cmp: ComparisonType.EQUALS},
operator: {cmp: UptimeComparisonType.EQUALS},
value: 'ok',
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import {
AssertionSuggestionCardPlaceholder,
} from 'sentry/views/alerts/rules/uptime/assertionSuggestionCard';
import type {
AssertionSuggestion,
AssertionSuggestionsResponse,
PreviewCheckPayload,
UptimeAssertionSuggestion,
UptimeAssertionSuggestionsResponse,
} from 'sentry/views/alerts/rules/uptime/types';

interface AssertionSuggestionsDrawerContentProps {
onApply: (suggestion: AssertionSuggestion) => void;
onApply: (suggestion: UptimeAssertionSuggestion) => void;
payload: PreviewCheckPayload;
}

Expand All @@ -40,21 +40,22 @@ export function AssertionSuggestionsDrawerContent({
}: AssertionSuggestionsDrawerContentProps) {
const organization = useOrganization();

const {data, isPending, isError, refetch} = useApiQuery<AssertionSuggestionsResponse>(
[
getApiUrl('/organizations/$organizationIdOrSlug/uptime-assertion-suggestions/', {
path: {organizationIdOrSlug: organization.slug},
}),
const {data, isPending, isError, refetch} =
useApiQuery<UptimeAssertionSuggestionsResponse>(
[
getApiUrl('/organizations/$organizationIdOrSlug/uptime-assertion-suggestions/', {
path: {organizationIdOrSlug: organization.slug},
}),
{
method: 'POST',
data: {...payload},
},
],
{
method: 'POST',
data: {...payload},
},
],
{
staleTime: 5 * 60 * 1000,
retry: false,
}
);
staleTime: 5 * 60 * 1000,
retry: false,
}
);

const suggestions = data?.suggestions ?? null;
const isLoading = isPending;
Expand Down
Loading
Loading