Skip to content

Commit

Permalink
added retry on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 committed Sep 20, 2023
1 parent aa36fe6 commit 8da466f
Show file tree
Hide file tree
Showing 40 changed files with 337 additions and 80 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ export function getSyntheticsSingleMetricConfig({ dataView }: ConfigProps): Seri
},
titlePosition: 'bottom',
},
columnFilter: { language: 'kuery', query: 'summary.up: *' },
columnFilter: {
language: 'kuery',
query: 'summary.final_attempt: true or ( not summary.final_attempt: * and summary:*)',
},
},
{
id: 'monitor_duration',
Expand Down Expand Up @@ -142,7 +145,10 @@ export function getSyntheticsSingleMetricConfig({ dataView }: ConfigProps): Seri
},
field: RECORDS_FIELD,
format: 'number',
columnFilter: { language: 'kuery', query: 'summary.down > 0' },
columnFilter: {
language: 'kuery',
query: 'summary.status: down and summary.final_attempt: true',
},
},
],
labels: FieldLabels,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ export const sampleMetricFormulaAttribute = {
dataType: 'number',
filter: {
language: 'kuery',
query: 'summary.up: *',
query:
'summary.final_attempt: true or ( not summary.final_attempt: * and summary:*)',
},
isBucketed: false,
label: 'Availability',
Expand All @@ -62,7 +63,8 @@ export const sampleMetricFormulaAttribute = {
dataType: 'number',
filter: {
language: 'kuery',
query: '(summary.up: *) AND (summary.down > 0)',
query:
'(summary.final_attempt: true or ( not summary.final_attempt: * and summary:*)) AND (summary.down > 0)',
},
isBucketed: false,
label: 'Part of Availability',
Expand All @@ -78,7 +80,8 @@ export const sampleMetricFormulaAttribute = {
dataType: 'number',
filter: {
language: 'kuery',
query: 'summary.up: *',
query:
'summary.final_attempt: true or ( not summary.final_attempt: * and summary:*)',
},
isBucketed: false,
label: 'Part of Availability',
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/synthetics/common/constants/client_defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ export const CLIENT_DEFAULTS = {
};

export const EXCLUDE_RUN_ONCE_FILTER = { bool: { must_not: { exists: { field: 'run_once' } } } };
export const SUMMARY_FILTER = {
exists: {
field: 'summary',
export const FINAL_SUMMARY_FILTER = {
term: {
'summary.final_attempt': true,
},
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ export const DEFAULT_COMMON_FIELDS: CommonFields = {
[ConfigKey.CONFIG_HASH]: '',
[ConfigKey.MONITOR_QUERY_ID]: '',
[ConfigKey.PARAMS]: '',
[ConfigKey.MAX_ATTEMPTS]: 2,
};

export const DEFAULT_BROWSER_ADVANCED_FIELDS: BrowserAdvancedFields = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ export enum ConfigKey {
USERNAME = 'username',
WAIT = 'wait',
MONITOR_QUERY_ID = 'id',
MAX_ATTEMPTS = 'max_attempts',
}

export const secretKeys = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ export const CommonFieldsCodec = t.intersection([
[ConfigKey.LOCATIONS]: MonitorLocationsCodec,
[ConfigKey.MONITOR_QUERY_ID]: t.string,
[ConfigKey.CONFIG_ID]: t.string,
[ConfigKey.MAX_ATTEMPTS]: t.number,
}),
t.partial({
[ConfigKey.FORM_MONITOR_TYPE]: FormMonitorTypeCodec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export const ProjectMonitorCodec = t.intersection([
wait: t.string,
hash: t.string,
namespace: t.string,
retestOnFailure: t.boolean,
}),
]);

Expand Down
18 changes: 14 additions & 4 deletions x-pack/plugins/synthetics/common/runtime_types/ping/ping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,18 @@ export const UrlType = t.partial({
path: t.string,
});

const SummaryCodec = t.type({
down: t.number,
up: t.number,
status: t.union([t.literal('up'), t.literal('down')]),
attempt: t.number,
max_attempts: t.number,
final_attempt: t.boolean,
retry_group: t.string,
});

export type TestSummary = t.TypeOf<typeof SummaryCodec>;

export const PingType = t.intersection([
t.type({
timestamp: t.string,
Expand Down Expand Up @@ -205,10 +217,7 @@ export const PingType = t.intersection([
us: t.number,
}),
}),
summary: t.partial({
down: t.number,
up: t.number,
}),
summary: SummaryCodec,
synthetics: SyntheticsDataType,
tags: t.array(t.string),
tcp: t.partial({
Expand Down Expand Up @@ -292,6 +301,7 @@ export const GetPingsParamsType = t.intersection([
monitorId: t.string,
sort: t.string,
status: t.string,
finalAttempt: t.boolean,
}),
]);

Expand Down
5 changes: 3 additions & 2 deletions x-pack/plugins/synthetics/e2e/helpers/synthetics_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,14 @@ export class SyntheticsRunner {
}
const { headless, match, pauseOnError } = this.params;
const noOfRuns = process.env.NO_OF_RUNS ? Number(process.env.NO_OF_RUNS) : 1;
const CI = process.env.CI === 'true';
console.log(`Running ${noOfRuns} times`);
let results: PromiseType<ReturnType<typeof syntheticsRun>> = {};
for (let i = 0; i < noOfRuns; i++) {
results = await syntheticsRun({
params: { kibanaUrl: this.kibanaUrl, getService: this.getService },
playwrightOptions: {
headless,
headless: headless ?? !CI,
chromiumSandbox: false,
timeout: 60 * 1000,
viewport: {
Expand All @@ -125,7 +126,7 @@ export class SyntheticsRunner {
},
},
match: match === 'undefined' ? '' : match,
pauseOnError,
pauseOnError: pauseOnError ?? !CI,
screenshots: 'only-on-failure',
reporter: TestReporter,
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { EuiFilterButton, EuiButtonColor } from '@elastic/eui';
import React from 'react';
import { useDispatch, useSelector } from 'react-redux';
import { selectStatusFilter, setStatusFilter } from '../../../state';

export interface FilterStatusButtonProps {
content: string | JSX.Element;
dataTestSubj: string;
isDisabled?: boolean;
value?: 'up' | 'down';
withNext: boolean;
}

export const FilterStatusButton = ({
content,
dataTestSubj,
isDisabled,
value,
withNext,
}: FilterStatusButtonProps) => {
const statusFilter = useSelector(selectStatusFilter);
const dispatch = useDispatch();

const isActive = statusFilter === value;
let color: EuiButtonColor = 'text';
if (isActive) {
color = value === 'up' ? 'success' : value === 'down' ? 'danger' : 'text';
}
return (
<EuiFilterButton
data-test-subj={dataTestSubj}
hasActiveFilters={isActive}
isDisabled={isDisabled}
onClick={() => {
dispatch(setStatusFilter(statusFilter === value ? undefined : value));
}}
withNext={withNext}
color={color}
>
{content}
</EuiFilterButton>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useMemo } from 'react';
import { Ping } from '../../../../../../common/runtime_types';
import {
EXCLUDE_RUN_ONCE_FILTER,
SUMMARY_FILTER,
FINAL_SUMMARY_FILTER,
} from '../../../../../../common/constants/client_defaults';
import { SYNTHETICS_INDEX_PATTERN } from '../../../../../../common/constants';
import { useSyntheticsRefreshContext } from '../../../contexts';
Expand All @@ -32,7 +32,7 @@ export function useErrorFailedTests() {
query: {
bool: {
filter: [
SUMMARY_FILTER,
FINAL_SUMMARY_FILTER,
EXCLUDE_RUN_ONCE_FILTER,
{
term: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useReduxEsSearch } from '../../../hooks/use_redux_es_search';
import { Ping } from '../../../../../../common/runtime_types';
import {
EXCLUDE_RUN_ONCE_FILTER,
SUMMARY_FILTER,
FINAL_SUMMARY_FILTER,
} from '../../../../../../common/constants/client_defaults';
import { SYNTHETICS_INDEX_PATTERN } from '../../../../../../common/constants';
import { useSyntheticsRefreshContext } from '../../../contexts';
Expand Down Expand Up @@ -39,7 +39,7 @@ export function useFindMyKillerState() {
query: {
bool: {
filter: [
SUMMARY_FILTER,
FINAL_SUMMARY_FILTER,
EXCLUDE_RUN_ONCE_FILTER,
{
term: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useReduxEsSearch } from '../../../hooks/use_redux_es_search';
import { Ping } from '../../../../../../common/runtime_types';
import {
EXCLUDE_RUN_ONCE_FILTER,
SUMMARY_FILTER,
FINAL_SUMMARY_FILTER,
} from '../../../../../../common/constants/client_defaults';
import { SYNTHETICS_INDEX_PATTERN } from '../../../../../../common/constants';
import { useSyntheticsRefreshContext } from '../../../contexts';
Expand All @@ -32,7 +32,7 @@ export function useErrorFailedTests() {
query: {
bool: {
filter: [
SUMMARY_FILTER,
FINAL_SUMMARY_FILTER,
EXCLUDE_RUN_ONCE_FILTER,
{
term: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1589,4 +1589,22 @@ export const FIELD = (readOnly?: boolean): FieldMap => ({
},
}),
},
[ConfigKey.MAX_ATTEMPTS]: {
fieldKey: ConfigKey.MAX_ATTEMPTS,
component: Switch,
controlled: true,
props: ({ setValue, field, trigger }): EuiSwitchProps => ({
id: 'syntheticsMonitorConfigMaxAttempts',
label: i18n.translate('xpack.synthetics.monitorConfig.retest.label', {
defaultMessage: 'Enable retest on failure',
}),
checked: field?.value === 2,
onChange: async (event) => {
const isChecked = !!event.target.checked;
setValue(ConfigKey.MAX_ATTEMPTS, isChecked ? 2 : 1);
await trigger(ConfigKey.MAX_ATTEMPTS);
},
'data-test-subj': 'syntheticsEnableAttemptSwitch',
}),
},
});
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ export const FORM_CONFIG = (readOnly: boolean): FieldConfig => ({
FIELD(readOnly)[ConfigKey.MAX_REDIRECTS],
FIELD(readOnly)[ConfigKey.TIMEOUT],
FIELD(readOnly)[ConfigKey.ENABLED],
FIELD(readOnly)[ConfigKey.MAX_ATTEMPTS],
FIELD(readOnly)[AlertConfigKey.STATUS_ENABLED],
FIELD(readOnly)[AlertConfigKey.TLS_ENABLED],
],
Expand All @@ -218,6 +219,7 @@ export const FORM_CONFIG = (readOnly: boolean): FieldConfig => ({
FIELD(readOnly)[`${ConfigKey.SCHEDULE}.number`],
FIELD(readOnly)[ConfigKey.TIMEOUT],
FIELD(readOnly)[ConfigKey.ENABLED],
FIELD(readOnly)[ConfigKey.MAX_ATTEMPTS],
FIELD(readOnly)[AlertConfigKey.STATUS_ENABLED],
FIELD(readOnly)[AlertConfigKey.TLS_ENABLED],
],
Expand All @@ -235,6 +237,7 @@ export const FORM_CONFIG = (readOnly: boolean): FieldConfig => ({
FIELD(readOnly)[ConfigKey.LOCATIONS],
FIELD(readOnly)[`${ConfigKey.SCHEDULE}.number`],
FIELD(readOnly)[ConfigKey.ENABLED],
FIELD(readOnly)[ConfigKey.MAX_ATTEMPTS],
FIELD(readOnly)[AlertConfigKey.STATUS_ENABLED],
],
step3: [FIELD(readOnly)['source.inline'], FIELD(readOnly)[ConfigKey.PARAMS]],
Expand All @@ -261,6 +264,7 @@ export const FORM_CONFIG = (readOnly: boolean): FieldConfig => ({
FIELD(readOnly)[ConfigKey.LOCATIONS],
FIELD(readOnly)[`${ConfigKey.SCHEDULE}.number`],
FIELD(readOnly)[ConfigKey.ENABLED],
FIELD(readOnly)[ConfigKey.MAX_ATTEMPTS],
FIELD(readOnly)[AlertConfigKey.STATUS_ENABLED],
],
advanced: [
Expand All @@ -286,6 +290,7 @@ export const FORM_CONFIG = (readOnly: boolean): FieldConfig => ({
FIELD(readOnly)[ConfigKey.WAIT],
FIELD(readOnly)[ConfigKey.TIMEOUT],
FIELD(readOnly)[ConfigKey.ENABLED],
FIELD(readOnly)[ConfigKey.MAX_ATTEMPTS],
FIELD(readOnly)[AlertConfigKey.STATUS_ENABLED],
],
advanced: [DEFAULT_DATA_OPTIONS(readOnly), ICMP_ADVANCED(readOnly).requestConfig],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,4 +163,5 @@ export interface FieldMap {
[ConfigKey.IGNORE_HTTPS_ERRORS]: FieldMeta<ConfigKey.IGNORE_HTTPS_ERRORS>;
[ConfigKey.MODE]: FieldMeta<ConfigKey.MODE>;
[ConfigKey.IPV4]: FieldMeta<ConfigKey.IPV4>;
[ConfigKey.MAX_ATTEMPTS]: FieldMeta<ConfigKey.MAX_ATTEMPTS>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { useSelectedLocation } from './use_selected_location';
import { Ping, PingState } from '../../../../../../common/runtime_types';
import {
EXCLUDE_RUN_ONCE_FILTER,
SUMMARY_FILTER,
FINAL_SUMMARY_FILTER,
} from '../../../../../../common/constants/client_defaults';
import { SYNTHETICS_INDEX_PATTERN } from '../../../../../../common/constants';
import { useSyntheticsRefreshContext } from '../../../contexts';
Expand All @@ -37,7 +37,7 @@ export function useMonitorErrors(monitorIdArg?: string) {
query: {
bool: {
filter: [
SUMMARY_FILTER,
FINAL_SUMMARY_FILTER,
EXCLUDE_RUN_ONCE_FILTER,
{
range: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ import { useDispatch, useSelector } from 'react-redux';

import { useSelectedMonitor } from './use_selected_monitor';
import { useSelectedLocation } from './use_selected_location';
import { getMonitorRecentPingsAction, selectMonitorPingsMetadata } from '../../../state';
import {
getMonitorRecentPingsAction,
selectMonitorPingsMetadata,
selectShowOnlyFinalAttempts,
selectStatusFilter,
} from '../../../state';

interface UseMonitorPingsProps {
lastRefresh?: number;
Expand All @@ -29,6 +34,10 @@ export const useMonitorPings = (props?: UseMonitorPingsProps) => {
const monitorId = monitor?.id;
const locationLabel = location?.label;

const showOnlyFinalAttempts = useSelector(selectShowOnlyFinalAttempts);

const statusFilter = useSelector(selectStatusFilter);

useEffect(() => {
if (monitorId && locationLabel) {
dispatch(
Expand All @@ -39,6 +48,8 @@ export const useMonitorPings = (props?: UseMonitorPingsProps) => {
pageIndex: props?.pageIndex,
from: props?.from,
to: props?.to,
finalAttempt: showOnlyFinalAttempts,
statusFilter,
})
);
}
Expand All @@ -51,6 +62,8 @@ export const useMonitorPings = (props?: UseMonitorPingsProps) => {
props?.pageIndex,
props?.from,
props?.to,
showOnlyFinalAttempts,
statusFilter,
]);

const { total, data: pings, loading } = useSelector(selectMonitorPingsMetadata);
Expand Down
Loading

0 comments on commit 8da466f

Please sign in to comment.