Skip to content

Commit

Permalink
[8.11] [Synthetics] Sumary query backward compatability (#168817) (#1…
Browse files Browse the repository at this point in the history
…69001)

# Backport

This will backport the following commits from `main` to `8.11`:
- [[Synthetics] Sumary query backward compatability
(#168817)](#168817)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Shahzad","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-10-16T16:24:58Z","message":"[Synthetics]
Sumary query backward compatability (#168817)\n\n## Summary\n\nSummary
query backward compatibility !!\n\n\n### Testing\n\nEasiest way to test
this is to test this SNAPSHOT version against\nsynthetics service prod
locations","sha":"36cd0c6045231098bfffa7245f380a9ed0a31a75","branchLabelMapping":{"^v8.12.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:uptime","release_note:skip","v8.11.0","v8.12.0"],"number":168817,"url":"https://github.com/elastic/kibana/pull/168817","mergeCommit":{"message":"[Synthetics]
Sumary query backward compatability (#168817)\n\n## Summary\n\nSummary
query backward compatibility !!\n\n\n### Testing\n\nEasiest way to test
this is to test this SNAPSHOT version against\nsynthetics service prod
locations","sha":"36cd0c6045231098bfffa7245f380a9ed0a31a75"}},"sourceBranch":"main","suggestedTargetBranches":["8.11"],"targetPullRequestStates":[{"branch":"8.11","label":"v8.11.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.12.0","labelRegex":"^v8.12.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/168817","number":168817,"mergeCommit":{"message":"[Synthetics]
Sumary query backward compatability (#168817)\n\n## Summary\n\nSummary
query backward compatibility !!\n\n\n### Testing\n\nEasiest way to test
this is to test this SNAPSHOT version against\nsynthetics service prod
locations","sha":"36cd0c6045231098bfffa7245f380a9ed0a31a75"}}]}]
BACKPORT-->

Co-authored-by: Shahzad <[email protected]>
  • Loading branch information
kibanamachine and shahzad31 authored Oct 16, 2023
1 parent be6f4bf commit e4222e5
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 124 deletions.
47 changes: 45 additions & 2 deletions x-pack/plugins/synthetics/common/constants/client_defaults.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,54 @@ export const CLIENT_DEFAULTS = {

export const EXCLUDE_RUN_ONCE_FILTER = { bool: { must_not: { exists: { field: 'run_once' } } } };
export const FINAL_SUMMARY_FILTER = {
term: {
'summary.final_attempt': true,
bool: {
filter: [
{
exists: {
field: 'summary',
},
},
{
bool: {
should: [
{
bool: {
should: [
{
match: {
'summary.final_attempt': true,
},
},
],
minimum_should_match: 1,
},
},
{
bool: {
must_not: {
bool: {
should: [
{
exists: {
field: 'summary.final_attempt',
},
},
],
minimum_should_match: 1,
},
},
},
},
],
minimum_should_match: 1,
},
},
],
},
};

export const SUMMARY_FILTER = { exists: { field: 'summary' } };

export const getLocationFilter = ({
locationName,
locationId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import { EuiDescriptionList } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import moment, { Moment } from 'moment';
import { useErrorFailedTests } from '../hooks/use_error_failed_tests';
import { useFindMyKillerState } from '../hooks/use_find_my_killer_state';
import { useErrorFailedTests } from '../hooks/use_last_error_state';

export const ErrorDuration: React.FC = () => {
const { failedTests } = useErrorFailedTests();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import React, { ReactElement } from 'react';
import { EuiDescriptionList, EuiSkeletonText } from '@elastic/eui';
import { i18n } from '@kbn/i18n';

import { useErrorFailedTests } from '../hooks/use_last_error_state';
import { useErrorFailedTests } from '../hooks/use_error_failed_tests';
import { useDateFormat } from '../../../../../hooks/use_date_format';

export const ErrorStartedAt: React.FC = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ export const FailedTestsList = ({

const formatter = useDateFormat();

// TODO: this is broken for ping monitors

const columns = [
{
field: '@timestamp',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
* 2.0.
*/

import { useEsSearch } from '@kbn/observability-shared-plugin/public';
import { useParams } from 'react-router-dom';
import { useMemo } from 'react';
import { useReduxEsSearch } from '../../../hooks/use_redux_es_search';
import { Ping } from '../../../../../../common/runtime_types';
import {
EXCLUDE_RUN_ONCE_FILTER,
FINAL_SUMMARY_FILTER,
SUMMARY_FILTER,
} from '../../../../../../common/constants/client_defaults';
import { SYNTHETICS_INDEX_PATTERN } from '../../../../../../common/constants';
import { useSyntheticsRefreshContext } from '../../../contexts';
Expand All @@ -24,15 +24,15 @@ export function useErrorFailedTests() {

const { dateRangeStart, dateRangeEnd } = useGetUrlParams();

const { data, loading } = useEsSearch(
const { data, loading } = useReduxEsSearch(
{
index: SYNTHETICS_INDEX_PATTERN,
body: {
size: 10000,
query: {
bool: {
filter: [
FINAL_SUMMARY_FILTER,
SUMMARY_FILTER,
EXCLUDE_RUN_ONCE_FILTER,
{
term: {
Expand Down

This file was deleted.

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,
FINAL_SUMMARY_FILTER,
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: [
FINAL_SUMMARY_FILTER,
SUMMARY_FILTER,
EXCLUDE_RUN_ONCE_FILTER,
{
range: {
Expand Down
48 changes: 2 additions & 46 deletions x-pack/plugins/synthetics/server/common/pings/query_pings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
QueryDslFieldAndFormat,
QueryDslQueryContainer,
} from '@elastic/elasticsearch/lib/api/typesWithBodyKey';
import { SUMMARY_FILTER } from '../../../common/constants/client_defaults';
import { UptimeEsClient } from '../../lib';
import {
GetPingsParams,
Expand All @@ -20,43 +21,6 @@ import {

const DEFAULT_PAGE_SIZE = 25;

/**
* This branch of filtering is used for monitors of type `browser`. This monitor
* type represents an unbounded set of steps, with each `check_group` representing
* a distinct journey. The document containing the `summary` field is indexed last, and
* contains the data necessary for querying a journey.
*
* Because of this, when querying for "pings", it is important that we treat `browser` summary
* checks as the "ping" we want. Without this filtering, we will receive >= N pings for a journey
* of N steps, because an individual step may also contain multiple documents.
*/
const REMOVE_NON_SUMMARY_BROWSER_CHECKS = {
must_not: [
{
bool: {
filter: [
{
term: {
'monitor.type': 'browser',
},
},
{
bool: {
must_not: [
{
exists: {
field: 'summary',
},
},
],
},
},
],
},
},
],
};

function isStringArray(value: unknown): value is string[] {
if (!Array.isArray(value)) return false;
// are all array items strings
Expand All @@ -72,14 +36,6 @@ type GetParamsWithFields<F> = GetPingsParams & {

type GetParamsWithoutFields = GetPingsParams;

export function queryPings(
params: GetPingsParams & { uptimeEsClient: UptimeEsClient }
): Promise<PingsResponse>;

export function queryPings<F>(
params: GetParamsWithFields<F> & { uptimeEsClient: UptimeEsClient }
): Promise<{ total: number; pings: F[] }>;

export async function queryPings<F>(
params: (GetParamsWithFields<F> | GetParamsWithoutFields) & { uptimeEsClient: UptimeEsClient }
): Promise<PingsResponse | { total: number; pings: F[] }> {
Expand All @@ -105,12 +61,12 @@ export async function queryPings<F>(
query: {
bool: {
filter: [
SUMMARY_FILTER,
{ range: { '@timestamp': { gte: from, lte: to } } },
...(monitorId ? [{ term: { 'monitor.id': monitorId } }] : []),
...(status ? [{ term: { 'monitor.status': status } }] : []),
...(finalAttempt ? [{ term: { 'summary.final_attempt': finalAttempt } }] : []),
] as QueryDslQueryContainer[],
...REMOVE_NON_SUMMARY_BROWSER_CHECKS,
},
},
sort: [{ '@timestamp': { order: (sort ?? 'desc') as 'asc' | 'desc' } }],
Expand Down

0 comments on commit e4222e5

Please sign in to comment.