diff --git a/core/stores/mon/model.go b/core/stores/mon/model.go index e58df7c889cb..80eccbf4e013 100644 --- a/core/stores/mon/model.go +++ b/core/stores/mon/model.go @@ -50,8 +50,15 @@ func NewModel(uri, db, collection string, opts ...Option) (*Model, error) { return nil, err } - name := strings.Join([]string{uri, collection}, "/") brk := breaker.GetBreaker(uri) + if withBreaker != nil { + brk = withBreaker.(breaker.Breaker) + } + if withoutBreaker != nil { + breaker.NoBreakerFor(uri) + } + + name := strings.Join([]string{uri, collection}, "/") coll := newCollection(cli.Database(db).Collection(collection), brk) return newModel(name, cli, coll, brk, opts...), nil } diff --git a/core/stores/mon/options.go b/core/stores/mon/options.go index 4097328faf02..c099017c8f9c 100644 --- a/core/stores/mon/options.go +++ b/core/stores/mon/options.go @@ -1,6 +1,7 @@ package mon import ( + "github.com/zeromicro/go-zero/core/breaker" "time" "github.com/zeromicro/go-zero/core/syncx" @@ -15,6 +16,9 @@ var ( logSlowMon = syncx.ForAtomicBool(true) ) +var withBreaker any +var withoutBreaker any + type ( options = mopt.ClientOptions @@ -50,3 +54,17 @@ func WithTimeout(timeout time.Duration) Option { opts.SetTimeout(timeout) } } + +// WithoutBreaker not use breaker. +func WithoutBreaker() Option { + return func(opts *options) { + withoutBreaker = struct{}{} + } +} + +// WithBreaker use customer breaker. +func WithBreaker(brk breaker.Breaker) Option { + return func(opts *options) { + withBreaker = brk + } +}