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

Introduce coverage to PR pipelines #5357

Merged
merged 18 commits into from
May 4, 2022

Conversation

MasslessParticle
Copy link
Contributor

@MasslessParticle MasslessParticle commented Feb 9, 2022

This PR is part one of two to introduce test coverage to our CI pipeline.

Toward #5344

The strategy is to:

  1. run tests against the PR and main seperately
  2. each test run drops a test_results.txt file
  3. the script diff_coverage will compare the results files and produce a coverage diff for the ingester, distributor, querier, ruler, and storage packages.
  4. post the diff to the open PR as an issue.

This PR is for steps 1 - 3. Because we need all branches to produce a test_results.txt file, this is a no-op until merged into main. Noop output: https://drone.grafana.net/grafana/loki/8632/1/6

Note on coverage.txt: The tests already produce a test profile but it only produces per-function results and the go tool coverage -html is currently broken so it was more sraight forward to search the tests results for package-level results dircetly.

@pull-request-size pull-request-size bot added size/M and removed size/S labels Feb 9, 2022
@MasslessParticle MasslessParticle changed the title Test CI Changes Introduce coverage to PR pipelines Feb 10, 2022
@MasslessParticle MasslessParticle marked this pull request as ready for review February 10, 2022 18:10
@MasslessParticle MasslessParticle requested a review from a team as a code owner February 10, 2022 18:10
Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

Looks good, but have a couple questions.
PS: once #5368 is merged you should merge in main to get rid of the unrelated changes to .drone.yml

fi

echo '```diff'
for pkg in ingester distributor querier ruler storage; do
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we make this list configurable in drone? I'd like to surface that there for clarity. This list would need to be amended, but is a pretty good start

Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason to only calculate the diff for these packages? I think it would make sense to show all packages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, did you research if there are existing tools to calculate/display coverage diffs based on go test output?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

think all packages could be overwhelming. We want to keep the signal-to-noise ratio high/useful

Although, this is using diff format so it might be enough to look for red lines.

I looked a couple of drone tools but the idea here was:

  1. something as minimal as possible
  2. something we control -- we've had security issues with other tools

The next step of this is to make a github comment from a drone job with the diff

.drone/drone.jsonnet Outdated Show resolved Hide resolved
Makefile Outdated
@@ -274,7 +274,10 @@ lint:
########

test: all
GOGC=10 $(GOTEST) -covermode=atomic -coverprofile=coverage.txt $(MOD_FLAG) -p=4 ./...
GOGC=10 $(GOTEST) -covermode=atomic -coverprofile=coverage.txt $(MOD_FLAG) -p=4 ./... | tee test_results.txt
Copy link
Contributor

Choose a reason for hiding this comment

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

You need to update the SHELL variable in the Makefile to use bash -o pipefail
Otherwise the exit code from go test is not propagated. I ran into the same issue once :D

Makefile Outdated
GOGC=10 $(GOTEST) -covermode=atomic -coverprofile=coverage.txt $(MOD_FLAG) -p=4 ./... | tee test_results.txt

compare-coverage:
./tools/diff_coverage.sh $(old) $(new)
Copy link
Contributor

Choose a reason for hiding this comment

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

I might miss something, but where are old and new declared?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

These are declared as part of the make run: make compare-coverage old=... new=...

This part can't be implemented until we have something to compare with

fi

echo '```diff'
for pkg in ingester distributor querier ruler storage; do
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason to only calculate the diff for these packages? I think it would make sense to show all packages.

fi

echo '```diff'
for pkg in ingester distributor querier ruler storage; do
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, did you research if there are existing tools to calculate/display coverage diffs based on go test output?

@pull-request-size pull-request-size bot added size/L and removed size/M labels Feb 16, 2022
@grafana grafana deleted a comment from grafanabot Feb 16, 2022
@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,ruler,storage
unable to compare test coverage: both old and new files must exist

@MasslessParticle
Copy link
Contributor Author

@dannykopping I realized there was no need to wait and implement the comment so I did it today. There's nothing interesting, yet, but future prs should have output like:

./tools/diff_coverage.sh ../tloki/results.txt test_results.txt ruler,ingester,querier

+       ruler	0
+    ingester	0
+     querier	0

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

Looks great @MasslessParticle! I've added two suggestions, and then LGTM

make('compare-coverage', container=false, args=[
'old=../loki-main/test_results.txt',
'new=test_results.txt',
'packages=ingester,distributor,querier,ruler,storage',
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
'packages=ingester,distributor,querier,ruler,storage',
'packages=ingester,distributor,querier,iter,storage',

The ruler is not super critical here, but the iter package has far-reaching consequences.
Maybe @cyriltovena can suggest any other critical packages we need to cover if there are any?

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 changed the list to these: ingester,distributor,querier,iter,storage,chunkenc,logql,loki

I think we can be fairly aggressive here because we ought to have color coding to help us see where to focus.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd like to also add querier/queryrange.

Copy link
Contributor

Choose a reason for hiding this comment

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

does it fail if the package name has changed ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We'd see a large diff, but this won't fail

Comment on lines 56 to 57
local make(target, container=true, args=[]) = run(target, [
'make ' + (if !container then 'BUILD_IN_CONTAINER=false ' else '') + target + ' ' + std.join(' ', args),
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
local make(target, container=true, args=[]) = run(target, [
'make ' + (if !container then 'BUILD_IN_CONTAINER=false ' else '') + target + ' ' + std.join(' ', args),
local make(target, container=true, args=[]) = run(target, [
std.join(' ', [
'make',
'BUILD_IN_CONTAINER=' + container,
target,
] + args),

This will get rid of the unrelated changes in drone.yml

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,iter,storage,chunkenc,logql,loki
unable to compare test coverage: both old and new files must exist

Copy link
Contributor

@dannykopping dannykopping left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @MasslessParticle! Excited for this

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki
unable to compare test coverage: both old and new files must exist

@stale
Copy link

stale bot commented Apr 16, 2022

Hi! This issue has been automatically marked as stale because it has not had any
activity in the past 30 days.

We use a stalebot among other tools to help manage the state of issues in this project.
A stalebot can be very useful in closing issues in a number of cases; the most common
is closing issues or PRs where the original reporter has not responded.

Stalebots are also emotionless and cruel and can close issues which are still very relevant.

If this issue is important to you, please add a comment to keep it open. More importantly, please add a thumbs-up to the original issue entry.

We regularly sort for closed issues which have a stale label sorted by thumbs up.

We may also:

  • Mark issues as revivable if we think it's a valid issue but isn't something we are likely
    to prioritize in the future (the issue will still remain closed).
  • Add a keepalive label to silence the stalebot if the issue is very common/popular/important.

We are doing our best to respond, organize, and prioritize all issues but it can be a challenging task,
our sincere apologies if you find yourself at the mercy of the stalebot.

@stale stale bot added the stale A stale issue or PR that will automatically be closed. label Apr 16, 2022
@stale stale bot closed this Apr 25, 2022
@stale stale bot removed the stale A stale issue or PR that will automatically be closed. label Apr 27, 2022
@dannykopping
Copy link
Contributor

@MasslessParticle following up on this: are we going to land this one?

@MasslessParticle
Copy link
Contributor Author

@dannykopping I think I've addressed all the feedback? afaik, this is ready to merge.

@grafanabot
Copy link
Collaborator

./tools/diff_coverage.sh ../loki-main/test_results.txt test_results.txt ingester,distributor,querier,querier/queryrange,iter,storage,chunkenc,logql,loki
unable to compare test coverage: both old and new files must exist

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants