Skip to content

Commit eef222f

Browse files
[Fleet] Add new keep_monitoring_alive flag to agent policies (#168865)
## Summary Ref #168629 Adds a new `keep_monitoring_alive` flag to agent policies that allows agent environments to keep the monitoring server if they choose. > [!note] > `monitoring_enabled: []` needs to be explicitly set for this flag to be honored. If `monitoring_enabled` is omitted entirely, Fleet defaults to enabling monitoring for logs and metrics. ## To test Create a preconfigured policy where logs/metrics monitoring is explicitly disabled and include this new flag e.g. ```yml xpack.fleet.agentPolicies: - name: Test preconfigured policy id: test-preconfigured-policy package_policies: [] monitoring_enabled: [] keep_monitoring_alive: true ``` Then, run Kibana and verify the `monitoring` block in the full agent policy has monitoring enabled, but logs/metrics as disabled, e.g. ![image](https://github.com/elastic/kibana/assets/6766512/f5b205ad-96f0-4e88-967a-43546bf2bf84) You can also verify the need for `monitoring_enabled: []` by creating another preconfigured policy e.g. ```yml - name: Test preconfigured policy 2 id: test-preconfigured-policy-2 package_policies: [] keep_monitoring_alive: true ``` This will generate a policy e.g. ![image](https://github.com/elastic/kibana/assets/6766512/013b0381-b605-49a4-8819-3dec713f1e1f) All other combinations of enabling monitoring for logs/metrics should also generate the policies as expected. If you want to verify every combination manually: ```yml xpack.fleet.agentPolicies: - name: Test preconfigured policy id: test-preconfigured-policy package_policies: [] monitoring_enabled: [] keep_monitoring_alive: true - name: Test preconfigured policy 2 id: test-preconfigured-policy-2 package_policies: [] keep_monitoring_alive: true - name: Test preconfigured policy 3 id: test-preconfigured-policy-3 package_policies: [] monitoring_enabled: ['logs'] - name: Test preconfigured policy 4 id: test-preconfigured-policy-4 package_policies: [] monitoring_enabled: ['metrics'] - name: Test preconfigured policy 5 id: test-preconfigured-policy-5 package_policies: [] monitoring_enabled: ['logs', 'metrics'] ``` --------- Co-authored-by: kibanamachine <42973632+kibanamachine@users.noreply.github.com>
1 parent 9080836 commit eef222f

11 files changed

Lines changed: 182 additions & 119 deletions

File tree

docs/settings/fleet-settings.asciidoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@ List of agent policies that are configured when the {fleet} app starts.
9595
String identifying this policy's namespace.
9696
`monitoring_enabled`:::
9797
List of keywords that specify the monitoring data to collect. Valid values include `['logs']`, `['metrics']`, and `['logs', 'metrics']`.
98+
`keep_monitoring_alive`:::
99+
If `true`, monitoring will be enabled, but logs/metrics collection will be disabled. Use this if you want to keep agent's monitoring server alive even when logs/metrics aren't being collected.
98100
`is_managed`:::
99101
If `true`, this policy is not editable by the user and can only be changed by updating the {kib} config.
100102
`is_default`:::

packages/kbn-check-mappings-update-cli/current_mappings.json

Lines changed: 103 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,9 @@
16451645
"overrides": {
16461646
"type": "flattened",
16471647
"index": false
1648+
},
1649+
"keep_monitoring_alive": {
1650+
"type": "boolean"
16481651
}
16491652
}
16501653
},
@@ -2594,6 +2597,106 @@
25942597
"dynamic": false,
25952598
"properties": {}
25962599
},
2600+
"infrastructure-ui-source": {
2601+
"dynamic": false,
2602+
"properties": {}
2603+
},
2604+
"inventory-view": {
2605+
"dynamic": false,
2606+
"properties": {}
2607+
},
2608+
"metrics-explorer-view": {
2609+
"dynamic": false,
2610+
"properties": {}
2611+
},
2612+
"upgrade-assistant-reindex-operation": {
2613+
"dynamic": false,
2614+
"properties": {
2615+
"indexName": {
2616+
"type": "keyword"
2617+
},
2618+
"status": {
2619+
"type": "integer"
2620+
}
2621+
}
2622+
},
2623+
"upgrade-assistant-ml-upgrade-operation": {
2624+
"dynamic": false,
2625+
"properties": {
2626+
"snapshotId": {
2627+
"type": "text",
2628+
"fields": {
2629+
"keyword": {
2630+
"type": "keyword",
2631+
"ignore_above": 256
2632+
}
2633+
}
2634+
}
2635+
}
2636+
},
2637+
"monitoring-telemetry": {
2638+
"properties": {
2639+
"reportedClusterUuids": {
2640+
"type": "keyword"
2641+
}
2642+
}
2643+
},
2644+
"apm-telemetry": {
2645+
"dynamic": false,
2646+
"properties": {}
2647+
},
2648+
"apm-server-schema": {
2649+
"properties": {
2650+
"schemaJson": {
2651+
"type": "text",
2652+
"index": false
2653+
}
2654+
}
2655+
},
2656+
"apm-service-group": {
2657+
"properties": {
2658+
"groupName": {
2659+
"type": "keyword"
2660+
},
2661+
"kuery": {
2662+
"type": "text"
2663+
},
2664+
"description": {
2665+
"type": "text"
2666+
},
2667+
"color": {
2668+
"type": "text"
2669+
}
2670+
}
2671+
},
2672+
"apm-custom-dashboards": {
2673+
"properties": {
2674+
"dashboardSavedObjectId": {
2675+
"type": "keyword"
2676+
},
2677+
"kuery": {
2678+
"type": "text"
2679+
},
2680+
"serviceEnvironmentFilterEnabled": {
2681+
"type": "boolean"
2682+
},
2683+
"serviceNameFilterEnabled": {
2684+
"type": "boolean"
2685+
}
2686+
}
2687+
},
2688+
"enterprise_search_telemetry": {
2689+
"dynamic": false,
2690+
"properties": {}
2691+
},
2692+
"app_search_telemetry": {
2693+
"dynamic": false,
2694+
"properties": {}
2695+
},
2696+
"workplace_search_telemetry": {
2697+
"dynamic": false,
2698+
"properties": {}
2699+
},
25972700
"siem-ui-timeline-note": {
25982701
"properties": {
25992702
"eventId": {
@@ -3055,105 +3158,5 @@
30553158
"index": false
30563159
}
30573160
}
3058-
},
3059-
"infrastructure-ui-source": {
3060-
"dynamic": false,
3061-
"properties": {}
3062-
},
3063-
"inventory-view": {
3064-
"dynamic": false,
3065-
"properties": {}
3066-
},
3067-
"metrics-explorer-view": {
3068-
"dynamic": false,
3069-
"properties": {}
3070-
},
3071-
"upgrade-assistant-reindex-operation": {
3072-
"dynamic": false,
3073-
"properties": {
3074-
"indexName": {
3075-
"type": "keyword"
3076-
},
3077-
"status": {
3078-
"type": "integer"
3079-
}
3080-
}
3081-
},
3082-
"upgrade-assistant-ml-upgrade-operation": {
3083-
"dynamic": false,
3084-
"properties": {
3085-
"snapshotId": {
3086-
"type": "text",
3087-
"fields": {
3088-
"keyword": {
3089-
"type": "keyword",
3090-
"ignore_above": 256
3091-
}
3092-
}
3093-
}
3094-
}
3095-
},
3096-
"monitoring-telemetry": {
3097-
"properties": {
3098-
"reportedClusterUuids": {
3099-
"type": "keyword"
3100-
}
3101-
}
3102-
},
3103-
"apm-telemetry": {
3104-
"dynamic": false,
3105-
"properties": {}
3106-
},
3107-
"apm-server-schema": {
3108-
"properties": {
3109-
"schemaJson": {
3110-
"type": "text",
3111-
"index": false
3112-
}
3113-
}
3114-
},
3115-
"apm-service-group": {
3116-
"properties": {
3117-
"groupName": {
3118-
"type": "keyword"
3119-
},
3120-
"kuery": {
3121-
"type": "text"
3122-
},
3123-
"description": {
3124-
"type": "text"
3125-
},
3126-
"color": {
3127-
"type": "text"
3128-
}
3129-
}
3130-
},
3131-
"apm-custom-dashboards": {
3132-
"properties": {
3133-
"dashboardSavedObjectId": {
3134-
"type": "keyword"
3135-
},
3136-
"kuery": {
3137-
"type": "text"
3138-
},
3139-
"serviceEnvironmentFilterEnabled": {
3140-
"type": "boolean"
3141-
},
3142-
"serviceNameFilterEnabled": {
3143-
"type": "boolean"
3144-
}
3145-
}
3146-
},
3147-
"enterprise_search_telemetry": {
3148-
"dynamic": false,
3149-
"properties": {}
3150-
},
3151-
"app_search_telemetry": {
3152-
"dynamic": false,
3153-
"properties": {}
3154-
},
3155-
"workplace_search_telemetry": {
3156-
"dynamic": false,
3157-
"properties": {}
31583161
}
31593162
}

