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 2 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 @@ -14,7 +14,7 @@ const getBaseOptions = () => ({
clusterHostSets: {},
clusterInputSets: {},
clusterModuleSets: {},
clusterArchitectureSets: {}
clusterArchitectureMaps: {}
});

describe('Get Beats Stats', () => {
Expand Down Expand Up @@ -114,7 +114,7 @@ describe('Get Beats Stats', () => {
},
architecture: {
count: 0,
names: []
architectures: []
}
},
});
Expand Down Expand Up @@ -147,7 +147,7 @@ describe('Get Beats Stats', () => {
},
architecture: {
count: 1,
names: [ 'x86_64/darwin' ]
architectures: [ 'x86_64/darwin' ]
}
},
FlV4ckTxQ0a78hmBkzzc9A: {
Expand Down Expand Up @@ -176,7 +176,7 @@ describe('Get Beats Stats', () => {
},
architecture: {
count: 0,
names: []
architectures: []
}
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const getBaseStats = () => ({
},
architecture: {
count: 0,
names: []
architectures: []
}
});

Expand All @@ -41,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, clusterArchitectureSets }) {
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 @@ -50,7 +50,7 @@ export function processResults(results = [], { clusters, clusterHostSets, cluste
clusterHostSets[clusterUuid] = new Set();
clusterInputSets[clusterUuid] = new Set();
clusterModuleSets[clusterUuid] = new Set();
clusterArchitectureSets[clusterUuid] = new Set();
clusterArchitectureMaps[clusterUuid] = new Map();
}

const processBeatsStatsResults = () => {
Expand Down Expand Up @@ -105,11 +105,21 @@ export function processResults(results = [], { clusters, clusterHostSets, cluste

const stateHost = get(hit, '_source.beats_state.state.host');
if (stateHost !== undefined) {
const hostSet = clusterArchitectureSets[clusterUuid];
const hostArchPlatform = `${stateHost.architecture}/${stateHost.os.platform}`;
hostSet.add(hostArchPlatform);
clusters[clusterUuid].architecture.names = Array.from(hostSet);
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.keys());
Copy link
Member

Choose a reason for hiding this comment

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

My intent was for the architectures to be equal to the values from the map, not the keys. (It would be more efficient to do what you were doing for just the keys).

clusters[clusterUuid].architecture.architectures = Array.from(hostMap.values());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahhhhh. I finally understand!

}
};

Expand Down Expand Up @@ -210,7 +220,7 @@ export async function getBeatsStats(server, callCluster, clusterUuids, start, en
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
clusterArchitectureSets: {} // 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