Skip to content

Commit

Permalink
Merge branch 'main' into lucene_snapshot_10_1
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisHegarty authored Jan 27, 2025
2 parents 33f7701 + 9d90d05 commit 097aa45
Show file tree
Hide file tree
Showing 116 changed files with 3,866 additions and 1,343 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,20 +187,12 @@ static String agentCommandLineOption(Path agentJar, Path tmpPropertiesFile) {
static void extractSecureSettings(SecureSettings secrets, Map<String, String> propertiesMap) {
final Set<String> settingNames = secrets.getSettingNames();
for (String key : List.of("api_key", "secret_token")) {
for (String prefix : List.of("telemetry.", "tracing.apm.")) {
if (settingNames.contains(prefix + key)) {
if (propertiesMap.containsKey(key)) {
throw new IllegalStateException(
Strings.format("Duplicate telemetry setting: [telemetry.%s] and [tracing.apm.%s]", key, key)
);
}

try (SecureString token = secrets.getString(prefix + key)) {
propertiesMap.put(key, token.toString());
}
String prefix = "telemetry.";
if (settingNames.contains(prefix + key)) {
try (SecureString token = secrets.getString(prefix + key)) {
propertiesMap.put(key, token.toString());
}
}

}
}

Expand All @@ -227,44 +219,12 @@ private static Map<String, String> extractDynamicSettings(Map<String, String> pr
static Map<String, String> extractApmSettings(Settings settings) throws UserException {
final Map<String, String> propertiesMap = new HashMap<>();

// tracing.apm.agent. is deprecated by telemetry.agent.
final String telemetryAgentPrefix = "telemetry.agent.";
final String deprecatedTelemetryAgentPrefix = "tracing.apm.agent.";

final Settings telemetryAgentSettings = settings.getByPrefix(telemetryAgentPrefix);
telemetryAgentSettings.keySet().forEach(key -> propertiesMap.put(key, String.valueOf(telemetryAgentSettings.get(key))));

final Settings apmAgentSettings = settings.getByPrefix(deprecatedTelemetryAgentPrefix);
for (String key : apmAgentSettings.keySet()) {
if (propertiesMap.containsKey(key)) {
throw new IllegalStateException(
Strings.format(
"Duplicate telemetry setting: [%s%s] and [%s%s]",
telemetryAgentPrefix,
key,
deprecatedTelemetryAgentPrefix,
key
)
);
}
propertiesMap.put(key, String.valueOf(apmAgentSettings.get(key)));
}

StringJoiner globalLabels = extractGlobalLabels(telemetryAgentPrefix, propertiesMap, settings);
if (globalLabels.length() == 0) {
globalLabels = extractGlobalLabels(deprecatedTelemetryAgentPrefix, propertiesMap, settings);
} else {
StringJoiner tracingGlobalLabels = extractGlobalLabels(deprecatedTelemetryAgentPrefix, propertiesMap, settings);
if (tracingGlobalLabels.length() != 0) {
throw new IllegalArgumentException(
"Cannot have global labels with tracing.agent prefix ["
+ globalLabels
+ "] and telemetry.apm.agent prefix ["
+ tracingGlobalLabels
+ "]"
);
}
}
if (globalLabels.length() > 0) {
propertiesMap.put("global_labels", globalLabels.toString());
}
Expand All @@ -274,7 +234,7 @@ static Map<String, String> extractApmSettings(Settings settings) throws UserExce
if (propertiesMap.containsKey(key)) {
throw new UserException(
ExitCodes.CONFIG,
"Do not set a value for [tracing.apm.agent." + key + "], as this is configured automatically by Elasticsearch"
"Do not set a value for [telemetry.agent." + key + "], as this is configured automatically by Elasticsearch"
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Function;

import static org.elasticsearch.test.MapMatcher.matchesMap;
import static org.hamcrest.Matchers.allOf;
import static org.hamcrest.Matchers.containsInAnyOrder;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.endsWith;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasEntry;
import static org.hamcrest.Matchers.hasKey;
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
Expand Down Expand Up @@ -82,109 +79,63 @@ public void testFileDeleteWorks() throws IOException {
}

public void testExtractSecureSettings() {
MockSecureSettings duplicateSecureSettings = new MockSecureSettings();
MockSecureSettings secureSettings = new MockSecureSettings();
secureSettings.setString("telemetry.secret_token", "token");
secureSettings.setString("telemetry.api_key", "key");

for (String prefix : List.of("telemetry.", "tracing.apm.")) {
MockSecureSettings secureSettings = new MockSecureSettings();
secureSettings.setString(prefix + "secret_token", "token");
secureSettings.setString(prefix + "api_key", "key");

duplicateSecureSettings.setString(prefix + "api_key", "secret");

Map<String, String> propertiesMap = new HashMap<>();
APMJvmOptions.extractSecureSettings(secureSettings, propertiesMap);

assertThat(propertiesMap, matchesMap(Map.of("secret_token", "token", "api_key", "key")));
}

Exception exception = expectThrows(
IllegalStateException.class,
() -> APMJvmOptions.extractSecureSettings(duplicateSecureSettings, new HashMap<>())
);
assertThat(exception.getMessage(), containsString("Duplicate telemetry setting"));
assertThat(exception.getMessage(), containsString("telemetry.api_key"));
assertThat(exception.getMessage(), containsString("tracing.apm.api_key"));
Map<String, String> propertiesMap = new HashMap<>();
APMJvmOptions.extractSecureSettings(secureSettings, propertiesMap);

assertThat(propertiesMap, matchesMap(Map.of("secret_token", "token", "api_key", "key")));
}

public void testExtractSettings() throws UserException {
Function<String, Settings.Builder> buildSettings = (prefix) -> Settings.builder()
.put(prefix + "server_url", "https://myurl:443")
.put(prefix + "service_node_name", "instance-0000000001");

for (String prefix : List.of("tracing.apm.agent.", "telemetry.agent.")) {
var name = "APM Tracing";
var deploy = "123";
var org = "456";
var extracted = APMJvmOptions.extractApmSettings(
buildSettings.apply(prefix)
.put(prefix + "global_labels.deployment_name", name)
.put(prefix + "global_labels.deployment_id", deploy)
.put(prefix + "global_labels.organization_id", org)
.build()
);

assertThat(
extracted,
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
not(hasKey("global_labels.organization_id")) // tests that we strip out the top level label keys
)
);

List<String> labels = Arrays.stream(extracted.get("global_labels").split(",")).toList();
assertThat(labels, hasSize(3));
assertThat(labels, containsInAnyOrder("deployment_name=APM Tracing", "organization_id=" + org, "deployment_id=" + deploy));

// test replacing with underscores and skipping empty
name = "APM=Tracing";
deploy = "";
org = ",456";
extracted = APMJvmOptions.extractApmSettings(
buildSettings.apply(prefix)
.put(prefix + "global_labels.deployment_name", name)
.put(prefix + "global_labels.deployment_id", deploy)
.put(prefix + "global_labels.organization_id", org)
.build()
);
labels = Arrays.stream(extracted.get("global_labels").split(",")).toList();
assertThat(labels, hasSize(2));
assertThat(labels, containsInAnyOrder("deployment_name=APM_Tracing", "organization_id=_456"));
}

IllegalStateException err = expectThrows(
IllegalStateException.class,
() -> APMJvmOptions.extractApmSettings(
Settings.builder()
.put("tracing.apm.agent.server_url", "https://myurl:443")
.put("telemetry.agent.server_url", "https://myurl-2:443")
.build()
)
);
assertThat(err.getMessage(), is("Duplicate telemetry setting: [telemetry.agent.server_url] and [tracing.apm.agent.server_url]"));
}

public void testNoMixedLabels() {
String telemetryAgent = "telemetry.agent.";
String tracingAgent = "tracing.apm.agent.";
Settings settings = Settings.builder()
.put("tracing.apm.enabled", true)
.put(telemetryAgent + "server_url", "https://myurl:443")
.put(telemetryAgent + "service_node_name", "instance-0000000001")
.put(tracingAgent + "global_labels.deployment_id", "123")
.put(telemetryAgent + "global_labels.organization_id", "456")
Settings defaults = Settings.builder()
.put("telemetry.agent.server_url", "https://myurl:443")
.put("telemetry.agent.service_node_name", "instance-0000000001")
.build();

IllegalArgumentException err = assertThrows(IllegalArgumentException.class, () -> APMJvmOptions.extractApmSettings(settings));
var name = "APM Tracing";
var deploy = "123";
var org = "456";
var extracted = APMJvmOptions.extractApmSettings(
Settings.builder()
.put(defaults)
.put("telemetry.agent.global_labels.deployment_name", name)
.put("telemetry.agent.global_labels.deployment_id", deploy)
.put("telemetry.agent.global_labels.organization_id", org)
.build()
);

assertThat(
err.getMessage(),
is(
"Cannot have global labels with tracing.agent prefix [organization_id=456] and"
+ " telemetry.apm.agent prefix [deployment_id=123]"
extracted,
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
not(hasKey("global_labels.organization_id")) // tests that we strip out the top level label keys
)
);

List<String> labels = Arrays.stream(extracted.get("global_labels").split(",")).toList();
assertThat(labels, hasSize(3));
assertThat(labels, containsInAnyOrder("deployment_name=APM Tracing", "organization_id=" + org, "deployment_id=" + deploy));

// test replacing with underscores and skipping empty
name = "APM=Tracing";
deploy = "";
org = ",456";
extracted = APMJvmOptions.extractApmSettings(
Settings.builder()
.put(defaults)
.put("telemetry.agent.global_labels.deployment_name", name)
.put("telemetry.agent.global_labels.deployment_id", deploy)
.put("telemetry.agent.global_labels.organization_id", org)
.build()
);
labels = Arrays.stream(extracted.get("global_labels").split(",")).toList();
assertThat(labels, hasSize(2));
assertThat(labels, containsInAnyOrder("deployment_name=APM_Tracing", "organization_id=_456"));
}

private Path makeFakeAgentJar() throws IOException {
Expand Down
11 changes: 11 additions & 0 deletions docs/changelog/119926.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
pr: 119926
summary: "Deprecated tracing.apm.* settings got removed."
area: Infra/Metrics
type: breaking
issues: []
breaking:
title: "Deprecated tracing.apm.* settings got removed."
area: Cluster and node setting
details: Deprecated `tracing.apm.*` settings got removed, use respective `telemetry.*` / `telemetry.tracing.*` settings instead.
impact: 9.x nodes will refuse to start if any such setting (including secret settings) is still present.
notable: false
16 changes: 16 additions & 0 deletions docs/changelog/120267.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pr: 120267
summary: Set allow_partial_search_results=true by default
area: EQL
type: breaking
issues: []
breaking:
title: Set allow_partial_search_results=true by default
area: REST API
details:
Before this change, in case of shard failures, EQL queries always returned an error.
With this change, they will keep running and will return partial results.
impact:
EQL queries that would previously fail due to shard failures, will now succeed and return partial results.
The previous defaults can be restored by setting `xpack.eql.default_allow_partial_results` cluster setting to `false`
or setting with `allow_partial_search_results` to `false` in the query request.
notable: false
6 changes: 6 additions & 0 deletions docs/changelog/120727.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 120727
summary: Esql - Support date nanos in date extract function
area: ES|QL
type: enhancement
issues:
- 110000
5 changes: 5 additions & 0 deletions docs/changelog/120799.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 120799
summary: Remove duplicate code in ESIntegTestCase
area: Search
type: bug
issues: []
Loading

0 comments on commit 097aa45

Please sign in to comment.