Metrics: Agent settings prefix telemetry.agent preferred over tracing.apm.agent#104345
Metrics: Agent settings prefix telemetry.agent preferred over tracing.apm.agent#104345stu-elastic merged 16 commits intoelastic:mainfrom
Conversation
….agent Prefer the telemetry.agent prefix for APM agent settings. Add a fallback prefix to Affix settings to migrating between an old prefix and a new prefix.
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
pgomulka
left a comment
There was a problem hiding this comment.
it looks good, I left comments
| allOf( | ||
| hasEntry("server_url", "https://myurl:443"), | ||
| hasEntry("service_node_name", "instance-0000000001"), | ||
| hasEntry(equalTo("global_labels"), not(endsWith(","))), // test that we have collapsed all global labels into one |
There was a problem hiding this comment.
why not asserting about the exact entry?
There was a problem hiding this comment.
@pgomulka See below
List<String> labels = Arrays.stream(extracted.get("global_labels").split(",")).toList();
assertThat(labels, hasSize(3));
assertThat(labels, containsInAnyOrder("deployment_name=APM Tracing", "organization_id=456", "deployment_id=123"));
There was a problem hiding this comment.
containsInAnyOrder with 3 args is implying the size 3. but I think it looks
| } | ||
|
|
||
| AffixKey(String prefix, String suffix) { | ||
| AffixKey(String prefix, String suffix, String fallbackPrefix) { |
There was a problem hiding this comment.
should we call deprecation logger when a fallback prefix was used?
There was a problem hiding this comment.
I'm moving this and related changes to another PR because it would be a backwards incompatible change.
distribution/tools/server-cli/src/main/java/org/elasticsearch/server/cli/APMJvmOptions.java
Show resolved
Hide resolved
| allOf( | ||
| hasEntry("server_url", "https://myurl:443"), | ||
| hasEntry("service_node_name", "instance-0000000001"), | ||
| hasEntry(equalTo("global_labels"), not(endsWith(","))), // test that we have collapsed all global labels into one |
There was a problem hiding this comment.
@pgomulka See below
List<String> labels = Arrays.stream(extracted.get("global_labels").split(",")).toList();
assertThat(labels, hasSize(3));
assertThat(labels, containsInAnyOrder("deployment_name=APM Tracing", "organization_id=456", "deployment_id=123"));
...ribution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/APMJvmOptionsTests.java
Outdated
Show resolved
Hide resolved
server/src/main/java/org/elasticsearch/common/settings/Setting.java
Outdated
Show resolved
Hide resolved
…refix for unknown settings in APMAgentSettingsTests.testRejectForbiddenOrUnknownSettings
|
I'm addressing the |
| allOf( | ||
| hasEntry("server_url", "https://myurl:443"), | ||
| hasEntry("service_node_name", "instance-0000000001"), | ||
| hasEntry(equalTo("global_labels"), not(endsWith(","))), // test that we have collapsed all global labels into one |
There was a problem hiding this comment.
containsInAnyOrder with 3 args is implying the size 3. but I think it looks
| agentSettings.keySet().forEach(key -> propertiesMap.put(key, String.valueOf(agentSettings.get(key)))); | ||
| // tracing.apm.agent. is deprecated by telemetry.agent. | ||
| final String telemetryAgentPrefix = "telemetry.agent."; | ||
| final String tracingAgentPrefix = "tracing.apm.agent."; |
There was a problem hiding this comment.
i wonder if it would be readable by naming those two telemetryAgentPrefix and deprecatedTelemetryAgentPrefix
That was a bit much for the implementation in getAsMap, duplicate settings are applied in any order already so I removed that part of the test. |
|
|
||
| map = setting.getAsMap(Settings.builder().put("bar.bar", "true").build()); | ||
| assertEquals(1, map.size()); | ||
| assertTrue(map.get("bar")); |
There was a problem hiding this comment.
we should prefer the new prefix over the old prefix in getAsMap.
That was a bit much for the implementation in getAsMap, duplicate settings are applied in any order already so I removed that part of the test.
map = setting.getAsMap(Settings.builder().put("foo.bar", "false").put("bar.bar", "true").build());
assertEquals(1, map.size());
assertFalse(map.get("bar"));I'm a bit worried about this not working, you might end up using a fallback rather than the correct setting value without noticing. Wouldn't something like below work, I haven't tested it. But the idea is, if the map already contains a value for namespace, only ever overwrite it the key is prefixed with the default prefix and not the fallback one.
public Map<String, T> getAsMap(Settings settings) {
Map<String, T> map = new HashMap<>();
matchStream(settings).distinct().forEach(key -> {
String namespace = this.key.getNamespace(key);
if (map.containsKey(namespace) == false || key.startsWith(this.key.prefix)) {
Setting<T> concreteSetting = getConcreteSetting(namespace, key);
map.put(namespace, concreteSetting.get(settings));
}
});
return Collections.unmodifiableMap(map);
}There was a problem hiding this comment.
I was under the mistaken impression that in normal settings the primary was not preferred, so it didn't make sense to add that behavior here. I confirmed in the case of a primary setting and it's fallback, the primary is preferred. Added a test to that effect.
I've also made AffixSettings match that behavior and restored the quoted test case.
Prefer the telemetry.agent prefix for APM agent settings.
Add a fallback prefix to Affix settings to migrating between an old prefix and a new prefix.