add meter and tracer across all options

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-01-22 23:32:33 +03:00
parent c67fe6f330
commit c7bafecce3
15 changed files with 377 additions and 77 deletions

View File

@ -6,13 +6,17 @@ import (
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/metadata" "github.com/unistack-org/micro/v3/metadata"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/store" "github.com/unistack-org/micro/v3/store"
"github.com/unistack-org/micro/v3/tracer"
) )
// NewOptions creates Options struct from slice of options // NewOptions creates Options struct from slice of options
func NewOptions(opts ...Option) Options { func NewOptions(opts ...Option) Options {
options := Options{ options := Options{
Tracer: tracer.DefaultTracer,
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,
Meter: meter.DefaultMeter,
} }
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
@ -41,6 +45,10 @@ type Options struct {
Addrs []string Addrs []string
// Logger sets the logger // Logger sets the logger
Logger logger.Logger Logger logger.Logger
// Meter sets tht meter
Meter meter.Meter
// Tracer
Tracer tracer.Tracer
// Context to store other options // Context to store other options
Context context.Context Context context.Context
} }
@ -288,3 +296,17 @@ func Logger(l logger.Logger) Option {
o.Logger = l o.Logger = l
} }
} }
// Meter sets the meter
func Meter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// Tracer sets the meter
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}

View File

