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

Health report integration tests bootstrapper and initial tests implementation #16467

Draft
wants to merge 1 commit into
base: feature/health-report-api
Choose a base branch
from

Conversation

mashhurs
Copy link
Contributor

Release notes

[rn:skip]

What does this PR do?

  • Sets up the python bootstrapper to run the scenarios defined in the tests folder.
  • Adds an initial slow-start test case

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

N.A

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

  • Continue adding defined scenarios

How to test this PR locally

  1. Clone this PR and build Logstash: ./gradlew clean bootstrap assemble installDefaultGems
  2. Install logstash-integration-failure_injector
  • Create logstash-integration-failure_injector folder under qa/support
  • Copy the logstash-integration-failure_injector-0.0.1.gem of Failure injector plugin implementation. #16466 to qa/support/logstash-integration-failure_injector folder
  • Install with bin/logstash-plugin install qa/support/logstash-integration-failure_injector/logstash-integration-failure_injector-0.0.1.gem
  1. Follow the README.md of this PR to run the integration test.

Related issues

Use cases

Screenshots

Logs

@mashhurs mashhurs force-pushed the health-report-bootstrap-and-integration-tests branch from 5f7dd0d to ffaac9a Compare September 18, 2024 17:22
@mashhurs mashhurs self-assigned this Sep 18, 2024
Copy link

Quality Gate passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarQube

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

cc @mashhurs

@mashhurs mashhurs changed the title Health report bootstrap and integration tests Health report integration tests bootstrapper and initial tests implementation Sep 18, 2024
Copy link
Contributor

@kaisecheng kaisecheng left a comment

Choose a reason for hiding this comment

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

I have tried to run a happy case and a sad case that changed expectation.status from yellow to red. However, both give me YAML 'expectation' section matches the stats.

[14:05:35] logstash git:(pr-16467) ✗ python3 .buildkite/scripts/health-report-tests/main.py
Starting Logstash Health Report Integration test.
LS_VERSION is not specified, using main branch.
logstash-integration-failure_injector successfully installed.
Validating /Users/kcheng/GitHub/kaisecheng/logstash/.buildkite/scripts/health-report-tests/tests/slow-start.yaml scenario file.
YAML file validation successful!
Logstash is running with PID: 55550.
Testing the scenario: [{'status': 'red'}, {'symptom': 'The pipeline is degraded or at risk of becoming unhealthy; 1 area is impacted and 1 diagnosis is available.'}, {'diagnosis': [{'cause': 'pipeline is loading'}]}, {'impacts': [{'description': 'pipeline is loading'}, {'impact_areas': 'pipeline_execution'}]}, {'details': [{'run_state': 'LOADING'}]}]
Logstash health report: {'path': '/_health_report', 'status': 404, 'error': {'message': 'Not Found'}}
YAML 'expectation' section matches the stats.

[14:46:10] logstash git:(pr-16467) ✗ python3 .buildkite/scripts/health-report-tests/main.py
Starting Logstash Health Report Integration test.
LS_VERSION is not specified, using main branch.
logstash-integration-failure_injector successfully installed.
Validating /Users/kcheng/GitHub/kaisecheng/logstash/.buildkite/scripts/health-report-tests/tests/slow-start.yaml scenario file.
YAML file validation successful!
Logstash is running with PID: 57476.
Testing the scenario: [{'status': 'yellow'}, {'symptom': 'The pipeline is degraded or at risk of becoming unhealthy; 1 area is impacted and 1 diagnosis is available.'}, {'diagnosis': [{'cause': 'pipeline is loading'}]}, {'impacts': [{'description': 'pipeline is loading'}, {'impact_areas': 'pipeline_execution'}]}, {'details': [{'run_state': 'LOADING'}]}]
Logstash health report: {'path': '/_health_report', 'status': 404, 'error': {'message': 'Not Found'}}
YAML 'expectation' section matches the stats.

def __init__(self):
pass

def __meets_expectation(self, scenario_content: list) -> None:
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
def __meets_expectation(self, scenario_content: list) -> None:
def __is_expected(self, scenario_content: list) -> None:


def on(self, scenario_name: str, scenario_content: list) -> None:
print(f"Testing the scenario: {scenario_content}")
if self.__meets_expectation(scenario_content) is False:
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
if self.__meets_expectation(scenario_content) is False:
if self.__is_expected(scenario_content) is False:

Comment on lines +1 to +8
- name: "Slow start pipeline"
- config:
- pipeline.id: slow-start-pp
config.string: |
input { heartbeat {} }
filter { failure_injector { degrade_at => [register] } }
output { stdout {} }
- expectation:
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an array containing three items, each of which is a map.
I think you need a map rather than an array of map.

name: "Slow start pipeline"
config:
  - pipeline.id: slow-start-pp
    config.string: |
      input { heartbeat {} }
      filter { failure_injector { degrade_at => [register] } }
      output { stdout {} }
expectation:
  - status: yellow
  - symptom: "The pipeline is degraded or at risk of becoming unhealthy; 1 area is impacted and 1 diagnosis is available."
  - diagnosis:
      - cause: "pipeline is loading"
  - impacts:
    - description: "pipeline is loading"
    - impact_areas: "pipeline_execution"
  - details:
    - run_state: "LOADING"

logstash_version = os.environ.get("LS_VERSION")
if logstash_version is None:
# version is not specified, use the main branch, no need to git checkout
print(f"LS_VERSION is not specified, using main branch.")
Copy link
Contributor

Choose a reason for hiding this comment

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

suggest to rename LS_VERSION to LS_BRANCH. It can't handle version, eg 8.13.4.

$ LS_VERSION="8.13.4" python3 .buildkite/scripts/health-report-tests/main.py
Starting Logstash Health Report Integration test.
Using specified branch: 8.13.4
error: pathspec '8.13.4' did not match any file(s) known to git
Traceback (most recent call last):
  File "/Users/kcheng/GitHub/kaisecheng/logstash/.buildkite/scripts/health-report-tests/main.py", line 74, in <module>
    main()
  File "/Users/kcheng/GitHub/kaisecheng/logstash/.buildkite/scripts/health-report-tests/main.py", line 42, in main
    with BootstrapContextManager() as bootstrap:
  File "/Users/kcheng/GitHub/kaisecheng/logstash/.buildkite/scripts/health-report-tests/main.py", line 20, in __enter__
    self.bootstrap = Bootstrap()
                     ^^^^^^^^^^^
  File "/Users/kcheng/GitHub/kaisecheng/logstash/.buildkite/scripts/health-report-tests/bootstrap.py", line 31, in __init__
    util.git_check_out_branch(logstash_version)
  File "/Users/kcheng/GitHub/kaisecheng/logstash/.buildkite/scripts/health-report-tests/util.py", line 17, in git_check_out_branch
    run_or_raise_error(["git", "checkout", branch_name],
  File "/Users/kcheng/GitHub/kaisecheng/logstash/.buildkite/scripts/health-report-tests/util.py", line 26, in run_or_raise_error
    raise Exception(f"{full_error_message}")
Exception: Error occurred while checking out the 8.13.4 branch

Copy link
Contributor

Choose a reason for hiding this comment

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

I have tried LS_VERSION=8.15. It doesn't run the test. Maybe that branch has no python script

$ LS_VERSION="8.15" python3 .buildkite/scripts/health-report-tests/main.py
Starting Logstash Health Report Integration test.
Using specified branch: 8.15
Switched to branch '8.15'
logstash-integration-failure_injector successfully installed.


def load(self, file_path: str) -> None:
"""Load the YAML file content into self.yaml_content."""
self.yaml_content: Union[List[Dict[str, Any]], None] = None
Copy link
Contributor

Choose a reason for hiding this comment

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

I have another comment related to the structure of yaml file. I think it can be simplified to Union[Dict[str, Any], None]

print(f"Logstash has successfully built.")

def apply_config(self, config: dict) -> None:
with open(os.getcwd() + "/config/pipelines.yml", 'w') as pipelines_file:
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: we need to be careful not to commit the test config/pipelines.yml, or use --path.settings to point the config files to other directory

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants