Skip to content

Commit

Permalink
[Synthetics] Remove unused sync telemetry (#141349)
Browse files Browse the repository at this point in the history
  • Loading branch information
shahzad31 authored Oct 3, 2022
1 parent c1d0b93 commit 31a6880
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,8 @@ import {
MONITOR_UPDATE_CHANNEL,
MONITOR_CURRENT_CHANNEL,
MONITOR_ERROR_EVENTS_CHANNEL,
MONITOR_SYNC_STATE_CHANNEL,
MONITOR_SYNC_EVENTS_CHANNEL,
} from '../../legacy_uptime/lib/telemetry/constants';
import { MonitorErrorEvent } from '../../legacy_uptime/lib/telemetry/types';
import { MonitorSyncEvent } from '../../legacy_uptime/lib/telemetry/types';

export interface UpgradeError {
key?: string;
Expand All @@ -50,23 +47,6 @@ export function sendTelemetryEvents(
}
}

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}`);
}
}

export function sendErrorTelemetryEvents(
logger: Logger,
eventsTelemetry: TelemetryEventsSender | undefined,
Expand Down Expand Up @@ -180,8 +160,6 @@ export function formatTelemetryDeleteEvent(
});
}

export function formatTelemetrySyncEvent() {}

function getScriptType(
attributes: Partial<MonitorFields>,
isInlineScript: boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ import {
TaskInstance,
} from '@kbn/task-manager-plugin/server';
import { sendErrorTelemetryEvents } from '../routes/telemetry/monitor_upgrade_sender';
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';
Expand Down Expand Up @@ -317,11 +315,6 @@ export class SyntheticsService {
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) {
Expand Down Expand Up @@ -490,70 +483,6 @@ export class SyntheticsService {
formatMonitorConfig(Object.keys(config) as ConfigKey[], config as Partial<MonitorFields>)
);
}

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 {
Expand Down

0 comments on commit 31a6880

Please sign in to comment.