src/core/server/integration_tests/saved_objects/migrations/group2/check_registered_types.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ describe('checking migration metadata changes on all registered SO types', () =>
104104
"index-pattern": "997108a9ea1e8076e22231e1c95517cdb192b9c5",
105105
"infrastructure-monitoring-log-view": "5f86709d3c27aed7a8379153b08ee5d3d90d77f5",
106106
"infrastructure-ui-source": "113182d6895764378dfe7fa9fa027244f3a457c4",
107-
"ingest-agent-policies": "f11cc19275f4c3e4ee7c5cd6423b6706b21b989d",
107+
"ingest-agent-policies": "7633e578f60c074f8267bc50ec4763845e431437",
108108
"ingest-download-sources": "279a68147e62e4d8858c09ad1cf03bd5551ce58d",
109109
"ingest-outputs": "b4e636b13a5d0f89f0400fb67811d4cca4736eb0",
110110
"ingest-package-policies": "a0c9fb48e04dcd638e593db55f1c6451523f90ea",

x-pack/plugins/fleet/common/openapi/bundled.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7036,6 +7036,11 @@
70367036
]
70377037
}
70387038
},
7039+
"keep_monitoring_alive": {
7040+
"description": "When set to true, monitoring will be enabled but logs/metrics collection will be disabled",
7041+
"type": "boolean",
7042+
"nullable": true
7043+
},
70397044
"data_output_id": {
70407045
"type": "string",
70417046
"nullable": true

x-pack/plugins/fleet/common/openapi/bundled.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4491,6 +4491,12 @@ components:
44914491
enum:
44924492
- metrics
44934493
- logs
4494+
keep_monitoring_alive:
4495+
description: >-
4496+
When set to true, monitoring will be enabled but logs/metrics
4497+
collection will be disabled
4498+
type: boolean
4499+
nullable: true
44944500
data_output_id:
44954501
type: string
44964502
nullable: true

x-pack/plugins/fleet/common/openapi/components/schemas/agent_policy.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ properties:
1616
enum:
1717
- metrics
1818
- logs
19+
keep_monitoring_alive:
20+
description: When set to true, monitoring will be enabled but logs/metrics collection will be disabled
21+
type: boolean
22+
nullable: true
1923
data_output_id:
2024
type: string
2125
nullable: true

x-pack/plugins/fleet/common/types/models/agent_policy.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ export interface AgentPolicy extends Omit<NewAgentPolicy, 'id'> {
5252
revision: number;
5353
agents?: number;
5454
is_protected: boolean;
55+
keep_monitoring_alive?: boolean;
5556
}
5657

5758
export interface FullAgentPolicyInputStream {
@@ -87,6 +88,14 @@ export type FullAgentPolicyOutput = Pick<Output, 'type' | 'hosts' | 'ca_sha256'>
8788
[key: string]: any;
8889
};
8990

91+
export interface FullAgentPolicyMonitoring {
92+
namespace?: string;
93+
use_output?: string;
94+
enabled: boolean;
95+
metrics: boolean;
96+
logs: boolean;
97+
}
98+
9099
export interface FullAgentPolicy {
91100
id: string;
92101
outputs: {
@@ -103,13 +112,7 @@ export interface FullAgentPolicy {
103112
inputs: FullAgentPolicyInput[];
104113
revision?: number;
105114
agent?: {
106-
monitoring: {
107-
namespace?: string;
108-
use_output?: string;
109-
enabled: boolean;
110-
metrics: boolean;
111-
logs: boolean;
112-
};
115+
monitoring: FullAgentPolicyMonitoring;
113116
download: { sourceURI: string };
114117
features: Record<string, { enabled: boolean }>;
115118
protection?: {

x-pack/plugins/fleet/server/saved_objects/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ const getSavedObjectTypes = (): { [key: string]: SavedObjectsType } => ({
147147
},
148148
is_protected: { type: 'boolean' },
149149
overrides: { type: 'flattened', index: false },
150+
keep_monitoring_alive: { type: 'boolean' },
150151
},
151152
},
152153
migrations: {

x-pack/plugins/fleet/server/services/agent_policies/full_agent_policy.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,20 @@ describe('getFullAgentPolicy', () => {
283283
});
284284
});
285285

286+
it('should return a policy with monitoring enabled but no logs/metrics if keep_monitoring_alive is true', async () => {
287+
mockAgentPolicy({
288+
keep_monitoring_alive: true,
289+
});
290+
291+
const agentPolicy = await getFullAgentPolicy(savedObjectsClientMock.create(), 'agent-policy');
292+
293+
expect(agentPolicy?.agent?.monitoring).toEqual({
294+
enabled: true,
295+
logs: false,
296+
metrics: false,
297+
});
298+
});
299+
286300
it('should get the permissions for monitoring', async () => {
287301
mockAgentPolicy({
288302
namespace: 'testnamespace',

0 commit comments

Comments
 (0)