Skip to content

Commit

Permalink
Deprecate Telemetry / APM legacy settings in favor of the new telemet…
Browse files Browse the repository at this point in the history
…ry.* settings (#104908)
  • Loading branch information
mosche authored Apr 11, 2024
1 parent 36d5282 commit 7ee5c73
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.Set;
import java.util.function.Function;

import static org.elasticsearch.common.settings.Setting.Property.DeprecatedWarning;
import static org.elasticsearch.common.settings.Setting.Property.NodeScope;
import static org.elasticsearch.common.settings.Setting.Property.OperatorDynamic;

Expand Down Expand Up @@ -230,10 +231,8 @@ public void setAgentSetting(String key, String value) {
"span_stack_trace_min_duration"
);

public static final Setting.AffixSetting<String> APM_AGENT_SETTINGS = Setting.prefixKeySetting(
TELEMETRY_SETTING_PREFIX + "agent.",
LEGACY_TRACING_APM_SETTING_PREFIX + "agent.",
(namespace, qualifiedKey) -> new Setting<>(qualifiedKey, "", (value) -> {
private static Setting<String> concreteAgentSetting(String namespace, String qualifiedKey, Setting.Property... properties) {
return new Setting<>(qualifiedKey, "", (value) -> {
if (qualifiedKey.equals("_na_") == false && PERMITTED_AGENT_KEYS.contains(namespace) == false) {
if (namespace.startsWith("global_labels.")) {
// The nested labels syntax is transformed in APMJvmOptions.
Expand All @@ -243,16 +242,26 @@ public void setAgentSetting(String key, String value) {
throw new IllegalArgumentException("Configuration [" + qualifiedKey + "] is either prohibited or unknown.");
}
return value;
}, Setting.Property.NodeScope, Setting.Property.OperatorDynamic)
}, properties);
}

public static final Setting.AffixSetting<String> APM_AGENT_SETTINGS = Setting.prefixKeySetting(
TELEMETRY_SETTING_PREFIX + "agent.",
LEGACY_TRACING_APM_SETTING_PREFIX + "agent.",
(namespace, qualifiedKey) -> qualifiedKey.startsWith(LEGACY_TRACING_APM_SETTING_PREFIX)
? concreteAgentSetting(namespace, qualifiedKey, NodeScope, OperatorDynamic, DeprecatedWarning)
: concreteAgentSetting(namespace, qualifiedKey, NodeScope, OperatorDynamic)
);

/**
* To be deprecated in favor of TELEMETRY_TRACING_NAMES_INCLUDE_SETTING.
* @deprecated in favor of TELEMETRY_TRACING_NAMES_INCLUDE_SETTING.
*/
@Deprecated
public static final Setting<List<String>> TRACING_APM_NAMES_INCLUDE_SETTING = Setting.stringListSetting(
LEGACY_TRACING_APM_SETTING_PREFIX + "names.include",
OperatorDynamic,
NodeScope
NodeScope,
DeprecatedWarning
);

public static final Setting<List<String>> TELEMETRY_TRACING_NAMES_INCLUDE_SETTING = Setting.listSetting(
Expand All @@ -264,12 +273,14 @@ public void setAgentSetting(String key, String value) {
);

/**
* To be deprecated in favor of TELEMETRY_TRACING_NAMES_EXCLUDE_SETTING.
* @deprecated in favor of TELEMETRY_TRACING_NAMES_EXCLUDE_SETTING.
*/
@Deprecated
public static final Setting<List<String>> TRACING_APM_NAMES_EXCLUDE_SETTING = Setting.stringListSetting(
LEGACY_TRACING_APM_SETTING_PREFIX + "names.exclude",
OperatorDynamic,
NodeScope
NodeScope,
DeprecatedWarning
);

public static final Setting<List<String>> TELEMETRY_TRACING_NAMES_EXCLUDE_SETTING = Setting.listSetting(
Expand All @@ -281,8 +292,9 @@ public void setAgentSetting(String key, String value) {
);

/**
* To be deprecated in favor of TELEMETRY_TRACING_SANITIZE_FIELD_NAMES.
* @deprecated in favor of TELEMETRY_TRACING_SANITIZE_FIELD_NAMES.
*/
@Deprecated
public static final Setting<List<String>> TRACING_APM_SANITIZE_FIELD_NAMES = Setting.stringListSetting(
LEGACY_TRACING_APM_SETTING_PREFIX + "sanitize_field_names",
List.of(
Expand All @@ -300,7 +312,8 @@ public void setAgentSetting(String key, String value) {
"set-cookie"
),
OperatorDynamic,
NodeScope
NodeScope,
DeprecatedWarning
);

public static final Setting<List<String>> TELEMETRY_TRACING_SANITIZE_FIELD_NAMES = Setting.listSetting(
Expand All @@ -312,13 +325,15 @@ public void setAgentSetting(String key, String value) {
);

/**
* To be deprecated in favor of TELEMETRY_TRACING_ENABLED_SETTING.
* @deprecated in favor of TELEMETRY_TRACING_ENABLED_SETTING.
*/
@Deprecated
public static final Setting<Boolean> TRACING_APM_ENABLED_SETTING = Setting.boolSetting(
LEGACY_TRACING_APM_SETTING_PREFIX + "enabled",
false,
OperatorDynamic,
NodeScope
NodeScope,
DeprecatedWarning
);

public static final Setting<Boolean> TELEMETRY_TRACING_ENABLED_SETTING = Setting.boolSetting(
Expand All @@ -336,11 +351,13 @@ public void setAgentSetting(String key, String value) {
);

/**
* To be deprecated in favor of TELEMETRY_SECRET_TOKEN_SETTING.
* @deprecated in favor of TELEMETRY_SECRET_TOKEN_SETTING.
*/
@Deprecated
public static final Setting<SecureString> TRACING_APM_SECRET_TOKEN_SETTING = SecureSetting.secureString(
LEGACY_TRACING_APM_SETTING_PREFIX + "secret_token",
null
null,
DeprecatedWarning
);

public static final Setting<SecureString> TELEMETRY_SECRET_TOKEN_SETTING = SecureSetting.secureString(
Expand All @@ -349,11 +366,13 @@ public void setAgentSetting(String key, String value) {
);

/**
* To be deprecated in favor of TELEMETRY_API_KEY_SETTING.
* @deprecated in favor of TELEMETRY_API_KEY_SETTING.
*/
@Deprecated
public static final Setting<SecureString> TRACING_APM_API_KEY_SETTING = SecureSetting.secureString(
LEGACY_TRACING_APM_SETTING_PREFIX + "api_key",
null
null,
DeprecatedWarning
);

public static final Setting<SecureString> TELEMETRY_API_KEY_SETTING = SecureSetting.secureString(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void testEnableTracingUsingLegacySetting() {
apmAgentSettings.initAgentSystemProperties(settings);

verify(apmAgentSettings).setAgentSetting("recording", "true");
assertWarnings("[tracing.apm.enabled] setting was deprecated in Elasticsearch and will be removed in a future release.");
}

public void testEnableMetrics() {
Expand Down Expand Up @@ -124,6 +125,7 @@ public void testDisableTracingUsingLegacySetting() {
apmAgentSettings.initAgentSystemProperties(settings);

verify(apmAgentSettings).setAgentSetting("recording", "false");
assertWarnings("[tracing.apm.enabled] setting was deprecated in Elasticsearch and will be removed in a future release.");
}

public void testDisableMetrics() {
Expand Down Expand Up @@ -187,6 +189,9 @@ public void testSetAgentsSettingsWithLegacyPrefix() {

verify(apmAgentSettings).setAgentSetting("recording", "true");
verify(apmAgentSettings).setAgentSetting("span_compression_enabled", "true");
assertWarnings(
"[tracing.apm.agent.span_compression_enabled] setting was deprecated in Elasticsearch and will be removed in a future release."
);
}

/**
Expand All @@ -201,8 +206,14 @@ public void testRejectForbiddenOrUnknownAgentSettings() {
}
// though, accept / ignore nested global_labels
for (String prefix : prefixes) {
Settings settings = Settings.builder().put(prefix + "global_labels." + randomAlphaOfLength(5), "123").build();
APM_AGENT_SETTINGS.getAsMap(settings);
Settings settings = Settings.builder().put(prefix + "global_labels.abc", "123").build();
APMAgentSettings.APM_AGENT_SETTINGS.getAsMap(settings);

if (prefix.startsWith("tracing.apm.agent.")) {
assertWarnings(
"[tracing.apm.agent.global_labels.abc] setting was deprecated in Elasticsearch and will be removed in a future release."
);
}
}
}

Expand All @@ -212,6 +223,7 @@ public void testTelemetryTracingNamesIncludeFallback() {
List<String> included = TELEMETRY_TRACING_NAMES_INCLUDE_SETTING.get(settings);

assertThat(included, containsInAnyOrder("abc", "xyz"));
assertWarnings("[tracing.apm.names.include] setting was deprecated in Elasticsearch and will be removed in a future release.");
}

public void testTelemetryTracingNamesExcludeFallback() {
Expand All @@ -220,6 +232,7 @@ public void testTelemetryTracingNamesExcludeFallback() {
List<String> included = TELEMETRY_TRACING_NAMES_EXCLUDE_SETTING.get(settings);

assertThat(included, containsInAnyOrder("abc", "xyz"));
assertWarnings("[tracing.apm.names.exclude] setting was deprecated in Elasticsearch and will be removed in a future release.");
}

public void testTelemetryTracingSanitizeFieldNamesFallback() {
Expand All @@ -228,6 +241,9 @@ public void testTelemetryTracingSanitizeFieldNamesFallback() {
List<String> included = TELEMETRY_TRACING_SANITIZE_FIELD_NAMES.get(settings);

assertThat(included, containsInAnyOrder("abc", "xyz"));
assertWarnings(
"[tracing.apm.sanitize_field_names] setting was deprecated in Elasticsearch and will be removed in a future release."
);
}

public void testTelemetryTracingSanitizeFieldNamesFallbackDefault() {
Expand All @@ -242,8 +258,8 @@ public void testTelemetrySecretTokenFallback() {

try (SecureString secureString = TELEMETRY_SECRET_TOKEN_SETTING.get(settings)) {
assertEquals("verysecret", secureString.toString());

}
assertWarnings("[tracing.apm.secret_token] setting was deprecated in Elasticsearch and will be removed in a future release.");
}

public void testTelemetryApiKeyFallback() {
Expand All @@ -253,8 +269,8 @@ public void testTelemetryApiKeyFallback() {

try (SecureString secureString = TELEMETRY_API_KEY_SETTING.get(settings)) {
assertEquals("abc", secureString.toString());

}
assertWarnings("[tracing.apm.api_key] setting was deprecated in Elasticsearch and will be removed in a future release.");
}

/**
Expand Down

0 comments on commit 7ee5c73

Please sign in to comment.