Skip to content

tests(health api): extract specific assertions from list validator#18937

Merged
yaauie merged 5 commits intomainfrom
yaauie-health-api-test-improvementws
Apr 6, 2026
Merged

tests(health api): extract specific assertions from list validator#18937
yaauie merged 5 commits intomainfrom
yaauie-health-api-test-improvementws

Conversation

@yaauie
Copy link
Copy Markdown
Member

@yaauie yaauie commented Apr 3, 2026

Release notes

[rn:skip]

What does this PR do?

The health check tests have a scenario validator that ties a specific validation for the only arrays in the current output to all arrays in the output, but pending changes introduce an array that won't satisfy it.

This refactors the validation logic to add a special $include for the substring-matching of that specific validation, and then uses it in all of the test expectations.

It also introduces a special $match that uses a grok-lite implementation for regexps or named patterns, along with a named pattern for ISO8601 that will be used in #18930.

Why is it important/What is the impact to the user?

No user impact, but enables us to validate the health report API as it evolves.

Checklist

  • My code follows the style guidelines of this project
  • I have commented my code, particularly in hard-to-understand areas
  • [ ] I have made corresponding changes to the documentation
  • [ ] I have made corresponding change to the default configuration files (and/or docker env variables)
  • [ ] I have added tests that prove my fix is effective or that my feature works

Author's Checklist

  • manually trigger buildkite (normally runs on main and supported minor X.x branches) -> build

How to test this PR locally

See: .buildkite/scripts/health-report-tests/README.md

@yaauie yaauie requested a review from mashhurs April 3, 2026 15:03
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 3, 2026

🤖 GitHub comments

Just comment with:

  • run docs-build : Re-trigger the docs validation. (use unformatted text in the comment!)
  • run exhaustive tests : Run the exhaustive tests Buildkite pipeline.

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented Apr 3, 2026

This pull request does not have a backport label. Could you fix it @yaauie? 🙏
To fixup this pull request, you need to add the backport labels for the needed
branches, such as:

  • backport-8./d is the label to automatically backport to the 8./d branch. /d is the digit.
  • If no backport is necessary, please add the backport-skip label

@yaauie yaauie force-pushed the yaauie-health-api-test-improvementws branch from 7c911b4 to 3641c97 Compare April 3, 2026 15:14
@yaauie yaauie force-pushed the yaauie-health-api-test-improvementws branch from 3641c97 to 867dd60 Compare April 3, 2026 15:32
for result in results:
if result.get('help_url') and "health-report-pipeline-" not in result.get('help_url'):
return False
if not all(key in result and result[key] == value for key, value in expect.items()):
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

none of the current validators actually require unordered comparison, so the replacement does ordered comparison. If/when we need that, we can add an $unordered matcher like the new $include matcher to do the unordered matching.

diagnosis:
- cause: "pipeline is not running, likely because it has encountered an error"
action: "view logs to determine the cause of abnormal pipeline shutdown"
help_url: { $include: "health-report-pipeline-" }
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.

Initial implementation was to validate make sure help_url exists when pipeline faces trouble(s).
It looks like we can extend this now to be more specific, like getting

Will you have another change with a new test which expects { $include: "health-report-pipeline-recovery" }? Otherwise, it looks like will be same with hard-coded logic.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can, but I'd prefer to keep that scope expansion out of this PR and follow up separately.

if inclusion not in actual:
differences.append(f"Value at path `{path}` does not include:`{inclusion}`; got:`{actual}`")
# $match is a grok-like matcher that anchors the pattern at both ends
case {"$match": pattern_spec} if isinstance(expect, dict) and len(expect) == 1 and isinstance(actual, str):
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.

It looks like we don't have match usage yet? Will you have use-case with your recovery change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

correct. We will have it with #18930.

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.

Sounds good, your this suggestion clarifies the situation - https://github.com/elastic/logstash/pull/18930/changes#r3037810698

Co-authored-by: Mashhur <99575341+mashhurs@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@mashhurs mashhurs left a comment

Choose a reason for hiding this comment

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

It looks like current CI failures indicate rubygems repository is unreachable. Current changes are reasonable. With the next iteration or including test cases in #18930 will make this PR in action.

LGTM with 🟢 CIs.

@elasticmachine
Copy link
Copy Markdown

💚 Build Succeeded

History

@yaauie
Copy link
Copy Markdown
Member Author

yaauie commented Apr 6, 2026

health tests with this branch: https://buildkite.com/elastic/logstash-health-report-tests-pipeline/builds/628/steps/waterfall

build is green.

@yaauie yaauie merged commit 70c8e1a into main Apr 6, 2026
11 checks passed
@yaauie yaauie deleted the yaauie-health-api-test-improvementws branch April 6, 2026 22:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants