diff --git a/x-pack/plugins/fleet/server/telemetry/sender.test.ts b/x-pack/plugins/fleet/server/telemetry/sender.test.ts index a1ba0693bf3f3..1ed77d43b06ad 100644 --- a/x-pack/plugins/fleet/server/telemetry/sender.test.ts +++ b/x-pack/plugins/fleet/server/telemetry/sender.test.ts @@ -32,6 +32,15 @@ describe('TelemetryEventsSender', () => { beforeEach(() => { logger = loggingSystemMock.createLogger(); sender = new TelemetryEventsSender(logger); + sender['fetchClusterInfo'] = jest.fn(async () => { + return { + cluster_uuid: '1', + cluster_name: 'name', + version: { + number: '8.0.0', + }, + } as InfoResponse; + }); sender.start(undefined, { elasticsearch: { client: { asInternalUser: { info: jest.fn(async () => ({})) } } }, } as any); @@ -76,7 +85,7 @@ describe('TelemetryEventsSender', () => { expect(sender['sendEvents']).toHaveBeenCalledWith( 'https://telemetry-staging.elastic.co/v3/send/fleet-upgrades', - undefined, + { cluster_name: 'name', cluster_uuid: '1', version: { number: '8.0.0' } }, expect.anything() ); }); @@ -113,16 +122,6 @@ describe('TelemetryEventsSender', () => { ), }; - sender['fetchClusterInfo'] = jest.fn(async () => { - return { - cluster_uuid: '1', - cluster_name: 'name', - version: { - number: '8.0.0', - }, - } as InfoResponse; - }); - const myChannelEvents = [{ 'event.kind': '1' }, { 'event.kind': '2' }]; // @ts-ignore sender.queueTelemetryEvents('my-channel', myChannelEvents); diff --git a/x-pack/plugins/fleet/server/telemetry/sender.ts b/x-pack/plugins/fleet/server/telemetry/sender.ts index e7413872b6245..473ff470842bf 100644 --- a/x-pack/plugins/fleet/server/telemetry/sender.ts +++ b/x-pack/plugins/fleet/server/telemetry/sender.ts @@ -34,6 +34,7 @@ export class TelemetryEventsSender { private queuesPerChannel: { [channel: string]: TelemetryQueue } = {}; private isOptedIn?: boolean = true; // Assume true until the first check private esClient?: ElasticsearchClient; + private clusterInfo?: InfoResponse; constructor(logger: Logger) { this.logger = logger; @@ -46,6 +47,7 @@ export class TelemetryEventsSender { public async start(telemetryStart?: TelemetryPluginStart, core?: CoreStart) { this.telemetryStart = telemetryStart; this.esClient = core?.elasticsearch.client.asInternalUser; + this.clusterInfo = await this.fetchClusterInfo(); this.logger.debug(`Starting local task`); setTimeout(() => { @@ -92,12 +94,10 @@ export class TelemetryEventsSender { return; } - const clusterInfo = await this.fetchClusterInfo(); - for (const channel of Object.keys(this.queuesPerChannel)) { await this.sendEvents( await this.fetchTelemetryUrl(channel), - clusterInfo, + this.clusterInfo, this.queuesPerChannel[channel] ); }