-
Notifications
You must be signed in to change notification settings - Fork 24.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
When we launch Elasticsearch with the APM monitoring agent, we create a temporary configuration file to securely pass the API key or secret. This temporary file is cleaned up on Elasticsearch Node creation. After we renamed the APM module, the delete logic didn't get updated, which means we never delete the file anymore. This commit: - fixes the APM module pattern match when we delete - adds additional delete safety net on failed node start - adds tests for ensuring the naming dependency isn't broken again.
- Loading branch information
Showing
4 changed files
with
120 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 74 additions & 0 deletions
74
...ution/tools/server-cli/src/test/java/org/elasticsearch/server/cli/APMJvmOptionsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
* or more contributor license agreements. Licensed under the Elastic License | ||
* 2.0 and the Server Side Public License, v 1; you may not use this file except | ||
* in compliance with, at your election, the Elastic License 2.0 or the Server | ||
* Side Public License, v 1. | ||
*/ | ||
|
||
package org.elasticsearch.server.cli; | ||
|
||
import org.elasticsearch.cli.UserException; | ||
import org.elasticsearch.monitor.jvm.JvmInfo; | ||
import org.elasticsearch.node.Node; | ||
import org.elasticsearch.test.ESTestCase; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
|
||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
|
||
@ESTestCase.WithoutSecurityManager | ||
public class APMJvmOptionsTests extends ESTestCase { | ||
|
||
private Path installDir; | ||
private Path agentPath; | ||
|
||
@Before | ||
public void setup() throws IOException, UserException { | ||
installDir = makeFakeAgentJar(); | ||
agentPath = APMJvmOptions.findAgentJar(installDir.toAbsolutePath().toString()); | ||
} | ||
|
||
@After | ||
public void cleanup() throws IOException { | ||
Files.delete(agentPath); | ||
} | ||
|
||
public void testFindJar() throws IOException { | ||
assertNotNull(agentPath); | ||
|
||
Path anotherPath = Files.createDirectories(installDir.resolve("another")); | ||
Path apmPathDir = anotherPath.resolve("modules").resolve("apm"); | ||
Files.createDirectories(apmPathDir); | ||
|
||
assertTrue( | ||
expectThrows(UserException.class, () -> APMJvmOptions.findAgentJar(anotherPath.toAbsolutePath().toString())).getMessage() | ||
.contains("Installation is corrupt") | ||
); | ||
} | ||
|
||
public void testFileDeleteWorks() throws IOException { | ||
var tempFile = APMJvmOptions.createTemporaryPropertiesFile(agentPath.getParent()); | ||
var commandLineOption = APMJvmOptions.agentCommandLineOption(agentPath, tempFile); | ||
var jvmInfo = mock(JvmInfo.class); | ||
doReturn(new String[] { commandLineOption }).when(jvmInfo).getInputArguments(); | ||
assertTrue(Files.exists(tempFile)); | ||
Node.deleteTemporaryApmConfig(jvmInfo, (e, p) -> fail("Shouldn't hit an exception")); | ||
assertFalse(Files.exists(tempFile)); | ||
} | ||
|
||
private Path makeFakeAgentJar() throws IOException { | ||
Path tempFile = createTempFile(); | ||
Path apmPathDir = tempFile.getParent().resolve("modules").resolve("apm"); | ||
Files.createDirectories(apmPathDir); | ||
Path apmAgentFile = apmPathDir.resolve("elastic-apm-agent-0.0.0.jar"); | ||
Files.move(tempFile, apmAgentFile); | ||
|
||
return tempFile.getParent(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
pr: 91058 | ||
summary: Fix APM configuration file delete | ||
area: Infra/Core | ||
type: bug | ||
issues: | ||
- 89439 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters