mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
[Synthetics] Added sync telemetry (#132657)
This commit is contained in:
parent
1590cba32f
commit
b9c7b73644
4 changed files with 111 additions and 2 deletions
|
@ -7,3 +7,5 @@
|
|||
|
||||
export const MONITOR_UPDATE_CHANNEL = 'synthetics-monitor-update';
|
||||
export const MONITOR_CURRENT_CHANNEL = 'synthetics-monitor-current';
|
||||
export const MONITOR_SYNC_STATE_CHANNEL = 'synthetics-monitor-sync-state';
|
||||
export const MONITOR_SYNC_EVENTS_CHANNEL = 'synthetics-monitor-sync-events';
|
||||
|
|
|
@ -6,6 +6,16 @@
|
|||
*/
|
||||
import { ServiceLocationErrors } from '../../../../common/runtime_types/monitor_management';
|
||||
|
||||
export interface MonitorSyncEvent {
|
||||
total: number;
|
||||
totalTests: number;
|
||||
browserTests24h: number;
|
||||
httpTests24h: number;
|
||||
icmpTests24h: number;
|
||||
tcpTests24h: number;
|
||||
[key: string]: number;
|
||||
}
|
||||
|
||||
export interface MonitorUpdateEvent {
|
||||
updatedAt?: string;
|
||||
lastUpdatedAt?: string;
|
||||
|
@ -27,6 +37,8 @@ export interface MonitorUpdateTelemetryChannelEvents {
|
|||
// channel name => event type
|
||||
'synthetics-monitor-update': MonitorUpdateEvent;
|
||||
'synthetics-monitor-current': MonitorUpdateEvent;
|
||||
'synthetics-monitor-sync-state': MonitorSyncEvent;
|
||||
'synthetics-monitor-sync-events': MonitorSyncEvent;
|
||||
}
|
||||
|
||||
export type MonitorUpdateTelemetryChannel = keyof MonitorUpdateTelemetryChannelEvents;
|
||||
|
|
|
@ -20,7 +20,10 @@ import { TelemetryEventsSender } from '../../legacy_uptime/lib/telemetry/sender'
|
|||
import {
|
||||
MONITOR_UPDATE_CHANNEL,
|
||||
MONITOR_CURRENT_CHANNEL,
|
||||
MONITOR_SYNC_STATE_CHANNEL,
|
||||
MONITOR_SYNC_EVENTS_CHANNEL,
|
||||
} from '../../legacy_uptime/lib/telemetry/constants';
|
||||
import { MonitorSyncEvent } from '../../legacy_uptime/lib/telemetry/types';
|
||||
|
||||
export interface UpgradeError {
|
||||
key?: string;
|
||||
|
@ -40,7 +43,24 @@ export function sendTelemetryEvents(
|
|||
eventsTelemetry.queueTelemetryEvents(MONITOR_UPDATE_CHANNEL, [updateEvent]);
|
||||
eventsTelemetry.queueTelemetryEvents(MONITOR_CURRENT_CHANNEL, [updateEvent]);
|
||||
} catch (exc) {
|
||||
logger.error(`queing telemetry events failed ${exc}`);
|
||||
logger.error(`queuing telemetry events failed ${exc}`);
|
||||
}
|
||||
}
|
||||
|
||||
export function sendSyncTelemetryEvents(
|
||||
logger: Logger,
|
||||
eventsTelemetry: TelemetryEventsSender | undefined,
|
||||
updateEvent: MonitorSyncEvent
|
||||
) {
|
||||
if (eventsTelemetry === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
eventsTelemetry.queueTelemetryEvents(MONITOR_SYNC_STATE_CHANNEL, [updateEvent]);
|
||||
eventsTelemetry.queueTelemetryEvents(MONITOR_SYNC_EVENTS_CHANNEL, [updateEvent]);
|
||||
} catch (exc) {
|
||||
logger.error(`queuing telemetry events failed ${exc}`);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -141,6 +161,8 @@ export function formatTelemetryDeleteEvent(
|
|||
});
|
||||
}
|
||||
|
||||
export function formatTelemetrySyncEvent() {}
|
||||
|
||||
function getScriptType(
|
||||
attributes: Partial<MonitorFields>,
|
||||
isInlineScript: boolean
|
||||
|
|
|
@ -15,6 +15,8 @@ import {
|
|||
TaskManagerStartContract,
|
||||
TaskInstance,
|
||||
} from '@kbn/task-manager-plugin/server';
|
||||
import { MonitorSyncEvent } from '../legacy_uptime/lib/telemetry/types';
|
||||
import { sendSyncTelemetryEvents } from '../routes/telemetry/monitor_upgrade_sender';
|
||||
import { UptimeServerSetup } from '../legacy_uptime/lib/adapters';
|
||||
import { installSyntheticsIndexTemplates } from '../routes/synthetics_service/install_index_templates';
|
||||
import { SyntheticsServiceApiKey } from '../../common/runtime_types/synthetics_service_api_key';
|
||||
|
@ -252,12 +254,19 @@ export class SyntheticsService {
|
|||
}
|
||||
|
||||
async pushConfigs(configs?: SyntheticsConfig[], isEdit?: boolean) {
|
||||
const monitors = this.formatConfigs(configs || (await this.getMonitorConfigs()));
|
||||
const monitorConfigs = configs ?? (await this.getMonitorConfigs());
|
||||
const monitors = this.formatConfigs(monitorConfigs);
|
||||
|
||||
if (monitors.length === 0) {
|
||||
this.logger.debug('No monitor found which can be pushed to service.');
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!configs && monitorConfigs.length > 0) {
|
||||
const telemetry = this.getSyncTelemetry(monitorConfigs);
|
||||
sendSyncTelemetryEvents(this.logger, this.server.telemetry, telemetry);
|
||||
}
|
||||
|
||||
this.apiKey = await this.getApiKey();
|
||||
|
||||
if (!this.apiKey) {
|
||||
|
@ -412,6 +421,70 @@ export class SyntheticsService {
|
|||
formatMonitorConfig(Object.keys(config) as ConfigKey[], config)
|
||||
);
|
||||
}
|
||||
|
||||
getSyncTelemetry(monitors: SyntheticsMonitorWithId[]): MonitorSyncEvent {
|
||||
let totalRuns = 0;
|
||||
let browserTestRuns = 0;
|
||||
let httpTestRuns = 0;
|
||||
let icmpTestRuns = 0;
|
||||
let tcpTestRuns = 0;
|
||||
|
||||
const locationRuns: Record<string, number> = {};
|
||||
const locationMonitors: Record<string, number> = {};
|
||||
|
||||
const testRunsInDay = (schedule: string) => {
|
||||
return (24 * 60) / Number(schedule);
|
||||
};
|
||||
|
||||
const monitorsByType: Record<string, number> = {
|
||||
browser: 0,
|
||||
http: 0,
|
||||
tcp: 0,
|
||||
icmp: 0,
|
||||
};
|
||||
|
||||
monitors.forEach((monitor) => {
|
||||
if (monitor.schedule.number) {
|
||||
totalRuns += testRunsInDay(monitor.schedule.number);
|
||||
}
|
||||
switch (monitor.type) {
|
||||
case 'browser':
|
||||
browserTestRuns += testRunsInDay(monitor.schedule.number);
|
||||
break;
|
||||
case 'http':
|
||||
httpTestRuns += testRunsInDay(monitor.schedule.number);
|
||||
break;
|
||||
case 'icmp':
|
||||
icmpTestRuns += testRunsInDay(monitor.schedule.number);
|
||||
break;
|
||||
case 'tcp':
|
||||
tcpTestRuns += testRunsInDay(monitor.schedule.number);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
monitorsByType[monitor.type] = (monitorsByType[monitor.type] ?? 0) + 1;
|
||||
|
||||
monitor.locations.forEach(({ id }) => {
|
||||
locationRuns[id + 'Tests'] =
|
||||
(locationRuns[id + 'Tests'] ?? 0) + testRunsInDay(monitor.schedule.number);
|
||||
locationMonitors[id + 'Monitors'] = (locationMonitors[id + 'Monitors'] ?? 0) + 1;
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
total: monitors.length,
|
||||
totalTests: totalRuns,
|
||||
browserTests24h: browserTestRuns,
|
||||
httpTests24h: httpTestRuns,
|
||||
icmpTests24h: icmpTestRuns,
|
||||
tcpTests24h: tcpTestRuns,
|
||||
...locationRuns,
|
||||
...locationMonitors,
|
||||
...monitorsByType,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
class IndexTemplateInstallationError extends Error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue