Skip to content

Conversation

@adriansr
Copy link
Contributor

This PR updates the pipeline tests to generate code-coverage (at the processor level) for ingest pipelines:

image
image

Changes in CI will be needed so that coverage reports are visible in CI.

For local testing, reports are available under build/test-coverage and can be visualized with a tool like Report Generator.

This improves the coverage reporting (--test-coverage flag) to include
detailed coverage for ingest pipelines in the pipeline test.

if testCoverage && len(dataStreams) > 0 {
return cobraext.FlagParsingError(errors.New("test coverage can be calculated only if all data streams are selected"), cobraext.DataStreamsFlagName)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This restriction has been removed for convenience, as coverage reports are useful during development and we may want to test as quick as possible and only the data stream being developed.

@adriansr adriansr added Team:Ecosystem Label for the Packages Ecosystem team Team:Integrations Label for the Integrations team Team:Security-External Integrations labels Feb 17, 2022
@elasticmachine
Copy link
Collaborator

Pinging @elastic/integrations (Team:Integrations)

@elasticmachine
Copy link
Collaborator

elasticmachine commented Feb 17, 2022

💚 Build Succeeded

the below badges are clickable and redirect to their specific view in the CI or DOCS
Pipeline View Test View Changes Artifacts preview [preview](https://ci-stats.elastic.co/app/apm/services/beats-ci/transactions/view?rangeFrom=2022-03-08T14:18:52.869Z&rangeTo=2022-03-08T14:38:52.869Z&transactionName=BUILD Ingest-manager/elastic-package/PR-{number}&transactionType=job&latencyAggregationType=avg&traceId=7796a29faab38fc70c5865930f7c6ed6&transactionId=1fe1d68780b695d3)

Expand to view the summary

Build stats

  • Start Time: 2022-03-08T14:28:52.869+0000

  • Duration: 16 min 47 sec

Test stats 🧪

Test Results
Failed 0
Passed 536
Skipped 1
Total 537

🤖 GitHub comments

To re-run your PR in the CI, just comment with:

  • /test : Re-trigger the build.

@mtojek mtojek requested a review from a team February 21, 2022 09:04
Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Could you please describe how will the coverage calculation change once this PR is merged?

Consider the following cases:

  1. Run test - cover all data streams of a package
  2. Run test --data-stream foo - cover only the foo data stream
  3. Run test pipeline - cover all data streams, but only pipeline tests
  4. Run test - but no tests present

Sorry for adding more tasks to do, but I'd like to double-check if there are any risky side effects.

Also, what kind of changes do we need on the CI side?


type coberturaCoverage struct {
// CoberturaCoverage is the root element for a Cobertura XML report.
type CoberturaCoverage struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there any reason why these properties are exposed? Is it for the consistency with CoberturaCoverage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I got mixed here a little bit. The original idea was for the test runners to have the option to generate their own coverage in Cobertura format (via the new TestResult.Coverage), that's why these types are exposed.

To align with this idea, I think it makes more sense to put GetPipelineCoverage into the pipeline runner instead of the global testrunner package as is now.

Copy link
Contributor

Choose a reason for hiding this comment

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

To align with this idea, I think it makes more sense to put GetPipelineCoverage into the pipeline runner instead of the global testrunner package as is now.

Yes, I have a similar feeling about this :)

API: esClient.API,
DeferCleanup: deferCleanup,
ServiceVariant: variantFlag,
WithCoverage: testCoverage,
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this property apply to all test runners (system tests, static tests, etc.)? Maybe we should add a WARN informing if we can't calculate the coverage properly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The way I see it we have the old default coverage, which only tells whether we have a particular kind of test for the package, and the opt-in detailed coverage added by this PR. Each individual test runner can err if they wanted to calculate detailed coverage but failed, as the pipeline tests will do after this PR.

@mtojek mtojek requested a review from a team February 21, 2022 09:22
@mtojek
Copy link
Contributor

mtojek commented Feb 24, 2022

@adriansr Please re-request the review when this PR is ready for another round. It would be great to research these cases.

@adriansr
Copy link
Contributor Author

adriansr commented Mar 7, 2022

Run test - cover all data streams of a package

Before this PR, it generates a reduced coverage report for each kind of test (system, static, asset, pipeline...).

Each of these tests contains a single package (name of integration package), then one class per data_stream (class name: test type, class filename: package/datastream).
Each class contains a single method, named OK or Missing depending on this type of test being present for the given datastream.

After this PR, the output is the same, except for the pipeline coverage report, which contains processor coverage of the ingest pipelines:
Each package represent a data_stream, which contains classes representing each pipeline under the datastream, which consist of methods, one per each processor in the pipeline.

Run test --data-stream foo - cover only the foo data stream

Before: It's not possible to run a coverage report for a single data-stream.
After: you get a coverage report with code coverage for the different pipelines.

Run test pipeline - cover all data streams, but only pipeline tests

Before: You get the reduced coverage report (OK / Missing).
After: you get a coverage report with code coverage for the different pipelines.

Run test - but no tests present

Only the reduced coverage reports are present.

Also, what kind of changes do we need on the CI side?

It needs some investigation, but basically make sure that the source code for pipelines is in place by the time the coverage reports are rendered.

@adriansr adriansr requested a review from mtojek March 7, 2022 16:55
Copy link
Contributor

@mtojek mtojek left a comment

Choose a reason for hiding this comment

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

Thanks for providing more information, Adrian. I see only concerns around integrating this change with our CI. I left a comment in a relevant place in the source code.

Apart from this, I think it's 👍 .

wantErr bool
}{
{
name: "merge sources",
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: I'm thinking now if it isn't simpler and easier to read to load these tests from a testdata directory. WDYT?


// GetPipelineCoverage returns a coverage report for the provided set of ingest pipelines.
func GetPipelineCoverage(options testrunner.TestOptions, pipelines []ingest.Pipeline) (*testrunner.CoberturaCoverage, error) {
packagePath, err := packages.MustFindPackageRoot()
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the package root present in TestOptions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out it is.

pipelineName = pipelineName[:nameEnd]
}

// File path has to be relative to the packagePath added to the cobertura Sources list
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's discuss the safe deployment of this feature.

If we merge this PR and release a new elastic-package, will it break the CI tests for Elastic Integrations? If it breaks, then we need to go the other way round and adjust the Jenkinsfile first and make sure that pipeline sources are in the right directory (relative to the runner?).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There's no reason to believe it will break any tests, I've tested it multiple times with all the existing integrations.

I think you're misunderstanding the CI issues that will need to be addressed. I explained them in this comment: #585 (comment)

Those issues will not cause a test failure. Just the coverage report displayed in CI will not show annotated source code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, that's what I mean. Let me share my concerns, Jenkins uses coverageReport function to collect the coverage stats. I don't know what will happen if that function files (due to missing pipeline sources). Will it not show the coverage split by source code or fail the entire CI pipeline?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

Understood, thanks for clarifying this.

@adriansr adriansr merged commit 11a955c into elastic:main Mar 9, 2022
@adriansr adriansr deleted the pipeline_processor_coverage branch March 9, 2022 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Team:Ecosystem Label for the Packages Ecosystem team Team:Integrations Label for the Integrations team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants