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

chore: slave cleanup and introduce tests #3728

Merged

Conversation

achettyiitr
Copy link
Member

@achettyiitr achettyiitr commented Aug 9, 2023

Description

  • Coverage for warehouse slaves.
  • Code shuffling from slave to slave_worker.go and slave_worker_job.go
  • Introducing slaveNotifier - Deals with activities related to pgNotifier for slave
  • Introducing constrainsManager- Deals with constraints
  • Coverage [Slave] - [>85%]
  • Removed Init6()
  • Avoiding globals

Linear Ticket

Security

  • The code changed/added as part of this pull request won't create any security issues with how the software is being used.

Copy link
Member

@lvrach lvrach left a comment

Choose a reason for hiding this comment

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

I assume we going to use structure logs in a second pass ?

for i := 0; i < workerJobs; i++ {
subscriberCh <- claim
}
}()
Copy link
Member

Choose a reason for hiding this comment

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

Should we wait for this go routine to return before the test function concludes?

Copy link
Member Author

Choose a reason for hiding this comment

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

We are waiting below response := <-publishCh

return nil, err
}

jr.uuidTS = timeutil.Now()
Copy link
Member

Choose a reason for hiding this comment

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

Should we DI the Now() in our receiver instead of using timeutil ?

@achettyiitr
Copy link
Member Author

I assume we going to use structure logs in a second pass ?

Yes.

@achettyiitr achettyiitr force-pushed the chore.whBackendConfig+warehouse-handle-to-router+slave branch from 847e985 to 4c463b5 Compare August 9, 2023 19:49
Copy link
Member

@lvrach lvrach left a comment

Choose a reason for hiding this comment

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

Having a quick pass, assuming most of the code was moved and can be further improved on a second pass.

The introduction of tests is really appropriated. Some of the are too specific and testing private methods (example: testing schema is sorted), we might want to cover those private methods in a more behavioural way.

The usage of generator pattern and limit group for upload was a nice touch.

Keep them coming.

@achettyiitr achettyiitr force-pushed the chore.whBackendConfig+warehouse-handle-to-router+slave branch 2 times, most recently from 89206f2 to f8aa39b Compare August 9, 2023 20:23
@codecov
Copy link

codecov bot commented Aug 9, 2023

Codecov Report

Patch coverage: 82.90% and project coverage change: +0.49% 🎉

Comparison is base (5017146) 68.14% compared to head (8486f25) 68.63%.
Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3728      +/-   ##
==========================================
+ Coverage   68.14%   68.63%   +0.49%     
==========================================
  Files         334      337       +3     
  Lines       51517    51601      +84     
==========================================
+ Hits        35105    35417     +312     
+ Misses      14129    13918     -211     
+ Partials     2283     2266      -17     
Files Changed Coverage Δ
runner/runner.go 69.79% <ø> (-0.25%) ⬇️
warehouse/stats.go 58.53% <ø> (-3.90%) ⬇️
warehouse/archive/cron.go 50.00% <25.00%> (ø)
warehouse/archive/archiver.go 67.25% <66.00%> (+1.20%) ⬆️
warehouse/types.go 70.00% <70.00%> (ø)
warehouse/slave_worker.go 81.48% <81.48%> (ø)
warehouse/slave_worker_job.go 85.58% <85.58%> (ø)
warehouse/constraint.go 87.50% <89.36%> (-1.74%) ⬇️
warehouse/slave.go 100.00% <100.00%> (+36.49%) ⬆️
warehouse/warehouse.go 55.00% <100.00%> (+0.47%) ⬆️

... and 15 files with indirect coverage changes

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

@achettyiitr achettyiitr force-pushed the chore.whBackendConfig+warehouse-handle-to-router+slave branch from f8aa39b to 9545713 Compare August 10, 2023 06:42
warehouse/constraint.go Outdated Show resolved Hide resolved
warehouse/constraint_test.go Show resolved Hide resolved
warehouse/slave_test.go Show resolved Hide resolved
Comment on lines 138 to 139
for i := 0; i < workerJobs; i++ {
response := <-publishCh
Copy link
Collaborator

Choose a reason for hiding this comment

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

If we wait for a proper shutdown we could also try to drain this channel at the end and assert that there are no more values in it and that it's been closed. I haven't checked the doability though, just posting here for feedback.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since these are mocked channels, not sure it would help much. Also, we are verifying the number of jobs send and received as well.

warehouse/slave_worker.go Outdated Show resolved Hide resolved
warehouse/slave_worker.go Outdated Show resolved Hide resolved
warehouse/slave_worker.go Outdated Show resolved Hide resolved
Comment on lines +431 to +433
sw.notifier.UpdateClaimedEvent(&claimedJob, &pgnotifier.ClaimResponse{
Payload: jobResultJSON,
})
Copy link
Collaborator

Choose a reason for hiding this comment

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

[questions] what is the side effect of these calls failing? I see that we log the errors but beside that, if we don't update the claimed event, what happens next?

Copy link
Member Author

Choose a reason for hiding this comment

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

If we don't update the claim event, the side effect is that the notifier.trackUploadBatch will wait for it to complete. Also, in case of failures, since we are just logging, there are maintenance workers who will mark them again as waiting so that it can be picked it up again by another slave.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Got it, thanks. Does trackUploadBatch wait forever or we got a timeout there?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it waits forever for the job to be completed. Although we have

  1. maintenance workers which upon some threshold mark the job as waiting.
  2. also, we have alerts on long-running tasks in cases it exceeds 2 hours.

Copy link
Member Author

Choose a reason for hiding this comment

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

We can definitely improve things on pgNotifier.

warehouse/slave_worker_job.go Outdated Show resolved Hide resolved
warehouse/slave_worker_job_test.go Show resolved Hide resolved
@achettyiitr
Copy link
Member Author

Thanks @lvrach and @fracasula for pointing out go-routine coordination around tests. I have made the changes.

Copy link
Collaborator

@fracasula fracasula left a comment

Choose a reason for hiding this comment

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

Nice one 👍

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.

None yet

3 participants