Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move docker env var settings handling out of bash #85913

Merged
merged 16 commits into from
Apr 18, 2022

Conversation

rjernst
Copy link
Member

@rjernst rjernst commented Apr 14, 2022

In docker ES allows settings to be set via environment variables. This
is currently handled in complex bash logic. This commit moves that logic
into EnvironmentAwareCommand where the rest of the initial settings are
found.

relates #85758

In docker ES allows settings to be set via environment variables. This
is currently handled in complex bash logic. This commit moves that logic
into EnvironmentAwareCommand where the rest of the initial settings are
found.

relates elastic#85758
@rjernst rjernst added >refactoring :Core/Infra/CLI CLI utilities, scripts, and infrastructure v8.3.0 labels Apr 14, 2022
@rjernst rjernst requested a review from pugnascotia April 14, 2022 18:49
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Apr 14, 2022
@elasticmachine
Copy link
Collaborator

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

rjernst and others added 7 commits April 14, 2022 12:22
Previously, in order to determine whether security had been disabled via
environment variables in Docker, we were able to check the command line
switches to the Elasticsearch process. That doesn't work now because
Elasticsearch processes the environment variables itself. Therefore,
change the check to look at the environment instead.
@@ -78,7 +78,7 @@ public class Docker {
* but that appeared to cause problems with repeatedly destroying and recreating containers with
* the same name.
*/
static String containerId = null;
public static String containerId = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need this now?

};
}

public void testNonDockerEnvVarsIgnored() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public void testNonDockerEnvVarsIgnored() throws Exception {
/**
* Check that env vars are not respected when the build type is not Docker.
*/
public void testNonDockerBuildIgnoresEnvVars() throws Exception {

execute();
}

public void testDockerEnvSettings() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public void testDockerEnvSettings() throws Exception {
/**
* Check that when the build type is Docker, then the different supported styles of passing settings
* via env vars are handled.
*/
public void testDockerBuildRespectsEnvVars() throws Exception {

mockEnvVars.put("setting.Ignored", "baz");
callback = env -> {
Settings settings = env.settings();
assertThat(settings.hasValue("simple.setting"), is(true));
Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think about also checking that the settings have the correct values as well?

Comment on lines 101 to 102
public void testDockerEnvSettingsOverride() throws Exception {
// docker env takes precedence over settings on the command line
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public void testDockerEnvSettingsOverride() throws Exception {
// docker env takes precedence over settings on the command line
/**
* Check that with the Docker build, env vars takes precedence over settings on the command line.
*/
public void testDockerBuildEnvVarsOverrideCommandLine() throws Exception {

import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

public class EnvironmentAwareCommandTests extends CommandTestCase {
Copy link
Contributor

@pugnascotia pugnascotia Apr 15, 2022

Choose a reason for hiding this comment

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

Can we also please replicate DockerTests.test087EnvironmentVariablesInIncorrectFormatAreIgnored()? It checks that env vars, which look like maybe they ought to be respected, are ignored due to being malformed.

You'll also need to remove these tests from DockerTests, because they rely on being able to inspect the Elasticsearch command line for options:

  • test086EnvironmentVariablesInSnakeCaseAreTranslated
  • test087EnvironmentVariablesInIncorrectFormatAreIgnored
  • test088EnvironmentVariablesInDottedFormatArePassedThrough

Copy link
Contributor

@pugnascotia pugnascotia left a comment

Choose a reason for hiding this comment

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

There are a number of debug statements that need to be removed as well.

@rjernst
Copy link
Member Author

rjernst commented Apr 15, 2022

Thanks Rory! I think I have a addressed all your comments. I normally don't like javadoc comments on test methods and having super descriptive names (which are actually harder to read IMO becauseOfTheLongRunningCamelCaseThatIsHardToVisuallyParse ;) But I added some simple comments to each method to describe what they are checking and standardized on method naming.

rjernst and others added 4 commits April 15, 2022 08:19
We were checked whether security was enabled or disabled in the
environment by running the `env` command and passing it through `grep`.
Unforunately, and somewhat obviously, `grep` exits non-zero if it
doesn't find a match, which causes `Shell.run` to throw and exception.
We could fix it with `runScriptIgnoreExitCode` instead of `run`, but
instead I chose just fetch all the `env` values and check them in the
Java code.
@rjernst
Copy link
Member Author

rjernst commented Apr 18, 2022

Thanks for the docker test fixes Rory. I think this is ready for a final review now that all tests are passing.

@rjernst rjernst merged commit aafd2f9 into elastic:master Apr 18, 2022
@rjernst rjernst deleted the cli/env_passthrough branch April 18, 2022 16:26
weizijun added a commit to weizijun/elasticsearch that referenced this pull request Apr 21, 2022
* master: (104 commits)
  fix: ordering terms aggregation on top metrics null values (elastic#85774)
  Fix up whitespace error introduced in elastic#85948
  More docs re. removing cluster.initial_master_nodes (elastic#85948)
  [Test] Remove API key methods from HLRC (elastic#85802)
  Remove references to bootstrap.system_call_filter (elastic#85964)
  Move docker cgroup override to SystemJvmOptions (elastic#85960)
  Add connection accounting tests (elastic#85966)
  Remove MacOS from platform support testing matrix
  Remove custom KnnVectorFieldExistsQuery (elastic#85945)
  Relax data path deprecations from critical to warn (elastic#85952)
  Remove hppc from some "common" classes (elastic#85957)
  Move docker env var settings handling out of bash (elastic#85913)
  Remove hppc from task manager (elastic#85889)
  [ML] rename trained model allocations to assignments (elastic#85503)
  Remove hppc from multi*shard request and responses (elastic#85888)
  Consolidating logging initialization in cli launcher (elastic#85920)
  Convert license tools to use unified cli entrypoint (elastic#85919)
  Add noop detection to node shutdown actions (elastic#85914)
  Adjust SQL expended test output
  TSDB: Add timestamp provider to AggregationExecutionContext (elastic#85850)
  ...

# Conflicts:
#	server/src/main/java/org/elasticsearch/search/aggregations/AggregationExecutionContext.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Core/Infra/CLI CLI utilities, scripts, and infrastructure >refactoring Team:Core/Infra Meta label for core/infra team v8.3.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants