Skip to content

Commit

Permalink
Merge pull request #196 from elastic/main
Browse files Browse the repository at this point in the history
🤖 ESQL: Merge upstream
  • Loading branch information
bpintea committed Aug 10, 2022
2 parents 1210ae5 + d663231 commit f22bfce
Show file tree
Hide file tree
Showing 159 changed files with 4,379 additions and 1,969 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Expand Up @@ -15,3 +15,7 @@ x-pack/plugin/core/src/main/resources/monitoring-logstash-mb.json @elastic/infra
x-pack/plugin/core/src/main/resources/monitoring-logstash.json @elastic/infra-monitoring-ui
x-pack/plugin/core/src/main/resources/monitoring-mb-ilm-policy.json @elastic/infra-monitoring-ui
x-pack/plugin/monitoring/src/main/java/org/elasticsearch/xpack/monitoring/MonitoringTemplateRegistry.java @elastic/infra-monitoring-ui

# Elastic Agent
x-pack/plugin/fleet/src/main/java/org/elasticsearch/xpack/fleet @elastic/elastic-agent-control-plane
x-pack/plugin/core/src/main/resources/fleet-* @elastic/elastic-agent-control-plane
2 changes: 1 addition & 1 deletion TRACING.md
Expand Up @@ -45,7 +45,7 @@ For context, the APM agent pulls configuration from [multiple
sources][agent-config], with a hierarchy that means, for example, that options
set in the config file cannot be overridden via system properties.

