-
Notifications
You must be signed in to change notification settings - Fork 127
Report ingest pipeline processor coverage #585
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
Conversation
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
🤖 GitHub commentsTo re-run your PR in the CI, just comment with:
|
|
The coverage reports in CI are not including the pipeline source code: Looks like by the time the report is generated, the source code is not available. @mdelapenya @mtojek can you help? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool feature, Adrian!
Looks like by the time the report is generated, the source code is not available. @mdelapenya @mtojek can you help?
First guess: I think this might be caused by having paths as names and you can't refer to these paths from the repository root.
I'm afraid that you need to analyze the Cobertura XML report manually and adjust the implementation later on. This is the path I went last time: elastic/integrations#755 (comment) and static files in #440 .
Screenshot taken from Report Generator.
If you plan to merge this feature, we'll kindly ask you to prepare a doc page describing how to use it.
| return cobraext.FlagParsingError(err, cobraext.DataStreamsFlagName) | ||
| } | ||
|
|
||
| if testCoverage && len(dataStreams) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This condition was placed here to prevent coverage miscalculation. The runner is not aware of data stream presence (or being skipped) so it always assumes that all data streams have been selected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand that. But given that (afaik) the CI never tests a single datastream, it would be very useful for pipeline developers to be able to run tests for a single datastream locally and get coverage results.
| BranchRate float32 `xml:"branch-rate,attr"` | ||
| Complexity float32 `xml:"complexity,attr"` | ||
| Methods []*coberturaMethod `xml:"methods>method"` | ||
| Methods []*CoberturaMethod `xml:"methods>method"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will have to update the docs with new mapping information: https://github.com/elastic/integrations/blob/master/docs/testing_and_validation.md#review-test-coverage
|
@mtojek I'm not sure how it works during CI, but my understanding is that the coverage results are uploaded to GCloud storage (in elastic-package/.ci/Jenkinsfile Line 205 in 490e70d
elastic-package/.ci/Jenkinsfile Line 192 in 490e70d
The generated coverage file contains absolute paths to the code. For example in and then: My understanding is that when the report is generated, the source code is not available at this path, but I don't understand in what context the |
|
|
| if tcd.cobertura != nil && result.Coverage != nil { | ||
| tcd.cobertura.Merge(result.Coverage) | ||
| } else { | ||
| tcd.cobertura = result.Coverage |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happens if result.Coverage is nil and tcd.cobertura is not? In that line we will be setting the latter to nil. Is that correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks
| } | ||
|
|
||
| // Merge merges two coverage reports for a given class. | ||
| func (c *CoberturaClass) Merge(b *CoberturaClass) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you see feasible adding unit tests for this method? I see a lot of calculations that would benefit for the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
| "gopkg.in/yaml.v3" | ||
| ) | ||
|
|
||
| type Processor struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you see feasible adding unit tests for this method? I see a lot of calculations that would benefit for the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @adriansr, this is great!
Is there something else keeping this as draft?
| "github.com/elastic/go-elasticsearch/v7" | ||
| "github.com/pkg/errors" | ||
|
|
||
| es "github.com/elastic/elastic-package/internal/elasticsearch" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Trying to reduce the need of these es aliases in #596.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| if err := entry.Content[0].Decode(&proc.Type); err != nil { | ||
| return nil, errors.Wrapf(err, "error decoding processor#%d type", idx) | ||
| } | ||
| proc.Line = entry.Line |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit. Could the Line of the last Content be used as the last line of the processor so we have per-line coverage instead of per-processor coverage? (and Cobertura paints red/green the whole processor 🙂)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense, done.
Originally I decided against it because it will mark the inner processors of a compound processor as covered (inner processor of foreach, and on_failure processors), while ES doesn't provide coverage information for those.
|
This is currently waiting for the required CI fixes to have source code displayed in Jenkins coverage reports. Once that is sorted out I'll make any required adjustments to the format (for now only tested it with a different coverage tool) and prepare the new documentation. |
This improves the coverage reporting (--test-coverage flag) to include detailed coverage for ingest pipelines in the pipeline test.
|
Pinging @elastic/integrations (Team:Integrations) |
|
This is ready to review pending adjustments to CI in order to make the new source code reports available. Updated docs at elastic/integrations#2371 |
|
We collect Cobertura reports also for elastic-package. @adriansr Could you please double check if this new feature is enabled also here? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, this PR is massive. Do you think you can split it into smaller, reviewable chunks? It would be easier to fully understand what's going on behind the scenes.
| // or more contributor license agreements. Licensed under the Elastic License; | ||
| // you may not use this file except in compliance with the Elastic License. | ||
|
|
||
| package node_stats |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please rename it to nodestats.
| ) | ||
|
|
||
| // Get returns a coverage report for the provided set of ingest pipelines. | ||
| func Get(options testrunner.TestOptions, pipelines []pipeline.Resource) (*testrunner.CoberturaCoverage, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here is a bit of spaghetti code that has to be untangled first. Code coverage isn't the responsibility of Elasticsearch client or Pipeline, but test runners and it should stay there.
I suggest refactoring (moving around) this dependency first, then we can continue reviewing as this PR is relatively big.

This PR updates the pipeline tests to generate code-coverage (at the processor level) for ingest pipelines:
Screenshots taken using Report Generator.