Skip to content

CI: set -coverpkg when calling go test in nightly builds#3185

Merged
algorandskiy merged 30 commits intoalgorand:masterfrom
cce:coverpkg
Feb 3, 2026
Merged

CI: set -coverpkg when calling go test in nightly builds#3185
algorandskiy merged 30 commits intoalgorand:masterfrom
cce:coverpkg

Conversation

@cce
Copy link
Copy Markdown
Contributor

@cce cce commented Nov 4, 2021

Summary

By default, Go test with -coverprofile enabled only measures the coverage of files in the same package as the tests. Providing -coverpkg provides go test with additional names of packages for which you'd like it to measure coverage. Today we don't see the true coverage of source files called from tests in other packages.

Test Plan

This should not impact test correctness, but slows down tests due to the extra line counting required to measure coverage across more packages.

Due to the performance impact I updated the PR to only do "full coverage" reporting for nightly builds and am using the codecov flags feature to have these nightly builds be separately categorized by Codecov.

https://docs.codecov.com/docs/flags#hide-builds-eg-nightly-builds

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Nov 4, 2021

Codecov Report

❌ Patch coverage is 92.85714% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 47.75%. Comparing base (172f19d) to head (f2276b4).
⚠️ Report is 2 commits behind head on master.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
util/metrics/reporter.go 50.00% 1 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3185      +/-   ##
==========================================
- Coverage   47.90%   47.75%   -0.15%     
==========================================
  Files         662      645      -17     
  Lines       87991    87795     -196     
==========================================
- Hits        42149    41930     -219     
- Misses      43085    43118      +33     
+ Partials     2757     2747      -10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cce
Copy link
Copy Markdown
Contributor Author

cce commented Nov 4, 2021

There is some anecdotal evidence that this change makes the time.Sleep() timing assumptions in the metrics tests flakier.. the metrics tests are failing on all three platforms.
https://app.circleci.com/pipelines/github/algorand/go-algorand/3189/workflows/b08be5df-27a3-4aaa-b7c6-04c492bdc3e9/jobs/42614/tests
https://app.circleci.com/pipelines/github/algorand/go-algorand/3189/workflows/b08be5df-27a3-4aaa-b7c6-04c492bdc3e9/jobs/42610/tests
https://app.circleci.com/pipelines/github/algorand/go-algorand/3189/workflows/b08be5df-27a3-4aaa-b7c6-04c492bdc3e9/jobs/42619/tests
image


Update: fixed by removing ledger/testing from the coverpkg list, it had a call to crypto.GenerateSignatureSecrets in its init() function that was bumping a metric, and we don't need to track coverage for packages that are only used by tests.

@cce
Copy link
Copy Markdown
Contributor Author

cce commented Nov 5, 2021

Well, the tests pass now, and coverage reports more accurately reflect what is being tested, but collecting atomic coverage reports from all the lines in these previously-uncounted go-algorand package import dependencies made the {amd64,arm64,mac_amd64}_test jobs get ~50% slower, from ~22 minutes to ~34 minutes. So without more parallelism that would make the test jobs the new slowest jobs, previously they were taking roughly about the same amount of time as the expect tests (~25 minutes).

@cce
Copy link
Copy Markdown
Contributor Author

cce commented Jan 5, 2022

Can revisit later

@cce cce closed this Jan 5, 2022
@cce cce reopened this May 20, 2022
@cce cce changed the title set -coverpkg when calling go test CI: set -coverpkg when calling go test May 20, 2022
@cce cce changed the title CI: set -coverpkg when calling go test CI: set -coverpkg when calling go test in nightly builds Jun 7, 2022
Comment thread Makefile
Comment thread scripts/travis/upload_coverage.sh Outdated
cce added 2 commits January 29, 2026 17:30
Port the -coverpkg nightly coverage changes from the old CircleCI
config to the GitHub Actions ci-nightly.yml workflow. Remove the
now-deleted .circleci/config.yml. Pass "$@" through in
upload_coverage.sh and add the full_coverage codecov flag to nightly
coverage uploads.
Add a workflow_dispatch trigger to ci-pr.yml with a full_coverage
option. When enabled, the test job passes -coverpkg to go test to
measure coverage across all packages, and tags the codecov upload
with the full_coverage flag. Also rename the codecov flag from
"nightly" to "full_coverage" to match the actual upload tag.
@cce cce reopened this Jan 29, 2026
cce added 2 commits January 30, 2026 15:00
Export the previously unexported makeCounter/makeGauge constructors so
callers outside the metrics package can create metrics without
auto-registering on the default registry. Use these in tests and in
metricsTracker to avoid the Deregister(nil)+Register(registry) pattern.

