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: cleanup notifier #3867

Merged
merged 38 commits into from
Sep 21, 2023
Merged

chore: cleanup notifier #3867

merged 38 commits into from
Sep 21, 2023

Conversation

achettyiitr
Copy link
Member

@achettyiitr achettyiitr commented Sep 14, 2023

Description

  • Introducing repository and model for Notifier.
  • Renamed it to notifier instead of pgNotifier since we don't need to expose the implementation details like it is implemented for Postgres.
  • Removing globals.
  • Removed notifier.Init().
  • Introduced background errgroup to gracefully shut down the goroutines being created during track batch and subscribe.

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.

dependabot bot and others added 30 commits August 22, 2023 22:08
@codecov
Copy link

codecov bot commented Sep 14, 2023

Codecov Report

Patch coverage: 82.13% and project coverage change: -0.01% ⚠️

Comparison is base (b06dc36) 68.98% compared to head (2d43e31) 68.97%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3867      +/-   ##
==========================================
- Coverage   68.98%   68.97%   -0.01%     
==========================================
  Files         351      352       +1     
  Lines       52816    52971     +155     
==========================================
+ Hits        36435    36538     +103     
- Misses      14067    14117      +50     
- Partials     2314     2316       +2     
Files Changed Coverage Δ
runner/runner.go 68.37% <ø> (-0.14%) ⬇️
warehouse/http.go 77.58% <0.00%> (ø)
warehouse/router.go 88.45% <33.33%> (+1.23%) ⬆️
warehouse/jobs/runner.go 59.56% <57.14%> (-1.90%) ⬇️
warehouse/internal/loadfiles/loadfiles.go 72.95% <68.88%> (-2.49%) ⬇️
warehouse/slave_worker.go 79.88% <77.41%> (-0.68%) ⬇️
services/notifier/notifier.go 80.24% <80.24%> (ø)
warehouse/warehouse.go 78.32% <83.33%> (+0.27%) ⬆️
services/notifier/repo.go 89.47% <89.47%> (ø)
warehouse/jobs/http.go 76.63% <100.00%> (ø)
... and 3 more

... and 13 files with indirect coverage changes

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

Comment on lines +112 to +122
n.config.host = n.conf.GetString("PGNOTIFIER_DB_HOST", "localhost")
n.config.user = n.conf.GetString("PGNOTIFIER_DB_USER", "ubuntu")
n.config.database = n.conf.GetString("PGNOTIFIER_DB_NAME", "ubuntu")
n.config.port = n.conf.GetInt("PGNOTIFIER_DB_PORT", 5432)
n.config.password = n.conf.GetString("PGNOTIFIER_DB_PASSWORD", "ubuntu")
n.config.sslMode = n.conf.GetString("PGNOTIFIER_DB_SSL_MODE", "disable")
n.config.maxAttempt = n.conf.GetInt("PgNotifier.maxAttempt", 3)
n.config.maxOpenConnections = n.conf.GetInt("PgNotifier.maxOpenConnections", 20)
n.config.shouldForceSetLowerVersion = n.conf.GetBool("SQLMigrator.forceSetLowerVersion", true)
n.config.trackBatchInterval = n.conf.GetDuration("PgNotifier.trackBatchIntervalInS", 2, time.Second)
n.config.queryTimeout = n.conf.GetDuration("Warehouse.pgNotifierQueryTimeout", 5, time.Minute)
Copy link
Member

Choose a reason for hiding this comment

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

why not:

Suggested change
n.config.host = n.conf.GetString("PGNOTIFIER_DB_HOST", "localhost")
n.config.user = n.conf.GetString("PGNOTIFIER_DB_USER", "ubuntu")
n.config.database = n.conf.GetString("PGNOTIFIER_DB_NAME", "ubuntu")
n.config.port = n.conf.GetInt("PGNOTIFIER_DB_PORT", 5432)
n.config.password = n.conf.GetString("PGNOTIFIER_DB_PASSWORD", "ubuntu")
n.config.sslMode = n.conf.GetString("PGNOTIFIER_DB_SSL_MODE", "disable")
n.config.maxAttempt = n.conf.GetInt("PgNotifier.maxAttempt", 3)
n.config.maxOpenConnections = n.conf.GetInt("PgNotifier.maxOpenConnections", 20)
n.config.shouldForceSetLowerVersion = n.conf.GetBool("SQLMigrator.forceSetLowerVersion", true)
n.config.trackBatchInterval = n.conf.GetDuration("PgNotifier.trackBatchIntervalInS", 2, time.Second)
n.config.queryTimeout = n.conf.GetDuration("Warehouse.pgNotifierQueryTimeout", 5, time.Minute)
n.config = config{
host: n.conf.GetString("PGNOTIFIER_DB_HOST", "localhost")
user: n.conf.GetString("PGNOTIFIER_DB_USER", "ubuntu")
database: n.conf.GetString("PGNOTIFIER_DB_NAME", "ubuntu")
....

Copy link
Member Author

Choose a reason for hiding this comment

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

This will require creating a new standalone struct which I am not sure is required here. We are okay with an anonymous structure here.

services/notifier/repo/subscriber.go Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest the following structure:

moving this file to notifier/notifier.go containing models part of a the common interface, shared between multiple implementations. Having to access them from model package seems a bit counter intuitive for a library.

move notifier/notifier.go -> notifier/pgnotifer.go and instead of notifier.New() -> notifier.NewPG() -- since it a specific implementation.

Copy link
Member Author

Choose a reason for hiding this comment

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

moving this file to notifier/notifier.go containing models part of a the common interface, shared between multiple implementations. Having to access them from model package seems a bit counter intuitive for a library.

Makes sense. Since it's a package, it should provide a single interface for accessing it. I was initially targeting a repo package and since this model will be shared so moved models to a separate package. Moving everything to the notifier package.

Copy link
Member Author

Choose a reason for hiding this comment

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

move notifier/notifier.go -> notifier/pgnotifer.go and instead of notifier.New() -> notifier.NewPG() -- since it a specific implementation

I am not sure whether the consumers need to be aware of the implementation details like whether it is implemented for Postgres, Pulsar, or something else.

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.

I left a bunch of questions 🙂

services/notifier/notifier.go Outdated Show resolved Hide resolved
services/notifier/notifier.go Outdated Show resolved Hide resolved
services/notifier/notifier.go Show resolved Hide resolved
services/notifier/notifier.go Outdated Show resolved Hide resolved
services/notifier/notifier.go Outdated Show resolved Hide resolved
services/notifier/notifier.go Show resolved Hide resolved
services/notifier/notifier.go Show resolved Hide resolved
warehouse/internal/loadfiles/loadfiles.go Outdated Show resolved Hide resolved
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.

Good stuff 😎 👍

@fracasula fracasula merged commit 98498ee into master Sep 21, 2023
35 checks passed
@fracasula fracasula deleted the chore.pg-notifier-clean-up-pt-1 branch September 21, 2023 08:54
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