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 beats architecture stats to telemetry #21227

Merged
Merged
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 @@ -34,6 +34,26 @@
}
}
},
{
"_source": {
"type": "beats_state",
"cluster_uuid": "W7hppdX7R229Oy3KQbZrTw",
"beats_state": {
"state": {
"host": {
"name": "Elastic-MBP.local",
"architecture": "x86_64",
"os": {
"platform": "darwin",
"version": "10.13.6",
"family": "darwin",
"build": "17G65"
}
}
}
}
}
},
{
"_source": {
"type": "beats_stats",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ const getBaseOptions = () => ({
clusterHostSets: {},
clusterInputSets: {},
clusterModuleSets: {},
clusterArchitectureMaps: {}
});

describe('Get Beats Stats', () => {
Expand Down Expand Up @@ -111,6 +112,10 @@ describe('Get Beats Stats', () => {
count: 0,
names: [],
},
architecture: {
count: 0,
architectures: []
}
},
});
});
Expand Down Expand Up @@ -140,6 +145,16 @@ describe('Get Beats Stats', () => {
count: 1,
names: [ 'firehose' ],
},
architecture: {
count: 1,
architectures: [
{
architecture: 'x86_64',
count: 1,
name: 'darwin'
}
]
}
},
FlV4ckTxQ0a78hmBkzzc9A: {
count: 405,
Expand All @@ -165,6 +180,10 @@ describe('Get Beats Stats', () => {
count: 0,
names: [],
},
architecture: {
count: 0,
architectures: []
}
},
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ const getBaseStats = () => ({
count: 0,
names: []
},
architecture: {
count: 0,
architectures: []
}
});


Expand All @@ -37,7 +41,7 @@ const getBaseStats = () => ({
* @param {Object} clusterHostSets - the object keyed by cluster UUIDs to count the unique hosts
* @param {Object} clusterModuleSets - the object keyed by cluster UUIDs to count the unique modules
*/
export function processResults(results = [], { clusters, clusterHostSets, clusterInputSets, clusterModuleSets }) {
export function processResults(results = [], { clusters, clusterHostSets, clusterInputSets, clusterModuleSets, clusterArchitectureMaps }) {
const currHits = get(results, 'hits.hits', []);
currHits.forEach(hit => {
const clusterUuid = get(hit, '_source.cluster_uuid');
Expand All @@ -46,6 +50,7 @@ export function processResults(results = [], { clusters, clusterHostSets, cluste
clusterHostSets[clusterUuid] = new Set();
clusterInputSets[clusterUuid] = new Set();
clusterModuleSets[clusterUuid] = new Set();
clusterArchitectureMaps[clusterUuid] = new Map();
}

const processBeatsStatsResults = () => {
Expand Down Expand Up @@ -97,6 +102,25 @@ export function processResults(results = [], { clusters, clusterHostSets, cluste
clusters[clusterUuid].module.names = Array.from(moduleSet);
clusters[clusterUuid].module.count += stateModule.count;
}

const stateHost = get(hit, '_source.beats_state.state.host');
if (stateHost !== undefined) {
const hostMap = clusterArchitectureMaps[clusterUuid];
const hostKey = `${stateHost.architecture}/${stateHost.os.platform}`;
let os = hostMap.get(hostKey);

if (!os) { // undefined if new
os = { name: stateHost.os.platform, architecture: stateHost.architecture, count: 0 };
hostMap.set(hostKey, os);
}

// total per os/arch
os.count += 1;

// overall total (which should be the same number as the sum of all os.count values)
clusters[clusterUuid].architecture.count += 1;
clusters[clusterUuid].architecture.architectures = Array.from(hostMap.values());
}
};

if (get(hit, '_source.type') === 'beats_stats') {
Expand Down Expand Up @@ -136,6 +160,7 @@ async function fetchBeatsByType(server, callCluster, clusterUuids, start, end, {
'hits.hits._source.beats_stats.metrics.libbeat.output.type',
'hits.hits._source.beats_state.state.input',
'hits.hits._source.beats_state.state.module',
'hits.hits._source.beats_state.state.host',
],
body: {
query: createQuery({
Expand Down Expand Up @@ -194,7 +219,8 @@ export async function getBeatsStats(server, callCluster, clusterUuids, start, en
clusters: {}, // the result object to be built up
clusterHostSets: {}, // passed to processResults for tracking state in the results generation
clusterInputSets: {}, // passed to processResults for tracking state in the results generation
clusterModuleSets: {} // passed to processResults for tracking state in the results generation
clusterModuleSets: {}, // passed to processResults for tracking state in the results generation
clusterArchitectureMaps: {} // passed to processResults for tracking state in the results generation
Copy link
Member

Choose a reason for hiding this comment

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

I apologize for writing this module this way :( Let me know if you want to get together and think of some other ideas for this. I don't like having an object passed to a function, and the function mutates the object for the caller.

};

await Promise.all([
Expand Down