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

[EPIC] Refactor Elasticsearch Exporter Tests #8609

Closed
9 tasks done
lenaschoenburg opened this issue Jan 18, 2022 · 4 comments · Fixed by #9381
Closed
9 tasks done

[EPIC] Refactor Elasticsearch Exporter Tests #8609

lenaschoenburg opened this issue Jan 18, 2022 · 4 comments · Fixed by #9381
Assignees
Labels
area/test Marks an issue as improving or extending the test coverage of the project kind/epic Categorizes an issue as an umbrella issue (e.g. OKR) which references other, smaller issues kind/toil Categorizes an issue or PR as general maintenance, i.e. cleanup, refactoring, etc. scope/broker Marks an issue or PR to appear in the broker section of the changelog version:8.1.0-alpha2 version:8.1.0 Marks an issue as being completely or in parts released in 8.1.0

Comments

@lenaschoenburg
Copy link
Member

lenaschoenburg commented Jan 18, 2022

Description

The elasticsearch-exporter integration tests are currently quite convoluted. Historically, the elasticsearch-exporter tests used to depend on zeebe-test which was removed in #8608. During the removal, some of the zeebe-test utilities ended up in the elasticsearch-exporter module where we also needed to add a lot of test scoped dependencies.

The main goals here were:

  • Cover as much as possible via only unit tests. This gives us a faster feedback cycle when changing something - developers can focus on first fixing unit tests, which have smaller blast radius and faster execution, before even looking at integration tests.
  • Narrow the scope of the integration tests as much as possible. This meant getting rid of the broker, workflow engine semantics, etc., and just testing the integration of the exporter instance with Elasticsearch.

In general, I wanted to keep the same coverage as before. I think the coverage is now higher, but that was not the original motivation.

Breakdown

@lenaschoenburg lenaschoenburg added the kind/toil Categorizes an issue or PR as general maintenance, i.e. cleanup, refactoring, etc. label Jan 18, 2022
ghost pushed a commit that referenced this issue Jan 18, 2022
8608: Remove `zeebe-test` leftovers r=oleschoenburg a=oleschoenburg

## Description

* **Removes the `zeebe-test` module**
* Moves `protocol-jackson` integration test to qa module
* Moves the remaining utilities from `zeebe-test` to the elasticsearch exporter tests


## Related issues

closes #8549

next follow-up: #8609



Co-authored-by: Ole Schönburg <ole.schoenburg@gmail.com>
@lenaschoenburg lenaschoenburg self-assigned this Jan 20, 2022
@lenaschoenburg lenaschoenburg added this to In progress in Zeebe Jan 20, 2022
@lenaschoenburg
Copy link
Member Author

Currently

This is an overview of the current tests in the elasticsearch module. There is one class with unit tests and a couple more for integration tests.

Unit Tests in ElasticsearchExporterTest

  • don't fail on open if elasticsearch is unreachable
  • create index templates
  • exporting respects enabled/disabled value and record types
  • exceptions during flush are not swallowed
  • position is updated on flush, also with bulk delay enabled
  • configured prefix is validated

Integration Tests in Elasticsearch*IT

  • records are exported even if elasticsearch is initially not available
  • indexes are correctly configured (number of shards and replicas)
  • bulk flush throws on invalid json
  • repeated records are ignored and not exported more than once
  • bulk flush occurs when memory limit is reached
  • the exporter can authenticate with elasticsearch
  • configuration values are validated

ghost pushed a commit that referenced this issue Jan 21, 2022
8633: Remove elasticsearch exporter TLS test r=oleschoenburg a=oleschoenburg

## Description

This test was only testing the interaction between the official client and docker container and wasn't providing much value.

## Related issues

<!-- Which issues are closed by this PR or are related -->

relates to #8609 



Co-authored-by: Ole Schönburg <ole.schoenburg@gmail.com>
ghost pushed a commit that referenced this issue Jan 24, 2022
8631: Refactor elasticsearch exporter unit tests r=oleschoenburg a=oleschoenburg

## Description

This is a rewrite of the old unit tests from `ElasticsearchExporterTest`.
* Removes various `Mock*` classes and prefers creating mocks as necessary per test.
* Splits the unit tests into three classes, one for flush-related tests, one for configuration and one for the rest.
* Removes the dependency on broker internals in the unit tests. They are still required for integration tests though.

## Related issues

<!-- Which issues are closed by this PR or are related -->

relates to #8609

Co-authored-by: Ole Schönburg <ole.schoenburg@gmail.com>
ghost pushed a commit that referenced this issue Jan 24, 2022
8631: Refactor elasticsearch exporter unit tests r=oleschoenburg a=oleschoenburg

## Description

This is a rewrite of the old unit tests from `ElasticsearchExporterTest`.
* Removes various `Mock*` classes and prefers creating mocks as necessary per test.
* Splits the unit tests into three classes, one for flush-related tests, one for configuration and one for the rest.
* Removes the dependency on broker internals in the unit tests. They are still required for integration tests though.

## Related issues

<!-- Which issues are closed by this PR or are related -->

relates to #8609

