Skip to content

Metrics: Agent settings prefix telemetry.agent preferred over tracing.apm.agent#104345

Merged
stu-elastic merged 16 commits intoelastic:mainfrom
stu-elastic:telemetry-agent-fallback
Jan 22, 2024
Merged

Metrics: Agent settings prefix telemetry.agent preferred over tracing.apm.agent#104345
stu-elastic merged 16 commits intoelastic:mainfrom
stu-elastic:telemetry-agent-fallback

Conversation

@stu-elastic
Copy link
Copy Markdown
Contributor

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.

….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.
@stu-elastic stu-elastic added >non-issue :Core/Infra/Core Core issues without another label labels Jan 12, 2024
@elasticsearchmachine elasticsearchmachine added v8.13.0 Team:Core/Infra Meta label for core/infra team labels Jan 12, 2024
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Copy link
Copy Markdown
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not asserting about the exact entry?

Copy link
Copy Markdown
Contributor

@mosche mosche Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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"));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we call deprecation logger when a fallback prefix was used?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm moving this and related changes to another PR because it would be a backwards incompatible change.

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
Copy link
Copy Markdown
Contributor

@mosche mosche Jan 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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"));

@stu-elastic
Copy link
Copy Markdown
Contributor Author

stu-elastic commented Jan 17, 2024

I'm addressing the testPrefixKeySettingFallbackAsMap failure, we should prefer the new prefix over the old prefix in getAsMap.

Copy link
Copy Markdown
Contributor

@pgomulka pgomulka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.";
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i wonder if it would be readable by naming those two telemetryAgentPrefix and deprecatedTelemetryAgentPrefix

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed.

@stu-elastic
Copy link
Copy Markdown
Contributor Author

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("bar.bar", "true").build());
assertEquals(1, map.size());
assertTrue(map.get("bar"));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@stu-elastic stu-elastic changed the title Metrics: Agent settings prefix telemetry.agent deprecates tracing.apm.agent Metrics: Agent settings prefix telemetry.agent preferred over tracing.apm.agent Jan 18, 2024
Copy link
Copy Markdown
Contributor

@mosche mosche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v8.13.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants