Skip to content

Commit b73ec5b

Browse files
[AutoOps] Flatten Cluster Settings (#48454) (#48474)
This removes the unnecessary exporting of `cluster_settings` by only sending the settings _that apply_. For instance, if a setting is both set as a transient and persistent setting, then only the transient value matters. (cherry picked from commit 93dc66d) Co-authored-by: Chris Earle <pickypg@users.noreply.github.com>
1 parent fbc8881 commit b73ec5b

5 files changed

Lines changed: 93 additions & 5 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# REQUIRED
2+
# Kind can be one of:
3+
# - breaking-change: a change to previously-documented behavior
4+
# - deprecation: functionality that is being removed in a later release
5+
# - bug-fix: fixes a problem in a previous version
6+
# - enhancement: extends functionality but does not break or fix existing behavior
7+
# - feature: new functionality
8+
# - known-issue: problems that we are aware of in a given version
9+
# - security: impacts on the security of a product or a user’s deployment.
10+
# - upgrade: important information for someone upgrading from a prior version
11+
# - other: does not fit into any of the other categories
12+
kind: bug-fix
13+
14+
# REQUIRED for all kinds
15+
# Change summary; a 80ish characters long description of the change.
16+
summary: Flatten AutoOps Cluster Settings to avoid unnecessary nesting and information
17+
18+
# REQUIRED for breaking-change, deprecation, known-issue
19+
# Long description; in case the summary is not enough to describe the change
20+
# this field accommodate a description without length limits.
21+
# description:
22+
23+
# REQUIRED for breaking-change, deprecation, known-issue
24+
# impact:
25+
26+
# REQUIRED for breaking-change, deprecation, known-issue
27+
# action:
28+
29+
# REQUIRED for all kinds
30+
# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
31+
component: metricbeat
32+
33+
# AUTOMATED
34+
# OPTIONAL to manually add other PR URLs
35+
# PR URL: A link the PR that added the changeset.
36+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
37+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
38+
# Please provide it if you are adding a fragment for a different PR.
39+
# pr: https://github.com/owner/repo/1234
40+
41+
# AUTOMATED
42+
# OPTIONAL to manually add other issue URLs
43+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
44+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
45+
issue: https://github.com/elastic/beats/issues/48453

x-pack/metricbeat/module/autoops_es/cluster_settings/_meta/test/cluster_settings.my-cluster.7.17.0.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"enable": "true"
1010
}
1111
},
12+
"max_shards_per_node": "2000",
1213
"metadata": {
1314
"display_name": "my-cluster"
1415
}
@@ -17,6 +18,9 @@
1718
"transient": {
1819
"action": {
1920
"auto_create_index": "false"
21+
},
22+
"cluster": {
23+
"max_shards_per_node": "4000"
2024
}
2125
},
2226
"defaults": {
@@ -198,6 +202,11 @@
198202
"rewrite_to_filter_by_filter": "true"
199203
}
200204
},
205+
"serverless": {
206+
"search": {
207+
"search_power_min": "3"
208+
}
209+
},
201210
"path": {
202211
"data": ["/app/data"]
203212
},

x-pack/metricbeat/module/autoops_es/cluster_settings/_meta/test/cluster_settings.my-cluster.8.15.3.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
}
1313
},
1414
"metadata": {
15-
"display_name": "my-cluster"
15+
"display_name": "my-overridden-cluster-name"
1616
},
1717
"max_shards_per_node": "4000"
1818
},
@@ -23,11 +23,21 @@
2323
},
2424
"action": {
2525
"auto_create_index": ".ent-search-*-logs-*,-.ent-search-*,+*"
26+
},
27+
"serverless": {
28+
"search": {
29+
"search_power_min": "3"
30+
}
2631
}
2732
},
2833
"transient": {
2934
"action": {
3035
"auto_create_index": ".ent-search-*-logs-*,-.ent-search-*,+*"
36+
},
37+
"cluster": {
38+
"metadata": {
39+
"display_name": "my-cluster"
40+
}
3141
}
3242
},
3343
"defaults": {

x-pack/metricbeat/module/autoops_es/cluster_settings/data.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package cluster_settings
77
import (
88
"fmt"
99

10+
"github.com/elastic/elastic-agent-libs/mapstr"
11+
1012
"github.com/elastic/beats/v7/x-pack/metricbeat/module/autoops_es/events"
1113

1214
s "github.com/elastic/beats/v7/libbeat/common/schema"
@@ -213,6 +215,25 @@ var (
213215
}
214216
)
215217

218+
// flattenSettings merges transient, persistent, and defaults settings
219+
// with precedence: transient > persistent > defaults
220+
func flattenSettings(metricSetFields mapstr.M) mapstr.M {
221+
result := mapstr.M{}
222+
223+
// Apply in reverse precedence order (defaults first, transient last)
224+
if defaults, ok := metricSetFields["defaults"].(mapstr.M); ok {
225+
result.DeepUpdate(defaults)
226+
}
227+
if persistent, ok := metricSetFields["persistent"].(mapstr.M); ok {
228+
result.DeepUpdate(persistent)
229+
}
230+
if transient, ok := metricSetFields["transient"].(mapstr.M); ok {
231+
result.DeepUpdate(transient)
232+
}
233+
234+
return result
235+
}
236+
216237
func eventsMapping(r mb.ReporterV2, info *utils.ClusterInfo, settings *map[string]interface{}) error {
217238
metricSetFields, err := schema.Apply(*settings)
218239

@@ -222,7 +243,8 @@ func eventsMapping(r mb.ReporterV2, info *utils.ClusterInfo, settings *map[strin
222243
return nil
223244
}
224245

225-
r.Event(events.CreateEventWithRandomTransactionId(info, metricSetFields))
246+
// Flatten settings with precedence: transient > persistent > defaults
247+
r.Event(events.CreateEventWithRandomTransactionId(info, flattenSettings(metricSetFields)))
226248

227249
return nil
228250
}

x-pack/metricbeat/module/autoops_es/cluster_settings/data_test.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,15 @@ func expectValidParsedData(t *testing.T, data metricset.FetcherData[map[string]i
2929

3030
// metrics exist
3131
require.True(t, len(*event.MetricSetFields.FlattenKeys()) > 3)
32-
require.NotNil(t, auto_ops_testing.GetObjectValue(event.MetricSetFields, "defaults"))
3332

3433
// filename includes the "display_name" as the second part
3534
displayName := strings.Split(data.File, ".")[1]
3635

37-
require.Equal(t, displayName, auto_ops_testing.GetObjectValue(event.MetricSetFields, "persistent.cluster.metadata.display_name"))
38-
require.ElementsMatch(t, []string{"/app/data"}, auto_ops_testing.GetObjectValue(event.MetricSetFields, "defaults.path.data"))
36+
// Settings are flattened with precedence: transient > persistent > defaults
37+
require.Equal(t, "4000", auto_ops_testing.GetObjectValue(event.MetricSetFields, "cluster.max_shards_per_node"))
38+
require.Equal(t, displayName, auto_ops_testing.GetObjectValue(event.MetricSetFields, "cluster.metadata.display_name"))
39+
require.ElementsMatch(t, []string{"/app/data"}, auto_ops_testing.GetObjectValue(event.MetricSetFields, "path.data"))
40+
require.Equal(t, "3", auto_ops_testing.GetObjectValue(event.MetricSetFields, "serverless.search.search_power_min"))
3941

4042
// schema is expected to drop this field if it appears (it does in one file)
4143
require.Nil(t, auto_ops_testing.GetObjectValue(event.MetricSetFields, "ignored_field"))

0 commit comments

Comments
 (0)