Skip to content

Commit

Permalink
[8.8] [Synthetics] adjust monitor status rule location logic (#156432) (
Browse files Browse the repository at this point in the history
#156546)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[Synthetics] adjust monitor status rule location logic
(#156432)](#156432)

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

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

<!--BACKPORT [{"author":{"name":"Dominique
Clarke","email":"[email protected]"},"sourceCommit":{"committedDate":"2023-05-03T13:41:19Z","message":"[Synthetics]
adjust monitor status rule location logic (#156432)\n\n##
Summary\r\n\r\nResolves
https://github.com/elastic/kibana/issues/156223\r\n\r\nIn previous stack
versions, the label was not saved to the saved object.\r\n\r\nThis
ensures that alerting works both for those early versions as
well\r\ncurrent versions, by adjusting the logic to consider both
the\r\nlocation.label and location.id in alerting logic.\r\n\r\n###
Testing\r\n\r\n1. Create a new oblt-cli cluster and connect to the
synthetics service,\r\nlocally or via the dev environment\r\n2. Checkout
v8.5.3\r\n3. Create a monitor. Make sure it's down and wait for the
first down\r\ncheck\r\n4. Check out this branch\r\n5. Navigate to
Observabillity alerts. Ensure that an alert is generated\r\nfor the
monitor. You may have to wait a few
minutes.\r\n\r\n---------\r\n\r\nCo-authored-by: Shahzad
<[email protected]>","sha":"77cebee6f754d8bbd439008f8c8466bceebd54ac","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:uptime","release_note:skip","v8.8.0","v8.9.0"],"number":156432,"url":"https://github.com/elastic/kibana/pull/156432","mergeCommit":{"message":"[Synthetics]
adjust monitor status rule location logic (#156432)\n\n##
Summary\r\n\r\nResolves
https://github.com/elastic/kibana/issues/156223\r\n\r\nIn previous stack
versions, the label was not saved to the saved object.\r\n\r\nThis
ensures that alerting works both for those early versions as
well\r\ncurrent versions, by adjusting the logic to consider both
the\r\nlocation.label and location.id in alerting logic.\r\n\r\n###
Testing\r\n\r\n1. Create a new oblt-cli cluster and connect to the
synthetics service,\r\nlocally or via the dev environment\r\n2. Checkout
v8.5.3\r\n3. Create a monitor. Make sure it's down and wait for the
first down\r\ncheck\r\n4. Check out this branch\r\n5. Navigate to
Observabillity alerts. Ensure that an alert is generated\r\nfor the
monitor. You may have to wait a few
minutes.\r\n\r\n---------\r\n\r\nCo-authored-by: Shahzad
<[email protected]>","sha":"77cebee6f754d8bbd439008f8c8466bceebd54ac"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/156432","number":156432,"mergeCommit":{"message":"[Synthetics]
adjust monitor status rule location logic (#156432)\n\n##
Summary\r\n\r\nResolves
https://github.com/elastic/kibana/issues/156223\r\n\r\nIn previous stack
versions, the label was not saved to the saved object.\r\n\r\nThis
ensures that alerting works both for those early versions as
well\r\ncurrent versions, by adjusting the logic to consider both
the\r\nlocation.label and location.id in alerting logic.\r\n\r\n###
Testing\r\n\r\n1. Create a new oblt-cli cluster and connect to the
synthetics service,\r\nlocally or via the dev environment\r\n2. Checkout
v8.5.3\r\n3. Create a monitor. Make sure it's down and wait for the
first down\r\ncheck\r\n4. Check out this branch\r\n5. Navigate to
Observabillity alerts. Ensure that an alert is generated\r\nfor the
monitor. You may have to wait a few
minutes.\r\n\r\n---------\r\n\r\nCo-authored-by: Shahzad
<[email protected]>","sha":"77cebee6f754d8bbd439008f8c8466bceebd54ac"}}]}]
BACKPORT-->

Co-authored-by: Dominique Clarke <[email protected]>
  • Loading branch information
kibanamachine and dominiqueclarke authored May 3, 2023
1 parent d881c9a commit e204707
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,37 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { StatusRuleExecutor } from './status_rule_executor';
import moment from 'moment';
import { loggerMock } from '@kbn/logging-mocks';
import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks';
import { StatusRuleExecutor } from './status_rule_executor';
import { UptimeServerSetup } from '../../legacy_uptime/lib/adapters';
import { mockEncryptedSO } from '../../synthetics_service/utils/mocks';
import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks';
import { SyntheticsMonitorClient } from '../../synthetics_service/synthetics_monitor/synthetics_monitor_client';
import { SyntheticsService } from '../../synthetics_service/synthetics_service';
import moment from 'moment';
import * as monitorUtils from '../../saved_objects/synthetics_monitor/get_all_monitors';
import * as locationsUtils from '../../synthetics_service/get_all_locations';
import type { PublicLocation } from '../../../common/runtime_types';

describe('StatusRuleExecutor', () => {
const mockEsClient = elasticsearchClientMock.createElasticsearchClient();
const logger = loggerMock.create();
const soClient = savedObjectsClientMock.create();
jest.spyOn(locationsUtils, 'getAllLocations').mockResolvedValue({
// @ts-ignore
publicLocations: [
{
id: 'us_central_qa',
label: 'US Central QA',
},
{
id: 'us_central_dev',
label: 'US Central DEV',
},
] as unknown as PublicLocation,
privateLocations: [],
});

const serverMock: UptimeServerSetup = {
logger,
Expand Down Expand Up @@ -64,6 +79,7 @@ describe('StatusRuleExecutor', () => {
soClient,
});
});

it('marks deleted configs as expected', async () => {
jest.spyOn(monitorUtils, 'getAllMonitors').mockResolvedValue(testMonitors);
const statusRule = new StatusRuleExecutor(
Expand Down Expand Up @@ -127,6 +143,84 @@ describe('StatusRuleExecutor', () => {
},
});
});

it('does not mark deleted config when monitor does not contain location label', async () => {
jest.spyOn(monitorUtils, 'getAllMonitors').mockResolvedValue([
{
...testMonitors[0],
attributes: {
...testMonitors[0].attributes,
locations: [
{
geo: { lon: -95.86, lat: 41.25 },
isServiceManaged: true,
id: 'us_central_qa',
},
],
},
},
]);
const statusRule = new StatusRuleExecutor(
moment().toDate(),
{},
soClient,
mockEsClient,
serverMock,
monitorClient
);

const { downConfigs } = await statusRule.getDownChecks({});

expect(downConfigs).toEqual({});

const staleDownConfigs = await statusRule.markDeletedConfigs({
id1: {
location: 'us-east-1',
configId: 'id1',
status: 'down',
timestamp: '2021-06-01T00:00:00.000Z',
monitorQueryId: 'test',
ping: {} as any,
},
'2548dab3-4752-4b4d-89a2-ae3402b6fb04-us_central_dev': {
location: 'US Central DEV',
configId: '2548dab3-4752-4b4d-89a2-ae3402b6fb04',
status: 'down',
timestamp: '2021-06-01T00:00:00.000Z',
monitorQueryId: 'test',
ping: {} as any,
},
'2548dab3-4752-4b4d-89a2-ae3402b6fb04-us_central_qa': {
location: 'US Central QA',
configId: '2548dab3-4752-4b4d-89a2-ae3402b6fb04',
status: 'down',
timestamp: '2021-06-01T00:00:00.000Z',
monitorQueryId: 'test',
ping: {} as any,
},
});

expect(staleDownConfigs).toEqual({
id1: {
configId: 'id1',
isDeleted: true,
location: 'us-east-1',
monitorQueryId: 'test',
ping: {},
status: 'down',
timestamp: '2021-06-01T00:00:00.000Z',
},
'2548dab3-4752-4b4d-89a2-ae3402b6fb04-us_central_dev': {
configId: '2548dab3-4752-4b4d-89a2-ae3402b6fb04',
isLocationRemoved: true,
location: 'US Central DEV',
monitorQueryId: 'test',
ping: {},
status: 'down',
timestamp: '2021-06-01T00:00:00.000Z',
},
});
});
});

const testMonitors = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,10 @@ export class StatusRuleExecutor {
delete downConfigs[locPlusId];
} else {
const { locations } = monitor.attributes;
if (!locations.some((l) => l.label === downConfig.location)) {
const isLocationRemoved = !locations.some(
(l) => l.id === this.getLocationId(downConfig.location)
);
if (isLocationRemoved) {
staleDownConfigs[locPlusId] = { ...downConfig, isLocationRemoved: true };
delete downConfigs[locPlusId];
}
Expand Down

0 comments on commit e204707

Please sign in to comment.