meter: use plan map and metadata
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
202a942eef
commit
263ea8910d
@ -3,8 +3,6 @@ package meter
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -25,13 +23,13 @@ var (
|
||||
// Meter is an interface for collecting and instrumenting metrics
|
||||
type Meter interface {
|
||||
Init(...Option) error
|
||||
Counter(string, metadata.Metadata) Counter
|
||||
FloatCounter(string, metadata.Metadata) FloatCounter
|
||||
Gauge(string, func() float64, metadata.Metadata) Gauge
|
||||
Set(metadata.Metadata) Meter
|
||||
Histogram(string, metadata.Metadata) Histogram
|
||||
Summary(string, metadata.Metadata) Summary
|
||||
SummaryExt(string, time.Duration, []float64, metadata.Metadata) Summary
|
||||
Counter(string, map[string]string) Counter
|
||||
FloatCounter(string, map[string]string) FloatCounter
|
||||
Gauge(string, func() float64, map[string]string) Gauge
|
||||
Set(map[string]string) Meter
|
||||
Histogram(string, map[string]string) Histogram
|
||||
Summary(string, map[string]string) Summary
|
||||
SummaryExt(string, time.Duration, []float64, map[string]string) Summary
|
||||
Options() Options
|
||||
String() string
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
// NoopMeter is an noop implementation of Meter
|
||||
type noopMeter struct {
|
||||
opts Options
|
||||
md metadata.Metadata
|
||||
md map[string]string
|
||||
}
|
||||
|
||||
// NewMeter returns a configured noop reporter:
|
||||
@ -28,37 +28,37 @@ func (r *noopMeter) Init(opts ...Option) error {
|
||||
}
|
||||
|
||||
// Counter implements the Meter interface
|
||||
func (r *noopMeter) Counter(name string, md metadata.Metadata) Counter {
|
||||
func (r *noopMeter) Counter(name string, md map[string]string) Counter {
|
||||
return &noopCounter{}
|
||||
}
|
||||
|
||||
// FloatCounter implements the Meter interface
|
||||
func (r *noopMeter) FloatCounter(name string, md metadata.Metadata) FloatCounter {
|
||||
func (r *noopMeter) FloatCounter(name string, md map[string]string) FloatCounter {
|
||||
return &noopFloatCounter{}
|
||||
}
|
||||
|
||||
// Gauge implements the Meter interface
|
||||
func (r *noopMeter) Gauge(name string, f func() float64, md metadata.Metadata) Gauge {
|
||||
func (r *noopMeter) Gauge(name string, f func() float64, md map[string]string) Gauge {
|
||||
return &noopGauge{}
|
||||
}
|
||||
|
||||
// Summary implements the Meter interface
|
||||
func (r *noopMeter) Summary(name string, md metadata.Metadata) Summary {
|
||||
func (r *noopMeter) Summary(name string, md map[string]string) Summary {
|
||||
return &noopSummary{}
|
||||
}
|
||||
|
||||
// SummaryExt implements the Meter interface
|
||||
func (r *noopMeter) SummaryExt(name string, window time.Duration, quantiles []float64, md metadata.Metadata) Summary {
|
||||
func (r *noopMeter) SummaryExt(name string, window time.Duration, quantiles []float64, md map[string]string) Summary {
|
||||
return &noopSummary{}
|
||||
}
|
||||
|
||||
// Histogram implements the Meter interface
|
||||
func (r *noopMeter) Histogram(name string, md metadata.Metadata) Histogram {
|
||||
func (r *noopMeter) Histogram(name string, md map[string]string) Histogram {
|
||||
return &noopHistogram{}
|
||||
}
|
||||
|
||||
// Set implements the Meter interface
|
||||
func (r *noopMeter) Set(md metadata.Metadata) Meter {
|
||||
func (r *noopMeter) Set(md map[string]string) Meter {
|
||||
return &noopMeter{opts: r.opts, md: metadata.Copy(md)}
|
||||
}
|
||||
|
||||
|
@ -4,7 +4,6 @@ import (
|
||||
"context"
|
||||
|
||||
"github.com/unistack-org/micro/v3/logger"
|
||||
"github.com/unistack-org/micro/v3/metadata"
|
||||
)
|
||||
|
||||
// Option powers the configuration for metrics implementations:
|
||||
@ -14,7 +13,7 @@ type Option func(*Options)
|
||||
type Options struct {
|
||||
Address string
|
||||
Path string
|
||||
Metadata metadata.Metadata
|
||||
Metadata map[string]string
|
||||
//TimingObjectives map[float64]float64
|
||||
Logger logger.Logger
|
||||
Context context.Context
|
||||
@ -26,7 +25,7 @@ type Options struct {
|
||||
func NewOptions(opt ...Option) Options {
|
||||
opts := Options{
|
||||
Address: DefaultAddress,
|
||||
Metadata: metadata.New(3), // 3 elements contains service name, version and id
|
||||
Metadata: make(map[string]string, 3), // 3 elements contains service name, version and id
|
||||
Path: DefaultPath,
|
||||
Context: context.Background(),
|
||||
Logger: logger.DefaultLogger,
|
||||
@ -63,9 +62,11 @@ func Address(value string) Option {
|
||||
}
|
||||
|
||||
// Metadata will be added to every metric
|
||||
func Metadata(md metadata.Metadata) Option {
|
||||
func Metadata(md map[string]string) Option {
|
||||
return func(o *Options) {
|
||||
o.Metadata = metadata.Copy(md)
|
||||
for k, v := range md {
|
||||
o.Metadata[k] = v
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user