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): Remove the AppConfig and KeyManager singletons #625

Merged
merged 14 commits into from
Nov 12, 2024

Conversation

mcamou
Copy link
Contributor

@mcamou mcamou commented Nov 8, 2024

Description

Singletons are a bad practice which makes it difficult to write proper tests for the code. This PR (almost) removes the two singletons we have:

  • The AppConfig singleton, used throughout the codebase to get access to the node configuration
  • The KeyManager singleton, used to get access to private and public keys

We remove both singletons in one go since it is very complicated to remove just AppConfig without removing KeyManager. They are replaced either with functional options, by adding some fields to other objects (i.e. OracleNode) or, in cases where there are just one or config parameter needed in one place in the code, passing them directly as parameters.

This PR removes config.GetInstance() from everywhere except the Sentiment-related files, since those will be removed as part of a separate PR (see #626).

Notes to reviewers

If the full PR is a bit much, the commit history should be more manageable. If preferred, I could split this into multiple PRs.

Signed commits

  • Yes, I signed my commits.

Copy link

codecov bot commented Nov 8, 2024

Codecov Report

Attention: Patch coverage is 0.55866% with 178 lines in your changes missing coverage. Please review.

Project coverage is 9.04%. Comparing base (b5d1120) to head (d97c7a4).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
pkg/llmbridge/sentiment.go 0.00% 52 Missing ⚠️
pkg/masacrypto/key_manager.go 0.00% 18 Missing ⚠️
cmd/masa-node/config.go 0.00% 17 Missing ⚠️
node/options.go 0.00% 16 Missing ⚠️
cmd/masa-node/main.go 0.00% 9 Missing ⚠️
node/oracle_node.go 0.00% 8 Missing ⚠️
pkg/workers/options.go 0.00% 8 Missing ⚠️
pkg/workers/handlers/llm.go 0.00% 6 Missing ⚠️
cmd/masa-node/staking.go 0.00% 5 Missing ⚠️
pkg/llmbridge/client.go 0.00% 5 Missing ⚠️
... and 15 more
Additional details and impacted files
@@           Coverage Diff            @@
##            main    #625      +/-   ##
========================================
+ Coverage   8.99%   9.04%   +0.04%     
========================================
  Files         99      99              
  Lines       7761    7809      +48     
========================================
+ Hits         698     706       +8     
- Misses      6989    7030      +41     
+ Partials      74      73       -1     

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


🚨 Try these New Features:

@mcamou mcamou marked this pull request as ready for review November 11, 2024 10:13
@mcamou mcamou requested a review from mudler November 11, 2024 10:13
@mudler mudler requested a review from a team November 11, 2024 17:16
@mcamou mcamou changed the title chore(cleanup): Remove some usages of config.GetInstance() chore(cleanup): Remove most usages of config.GetInstance() Nov 12, 2024
@mcamou mcamou changed the title chore(cleanup): Remove most usages of config.GetInstance() chore(cleanup): Remove most usages of config.GetInstance() and the KeyManager singleton Nov 12, 2024
@mcamou mcamou changed the title chore(cleanup): Remove most usages of config.GetInstance() and the KeyManager singleton chore(cleanup): Remove usages of the AppConfig and KeyManager singletons Nov 12, 2024
@mcamou mcamou changed the title chore(cleanup): Remove usages of the AppConfig and KeyManager singletons chore(cleanup): Remove the AppConfig and KeyManager singletons Nov 12, 2024
node/options.go Outdated Show resolved Hide resolved
mudler
mudler previously approved these changes Nov 12, 2024
Copy link
Contributor

@mudler mudler left a comment

Choose a reason for hiding this comment

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

looking good to me! finally! :)

Co-authored-by: Ettore Di Giacinto <[email protected]>
Signed-off-by: Mario Camou <[email protected]>
mudler
mudler previously approved these changes Nov 12, 2024
Copy link
Contributor

@mudler mudler left a comment

Choose a reason for hiding this comment

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

Looking good!

@mcamou mcamou merged commit c58fe2a into main Nov 12, 2024
15 of 17 checks passed
@mcamou mcamou deleted the mc/rm-config-singleton-1 branch November 12, 2024 17:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants