-
Notifications
You must be signed in to change notification settings - Fork 1.7k
En/db resolver #2140
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
Open
Umang01-hash
wants to merge
45
commits into
development
Choose a base branch
from
en/db_resolver
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
En/db resolver #2140
Changes from 17 commits
Commits
Show all changes
45 commits
Select commit
Hold shift + click to select a range
9888798
initial commit
Umang01-hash 0a8c265
add traces metrics and logs
Umang01-hash a1799e9
Merge remote-tracking branch 'origin/development' into en/db_resolver
Umang01-hash c75b89e
Merge remote-tracking branch 'origin/development' into en/db_resolver
Umang01-hash 75956df
resolve linters
Umang01-hash 2d4c32d
Merge remote-tracking branch 'origin' into en/db_resolver
Umang01-hash 7baeb33
add mocks and tests
Umang01-hash 547602c
improve test coverage
Umang01-hash 686ada4
build(deps): bump go.opentelemetry.io/otel/exporters/prometheus
dependabot[bot] 847ecf5
build(deps): bump google.golang.org/api from 0.243.0 to 0.244.0
dependabot[bot] af78d89
build(deps): bump gofr.dev in /examples/using-add-filestore
dependabot[bot] 006ad33
fix connection issues of replica's
Umang01-hash 2a3c0c6
optimize implementation for performance
Umang01-hash 2aa7e57
fix performance bottlenecks
Umang01-hash 552f580
add documentation
Umang01-hash cd6bed2
Merge remote-tracking branch 'origin' into en/db_resolver
Umang01-hash d3a342e
fix linters
Umang01-hash c4f1a23
resolve small issue in external_db.go
Umang01-hash f38c2ef
fix import in datasources.go
Umang01-hash 6f22477
fix import issue in datasources.go
Umang01-hash a264cd5
retry import fixing
Umang01-hash c448892
Merge branch 'development' into en/db_resolver
Umang01-hash 6b66f6b
resolve reveiw comments
Umang01-hash 2b9c180
enforce dbresovler to use go 1.24.0
Umang01-hash 11a3a07
enforce dbresovler to use go 1.24.0
Umang01-hash 64236a9
Merge remote-tracking branch 'origin' into en/db_resolver
Umang01-hash ee93394
Merge branch 'development' into en/db_resolver
Umang01-hash eae293b
Merge branch 'development' into en/db_resolver
Umang01-hash 6419c98
Merge branch 'development' into en/db_resolver
Umang01-hash da15a7d
Merge branch 'development' into en/db_resolver
Umang01-hash 17a33c4
Merge remote-tracking branch 'origin' into en/db_resolver
Umang01-hash f5d0101
sort go.work dependencies
Umang01-hash 02cc07a
Merge remote-tracking branch 'origin' into en/db_resolver
Umang01-hash 50ed2aa
resolve review comments
Umang01-hash 1340259
Merge branch 'development' into en/db_resolver
Umang01-hash 0a08490
Merge remote-tracking branch 'origin' into en/db_resolver
Umang01-hash b379e4e
resolve PR review comments
Umang01-hash 33d8e50
add new configs for db_replica_users and passwords
Umang01-hash b53ab3b
Merge branch 'development' into en/db_resolver
coolwednesday 7ef7fc5
add new configs in docs
Umang01-hash a8440e2
Merge remote-tracking branch 'origin' into en/db_resolver
Umang01-hash 2adf3f0
Merge remote-tracking branch 'origin/en/db_resolver' into en/db_resolver
Umang01-hash ae3b0d5
resolve linters
Umang01-hash 64cf385
Merge branch 'development' into en/db_resolver
Umang01-hash de83572
Merge branch 'development' into en/db_resolver
Umang01-hash File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
package dbresolver | ||
|
||
import ( | ||
"errors" | ||
|
||
"go.opentelemetry.io/otel/trace" | ||
"gofr.dev/pkg/gofr/container" | ||
) | ||
Umang01-hash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
var ( | ||
errPrimaryNil = errors.New("primary database cannot be nil") | ||
errReplicaFailedNoFallback = errors.New("replica query failed and fallback disabled") | ||
) | ||
|
||
// ResolverWrapper implements container.DBResolverProvider interface | ||
// It acts as a factory that creates a Resolver with given config. | ||
type ResolverWrapper struct { | ||
logger Logger | ||
metrics Metrics | ||
tracer trace.Tracer | ||
strategyName string | ||
readFallback bool | ||
} | ||
|
||
// NewProvider creates a new ResolverWrapper with strategy and fallback config. | ||
func NewProvider(strategy string, readFallback bool) *ResolverWrapper { | ||
Umang01-hash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return &ResolverWrapper{ | ||
strategyName: strategy, | ||
readFallback: readFallback, | ||
} | ||
} | ||
|
||
// UseLogger sets the logger instance. | ||
func (r *ResolverWrapper) UseLogger(logger any) { | ||
if l, ok := logger.(Logger); ok { | ||
r.logger = l | ||
} | ||
} | ||
|
||
// UseMetrics sets the metrics instance. | ||
func (r *ResolverWrapper) UseMetrics(metrics any) { | ||
if m, ok := metrics.(Metrics); ok { | ||
r.metrics = m | ||
} | ||
} | ||
|
||
// UseTracer sets the tracer instance. | ||
func (r *ResolverWrapper) UseTracer(tracer any) { | ||
if t, ok := tracer.(trace.Tracer); ok { | ||
r.tracer = t | ||
} | ||
} | ||
|
||
// Connect is no-op for wrapper as connections are created externally. | ||
func (*ResolverWrapper) Connect() { | ||
// no-op | ||
} | ||
|
||
// Build creates a Resolver instance with primary and replica DBs. | ||
func (r *ResolverWrapper) Build(primary container.DB, replicas []container.DB) (container.DB, error) { | ||
if primary == nil { | ||
return nil, errPrimaryNil | ||
} | ||
|
||
// Create options slice | ||
var opts []Option | ||
|
||
var strategy Strategy | ||
if r.strategyName == "random" { | ||
strategy = NewRandomStrategy() | ||
} else { | ||
// Default to round-robin for any other value including "round-robin" | ||
strategy = NewRoundRobinStrategy(len(replicas)) | ||
} | ||
Umang01-hash marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// Add options. | ||
opts = append(opts, WithStrategy(strategy), WithFallback(r.readFallback)) | ||
|
||
// Create and return the resolver. | ||
return NewResolver(primary, replicas, r.logger, r.metrics, opts...), nil | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.