|
4 | 4 | * 2.0; you may not use this file except in compliance with the Elastic License |
5 | 5 | * 2.0. |
6 | 6 | */ |
7 | | - |
8 | | -import { StatusRuleExecutor } from './status_rule_executor'; |
| 7 | +import moment from 'moment'; |
9 | 8 | import { loggerMock } from '@kbn/logging-mocks'; |
10 | 9 | import { savedObjectsClientMock } from '@kbn/core-saved-objects-api-server-mocks'; |
| 10 | +import { StatusRuleExecutor } from './status_rule_executor'; |
11 | 11 | import { UptimeServerSetup } from '../../legacy_uptime/lib/adapters'; |
12 | 12 | import { mockEncryptedSO } from '../../synthetics_service/utils/mocks'; |
13 | 13 | import { elasticsearchClientMock } from '@kbn/core-elasticsearch-client-server-mocks'; |
14 | 14 | import { SyntheticsMonitorClient } from '../../synthetics_service/synthetics_monitor/synthetics_monitor_client'; |
15 | 15 | import { SyntheticsService } from '../../synthetics_service/synthetics_service'; |
16 | | -import moment from 'moment'; |
17 | 16 | import * as monitorUtils from '../../saved_objects/synthetics_monitor/get_all_monitors'; |
| 17 | +import * as locationsUtils from '../../synthetics_service/get_all_locations'; |
| 18 | +import type { PublicLocation } from '../../../common/runtime_types'; |
18 | 19 |
|
19 | 20 | describe('StatusRuleExecutor', () => { |
20 | 21 | const mockEsClient = elasticsearchClientMock.createElasticsearchClient(); |
21 | 22 | const logger = loggerMock.create(); |
22 | 23 | const soClient = savedObjectsClientMock.create(); |
| 24 | + jest.spyOn(locationsUtils, 'getAllLocations').mockResolvedValue({ |
| 25 | + // @ts-ignore |
| 26 | + publicLocations: [ |
| 27 | + { |
| 28 | + id: 'us_central_qa', |
| 29 | + label: 'US Central QA', |
| 30 | + }, |
| 31 | + { |
| 32 | + id: 'us_central_dev', |
| 33 | + label: 'US Central DEV', |
| 34 | + }, |
| 35 | + ] as unknown as PublicLocation, |
| 36 | + privateLocations: [], |
| 37 | + }); |
23 | 38 |
|
24 | 39 | const serverMock: UptimeServerSetup = { |
25 | 40 | logger, |
@@ -64,6 +79,7 @@ describe('StatusRuleExecutor', () => { |
64 | 79 | soClient, |
65 | 80 | }); |
66 | 81 | }); |
| 82 | + |
67 | 83 | it('marks deleted configs as expected', async () => { |
68 | 84 | jest.spyOn(monitorUtils, 'getAllMonitors').mockResolvedValue(testMonitors); |
69 | 85 | const statusRule = new StatusRuleExecutor( |
@@ -127,6 +143,84 @@ describe('StatusRuleExecutor', () => { |
127 | 143 | }, |
128 | 144 | }); |
129 | 145 | }); |
| 146 | + |
| 147 | + it('does not mark deleted config when monitor does not contain location label', async () => { |
| 148 | + jest.spyOn(monitorUtils, 'getAllMonitors').mockResolvedValue([ |
| 149 | + { |
| 150 | + ...testMonitors[0], |
| 151 | + attributes: { |
| 152 | + ...testMonitors[0].attributes, |
| 153 | + locations: [ |
| 154 | + { |
| 155 | + geo: { lon: -95.86, lat: 41.25 }, |
| 156 | + isServiceManaged: true, |
| 157 | + id: 'us_central_qa', |
| 158 | + }, |
| 159 | + ], |
| 160 | + }, |
| 161 | + }, |
| 162 | + ]); |
| 163 | + const statusRule = new StatusRuleExecutor( |
| 164 | + moment().toDate(), |
| 165 | + {}, |
| 166 | + soClient, |
| 167 | + mockEsClient, |
| 168 | + serverMock, |
| 169 | + monitorClient |
| 170 | + ); |
| 171 | + |
| 172 | + const { downConfigs } = await statusRule.getDownChecks({}); |
| 173 | + |
| 174 | + expect(downConfigs).toEqual({}); |
| 175 | + |
| 176 | + const staleDownConfigs = await statusRule.markDeletedConfigs({ |
| 177 | + id1: { |
| 178 | + location: 'us-east-1', |
| 179 | + configId: 'id1', |
| 180 | + status: 'down', |
| 181 | + timestamp: '2021-06-01T00:00:00.000Z', |
| 182 | + monitorQueryId: 'test', |
| 183 | + ping: {} as any, |
| 184 | + }, |
| 185 | + '2548dab3-4752-4b4d-89a2-ae3402b6fb04-us_central_dev': { |
| 186 | + location: 'US Central DEV', |
| 187 | + configId: '2548dab3-4752-4b4d-89a2-ae3402b6fb04', |
| 188 | + status: 'down', |
| 189 | + timestamp: '2021-06-01T00:00:00.000Z', |
| 190 | + monitorQueryId: 'test', |
| 191 | + ping: {} as any, |
| 192 | + }, |
| 193 | + '2548dab3-4752-4b4d-89a2-ae3402b6fb04-us_central_qa': { |
| 194 | + location: 'US Central QA', |
| 195 | + configId: '2548dab3-4752-4b4d-89a2-ae3402b6fb04', |
| 196 | + status: 'down', |
| 197 | + timestamp: '2021-06-01T00:00:00.000Z', |
| 198 | + monitorQueryId: 'test', |
| 199 | + ping: {} as any, |
| 200 | + }, |
| 201 | + }); |
| 202 | + |
| 203 | + expect(staleDownConfigs).toEqual({ |
| 204 | + id1: { |
| 205 | + configId: 'id1', |
| 206 | + isDeleted: true, |
| 207 | + location: 'us-east-1', |
| 208 | + monitorQueryId: 'test', |
| 209 | + ping: {}, |
| 210 | + status: 'down', |
| 211 | + timestamp: '2021-06-01T00:00:00.000Z', |
| 212 | + }, |
| 213 | + '2548dab3-4752-4b4d-89a2-ae3402b6fb04-us_central_dev': { |
| 214 | + configId: '2548dab3-4752-4b4d-89a2-ae3402b6fb04', |
| 215 | + isLocationRemoved: true, |
| 216 | + location: 'US Central DEV', |
| 217 | + monitorQueryId: 'test', |
| 218 | + ping: {}, |
| 219 | + status: 'down', |
| 220 | + timestamp: '2021-06-01T00:00:00.000Z', |
| 221 | + }, |
| 222 | + }); |
| 223 | + }); |
130 | 224 | }); |
131 | 225 |
|
132 | 226 | const testMonitors = [ |
|
0 commit comments