@ -6,27 +6,30 @@ import (
"github.com/unistack-org/micro/v3/codec" "github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/registry" "github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/tracer"
) )
// Options struct // Options struct
type Options struct { type Options struct {
Addrs []string // Addrs useed by broker
Secure bool Addrs []string
// ErrorHandler executed when errors occur processing messages
// Codec
Codec codec.Codec
// Logger the logger
Logger logger.Logger
// Handler executed when errors occur processing messages
ErrorHandler Handler ErrorHandler Handler
// Codec used to marshal/unmarshal messages
Codec codec.Codec
// Logger the used logger
Logger logger.Logger
// Meter the used for metrics
Meter meter.Meter
// Tracer used for trace
Tracer tracer.Tracer
// TLSConfig for secure communication
TLSConfig *tls.Config TLSConfig *tls.Config
// Registry used for clustering // Registry used for clustering
Registry registry.Registry Registry registry.Registry
// Other options for implementations of the interface // Context is used for non default options
// can be stored in a context
Context context.Context Context context.Context
} }
@ -36,6 +39,9 @@ func NewOptions(opts ...Option) Options {
Registry: registry.DefaultRegistry, Registry: registry.DefaultRegistry,
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,
Context: context.Background(), Context: context.Background(),
Meter: meter.DefaultMeter,
Codec: codec.DefaultCodec,
Tracer: tracer.DefaultTracer,
} }
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
@ -54,8 +60,7 @@ func Context(ctx context.Context) Option {
type PublishOptions struct { type PublishOptions struct {
// BodyOnly says that only body of the message must be published // BodyOnly says that only body of the message must be published
BodyOnly bool BodyOnly bool
// Other options for implementations of the interface // Context for non default options
// can be stored in a context
Context context.Context Context context.Context
} }
@ -77,10 +82,10 @@ type SubscribeOptions struct {
// AutoAck ack messages if handler returns nil err // AutoAck ack messages if handler returns nil err
AutoAck bool AutoAck bool
// Handler executed when errors occur processing messages // ErrorHandler executed when errors occur processing messages
ErrorHandler Handler ErrorHandler Handler
// Subscribers with the same group name // Group for subscriber, Subscribers with the same group name
// will create a shared subscription where each // will create a shared subscription where each
// receives a subset of messages. // receives a subset of messages.
Group string Group string
@ -88,8 +93,7 @@ type SubscribeOptions struct {
// BodyOnly says that consumed only body of the message // BodyOnly says that consumed only body of the message
BodyOnly bool BodyOnly bool
// Other options for implementations of the interface // Context is used for non default options
// can be stored in a context
Context context.Context Context context.Context
} }
@ -205,13 +209,6 @@ func Registry(r registry.Registry) Option {
} }
} }
// Secure communication with the broker
func Secure(b bool) Option {
return func(o *Options) {
o.Secure = b
}
}
// TLSConfig sets the TLS Config // TLSConfig sets the TLS Config
func TLSConfig(t *tls.Config) Option { func TLSConfig(t *tls.Config) Option {
return func(o *Options) { return func(o *Options) {
@ -226,6 +223,20 @@ func Logger(l logger.Logger) Option {
} }
} }
// Tracer to be used for tracing
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}
// Meter sets the meter
func Meter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// SubscribeContext set context // SubscribeContext set context
func SubscribeContext(ctx context.Context) SubscribeOption { func SubscribeContext(ctx context.Context) SubscribeOption {
return func(o *SubscribeOptions) { return func(o *SubscribeOptions) {

View File

@ -7,11 +7,13 @@ import (
"github.com/unistack-org/micro/v3/broker" "github.com/unistack-org/micro/v3/broker"
"github.com/unistack-org/micro/v3/codec" "github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/network/transport" "github.com/unistack-org/micro/v3/network/transport"
"github.com/unistack-org/micro/v3/registry" "github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/router" "github.com/unistack-org/micro/v3/router"
"github.com/unistack-org/micro/v3/selector" "github.com/unistack-org/micro/v3/selector"
"github.com/unistack-org/micro/v3/selector/random" "github.com/unistack-org/micro/v3/selector/random"
"github.com/unistack-org/micro/v3/tracer"
) )
// Options holds client options // Options holds client options
@ -28,21 +30,21 @@ type Options struct {
Selector selector.Selector Selector selector.Selector
Transport transport.Transport Transport transport.Transport
Logger logger.Logger Logger logger.Logger
Meter meter.Meter
// Lookup used for looking up routes // Lookup used for looking up routes
Lookup LookupFunc Lookup LookupFunc
// Connection Pool // Connection Pool
PoolSize int PoolSize int
PoolTTL time.Duration PoolTTL time.Duration
Tracer tracer.Tracer
// Middleware for client // Wrapper that used client
Wrappers []Wrapper Wrappers []Wrapper
// Default Call Options // CallOptions that used by default
CallOptions CallOptions CallOptions CallOptions
// Other options for implementations of the interface // Context is used for non default options
// can be stored in a context
Context context.Context Context context.Context
} }
@ -81,12 +83,9 @@ type CallOptions struct {
AuthToken bool AuthToken bool
// Network to lookup the route within // Network to lookup the route within
Network string Network string
// Middleware for low level call func // Middleware for low level call func
CallWrappers []CallWrapper CallWrappers []CallWrapper
// Context is uded for non default options
// Other options for implementations of the interface
// can be stored in a context
Context context.Context Context context.Context
} }
@ -142,7 +141,6 @@ func NewRequestOptions(opts ...RequestOption) RequestOptions {
type RequestOptions struct { type RequestOptions struct {
ContentType string ContentType string
Stream bool Stream bool
// Other options for implementations of the interface // Other options for implementations of the interface
// can be stored in a context // can be stored in a context
Context context.Context Context context.Context
@ -167,6 +165,8 @@ func NewOptions(opts ...Option) Options {
Selector: random.NewSelector(), Selector: random.NewSelector(),
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,
Broker: broker.DefaultBroker, Broker: broker.DefaultBroker,
Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer,
} }
for _, o := range opts { for _, o := range opts {
@ -183,6 +183,13 @@ func Broker(b broker.Broker) Option {
} }
} }
// Tracer to be used for tracing
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}
// Logger to be used for log mesages // Logger to be used for log mesages
func Logger(l logger.Logger) Option { func Logger(l logger.Logger) Option {
return func(o *Options) { return func(o *Options) {
@ -190,6 +197,13 @@ func Logger(l logger.Logger) Option {
} }
} }
// Meter to be used for metrics
func Meter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// Codec to be used to encode/decode requests for a given content type // Codec to be used to encode/decode requests for a given content type
func Codec(contentType string, c codec.Codec) Option { func Codec(contentType string, c codec.Codec) Option {
return func(o *Options) { return func(o *Options) {

View File

@ -25,7 +25,7 @@ var (
var ( var (
// DefaultMaxMsgSize specifies how much data codec can handle // DefaultMaxMsgSize specifies how much data codec can handle
DefaultMaxMsgSize = 1024 * 1024 * 4 // 4Mb DefaultMaxMsgSize int = 1024 * 1024 * 4 // 4Mb
DefaultCodec Codec = NewCodec() DefaultCodec Codec = NewCodec()
) )
@ -62,21 +62,6 @@ type Message struct {
Body []byte Body []byte
} }
// Option func
type Option func(*Options)
// Options contains codec options
type Options struct {
MaxMsgSize int64
}
// MaxMsgSize sets the max message size
func MaxMsgSize(n int64) Option {
return func(o *Options) {
o.MaxMsgSize = n
}
}
// NewMessage creates new codec message // NewMessage creates new codec message
func NewMessage(t MessageType) *Message { func NewMessage(t MessageType) *Message {
return &Message{Type: t, Header: metadata.New(0)} return &Message{Type: t, Header: metadata.New(0)}

61
codec/options.go Normal file
View File

@ -0,0 +1,61 @@
package codec
import (
"github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/tracer"
)
// Option func
type Option func(*Options)
// Options contains codec options
type Options struct {
MaxMsgSize int
Meter meter.Meter
Logger logger.Logger
Tracer tracer.Tracer
}
// MaxMsgSize sets the max message size
func MaxMsgSize(n int) Option {
return func(o *Options) {
o.MaxMsgSize = n
}
}
// Logger sets the logger
func Logger(l logger.Logger) Option {
return func(o *Options) {
o.Logger = l
}
}
// Tracer to be used for tracing
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}
// Meter sets the meter
func Meter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
func NewOptions(opts ...Option) Options {
options := Options{
Logger: logger.DefaultLogger,
Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer,
MaxMsgSize: DefaultMaxMsgSize,
}
for _, o := range opts {
o(&options)
}
return options
}

View File

@ -5,6 +5,8 @@ import (
"github.com/unistack-org/micro/v3/codec" "github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/tracer"
) )
type Options struct { type Options struct {
@ -15,13 +17,17 @@ type Options struct {
AfterSave []func(context.Context, Config) error AfterSave []func(context.Context, Config) error
// Struct that holds config data // Struct that holds config data
Struct interface{} Struct interface{}
// struct tag name // StructTag name
StructTag string StructTag string
// logger that will be used // Logger that will be used
Logger logger.Logger Logger logger.Logger
// codec that used for load/save // Meter that will be used
Meter meter.Meter
// Tracer used for trace
Tracer tracer.Tracer
// Codec that used for load/save
Codec codec.Codec Codec codec.Codec
// for alternative data // Context for alternative data
Context context.Context Context context.Context
} }
@ -30,6 +36,8 @@ type Option func(o *Options)
func NewOptions(opts ...Option) Options { func NewOptions(opts ...Option) Options {
options := Options{ options := Options{
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,
Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer,
Context: context.Background(), Context: context.Background(),
} }
for _, o := range opts { for _, o := range opts {
@ -88,6 +96,13 @@ func Logger(l logger.Logger) Option {
} }
} }
// Tracer to be used for tracing
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}
// Struct used as config // Struct used as config
func Struct(v interface{}) Option { func Struct(v interface{}) Option {
return func(o *Options) { return func(o *Options) {

View File

@ -3,9 +3,11 @@ package network
import ( import (
"github.com/google/uuid" "github.com/google/uuid"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/network/tunnel" "github.com/unistack-org/micro/v3/network/tunnel"
"github.com/unistack-org/micro/v3/proxy" "github.com/unistack-org/micro/v3/proxy"
"github.com/unistack-org/micro/v3/router" "github.com/unistack-org/micro/v3/router"
"github.com/unistack-org/micro/v3/tracer"
) )
// Option func // Option func
@ -31,6 +33,10 @@ type Options struct {
Proxy proxy.Proxy Proxy proxy.Proxy
// Logger // Logger
Logger logger.Logger Logger logger.Logger
// Meter
Meter meter.Meter
// Tracer
Tracer tracer.Tracer
} }
// Id sets the id of the network node // Id sets the id of the network node
@ -96,11 +102,34 @@ func Logger(l logger.Logger) Option {
} }
} }
// DefaultOptions returns network default options // Meter sets the meter
func DefaultOptions() Options { func Meter(m meter.Meter) Option {
return Options{ return func(o *Options) {
o.Meter = m
}
}
// Tracer to be used for tracing
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}
// NewOptions returns network default options
func NewOptions(opts ...Option) Options {
options := Options{
Id: uuid.New().String(), Id: uuid.New().String(),
Name: "go.micro", Name: "go.micro",
Address: ":0", Address: ":0",
Logger: logger.DefaultLogger,
Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer,
} }
for _, o := range opts {
o(&options)
}
return options
} }

View File

@ -7,6 +7,8 @@ import (
"github.com/unistack-org/micro/v3/codec" "github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/tracer"
) )
type Options struct { type Options struct {
@ -26,6 +28,10 @@ type Options struct {
Timeout time.Duration Timeout time.Duration
// Logger sets the logger // Logger sets the logger
Logger logger.Logger Logger logger.Logger
// Meter sets the meter
Meter meter.Meter
// Tracer
Tracer tracer.Tracer
// Other options for implementations of the interface // Other options for implementations of the interface
// can be stored in a context // can be stored in a context
Context context.Context Context context.Context
@ -35,6 +41,8 @@ type Options struct {
func NewOptions(opts ...Option) Options { func NewOptions(opts ...Option) Options {
options := Options{ options := Options{
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,
Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer,
Context: context.Background(), Context: context.Background(),
} }
@ -112,6 +120,13 @@ func Logger(l logger.Logger) Option {
} }
} }
// Meter sets the meter
func Meter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// Context sets the context // Context sets the context
func Context(ctx context.Context) Option { func Context(ctx context.Context) Option {
return func(o *Options) { return func(o *Options) {
@ -134,14 +149,6 @@ func Timeout(t time.Duration) Option {
} }
} }
// Use secure communication. If TLSConfig is not specified we
// use InsecureSkipVerify and generate a self signed cert
func Secure(b bool) Option {
return func(o *Options) {
o.Secure = b
}
}
// TLSConfig to be used for the transport. // TLSConfig to be used for the transport.
func TLSConfig(t *tls.Config) Option { func TLSConfig(t *tls.Config) Option {
return func(o *Options) { return func(o *Options) {
@ -162,3 +169,10 @@ func WithTimeout(d time.Duration) DialOption {
o.Timeout = d o.Timeout = d
} }
} }
// Tracer to be used for tracing
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}

View File

@ -5,7 +5,9 @@ import (
"github.com/google/uuid" "github.com/google/uuid"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/network/transport" "github.com/unistack-org/micro/v3/network/transport"
"github.com/unistack-org/micro/v3/tracer"
) )
var ( var (
@ -32,6 +34,10 @@ type Options struct {
Transport transport.Transport Transport transport.Transport
// Logger // Logger
Logger logger.Logger Logger logger.Logger
// Meter
Meter meter.Meter
// Tracer
Tracer tracer.Tracer
} }
// DialOption func // DialOption func
@ -74,6 +80,13 @@ func Logger(l logger.Logger) Option {
} }
} }
// Meter sets the meter
func Meter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// Address sets the tunnel address // Address sets the tunnel address
func Address(a string) Option { func Address(a string) Option {
return func(o *Options) { return func(o *Options) {
@ -152,9 +165,19 @@ func NewOptions(opts ...Option) Options {
Id: uuid.New().String(), Id: uuid.New().String(),
Address: DefaultAddress, Address: DefaultAddress,
Token: DefaultToken, Token: DefaultToken,
Logger: logger.DefaultLogger,
Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer,
} }
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
} }
return options return options
} }
// Tracer to be used for tracing
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}

View File

@ -11,6 +11,7 @@ import (
"github.com/unistack-org/micro/v3/debug/profile" "github.com/unistack-org/micro/v3/debug/profile"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/metadata" "github.com/unistack-org/micro/v3/metadata"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/registry" "github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/router" "github.com/unistack-org/micro/v3/router"
"github.com/unistack-org/micro/v3/runtime" "github.com/unistack-org/micro/v3/runtime"
@ -25,11 +26,13 @@ type Options struct {
Auth auth.Auth Auth auth.Auth
Broker broker.Broker Broker broker.Broker
Logger logger.Logger Logger logger.Logger
Meter meter.Meter
Configs []config.Config Configs []config.Config
Client client.Client Client client.Client
Server server.Server Server server.Server
Store store.Store Store store.Store
Registry registry.Registry Registry registry.Registry
Tracer tracer.Tracer
Router router.Router Router router.Router
Runtime runtime.Runtime Runtime runtime.Runtime
Profile profile.Profile Profile profile.Profile
@ -56,6 +59,8 @@ func NewOptions(opts ...Option) Options {
Router: router.DefaultRouter, Router: router.DefaultRouter,
Auth: auth.DefaultAuth, Auth: auth.DefaultAuth,
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,
Tracer: tracer.DefaultTracer,
Meter: meter.DefaultMeter,
Configs: []config.Config{config.DefaultConfig}, Configs: []config.Config{config.DefaultConfig},
Store: store.DefaultStore, Store: store.DefaultStore,
//Runtime runtime.Runtime //Runtime runtime.Runtime
@ -129,6 +134,13 @@ func Logger(l logger.Logger) Option {
} }
} }
// Meter set the meter to use
func Meter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// Registry sets the registry for the service // Registry sets the registry for the service
// and the underlying components // and the underlying components
func Registry(r registry.Registry) Option { func Registry(r registry.Registry) Option {
@ -152,10 +164,13 @@ func Registry(r registry.Registry) Option {
// Tracer sets the tracer for the service // Tracer sets the tracer for the service
func Tracer(t tracer.Tracer) Option { func Tracer(t tracer.Tracer) Option {
return func(o *Options) { return func(o *Options) {
o.Tracer = t
if o.Server != nil { if o.Server != nil {
//todo client trace
o.Server.Init(server.Tracer(t)) o.Server.Init(server.Tracer(t))
} }
if o.Client != nil {
o.Client.Init(client.Tracer(t))
}
} }
} }

View File

@ -4,7 +4,9 @@ package proxy
import ( import (
"github.com/unistack-org/micro/v3/client" "github.com/unistack-org/micro/v3/client"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/router" "github.com/unistack-org/micro/v3/router"
"github.com/unistack-org/micro/v3/tracer"
) )
// Options for proxy // Options for proxy
@ -19,11 +21,29 @@ type Options struct {
Links map[string]client.Client Links map[string]client.Client
// Logger // Logger
Logger logger.Logger Logger logger.Logger
// Meter
Meter meter.Meter
// Tracer
Tracer tracer.Tracer
} }
// Option func signature // Option func signature
type Option func(o *Options) type Option func(o *Options)
func NewOptions(opts ...Option) Options {
options := Options{
Logger: logger.DefaultLogger,
Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer,
}
for _, o := range opts {
o(&options)
}
return options
}
// WithEndpoint sets a proxy endpoint // WithEndpoint sets a proxy endpoint
func WithEndpoint(e string) Option { func WithEndpoint(e string) Option {
return func(o *Options) { return func(o *Options) {
@ -52,6 +72,13 @@ func WithLogger(l logger.Logger) Option {
} }
} }
// WithMeter specifies the meter to use
func WithMeter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// WithLink sets a link for outbound requests // WithLink sets a link for outbound requests
func WithLink(name string, c client.Client) Option { func WithLink(name string, c client.Client) Option {
return func(o *Options) { return func(o *Options) {
@ -61,3 +88,10 @@ func WithLink(name string, c client.Client) Option {
o.Links[name] = c o.Links[name] = c
} }
} }
// Tracer to be used for tracing
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}

View File

@ -6,16 +6,21 @@ import (
"time" "time"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/tracer"
) )
type Options struct { type Options struct {
Addrs []string Addrs []string
Timeout time.Duration Timeout time.Duration
Secure bool
TLSConfig *tls.Config TLSConfig *tls.Config
// Logger imp // Logger that will be used
Logger logger.Logger Logger logger.Logger
// Meter that will be used
Meter meter.Meter
// Tracer
Tracer tracer.Tracer
// Other options for implementations of the interface // Other options for implementations of the interface
// can be stored in a context // can be stored in a context
Context context.Context Context context.Context
@ -24,6 +29,8 @@ type Options struct {
func NewOptions(opts ...Option) Options { func NewOptions(opts ...Option) Options {
options := Options{ options := Options{
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,
Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer,
Context: context.Background(), Context: context.Background(),
} }
for _, o := range opts { for _, o := range opts {
@ -142,13 +149,6 @@ func Timeout(t time.Duration) Option {
} }
} }
// Secure communication with the registry
func Secure(b bool) Option {
return func(o *Options) {
o.Secure = b
}
}
// Logger sets the logger // Logger sets the logger
func Logger(l logger.Logger) Option { func Logger(l logger.Logger) Option {
return func(o *Options) { return func(o *Options) {
@ -156,6 +156,20 @@ func Logger(l logger.Logger) Option {
} }
} }
// Meter sets the meter
func Meter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// Tracer sets the tracer
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}
// Context sets the context // Context sets the context
func Context(ctx context.Context) Option { func Context(ctx context.Context) Option {
return func(o *Options) { return func(o *Options) {

View File

@ -12,6 +12,7 @@ import (
"github.com/unistack-org/micro/v3/codec" "github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/metadata" "github.com/unistack-org/micro/v3/metadata"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/network/transport" "github.com/unistack-org/micro/v3/network/transport"
"github.com/unistack-org/micro/v3/registry" "github.com/unistack-org/micro/v3/registry"
"github.com/unistack-org/micro/v3/tracer" "github.com/unistack-org/micro/v3/tracer"
@ -28,6 +29,7 @@ type Options struct {
Tracer tracer.Tracer Tracer tracer.Tracer
Auth auth.Auth Auth auth.Auth
Logger logger.Logger Logger logger.Logger
Meter meter.Meter
Transport transport.Transport Transport transport.Transport
Metadata metadata.Metadata Metadata metadata.Metadata
Name string Name string
@ -78,6 +80,7 @@ func NewOptions(opts ...Option) Options {
RegisterTTL: DefaultRegisterTTL, RegisterTTL: DefaultRegisterTTL,
RegisterCheck: DefaultRegisterCheck, RegisterCheck: DefaultRegisterCheck,
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,
Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer, Tracer: tracer.DefaultTracer,
Broker: broker.DefaultBroker, Broker: broker.DefaultBroker,
Registry: registry.DefaultRegistry, Registry: registry.DefaultRegistry,
@ -117,6 +120,13 @@ func Logger(l logger.Logger) Option {
} }
} }
// Meter sets the meter option
func Meter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// Id unique server id // Id unique server id
func Id(id string) Option { func Id(id string) Option {
return func(o *Options) { return func(o *Options) {
@ -235,7 +245,6 @@ func TLSConfig(t *tls.Config) Option {
// set the transport tls // set the transport tls
o.Transport.Init( o.Transport.Init(
transport.Secure(true),
transport.TLSConfig(t), transport.TLSConfig(t),
) )
} }

View File

@ -7,6 +7,8 @@ import (
"github.com/unistack-org/micro/v3/codec" "github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/metadata" "github.com/unistack-org/micro/v3/metadata"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/tracer"
) )
// Options contains configuration for the Store // Options contains configuration for the Store
@ -23,6 +25,10 @@ type Options struct {
Codec codec.Codec Codec codec.Codec
// Logger the logger // Logger the logger
Logger logger.Logger Logger logger.Logger
// Meter the meter
Meter meter.Meter
// Tracer the tacer
Tracer tracer.Tracer
// Context should contain all implementation specific options, using context.WithValue. // Context should contain all implementation specific options, using context.WithValue.
Context context.Context Context context.Context
} }
@ -33,6 +39,8 @@ func NewOptions(opts ...Option) Options {
Logger: logger.DefaultLogger, Logger: logger.DefaultLogger,
Context: context.Background(), Context: context.Background(),
Codec: codec.DefaultCodec, Codec: codec.DefaultCodec,
Tracer: tracer.DefaultTracer,
Meter: meter.DefaultMeter,
} }
for _, o := range opts { for _, o := range opts {
o(&options) o(&options)
@ -64,6 +72,20 @@ func Logger(l logger.Logger) Option {
} }
} }
// Meter sets the meter
func Meter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// Tracer sets the tracer
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}
// Nodes contains the addresses or other connection information of the backing storage. // Nodes contains the addresses or other connection information of the backing storage.
// For example, an etcd implementation would contain the nodes of the cluster. // For example, an etcd implementation would contain the nodes of the cluster.
// A SQL implementation could contain one or more connection strings. // A SQL implementation could contain one or more connection strings.

View File

@ -4,16 +4,34 @@ import (
"time" "time"
"github.com/unistack-org/micro/v3/logger" "github.com/unistack-org/micro/v3/logger"
"github.com/unistack-org/micro/v3/meter"
"github.com/unistack-org/micro/v3/tracer"
) )
type Options struct { type Options struct {
Nodes []string Nodes []string
Prefix string Prefix string
Logger logger.Logger Logger logger.Logger
Tracer tracer.Tracer
Meter meter.Meter
} }
type Option func(o *Options) type Option func(o *Options)
func NewOptions(opts ...Option) Options {
options := Options{
Logger: logger.DefaultLogger,
Meter: meter.DefaultMeter,
Tracer: tracer.DefaultTracer,
}
for _, o := range opts {
o(&options)
}
return options
}
type LeaderOptions struct{} type LeaderOptions struct{}
type LeaderOption func(o *LeaderOptions) type LeaderOption func(o *LeaderOptions)
@ -32,6 +50,20 @@ func Logger(l logger.Logger) Option {
} }
} }
// Meter sets the logger
func Meter(m meter.Meter) Option {
return func(o *Options) {
o.Meter = m
}
}
// Tracer sets the tracer
func Tracer(t tracer.Tracer) Option {
return func(o *Options) {
o.Tracer = t
}
}
// Nodes sets the addresses to use // Nodes sets the addresses to use
func Nodes(a ...string) Option { func Nodes(a ...string) Option {
return func(o *Options) { return func(o *Options) {