Co-authored-by: Ole Schönburg <ole.schoenburg@gmail.com>
@lenaschoenburg
Copy link
Member Author

lenaschoenburg commented Jan 24, 2022

Unit tests are looking better now but we can still make some improvements to the integration tests:

  • Get rid of AbstractElasticsearchExporterIntegrationTestCase and the rules in io.camunda.zeebe.exporter.util.it
    • These are tech-debt from the now-removed zeebe-test module. We should have good alternatives for all of the rules, for example ClusteringRule
  • Rewrite some tests as unit tests
    • ElasticsearchExporterConfigurationIT seems like a good candidate
  • Split integration tests
    • Integration tests between the exporter and elasticsearch should stay in the elasticsearch-exporter module
    • End to end tests between the broker, exporter and elasticsearch should move to the qa module

@lenaschoenburg lenaschoenburg removed their assignment Jan 28, 2022
@lenaschoenburg lenaschoenburg moved this from In progress to Ready in Zeebe Jan 28, 2022
@npepinpe npepinpe self-assigned this Feb 17, 2022
@npepinpe npepinpe moved this from Ready to In progress in Zeebe Feb 17, 2022
@npepinpe
Copy link
Member

Here's what I'm thinking of doing, in no special order. I'm adding a bit of refactoring to clean things up as well, but most likely that will be done towards the end. The end goal is that the tests should be mostly unit tests, and the integration tests living in the exporter module will only starting the exporter without the whole broker around them, and testing the integration of the exporter itself with Elastic. Again, without the broker. This should greatly reduce flakiness surrounding the tests, and additionally make them much simpler. There will still be some end to end tests in the QA module, but much less than what currently exists.

  • Introduce a new exporter-tests module, which provides a simple test harness to test the exporter by itself without a broker. This will be similar to the old test harness, but with a much reduced API surface. This is also not meant to be a public module for now.
  • Split up the exporter into smaller components to allow testing them separately without the complete test harness
  • Split up the ElasticsearchExporterClient into smaller components for easier testing and maintainability
  • Rewrite the integration tests to make use of the new test harness
  • Delete the AbstractElasticsearchExporterIntegrationTestCase class
  • Replace using the WorkloadGenerator here in favor of a simpler record factory. Using protocol-jackson, we can just have a factory which returns exactly one of each record. We can even test to make sure that a record for each known ValueType is returned. This greatly simplifies testing, but keeps the same coverage (and perhaps more, actually). This may require us to do Export missing records to ES #8337 as well. Doing this also allows us to export these records, deserialize them back from ES, and use plain equals() to compare them.

There might be more. I'll do a quick spike, then split it off in issues where applicable. Let me know if anything sounds crazy.

@KerstinHebel KerstinHebel removed this from In progress in Zeebe Mar 23, 2022
@npepinpe npepinpe added Release: 8.0.0-rc1 kind/epic Categorizes an issue as an umbrella issue (e.g. OKR) which references other, smaller issues and removed target/8.1 labels Mar 28, 2022
@npepinpe npepinpe changed the title Refactor Elasticsearch Exporter Tests [EPIC] Refactor Elasticsearch Exporter Tests Mar 30, 2022
@npepinpe npepinpe added area/reliability Marks an issue as related to improving the reliability of our software (i.e. it behaves as expected) scope/broker Marks an issue or PR to appear in the broker section of the changelog area/test Marks an issue as improving or extending the test coverage of the project and removed Impact: Tech Debt area/reliability Marks an issue as related to improving the reliability of our software (i.e. it behaves as expected) labels Apr 11, 2022
@npepinpe
Copy link
Member

npepinpe commented May 6, 2022

Alright, so the spike was accepted and we'll now start breaking it down and merging it piece by piece. This means the end result will be something similar to #9258

Here's the breakdown:

  • Refactor ProtocolFactory to ensure that it uses a fixed seed.
  • Refactor ProtocolFactory for convenience to assign a type parameter for the value type.
  • Refactor ProtocolFactory to only generate positive values (>= 0) for objects of type long or Long.
  • Update the checkstyle configuration to allow suppressing specific checkstyle warnings via annotations. At the same time we need to update the code quality workflow to install build-tools first, so that the latest checkstyle configuration is always picked up before running the rest of our checks.
  • Add test implementations for the exporter-api.
  • Refactor ElasticsearchClient, splitting into separate concerns for easier testing.
  • Refactor the ElasticsearchExporter tests.
  • Clean up (removing outdated utilities and so on)

/cc @saig0 - regarding the ProtocolFactory, I will spread the reviews so it's not just you reviewing this.

@Zelldon Zelldon added the version:8.1.0 Marks an issue as being completely or in parts released in 8.1.0 label Oct 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/test Marks an issue as improving or extending the test coverage of the project kind/epic Categorizes an issue as an umbrella issue (e.g. OKR) which references other, smaller issues kind/toil Categorizes an issue or PR as general maintenance, i.e. cleanup, refactoring, etc. scope/broker Marks an issue or PR to appear in the broker section of the changelog version:8.1.0-alpha2 version:8.1.0 Marks an issue as being completely or in parts released in 8.1.0
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants