Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix maps telemetry #52439

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion x-pack/legacy/plugins/maps/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ export function maps(kibana) {
server.log(['info', 'maps'], 'Maps app disabled by configuration');
return;
}
initTelemetryCollection(usageCollection, server);

const coreSetup = server.newPlatform.setup.core;
const newPlatformPlugins = server.newPlatform.setup.plugins;
Expand Down Expand Up @@ -131,6 +130,19 @@ export function maps(kibana) {

const mapPluginSetup = new MapPlugin().setup(coreSetup, pluginsSetup, __LEGACY);
server.expose('getMapConfig', mapPluginSetup.getMapConfig);

const { kbnServer } = server.plugins.xpack_main.status.plugin;
kbnServer.afterPluginsInit(() => {
// The code block below can't await directly within "afterPluginsInit"
// callback due to circular dependency. The server isn't "ready" until
// this code block finishes. Migrations wait for server to be ready before
// executing. Saved objects repository waits for migrations to finish before
// finishing the request. To avoid this, we'll await within a separate
// function block.
(() => {
initTelemetryCollection(usageCollection, server);
})();
});
}
});
}
12 changes: 11 additions & 1 deletion x-pack/legacy/plugins/maps/mappings.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
},
"maps-telemetry": {
"properties": {
"settings": {
"properties": {
"showMapVisualizationTypes": {
"type": "boolean"
}
}
},
"indexPatternsWithGeoFieldCount": {
"type": "long"
},
"mapsTotalCount": {
"type": "long"
},
Expand Down Expand Up @@ -72,4 +82,4 @@
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
import _ from 'lodash';
import { TASK_ID, scheduleTask, registerMapsTelemetryTask } from './telemetry_task';

export function initTelemetryCollection(usageCollection, server) {
export async function initTelemetryCollection(usageCollection, server) {
registerMapsTelemetryTask(server);
scheduleTask(server);
await scheduleTask(server);
registerMapsUsageCollector(usageCollection, server);
}

Expand Down
32 changes: 10 additions & 22 deletions x-pack/legacy/plugins/maps/server/maps_telemetry/telemetry_task.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,35 +10,23 @@ const TELEMETRY_TASK_TYPE = 'maps_telemetry';

export const TASK_ID = `Maps-${TELEMETRY_TASK_TYPE}`;

export function scheduleTask(server) {
export async function scheduleTask(server) {
const taskManager = server.plugins.task_manager;

if (!taskManager) {
server.log(['debug', 'telemetry'], `Task manager is not available`);
return;
}

const { kbnServer } = server.plugins.xpack_main.status.plugin;

kbnServer.afterPluginsInit(() => {
// The code block below can't await directly within "afterPluginsInit"
// callback due to circular dependency. The server isn't "ready" until
// this code block finishes. Migrations wait for server to be ready before
// executing. Saved objects repository waits for migrations to finish before
// finishing the request. To avoid this, we'll await within a separate
// function block.
(async () => {
try {
await taskManager.ensureScheduled({
id: TASK_ID,
taskType: TELEMETRY_TASK_TYPE,
state: { stats: {}, runs: 0 },
});
} catch(e) {
server.log(['warning', 'maps'], `Error scheduling telemetry task, received ${e.message}`);
}
})();
});
try {
await taskManager.ensureScheduled({
id: TASK_ID,
taskType: TELEMETRY_TASK_TYPE,
state: { stats: {}, runs: 0 },
});
} catch(e) {
server.log(['warning', 'maps'], `Error scheduling telemetry task, received ${e.message}`);
}
}

export function registerMapsTelemetryTask(server) {
Expand Down