Now, in order to send tracing data to the APM server, ES needs to configured with
Now, in order to send tracing data to the APM server, ES needs to be configured with
either a `secret_key` or an `api_key`. We could configure these in the agent via
system properties, but then their values would be available to any Java code in
Elasticsearch that can read system properties.
Expand Down
4 changes: 2 additions & 2 deletions build-tools-internal/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionSha256Sum=97a52d145762adc241bad7fd18289bf7f6801e08ece6badf80402fe2b9f250b1
distributionSha256Sum=db9c8211ed63f61f60292c69e80d89196f9eb36665e369e7f00ac4cc841c2219
@@ -1 +1 @@
7.5
7.5.1
Expand Up @@ -67,7 +67,7 @@ protected void execute(Terminal terminal, OptionSet options, ProcessInfo process
preExecute(terminal, processInfo, serviceId);

List<String> procrunCmd = new ArrayList<>();
procrunCmd.add(procrun.toString());
procrunCmd.add(quote(procrun.toString()));
procrunCmd.add("//%s/%s".formatted(cmd, serviceId));
if (includeLogArgs()) {
procrunCmd.add(getLogArgs(serviceId, processInfo.workingDir(), processInfo.envVars()));
Expand All @@ -86,6 +86,11 @@ protected void execute(Terminal terminal, OptionSet options, ProcessInfo process
}
}

/** Quotes the given String. */
static String quote(String s) {
return '"' + s + '"';
}

/** Determines the service id for the Elasticsearch service that should be used */
private String getServiceId(OptionSet options, Map<String, String> env) throws UserException {
List<?> args = options.nonOptionArguments();
Expand Down
Expand Up @@ -42,7 +42,7 @@ protected String getAdditionalArgs(String serviceId, ProcessInfo pinfo) {
addArg(args, "--Classpath", pinfo.sysprops().get("java.class.path"));
addArg(args, "--JvmMs", "4m");
addArg(args, "--JvmMx", "64m");
addArg(args, "--JvmOptions", getJvmOptions(pinfo.sysprops()));
addQuotedArg(args, "--JvmOptions", getJvmOptions(pinfo.sysprops()));
addArg(args, "--PidFile", "%s.pid".formatted(serviceId));
addArg(
args,
Expand All @@ -55,10 +55,10 @@ protected String getAdditionalArgs(String serviceId, ProcessInfo pinfo) {
pinfo.envVars()
.getOrDefault("SERVICE_DESCRIPTION", "Elasticsearch %s Windows Service - https://elastic.co".formatted(Version.CURRENT))
);
addArg(args, "--Jvm", getJvmDll(getJavaHome(pinfo.sysprops())).toString());
addQuotedArg(args, "--Jvm", quote(getJvmDll(getJavaHome(pinfo.sysprops())).toString()));
addArg(args, "--StartMode", "jvm");
addArg(args, "--StopMode", "jvm");
addArg(args, "--StartPath", pinfo.workingDir().toString());
addQuotedArg(args, "--StartPath", quote(pinfo.workingDir().toString()));
addArg(args, "++JvmOptions", "-Dcli.name=windows-service-daemon");
addArg(args, "++JvmOptions", "-Dcli.libs=lib/tools/server-cli,lib/tools/windows-service-cli");
addArg(args, "++Environment", "HOSTNAME=%s".formatted(pinfo.envVars().get("COMPUTERNAME")));
Expand Down Expand Up @@ -89,6 +89,13 @@ private static void addArg(List<String> args, String arg, String value) {
args.add(value);
}

// Adds an arg with an already appropriately quoted value. Trivial, but explicit implementation.
// This method is typically used when adding args whose value contains a file-system path
private static void addQuotedArg(List<String> args, String arg, String value) {
args.add(arg);
args.add(value);
}

@SuppressForbidden(reason = "get java home path to pass through")
private static Path getJavaHome(Map<String, String> sysprops) {
return Paths.get(sysprops.get("java.home"));
Expand All @@ -107,7 +114,7 @@ private static String getJvmOptions(Map<String, String> sysprops) {
jvmOptions.add("-XX:+UseSerialGC");
// passthrough these properties
for (var prop : List.of("es.path.home", "es.path.conf", "es.distribution.type")) {
jvmOptions.add("-D%s=%s".formatted(prop, sysprops.get(prop)));
jvmOptions.add("-D%s=%s".formatted(prop, quote(sysprops.get(prop))));
}
return String.join(";", jvmOptions);
}
Expand Down
Expand Up @@ -25,6 +25,10 @@

public class ProcrunCommandTests extends WindowsServiceCliTestCase {

public ProcrunCommandTests(boolean spaceInPath) {
super(spaceInPath);
}

PreExecuteHook preExecuteHook;
boolean includeLogArgs;
String additionalArgs;
Expand Down
Expand Up @@ -8,6 +8,8 @@

package org.elasticsearch.windows.service;

import com.carrotsearch.randomizedtesting.annotations.ParametersFactory;

import org.elasticsearch.cli.CommandTestCase;
import org.junit.Before;

Expand Down Expand Up @@ -47,6 +49,15 @@ public abstract class WindowsServiceCliTestCase extends CommandTestCase {
int mockProcessExit = 0;
ProcessValidator mockProcessValidator = null;

@ParametersFactory
public static Iterable<Object[]> spaceInPathProvider() {
return List.of(new Object[] { true }, new Object[] { false });
}

protected WindowsServiceCliTestCase(boolean spaceInPath) {
super(spaceInPath);
}

interface ProcessValidator {
void validate(Map<String, String> env, ProcrunCall procrunCall);
}
Expand Down Expand Up @@ -106,16 +117,22 @@ protected Process mockProcess(ProcessBuilder processBuilder) throws IOException
private static final Pattern commandPattern = Pattern.compile("//([A-Z]{2})/([\\w-]+)");

private static ProcrunCall parseProcrunCall(String unparsedArgs) {
// command/exe is quoted
assert unparsedArgs.charAt(0) == '"';
int idx = unparsedArgs.indexOf('"', 1);
String exe = unparsedArgs.substring(0, idx + 1);
// Strip the leading command/exe from the args
unparsedArgs = unparsedArgs.substring(idx + 1).stripLeading();

String[] splitArgs = unparsedArgs.split(" ");
assertThat(unparsedArgs, splitArgs.length, greaterThanOrEqualTo(2));
assertThat(unparsedArgs, splitArgs.length, greaterThanOrEqualTo(1));
Map<String, List<String>> args = new HashMap<>();
String exe = splitArgs[0];
Matcher commandMatcher = commandPattern.matcher(splitArgs[1]);
assertThat(splitArgs[1], commandMatcher.matches(), is(true));
Matcher commandMatcher = commandPattern.matcher(splitArgs[0]);
assertThat(splitArgs[0], commandMatcher.matches(), is(true));
String command = commandMatcher.group(1);
String serviceId = commandMatcher.group(2);

int i = 2;
int i = 1;
while (i < splitArgs.length) {
String arg = splitArgs[i];
assertThat("procrun args begin with -- or ++", arg, anyOf(startsWith("--"), startsWith("++")));
Expand Down Expand Up @@ -165,8 +182,12 @@ public void resetMockProcess() throws Exception {

protected abstract String getDefaultFailureMessage();

static String quote(String s) {
return '"' + s + '"';
}

protected String getExe() {
return serviceExe.toString();
return quote(serviceExe.toString());
}

protected boolean includeLogsArgs() {
Expand Down
Expand Up @@ -31,6 +31,10 @@ public class WindowsServiceInstallCommandTests extends WindowsServiceCliTestCase

Path jvmDll;

public WindowsServiceInstallCommandTests(boolean spaceInPath) {
super(spaceInPath);
}

@Before
public void setupJvm() throws Exception {
jvmDll = javaHome.resolve("jre/bin/server/jvm.dll");
Expand Down Expand Up @@ -80,7 +84,7 @@ public void testAlternateDllLocation() throws Exception {
}

public void testDll() throws Exception {
assertServiceArgs(Map.of("Jvm", jvmDll.toString()));
assertServiceArgs(Map.of("Jvm", quote(jvmDll.toString())));
}

public void testPreExecuteOutput() throws Exception {
Expand All @@ -95,9 +99,9 @@ public void testJvmOptions() throws Exception {
sysprops.put("es.distribution.type", "testdistro");
List<String> expectedOptions = List.of(
"" + "-XX:+UseSerialGC",
"-Des.path.home=" + esHomeDir.toString(),
"-Des.path.conf=" + esHomeDir.resolve("config").toString(),
"-Des.distribution.type=testdistro"
"-Des.path.home=" + quote(esHomeDir.toString()),
"-Des.path.conf=" + quote(esHomeDir.resolve("config").toString()),
"-Des.distribution.type=" + quote("testdistro")
);
mockProcessValidator = (environment, procrunCall) -> {
List<String> options = procrunCall.args().get("JvmOptions");
Expand Down Expand Up @@ -136,7 +140,7 @@ public void testFixedArgs() throws Exception {
entry("StopMode", "jvm"),
entry("JvmMs", "4m"),
entry("JvmMx", "64m"),
entry("StartPath", esHomeDir.toString()),
entry("StartPath", quote(esHomeDir.toString())),
entry("Classpath", "javaclasspath") // dummy value for tests
)
);
Expand Down
Expand Up @@ -13,6 +13,11 @@
import java.io.IOException;

public class WindowsServiceManagerCommandTests extends WindowsServiceCliTestCase {

public WindowsServiceManagerCommandTests(boolean spaceInPath) {
super(spaceInPath);
}

@Override
protected Command newCommand() {
return new WindowsServiceManagerCommand() {
Expand All @@ -25,7 +30,7 @@ Process startProcess(ProcessBuilder processBuilder) throws IOException {

@Override
protected String getExe() {
return mgrExe.toString();
return quote(mgrExe.toString());
}

@Override
Expand Down
Expand Up @@ -13,6 +13,11 @@
import java.io.IOException;

public class WindowsServiceRemoveCommandTests extends WindowsServiceCliTestCase {

public WindowsServiceRemoveCommandTests(boolean spaceInPath) {
super(spaceInPath);
}

@Override
protected Command newCommand() {
return new WindowsServiceRemoveCommand() {
Expand Down
Expand Up @@ -13,6 +13,11 @@
import java.io.IOException;

public class WindowsServiceStartCommandTests extends WindowsServiceCliTestCase {

public WindowsServiceStartCommandTests(boolean spaceInPath) {
super(spaceInPath);
}

@Override
protected Command newCommand() {
return new WindowsServiceStartCommand() {
Expand Down
Expand Up @@ -13,6 +13,11 @@
import java.io.IOException;

public class WindowsServiceStopCommandTests extends WindowsServiceCliTestCase {

public WindowsServiceStopCommandTests(boolean spaceInPath) {
super(spaceInPath);
}

@Override
protected Command newCommand() {
return new WindowsServiceStopCommand() {
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog/88409.yaml
@@ -0,0 +1,5 @@
pr: 88409
summary: Enable `BloomFilter` for `_id` of non-datastream indices
area: Search
type: enhancement
issues: []
5 changes: 5 additions & 0 deletions docs/changelog/88903.yaml
@@ -0,0 +1,5 @@
pr: 88903
summary: Delete invalid settings for system indices
area: Infra/Core
type: bug
issues: [88324]
5 changes: 5 additions & 0 deletions docs/changelog/89014.yaml
@@ -0,0 +1,5 @@
pr: 89014
summary: Polling for cluster diagnostics information
area: Health
type: enhancement
issues: []
5 changes: 5 additions & 0 deletions docs/changelog/89023.yaml
@@ -0,0 +1,5 @@
pr: 89023
summary: User Profile - `GetProfile` API nows supports multiple UIDs
area: Security
type: enhancement
issues: []
5 changes: 5 additions & 0 deletions docs/changelog/89052.yaml
@@ -0,0 +1,5 @@
pr: 89052
summary: Add support for source fallback with the boolean field type
area: Mapping
type: enhancement
issues: []
5 changes: 5 additions & 0 deletions docs/changelog/89053.yaml
@@ -0,0 +1,5 @@
pr: 89053
summary: Add support for source fallback with scaled float field type
area: Mapping
type: enhancement
issues: []
6 changes: 6 additions & 0 deletions docs/changelog/89072.yaml
@@ -0,0 +1,6 @@
pr: 89072
summary: Quote paths with whitespace in Windows service CLIs
area: Infra/CLI
type: bug
issues:
- 89043
5 changes: 5 additions & 0 deletions docs/changelog/89166.yaml
@@ -0,0 +1,5 @@
pr: 89166
summary: Show assigned role descriptors in Get/QueryApiKey response
area: Security
type: enhancement
issues: []
5 changes: 5 additions & 0 deletions docs/changelog/89182.yaml
@@ -0,0 +1,5 @@
pr: 89182
summary: Fixing internal action names
area: Health
type: bug
issues: []
7 changes: 7 additions & 0 deletions docs/changelog/89199.yaml
@@ -0,0 +1,7 @@
pr: 89199
summary: Geo_line aggregation returns a geojson point when the resulting line has
only one point
area: Geo
type: bug
issues:
- 85748

0 comments on commit f22bfce

Please sign in to comment.