Skip to content

Change the approach to find the APM Agent property file in test#144928

Merged
mamazzol merged 10 commits intoelastic:mainfrom
mamazzol:ci-144357
Mar 27, 2026
Merged

Change the approach to find the APM Agent property file in test#144928
mamazzol merged 10 commits intoelastic:mainfrom
mamazzol:ci-144357

Conversation

@mamazzol
Copy link
Copy Markdown
Contributor

@mamazzol mamazzol commented Mar 25, 2026

Change the approach to find the APM Agent property file in tests to replicate what we do when deleting the file at startup.

Closes: #144357
Closes: #144358

@mamazzol mamazzol requested a review from a team as a code owner March 25, 2026 13:25
@mamazzol mamazzol added >test Issues or PRs that are addressing/adding tests Team:Core/Infra Meta label for core/infra team :Core/Infra/Metrics Metrics and metering infrastructure labels Mar 25, 2026
@elasticsearchmachine
Copy link
Copy Markdown
Collaborator

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

@mamazzol mamazzol changed the title Ci 144357 Change the approach to find the APM Agent property file in test Mar 25, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 25, 2026

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Tests were refactored so the APM properties extractor accepts a JVM options list, parses the -javaagent: argument to derive the =c= config path via a new findApmConfigPath helper, verifies the target is a regular file whose filename matches Node.APM_PROPFILE_REGEX, and loads it; missing matches now throw an AssertionError that includes the full options list. Node gained the public constant APM_PROPFILE_REGEX. muted-tests.yml adds a mute for org.elasticsearch.reindex.management.ReindexGetRelocationIT#testGetReindexFollowsRelocation; existing APMJvmOptionsTests mutes remain.

🚥 Pre-merge checks | ✅ 1 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Out of Scope Changes check ❓ Inconclusive The muted-tests.yml entry for ReindexGetRelocationIT appears unrelated to APM test stabilization; other changes align with fixing the intermittent APMJvmOptionsTests failure. Clarify why ReindexGetRelocationIT (issue #144364) was muted in this PR; verify it is not an accidental inclusion unrelated to issue #144357.
✅ Passed checks (1 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR directly addresses issue #144357 by refactoring test logic to locate APM config files using the same approach as production code, mitigating intermittent directory-vs-file IO errors.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • 🛠️ Update Documentation: Commit on current branch
  • 🛠️ Update Documentation: Create PR

Comment @coderabbitai help to get the list of available commands and usage tips.

@prdoyle
Copy link
Copy Markdown
Contributor

prdoyle commented Mar 25, 2026

I think I need more context on this one. Why was the old logic wrong?

@mamazzol
Copy link
Copy Markdown
Contributor Author

I think I need more context on this one. Why was the old logic wrong?

Based on the test failure, it still seems to pick up a directory every once in a while (which is surprising, but that's what the message says). So I changed the logic to replicate what we do in Production, so that it's tried and tested

Copy link
Copy Markdown
Contributor

@mark-vieira mark-vieira left a comment

Choose a reason for hiding this comment

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

Is this a side effect of the CLI launcher changes? If so, what exactly is different here?

@mamazzol
Copy link
Copy Markdown
Contributor Author

Is this a side effect of the CLI launcher changes? If so, what exactly is different here?

I don't think so. This current logic was brought in to fix a similar failure, see #144350

I reproduced that locally by running the test enough times, and it seems to have fixed it, but apparently it's still happening. So I am trying a different approach.

Copy link
Copy Markdown
Contributor

@prdoyle prdoyle left a comment

Choose a reason for hiding this comment

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

Sorry, I'm still not quite following. Could you link the that "what we do when deleting the file at startup" so I can follow the reasoning?

int configIndex = inputArgument.lastIndexOf("=c=");
if (configIndex > 0) {
final Path apmConfig = PathUtils.get(inputArgument.substring(configIndex + 3));
if (Files.isRegularFile(apmConfig) && apmConfig.getFileName().toString().matches("^\\.elstcapm\\..*\\.tmp$")) {
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 did this go back to being a regex?

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.

Replying to both at the same time, here is the logic I am referring to

public static void deleteTemporaryApmConfig(JvmInfo jvmInfo, BiConsumer<Exception, Path> errorHandler) {

This uses the regex so I put it back this way.

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.

Ah I see! Maybe let's make that a public constant that can be shared in the code rather than duplicating it? That would make the code itself answer both questions!.

@mamazzol mamazzol merged commit 9156c15 into elastic:main Mar 27, 2026
36 checks passed
mamazzol added a commit to mamazzol/elasticsearch that referenced this pull request Mar 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Core/Infra/Metrics Metrics and metering infrastructure Team:Core/Infra Meta label for core/infra team >test Issues or PRs that are addressing/adding tests v9.4.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[CI] APMJvmOptionsTests testAPMAgentAlwaysAttached failing [CI] APMJvmOptionsTests testAPMAgentMetricsDisabledWhenOtelMetricsEnabled failing

4 participants