Skip to content

Commit d4fb06e

Browse files
andselkaisechengkarenzone
authored
Introduce a new flag to explicitly permit legacy monitoring (#16586)
Introduce a new flag setting `xpack.monitoring.allow_legacy_collection` which eventually enable the legacy monitoring collector. Update the method to test if monitoring is enabled so that consider also `xpack.monitoring.allow_legacy_collection` to determine if `monitoring.*` settings are valid or not. By default it's false, the user has to intentionally enable it to continue to use the legacy monitoring settings. --------- Co-authored-by: kaisecheng <[email protected]> Co-authored-by: Karen Metts <[email protected]>
1 parent a94659c commit d4fb06e

File tree

14 files changed

+59
-7
lines changed

14 files changed

+59
-7
lines changed

.buildkite/scripts/benchmark/config/logstash.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pipeline.workers: ${WORKER}
33
pipeline.batch.size: ${BATCH_SIZE}
44
queue.type: ${QTYPE}
55

6+
xpack.monitoring.allow_legacy_collection: true
67
xpack.monitoring.enabled: true
78
xpack.monitoring.elasticsearch.username: ${MONITOR_ES_USER}
89
xpack.monitoring.elasticsearch.password: ${MONITOR_ES_PW}

config/logstash.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,8 @@
338338
#
339339
# X-Pack Monitoring
340340
# https://www.elastic.co/guide/en/logstash/current/monitoring-logstash.html
341+
# Flag to allow the legacy internal monitoring (default: false)
342+
#xpack.monitoring.allow_legacy_collection: false
341343
#xpack.monitoring.enabled: false
342344
#xpack.monitoring.elasticsearch.username: logstash_system
343345
#xpack.monitoring.elasticsearch.password: password

docker/data/logstash/env2yaml/env2yaml.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ package main
1717
import (
1818
"errors"
1919
"fmt"
20-
"gopkg.in/yaml.v2"
2120
"io/ioutil"
2221
"log"
2322
"os"
@@ -82,6 +81,7 @@ var validSettings = []string{
8281
"api.auth.basic.password_policy.include.symbol",
8382
"allow_superuser",
8483
"monitoring.cluster_uuid",
84+
"xpack.monitoring.allow_legacy_collection",
8585
"xpack.monitoring.enabled",
8686
"xpack.monitoring.collection.interval",
8787
"xpack.monitoring.elasticsearch.hosts",

docs/static/monitoring/monitoring-internal-legacy.asciidoc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77

88
deprecated[7.9.0]
99

10+
NOTE: Starting from version 9.0, legacy internal collection is behind a feature flag and is turned off by default.
11+
Set `xpack.monitoring.allow_legacy_collection` to `true` to allow access to the feature.
12+
13+
Using <<monitoring-with-ea,{agent} for monitoring>> is a better alternative for most {ls} deployments.
14+
1015
==== Components for legacy collection
1116

1217
Monitoring {ls} with legacy collection uses these components:
@@ -57,7 +62,7 @@ monitoring cluster will show the Logstash metrics under the _monitoring_ cluster
5762

5863
--
5964

60-
. Verify that the `xpack.monitoring.collection.enabled` setting is `true` on the
65+
. Verify that the `xpack.monitoring.allow_legacy_collection` and `xpack.monitoring.collection.enabled` settings are `true` on the
6166
production cluster. If that setting is `false`, the collection of monitoring data
6267
is disabled in {es} and data is ignored from all other sources.
6368

logstash-core/lib/logstash/api/commands/default_metadata.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ def http_address
7171

7272
private
7373
def enabled_xpack_monitoring?
74+
LogStash::SETTINGS.registered?("xpack.monitoring.allow_legacy_collection") &&
75+
LogStash::SETTINGS.get_value("xpack.monitoring.allow_legacy_collection") &&
7476
LogStash::SETTINGS.registered?("xpack.monitoring.enabled") &&
7577
LogStash::SETTINGS.get("xpack.monitoring.enabled")
7678
end

logstash-core/spec/logstash/api/commands/default_metadata_spec.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,22 @@ def registerIfNot(setting)
5454
)
5555
end
5656

57-
it "check monitoring exist when monitoring is enabled" do
57+
it "check monitoring section exist when legacy monitoring is enabled and allowed" do
58+
LogStash::SETTINGS.set_value("xpack.monitoring.allow_legacy_collection", true)
5859
LogStash::SETTINGS.set_value("xpack.monitoring.enabled", true)
5960
expect(report.keys).to include(
6061
:monitoring
6162
)
6263
end
6364

65+
it "check monitoring section does not appear when legacy monitoring is not allowed but enabled" do
66+
LogStash::SETTINGS.set_value("xpack.monitoring.allow_legacy_collection", false)
67+
LogStash::SETTINGS.set_value("xpack.monitoring.enabled", true)
68+
expect(report.keys).not_to include(
69+
:monitoring
70+
)
71+
end
72+
6473
it "check monitoring does not appear when not enabled and nor cluster_uuid is defined" do
6574
LogStash::SETTINGS.set_value("xpack.monitoring.enabled", false)
6675
LogStash::SETTINGS.get_setting("monitoring.cluster_uuid").reset

x-pack/lib/monitoring/monitoring.rb

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@ def after_agent(runner)
155155
# For versions prior to 6.3 the default value of "xpack.monitoring.enabled" was true
156156
# For versions 6.3+ the default of "xpack.monitoring.enabled" is false.
157157
# To help keep passivity, assume that if "xpack.monitoring.elasticsearch.hosts" has been set that monitoring should be enabled.
158-
# return true if xpack.monitoring.enabled=true (explicitly) or xpack.monitoring.elasticsearch.hosts is configured
158+
# return true if xpack.monitoring.allow_legacy_collection=true and xpack.monitoring.enabled=true (explicitly) or xpack.monitoring.elasticsearch.hosts is configured
159159
def monitoring_enabled?(settings)
160+
log_warn_if_legacy_is_enabled_and_not_allowed(settings)
161+
return false unless settings.get_value("xpack.monitoring.allow_legacy_collection")
160162
return settings.get_value("monitoring.enabled") if settings.set?("monitoring.enabled")
161163
return settings.get_value("xpack.monitoring.enabled") if settings.set?("xpack.monitoring.enabled")
162164

@@ -170,6 +172,15 @@ def monitoring_enabled?(settings)
170172
end
171173
end
172174

175+
def log_warn_if_legacy_is_enabled_and_not_allowed(settings)
176+
allowed = settings.get_value("xpack.monitoring.allow_legacy_collection")
177+
legacy_monitoring_enabled = (settings.get_value("xpack.monitoring.enabled") || settings.get_value("monitoring.enabled"))
178+
if !allowed && legacy_monitoring_enabled
179+
logger.warn("You have enabled legacy internal monitoring. However, starting from version 9.0, this feature is deactivated and behind a feature flag. Set `xpack.monitoring.allow_legacy_collection` to `true` to allow access to the feature.")
180+
end
181+
end
182+
private :log_warn_if_legacy_is_enabled_and_not_allowed
183+
173184
def setup_metrics_pipeline
174185
settings = LogStash::SETTINGS.clone
175186

@@ -195,7 +206,8 @@ def generate_pipeline_config(settings)
195206
raise ArgumentError.new("\"xpack.monitoring.enabled\" is configured while also \"monitoring.enabled\"")
196207
end
197208

198-
if any_set?(settings, /^xpack.monitoring/) && any_set?(settings, /^monitoring./)
209+
if any_set?(settings, /^xpack.monitoring/, "xpack.monitoring.allow_legacy_collection") &&
210+
any_set?(settings, /^monitoring./)
199211
raise ArgumentError.new("\"xpack.monitoring.*\" settings can't be configured while using \"monitoring.*\"")
200212
end
201213

@@ -225,8 +237,8 @@ def retrieve_collection_settings(settings, prefix = "")
225237
opt
226238
end
227239

228-
def any_set?(settings, regexp)
229-
!settings.get_subset(regexp).to_hash.keys.select { |k| settings.set?(k)}.empty?
240+
def any_set?(settings, regexp, to_avoid = [])
241+
!settings.get_subset(regexp).to_hash.keys.select{ |k| !to_avoid.include?(k)}.select { |k| settings.set?(k)}.empty?
230242
end
231243
end
232244

@@ -259,6 +271,9 @@ def additionals_settings(settings)
259271

260272
private
261273
def register_monitoring_settings(settings, prefix = "")
274+
if prefix == "xpack."
275+
settings.register(LogStash::Setting::Boolean.new("xpack.monitoring.allow_legacy_collection", false))
276+
end
262277
settings.register(LogStash::Setting::Boolean.new("#{prefix}monitoring.enabled", false))
263278
settings.register(LogStash::Setting::ArrayCoercible.new("#{prefix}monitoring.elasticsearch.hosts", String, ["http://localhost:9200"]))
264279
settings.register(LogStash::Setting::TimeValue.new("#{prefix}monitoring.collection.interval", "10s"))

x-pack/qa/integration/management/multiple_pipelines_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
"xpack.management.elasticsearch.hosts" => ["http://localhost:9200"],
3434
"xpack.management.elasticsearch.username" => "elastic",
3535
"xpack.management.elasticsearch.password" => elastic_password,
36+
"xpack.monitoring.allow_legacy_collection" => true,
3637
"xpack.monitoring.elasticsearch.username" => "elastic",
3738
"xpack.monitoring.elasticsearch.password" => elastic_password
3839

x-pack/qa/integration/monitoring/direct_shipping_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
@logstash_service = logstash_with_empty_default("bin/logstash -e '#{config}' -w 1 --pipeline.id #{SecureRandom.hex(8)}", {
1717
:settings => {
18+
"xpack.monitoring.allow_legacy_collection" => true,
1819
"monitoring.enabled" => true,
1920
"monitoring.elasticsearch.hosts" => ["http://localhost:9200", "http://localhost:9200"],
2021
"monitoring.collection.interval" => "1s",

x-pack/qa/integration/monitoring/es_documents_structure_validation_spec.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def start_monitoring_logstash(config, prefix = "")
8585
end
8686
logstash_with_empty_default("bin/logstash -e '#{config}' -w 1", {
8787
:settings => {
88+
"xpack.monitoring.allow_legacy_collection" => true,
8889
"#{mon_prefix}monitoring.enabled" => true,
8990
"#{mon_prefix}monitoring.elasticsearch.hosts" => ["http://localhost:9200", "http://localhost:9200"],
9091
"#{mon_prefix}monitoring.collection.interval" => "1s",

0 commit comments

Comments
 (0)