Add a registry field to metricsTracker so loadFromDisk and close
operate on the correct registry, fixing TestMetricsReload under
-coverpkg without needing t.Skip().
@cce cce requested a review from algorandskiy January 30, 2026 20:03
Copy link
Copy Markdown
Contributor

@algorandskiy algorandskiy left a comment

Choose a reason for hiding this comment

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

LGTM, please fix reviewdog

Comment thread util/metrics/serviceCommon.go
@cce cce requested a review from algorandskiy January 30, 2026 20:49
algorandskiy
algorandskiy previously approved these changes Jan 30, 2026
@cce cce requested review from Copilot and jannotti February 2, 2026 18:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR enhances Go test coverage reporting by adding support for cross-package coverage measurement using the -coverpkg flag. The changes enable more accurate coverage reporting by tracking coverage across all packages, not just within the same package as the tests.

Changes:

  • Added -coverpkg flag to nightly CI builds for comprehensive coverage reporting
  • Introduced optional registry parameter to metrics system to support test isolation
  • Refactored internal metric creation functions to be publicly exported for better testability

Reviewed changes

Copilot reviewed 16 out of 16 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
.github/workflows/ci-nightly.yml Added -coverpkg flag with filtered package list for full coverage measurement in nightly builds
.github/workflows/ci-pr.yml Added optional full_coverage workflow input parameter with conditional -coverpkg flag
.codecov.yml Configured full_coverage flag as separate, non-joined coverage reporting stream
Makefile Enhanced cover target with -coverpkg support and package filtering logic
scripts/travis/upload_coverage.sh Modified to pass through additional arguments to codecov script
util/metrics/serviceCommon.go Added optional registry field to ServiceConfig for test isolation
util/metrics/reporter.go Updated to use optional registry when available
util/metrics/counter.go Renamed makeCounter to MakeCounterUnregistered and made it public
util/metrics/gauge.go Renamed makeGauge to MakeGaugeUnregistered and made it public
util/metrics/prometheus.go Updated to use new public unregistered metric constructors
util/metrics/opencensus.go Updated to use new public unregistered metric constructors
util/metrics/registry_test.go Refactored to use non-default registry for test isolation
util/metrics/counter_test.go Updated all test functions to use non-default registry
util/metrics/gauge_test.go Updated to use non-default registry for test isolation
ledger/metrics.go Added registry field and updated to use unregistered constructors
ledger/metrics_test.go Updated to use non-default registry to avoid cross-package interference

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread .codecov.yml Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copy link
Copy Markdown
Contributor

@jannotti jannotti left a comment

Choose a reason for hiding this comment

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

If I'm honest, I have no idea what any of the metrics changes do.

I also didn't follow what actually happens after this change. Nightly coverage is calculated, but where does it show up? It seems like CI coverage is only useful if it's attached to the code that caused the changes. Where would I go to see the nightly coverage, and who will go look at it repeatedly to see how it changes?

@cce
Copy link
Copy Markdown
Contributor Author

cce commented Feb 2, 2026

If I'm honest, I have no idea what any of the metrics changes do.

I will update the PR description — they were touching global counter state and now that multiple packages are being compiled together, it was causing test assertions to fail that assumed that counter state was empty.

I also didn't follow what actually happens after this change. Nightly coverage is calculated, but where does it show up? It seems like CI coverage is only useful if it's attached to the code that caused the changes. Where would I go to see the nightly coverage, and who will go look at it repeatedly to see how it changes?

After this change you would go to the codecov website to see the nightly coverage — I need to get this merged so that we can start to see it show up as a base for comparison — and then could trigger coverage diffs on PRs by triggering a special Github Actions workflow to run it against your PR.

@jannotti
Copy link
Copy Markdown
Contributor

jannotti commented Feb 2, 2026

If I'm honest, I have no idea what any of the metrics changes do.

I will update the PR description — they were touching global counter state and now that multiple packages are being compiled together, it was causing test assertions to fail that assumed that counter state was empty.

You mentioned that in stand-up and I didn't have a chance to understand why, seemed like compiling together is not a problem. But reading comments above, it seems the issue is init blocks? So there's actually code being run in those other packages, outside of tests, that causes the problem?

I also didn't follow what actually happens after this change. Nightly coverage is calculated, but where does it show up? It seems like CI coverage is only useful if it's attached to the code that caused the changes. Where would I go to see the nightly coverage, and who will go look at it repeatedly to see how it changes?

After this change you would go to the codecov website to see the nightly coverage — I need to get this merged so that we can start to see it show up as a base for comparison — and then could trigger coverage diffs on PRs by triggering a special Github Actions workflow to run it against your PR.

okay!

@algorandskiy algorandskiy merged commit febb0e1 into algorand:master Feb 3, 2026
82 of 124 checks passed
@cce cce deleted the coverpkg branch February 3, 2026 01:42
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.

8 participants