Skip to content

Commit

Permalink
[Fleet] Add global data tags telemetry (elastic#186390)
Browse files Browse the repository at this point in the history
  • Loading branch information
nchaulet authored and bhapas committed Jun 18, 2024
1 parent 51f7704 commit ceb38e7
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
20 changes: 20 additions & 0 deletions x-pack/plugins/fleet/server/collectors/agent_policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import type { OutputSOAttributes, AgentPolicy } from '../types';
export interface AgentPoliciesUsage {
count: number;
output_types: string[];
count_with_global_data_tags: number;
avg_number_global_data_tags_per_policy?: number;
}

export const getAgentPoliciesUsage = async (
Expand Down Expand Up @@ -52,8 +54,26 @@ export const getAgentPoliciesUsage = async (
})
);

const [policiesWithGlobalDataTag, totalNumberOfGlobalDataTagFields] = agentPolicies.reduce(
([policiesNumber, fieldsNumber], agentPolicy) => {
if (agentPolicy.attributes.global_data_tags?.length ?? 0 > 0) {
return [
policiesNumber + 1,
fieldsNumber + (agentPolicy.attributes.global_data_tags?.length ?? 0),
];
}
return [policiesNumber, fieldsNumber];
},
[0, 0]
);

return {
count: totalAgentPolicies,
output_types: Array.from(uniqueOutputTypes),
count_with_global_data_tags: policiesWithGlobalDataTag,
avg_number_global_data_tags_per_policy:
policiesWithGlobalDataTag > 0
? Math.round(totalNumberOfGlobalDataTagFields / policiesWithGlobalDataTag)
: undefined,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,10 @@ describe('fleet usage telemetry', () => {
schema_version: '1.0.0',
data_output_id: 'output2',
monitoring_output_id: 'output3',
global_data_tags: [
{ name: 'test', value: 'test1' },
{ name: 'test2', value: 'test2' },
],
},
{ id: 'policy2' }
);
Expand All @@ -446,6 +450,10 @@ describe('fleet usage telemetry', () => {
schema_version: '1.0.0',
data_output_id: 'output4',
monitoring_output_id: 'output4',
global_data_tags: [
{ name: 'test', value: 'test1' },
{ name: 'test2', value: 'test2' },
],
},
{ id: 'policy3' }
);
Expand Down Expand Up @@ -566,6 +574,8 @@ describe('fleet usage telemetry', () => {
agent_policies: {
count: 3,
output_types: expect.arrayContaining(['elasticsearch', 'logstash', 'third_type']),
count_with_global_data_tags: 2,
avg_number_global_data_tags_per_policy: 2,
},
agent_logs_panics_last_hour: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,19 @@ export const fleetUsagesSchema: RootSchema<any> = {
_meta: { description: 'Output types of agent policies' },
},
},
count_with_global_data_tags: {
type: 'long',
_meta: {
description: 'Number of agent policies using global data tags',
},
},
avg_number_global_data_tags_per_policy: {
type: 'long',
_meta: {
description:
'Average number of global data tags defined per agent policy (accross policies using global data tags)',
},
},
},
},
agent_checkin_status: {
Expand Down

0 comments on commit ceb38e7

Please sign in to comment.