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

[Telemetry] Add canvas stats to Legacy telemetry bulk uploader #21103

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
Original file line number Diff line number Diff line change
Expand Up @@ -149,19 +149,24 @@ export class BulkUploader {
let statsResult;
const [ statsHeader, statsPayload ] = findItem(KIBANA_STATS_TYPE_MONITORING);
const [ reportingHeader, reportingPayload ] = findItem(KIBANA_REPORTING_TYPE);
const [ canvasHeader, canvasPayload ] = findItem('canvas'); // TODO replace with constant

if (statsHeader && statsPayload) {
statsHeader.index._type = 'kibana_stats'; // HACK to convert kibana_stats_monitoring to just kibana_stats for bwc
const [ usageHeader, usagePayload ] = findItem(KIBANA_USAGE_TYPE);
const kibanaUsage = (usageHeader && usagePayload) ? usagePayload : null;
const reportingUsage = (reportingHeader && reportingPayload) ? reportingPayload : null;
const canvasUsage = (canvasHeader && canvasPayload) ? canvasPayload : null;
statsResult = [ statsHeader, statsPayload ];
if (kibanaUsage) {
set(statsResult, '[1].usage', kibanaUsage);
}
if (reportingUsage) {
set(statsResult, '[1].usage.xpack.reporting', reportingUsage);
}
if (canvasUsage) {
set(statsResult, '[1].usage.xpack.canvas', canvasUsage);
}
}

// kibana settings
Expand Down
6 changes: 6 additions & 0 deletions x-pack/plugins/xpack_main/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ export const LOGSTASH_SYSTEM_ID = 'logstash';
*/
export const REPORTING_SYSTEM_ID = 'reporting';

/**
* The name of the Kibana System ID used to look up Reporting stats through the Monitoring system.
* @type {string}
*/
export const CANVAS_SYSTEM_ID = 'canvas';

/**
* The amount of time, in milliseconds, to wait between reports when enabled.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ import { get, set, merge } from 'lodash';
import {
KIBANA_SYSTEM_ID,
LOGSTASH_SYSTEM_ID,
CANVAS_SYSTEM_ID,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changing this file should not have to be necessary

REPORTING_SYSTEM_ID,
BEATS_SYSTEM_ID,
} from '../../../../common/constants';
import { getClusterUuids } from './get_cluster_uuids';
import { getElasticsearchStats } from './get_es_stats';
import { getKibanaStats } from './get_kibana_stats';
import { getReportingStats } from './get_reporting_stats';
import { getCanvasStats } from './get_canvas_stats';
import { getBeatsStats } from './get_beats_stats';
import { getHighLevelStats } from './get_high_level_stats';

Expand Down Expand Up @@ -66,13 +68,16 @@ function getAllStatsWithCaller(server, callCluster, start, end) {
}

return Promise.all([
getElasticsearchStats(server, callCluster, clusterUuids), // cluster_stats, stack_stats.xpack, cluster_name/uuid, license, version
getKibanaStats(server, callCluster, clusterUuids, start, end), // stack_stats.kibana
getElasticsearchStats(server, callCluster, clusterUuids), // cluster_stats, stack_stats.xpack, cluster_name/uuid, license, version
getKibanaStats(server, callCluster, clusterUuids, start, end), // stack_stats.kibana
getHighLevelStats(server, callCluster, clusterUuids, start, end, LOGSTASH_SYSTEM_ID), // stack_stats.logstash
getReportingStats(server, callCluster, clusterUuids, start, end), // stack_stats.xpack.reporting
getBeatsStats(server, callCluster, clusterUuids, start, end), // stack_stats.beats
])
.then(([esClusters, kibana, logstash, reporting, beats]) => handleAllStats(esClusters, { kibana, logstash, reporting, beats }));
getReportingStats(server, callCluster, clusterUuids, start, end), // stack_stats.xpack.reporting
getCanvasStats(server, callCluster, clusterUuids, start, end), // stack_stats.xpack.kibana_canvas
getBeatsStats(server, callCluster, clusterUuids, start, end), // stack_stats.beats
]).then(([esClusters, kibana, logstash, reporting, canvas, beats]) => {
return handleAllStats(esClusters, { kibana, logstash, reporting, canvas, beats });
}
);
});
}

Expand All @@ -85,12 +90,13 @@ function getAllStatsWithCaller(server, callCluster, start, end) {
* @param {Object} logstash The Logstash nodes keyed by Cluster UUID
* @return {Array} The clusters joined with the Kibana and Logstash instances under each cluster's {@code stack_stats}.
*/
export function handleAllStats(clusters, { kibana, logstash, reporting, beats }) {
export function handleAllStats(clusters, { kibana, logstash, reporting, canvas, beats }) {
return clusters.map(cluster => {
// if they are using Kibana or Logstash, then add it to the cluster details under cluster.stack_stats
addStackStats(cluster, kibana, KIBANA_SYSTEM_ID);
addStackStats(cluster, logstash, LOGSTASH_SYSTEM_ID);
addStackStats(cluster, beats, BEATS_SYSTEM_ID);
addXPackStats(cluster, canvas, CANVAS_SYSTEM_ID);
addXPackStats(cluster, reporting, REPORTING_SYSTEM_ID);
mergeXPackStats(cluster, kibana, 'graph_workspace', 'graph'); // copy graph_workspace info out of kibana, merge it into stack_stats.xpack.graph

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/*
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't really anything "canvas" specific in this file. It was copied from the reporting file. Seems like it could be made generic at a higher level

* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/

import { get } from 'lodash';
import { createQuery } from './create_query';
import { KIBANA_SYSTEM_ID, CANVAS_SYSTEM_ID } from '../../../../common/constants';

const canvasStatsPath = `${KIBANA_SYSTEM_ID}_stats.usage.xpack.${CANVAS_SYSTEM_ID}`;

export function fetchHighLevelCanvasStats(server, callCluster, clusterUuids, start, end) {
const config = server.config();
const params = {
index: config.get(`xpack.monitoring.${KIBANA_SYSTEM_ID}.index_pattern`),
size: config.get('xpack.monitoring.max_bucket_size'),
ignoreUnavailable: true,
body: {
query: createQuery({
start,
end,
type: `${KIBANA_SYSTEM_ID}_stats`, // canvas stats are in kibana_stats.xpack.canvas
filters: [ { terms: { cluster_uuid: clusterUuids } } ]
}),
collapse: {
field: 'cluster_uuid'
},
sort: [
{ 'timestamp': 'desc' }
],
_source: {
includes: [
'cluster_uuid',
canvasStatsPath,
]
},
}
};

return callCluster('search', params);
}

export function handleHighLevelCanvasStatsResponse(response) {
const hits = get(response, 'hits.hits', []);
return hits.reduce((accum, curr) => {
const clusterUuid = get(curr, '_source.cluster_uuid');
const stats = get(curr, `_source.${canvasStatsPath}`);
return {
...accum,
[clusterUuid]: stats
};
}, {});
}

export async function getCanvasStats(server, callCluster, clusterUuids, start, end) {
const rawStats = await fetchHighLevelCanvasStats(server, callCluster, clusterUuids, start, end, CANVAS_SYSTEM_ID);
const stats = handleHighLevelCanvasStatsResponse(rawStats);

return stats;
}