meter: complete interface

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
2021-01-27 00:54:19 +03:00
parent 286785491c
commit ac8a3a12c4
4 changed files with 157 additions and 33 deletions

View File

@@ -11,9 +11,9 @@ type Option func(*Options)
// Options for metrics implementations:
type Options struct {
Address string
Path string
Metadata map[string]string
Address string
Path string
Labels Labels
//TimingObjectives map[float64]float64
Logger logger.Logger
Context context.Context
@@ -25,7 +25,6 @@ type Options struct {
func NewOptions(opt ...Option) Options {
opts := Options{
Address: DefaultAddress,
Metadata: make(map[string]string, 3), // 3 elements contains service name, version and id
Path: DefaultPath,
Context: context.Background(),
Logger: logger.DefaultLogger,
@@ -61,14 +60,14 @@ func Address(value string) Option {
}
}
// Metadata will be added to every metric
func Metadata(md map[string]string) Option {
/*
// Labels be added to every metric
func Labels(labels []string) Option {
return func(o *Options) {
for k, v := range md {
o.Metadata[k] = v
}
o.Labels = labels
}
}
*/
/*
// TimingObjectives defines the desired spread of statistics for histogram / timing metrics:
@@ -85,3 +84,11 @@ func Logger(l logger.Logger) Option {
o.Logger = l
}
}
// Label sets the label
func Label(key, val string) Option {
return func(o *Options) {
o.Labels.keys = append(o.Labels.keys, key)
o.Labels.vals = append(o.Labels.vals, val)
}
}