Skip to content

Commit

Permalink
[Fleet UI] Set flag for traces in Agent policy's monitoring configu…
Browse files Browse the repository at this point in the history
…ration (elastic#191139)

## Summary

This PR sets the `traces` boolean flag in an Agent policy's monitoring
configuration if `traces` was included in the `monitoring_enabled`
array.
  • Loading branch information
ycombinator authored Aug 26, 2024
1 parent dc7e3ec commit d1cc0cb
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 49 deletions.
1 change: 1 addition & 0 deletions x-pack/plugins/fleet/common/types/models/agent_policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ export interface FullAgentPolicyMonitoring {
enabled: boolean;
metrics: boolean;
logs: boolean;
traces: boolean;
}

export interface FullAgentPolicy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ describe('Fleet cloud preconfiguration', () => {
enabled: false,
logs: false,
metrics: false,
traces: false,
},
protection: {
enabled: false,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ describe('getFullAgentPolicy', () => {
enabled: false,
logs: false,
metrics: false,
traces: false,
},
},
});
Expand Down Expand Up @@ -257,6 +258,7 @@ describe('getFullAgentPolicy', () => {
enabled: true,
logs: true,
metrics: false,
traces: false,
},
},
});
Expand Down Expand Up @@ -293,12 +295,50 @@ describe('getFullAgentPolicy', () => {
enabled: true,
logs: false,
metrics: true,
traces: false,
},
},
});
});

it('should return a policy with monitoring enabled but no logs/metrics if keep_monitoring_alive is true', async () => {
it('should return a policy with monitoring if monitoring is enabled for traces', async () => {
mockAgentPolicy({
namespace: 'default',
revision: 1,
monitoring_enabled: ['traces'],
});
const agentPolicy = await getFullAgentPolicy(savedObjectsClientMock.create(), 'agent-policy');

expect(agentPolicy).toMatchObject({
id: 'agent-policy',
outputs: {
default: {
type: 'elasticsearch',
hosts: ['http://127.0.0.1:9201'],
},
},
inputs: [],
revision: 1,
fleet: {
hosts: ['http://fleetserver:8220'],
},
agent: {
download: {
sourceURI: 'http://default-registry.co',
},
monitoring: {
namespace: 'default',
use_output: 'default',
enabled: true,
logs: false,
metrics: false,
traces: true,
},
},
});
});

it('should return a policy with monitoring enabled but no logs/metrics/traces if keep_monitoring_alive is true', async () => {
mockAgentPolicy({
keep_monitoring_alive: true,
});
Expand All @@ -309,6 +349,7 @@ describe('getFullAgentPolicy', () => {
enabled: true,
logs: false,
metrics: false,
traces: false,
});
});

Expand All @@ -325,6 +366,7 @@ describe('getFullAgentPolicy', () => {
{
logs: false,
metrics: true,
traces: false,
},
'testnamespace'
);
Expand Down Expand Up @@ -553,6 +595,7 @@ describe('getFullAgentPolicy', () => {
enabled: true,
logs: false,
metrics: true,
traces: false,
},
},
});
Expand Down Expand Up @@ -590,6 +633,7 @@ describe('getFullAgentPolicy', () => {
enabled: true,
logs: false,
metrics: true,
traces: false,
},
features: {
fqdn: {
Expand Down Expand Up @@ -743,6 +787,7 @@ describe('getFullAgentPolicy', () => {
enabled: false,
logs: false,
metrics: false,
traces: false,
},
},
fleet: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,19 +140,21 @@ export async function getFullAgentPolicy(
enabled: false,
logs: false,
metrics: false,
traces: false,
};

let monitoring: FullAgentPolicyMonitoring = { ...defaultMonitoringConfig };

// If the agent policy has monitoring enabled for at least one of "logs" or "metrics", generate
// a monitoring config for the resulting compiled agent policy
// If the agent policy has monitoring enabled for at least one of "logs", "metrics", or "traces"
// generate a monitoring config for the resulting compiled agent policy
if (agentPolicy.monitoring_enabled && agentPolicy.monitoring_enabled.length > 0) {
monitoring = {
namespace: agentPolicy.namespace,
use_output: getOutputIdForAgentPolicy(monitoringOutput),
enabled: true,
logs: agentPolicy.monitoring_enabled.includes(dataTypes.Logs),
metrics: agentPolicy.monitoring_enabled.includes(dataTypes.Metrics),
traces: agentPolicy.monitoring_enabled.includes(dataTypes.Traces),
};
// If the `keep_monitoring_alive` flag is set, enable monitoring but don't enable logs or metrics.
// This allows cloud or other environments to keep the monitoring server alive without tearing it down.
Expand All @@ -161,6 +163,7 @@ export async function getFullAgentPolicy(
enabled: true,
logs: false,
metrics: false,
traces: false,
};
}

Expand Down Expand Up @@ -249,6 +252,7 @@ export async function getFullAgentPolicy(
{
logs: agentPolicy.monitoring_enabled?.includes(dataTypes.Logs) ?? false,
metrics: agentPolicy.monitoring_enabled?.includes(dataTypes.Metrics) ?? false,
traces: agentPolicy.monitoring_enabled?.includes(dataTypes.Traces) ?? false,
},
agentPolicy.namespace
);
Expand Down
Loading

0 comments on commit d1cc0cb

Please sign in to comment.