-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(coverage): implement automated coverage validation tool (#14098) #14134
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
Open
sAchin-680
wants to merge
4
commits into
open-telemetry:main
Choose a base branch
from
sAchin-680:feat/coverage-validation-14098
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
560f0a3
feat(coverage): implement automated coverage validation tool (#14098)
sAchin-680 34a2cf9
test: improve coverage from 27.7% to 87.3%
sAchin-680 4985651
refactor: move checkcover to internal/cmd and gitignore binary
sAchin-680 b7b86cd
chore: cleanup schema and remove unnecessary summary files per review…
sAchin-680 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,175 @@ | ||
| # Code Coverage Requirements Guide for Component Authors | ||
|
|
||
| ## Overview | ||
|
|
||
| As of this implementation, all OpenTelemetry Collector components are subject to automated code coverage validation based on their stability level. | ||
|
|
||
| ## Default Requirements | ||
|
|
||
| ### Stable Components | ||
|
|
||
| - **Required**: 80% minimum code coverage | ||
| - **Automatic**: Enforced by CI for all components with `stable` in their stability map | ||
|
|
||
| ### Other Stability Levels (Alpha, Beta, Development) | ||
|
|
||
| - **Required**: No default minimum | ||
| - **Optional**: Can set custom requirements (see below) | ||
|
|
||
| ## Setting Custom Coverage Requirements | ||
|
|
||
| You can specify a higher coverage requirement for your component by adding the `coverage_minimum` field to your `metadata.yaml`: | ||
|
|
||
| ```yaml | ||
| type: mycomponent | ||
| status: | ||
| class: receiver | ||
| stability: | ||
| stable: [metrics, traces] | ||
| coverage_minimum: 85 # Require 85% coverage instead of the default 80% | ||
| ``` | ||
|
|
||
| ### Important Notes | ||
|
|
||
| 1. **Higher Standards Only**: The `coverage_minimum` field can only increase the requirement, not decrease it. Setting it to a value lower than the stability-based minimum (80% for stable) has no effect. | ||
|
|
||
| 2. **Value Range**: Must be between 0 and 100. Values outside this range will cause validation errors. | ||
|
|
||
| 3. **Repository Minimum**: If a repository-wide minimum is set (via CI configuration), your component must meet whichever is higher: the stability-based minimum, the repository minimum, or your custom `coverage_minimum`. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Example 1: Stable Component with Default Coverage | ||
|
|
||
| ```yaml | ||
| type: otlp | ||
| status: | ||
| class: receiver | ||
| stability: | ||
| stable: [metrics, traces, logs] | ||
| # No coverage_minimum specified | ||
| ``` | ||
|
|
||
| **Result**: Must have ≥80% coverage | ||
|
|
||
| ### Example 2: Stable Component with Higher Requirement | ||
|
|
||
| ```yaml | ||
| type: reliable | ||
| status: | ||
| class: exporter | ||
| stability: | ||
| stable: [metrics] | ||
| coverage_minimum: 90 | ||
| ``` | ||
|
|
||
| **Result**: Must have ≥90% coverage | ||
|
|
||
| ### Example 3: Alpha Component with Coverage Goal | ||
|
|
||
| ```yaml | ||
| type: experimental | ||
| status: | ||
| class: processor | ||
| stability: | ||
| alpha: [metrics] | ||
| coverage_minimum: 70 | ||
| ``` | ||
|
|
||
| **Result**: Must have ≥70% coverage (helps ensure quality even at alpha stage) | ||
|
|
||
| ### Example 4: Beta Component Preparing for Stable | ||
|
|
||
| ```yaml | ||
| type: maturing | ||
| status: | ||
| class: connector | ||
| stability: | ||
| beta: [traces] | ||
| coverage_minimum: 80 # Preparing for stable promotion | ||
| ``` | ||
|
|
||
| **Result**: Must have ≥80% coverage (matching stable requirements) | ||
|
|
||
| ## Checking Your Component's Coverage | ||
|
|
||
| ### Locally | ||
|
|
||
| You can check your component's coverage requirements and actual coverage: | ||
|
|
||
| ```bash | ||
| # Generate coverage data | ||
| make gotest-with-cover | ||
|
|
||
| # Run the coverage validator | ||
| cd internal/cmd/checkcover | ||
| go run . -c ../../../coverage.txt -r ../../.. -v | ||
| ``` | ||
|
|
||
| ### In CI | ||
|
|
||
| Coverage validation runs automatically in CI after tests complete. If your component doesn't meet requirements, the build will fail with a clear error message: | ||
|
|
||
| ``` | ||
| ❌ receiver/mycomponent: coverage 75.00% is below minimum 80% (stability: stable, module: go.opentelemetry.io/collector/receiver/mycomponent) | ||
|
Check warning on line 114 in docs/coverage-requirements.md
|
||
| ``` | ||
|
|
||
| ## Disabling Coverage Badge | ||
|
|
||
| If you want to disable the Codecov badge in your component's README (not recommended), you can use: | ||
|
|
||
| ```yaml | ||
| status: | ||
| disable_codecov_badge: true | ||
| ``` | ||
|
|
||
| **Note**: This only hides the badge; coverage validation still runs. | ||
|
|
||
| ## Best Practices | ||
|
|
||
| 1. **Set Realistic Goals**: If your component is stable, it should already meet or exceed 80% coverage. If not, work on adding tests before promoting to stable. | ||
|
|
||
| 2. **Incremental Improvement**: For alpha/beta components, consider setting a `coverage_minimum` that represents your goal, even if it's not required. This helps track progress. | ||
|
|
||
| 3. **Document Uncovered Code**: If certain code paths are difficult to test, document why in comments and consider if the design could be improved. | ||
|
|
||
| 4. **Review Coverage Reports**: Don't just aim for a percentage - ensure your tests are meaningful and cover important code paths. | ||
|
|
||
| 5. **CI First**: Always check that your changes pass coverage validation in CI before merging. | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| ### "Coverage X% is below minimum Y%" | ||
|
|
||
| - **Solution**: Add more tests to your component to increase coverage | ||
| - **Alternative**: If your component has difficult-to-test code, consider refactoring for testability | ||
|
|
||
| ### "Could not determine module path" | ||
|
|
||
| - **Cause**: The tool couldn't find a `go.mod` file for your component | ||
| - **Solution**: Ensure your component is in a proper Go module structure | ||
|
|
||
| ### "No coverage data found for module" | ||
|
|
||
| - **Cause**: No test coverage was collected for your component | ||
| - **Solution**: Ensure you have tests and they're being run by `make gotest-with-cover` | ||
|
|
||
| ## Getting Help | ||
|
|
||
| If you encounter issues with coverage validation: | ||
|
|
||
| 1. Check the [Component Stability](../../docs/component-stability.md) document | ||
| 2. Review the [checkcover README](../../internal/cmd/checkcover/README.md) | ||
| 3. Ask in the #otel-collector Slack channel | ||
| 4. Open an issue on GitHub with the label `coverage` | ||
|
|
||
| ## Future Considerations | ||
|
|
||
| The coverage requirements and validation tooling may evolve. Potential future changes include: | ||
|
|
||
| - Default minimums for beta (e.g., 60%) and alpha (e.g., 40%) components | ||
| - Coverage trend tracking | ||
| - Exemptions for specific files or packages | ||
| - HTML coverage reports | ||
|
|
||
| Stay tuned to repository announcements for any changes to coverage requirements. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| include ../../Makefile.Common |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.