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

[Monitoring] Remove dependency on source_node.uuid #23721

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
15 changes: 14 additions & 1 deletion x-pack/plugins/monitoring/server/lib/create_query.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ export const createTypeFilter = (type) => {
};
};

function getUuidFieldFromType(type) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need to either implicitly figure this out or explicitly require it for each metric. It's an issue once this is fixed

switch (type) {
case 'node_stats':
return 'node_stats.node_id';
}
throw 'Unable to infer uuid field from type: ' + type;
}

/*
* Creates the boilerplace for querying monitoring data, including filling in
* document UUIDs, start time and end time, and injecting additional filters.
Expand Down Expand Up @@ -59,7 +67,12 @@ export function createQuery(options) {
let uuidFilter;
// options.uuid can be null, for example getting all the clusters
if (uuid) {
const uuidField = get(options, 'metric.uuidField');
let uuidField = get(options, 'metric.uuidField');
if (!uuidField) {
const field = get(options, 'metric.field');
const documentType = field.split('.')[0];
uuidField = getUuidFieldFromType(documentType);
}
if (!uuidField) {
throw new MissingRequiredError('options.uuid given but options.metric.uuidField is false');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ export function handleResponse(clusterState, shardStats, nodeUuid) {
return response => {
let nodeSummary = {};
const nodeStatsHits = get(response, 'hits.hits', []);
const nodes = nodeStatsHits.map(hit => hit._source.source_node); // using [0] value because query results are sorted desc per timestamp
const nodes = nodeStatsHits.map(hit => hit._source.node_stats); // using [0] value because query results are sorted desc per timestamp
const node = nodes[0] || getDefaultNodeFromId(nodeUuid);
const sourceStats = get(response, 'hits.hits[0]._source.node_stats');
const clusterNode = get(clusterState, [ 'nodes', nodeUuid ]);
const stats = {
resolver: nodeUuid,
node_ids: nodes.map(node => node.uuid),
node_ids: nodes.map(node => node.node_id),
attributes: node.attributes,
transport_address: node.transport_address,
name: node.name,
Expand Down Expand Up @@ -68,7 +68,7 @@ export function getNodeSummary(req, esIndexPattern, clusterState, shardStats, {
// Build up the Elasticsearch request
const metric = ElasticsearchMetric.getMetricFields();
const filters = [{
term: { 'source_node.uuid': nodeUuid }
term: { 'node_stats.node_id': nodeUuid }
}];
const params = {
index: esIndexPattern,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,12 @@ export async function getNodes(req, esIndexPattern, clusterStats, shardStats) {
metric: metricFields
}),
collapse: {
field: 'source_node.uuid'
field: 'node_stats.node_id'
},
aggs: {
nodes: {
terms: {
field: `source_node.uuid`,
field: `node_stats.node_id`,
size: config.get('xpack.monitoring.max_bucket_size')
},
aggs: getMetricAggs(LISTING_METRICS_NAMES, bucketSize)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function getShardAggs(config, includeNodes) {
terms: { field: 'source_node.name', size: aggSize }
},
node_ids: {
terms: { field: 'source_node.uuid', size: 1 } // node can only have 1 id
terms: { field: 'shard.node', size: 1 } // node can only have 1 id
}
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class ElasticsearchMetric extends Metric {
super({
...opts,
app: 'elasticsearch',
uuidField: 'source_node.uuid',
timestampField: 'timestamp'
});

Expand All @@ -27,7 +26,6 @@ export class ElasticsearchMetric extends Metric {

static getMetricFields() {
return {
uuidField: 'source_node.uuid', // ???
timestampField: 'timestamp'
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ export const metrics = {
// CGroup CPU Utilization Fields
const quotaMetricConfig = {
app: 'elasticsearch',
uuidField: 'source_node.uuid',
uuidField: 'node_stats.node_id',
timestampField: 'timestamp',
fieldSource: 'node_stats.os.cgroup',
usageField: 'cpuacct.usage_nanos',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export function esNodeRoute(server) {
const clusterState = get(cluster, 'cluster_state', { nodes: {} });
const shardStats = await getShardStats(req, esIndexPattern, cluster, { includeIndices: true, includeNodes: true });
const nodeSummary = await getNodeSummary(req, esIndexPattern, clusterState, shardStats, { clusterUuid, nodeUuid, start, end });
const metrics = await getMetrics(req, esIndexPattern, metricSet, [{ term: { 'source_node.uuid': nodeUuid } }]);
const metrics = await getMetrics(req, esIndexPattern, metricSet, [{ term: { 'node_stats.node_id': nodeUuid } }]);

let shardAllocation;
if (!isAdvanced) {
Expand Down