From 874552803e6d69ebbdc7263c06bbb1c421395b4b Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Wed, 28 Apr 2021 01:13:08 +0300 Subject: [PATCH] update for latest micro Signed-off-by: Vasiliy Tolstov --- go.mod | 2 +- go.sum | 8 +++--- victoriametrics.go | 56 ++++++++++++++++++++--------------------- victoriametrics_test.go | 5 ++-- 4 files changed, 35 insertions(+), 36 deletions(-) diff --git a/go.mod b/go.mod index 1ecd7b6..361ce2f 100644 --- a/go.mod +++ b/go.mod @@ -4,5 +4,5 @@ go 1.16 require ( github.com/VictoriaMetrics/metrics v1.17.2 - github.com/unistack-org/micro/v3 v3.3.16 + github.com/unistack-org/micro/v3 v3.3.17 ) diff --git a/go.sum b/go.sum index 8c80a2e..1812389 100644 --- a/go.sum +++ b/go.sum @@ -8,15 +8,15 @@ github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaRUnok+kx1WdO15EQc= github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ= github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I= -github.com/unistack-org/micro/v3 v3.3.16 h1:v0h/oC0TO2n1djQJeOjD2jNEqKkiykwI6cpflEVTlQE= -github.com/unistack-org/micro/v3 v3.3.16/go.mod h1:ETGcQQUcjxGaD44LUMX+0fgo8Loh7ExldfIPLvfUmDo= +github.com/unistack-org/micro/v3 v3.3.17 h1:WcyS7InP0DlS/JpRQGLh5sG6VstkdHJbgpMp+gmHmwg= +github.com/unistack-org/micro/v3 v3.3.17/go.mod h1:022EOEZZ789hZY3yB5ZSMXU6jLiadBgcNB/cpediV3c= github.com/valyala/fastrand v1.0.0 h1:LUKT9aKer2dVQNUi3waewTbKV+7H17kvWFNKs2ObdkI= github.com/valyala/fastrand v1.0.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ= github.com/valyala/histogram v1.1.2 h1:vOk5VrGjMBIoPR5k6wA8vBaC8toeJ8XO0yfRjFEc1h8= github.com/valyala/histogram v1.1.2/go.mod h1:CZAr6gK9dbD7hYx2s8WSPh0p5x5wETjC+2b3PJVtEdg= -golang.org/x/net v0.0.0-20210415231046-e915ea6b2b7d/go.mod h1:9tjilg8BloeKEkVJvy7fQ90B1CfIiPueXVOjqfkSzI8= +golang.org/x/net v0.0.0-20210423184538-5f58ad60dda6/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/victoriametrics.go b/victoriametrics.go index 7be9b02..efa51cf 100644 --- a/victoriametrics.go +++ b/victoriametrics.go @@ -22,35 +22,31 @@ func (r *victoriametricsMeter) Name() string { return r.opts.Name } -func (r *victoriametricsMeter) buildName(name string, opts ...meter.Option) string { +func (r *victoriametricsMeter) buildName(name string, labels ...string) string { var b strings.Builder - options := r.opts - for _, o := range opts { - o(&options) - } - - if len(options.MetricPrefix) > 0 { - _, _ = b.WriteString(options.MetricPrefix) + labels = append(r.opts.Labels, labels...) + if len(r.opts.MetricPrefix) > 0 { + _, _ = b.WriteString(r.opts.MetricPrefix) } labelPrefix := false - if len(options.LabelPrefix) > 0 { + if len(r.opts.LabelPrefix) > 0 { labelPrefix = true } _, _ = b.WriteString(name) - if len(options.Labels) > 0 { - meter.Sort(&options.Labels) + if len(labels) > 0 { + meter.Sort(&labels) _, _ = b.WriteRune('{') - for idx := 0; idx < len(options.Labels); idx += 2 { + for idx := 0; idx < len(labels); idx += 2 { if idx > 0 { _, _ = b.WriteRune(',') } if labelPrefix { - _, _ = b.WriteString(options.LabelPrefix) + _, _ = b.WriteString(r.opts.LabelPrefix) } - _, _ = b.WriteString(options.Labels[idx]) + _, _ = b.WriteString(labels[idx]) _, _ = b.WriteString(`="`) - _, _ = b.WriteString(options.Labels[idx+1]) + _, _ = b.WriteString(labels[idx+1]) _, _ = b.WriteString(`"`) } _, _ = b.WriteRune('}') @@ -59,32 +55,36 @@ func (r *victoriametricsMeter) buildName(name string, opts ...meter.Option) stri return b.String() } -func (r *victoriametricsMeter) Counter(name string, opts ...meter.Option) meter.Counter { - return r.set.GetOrCreateCounter(r.buildName(name, opts...)) +func (r *victoriametricsMeter) Counter(name string, labels ...string) meter.Counter { + return r.set.GetOrCreateCounter(r.buildName(name, labels...)) } -func (r *victoriametricsMeter) FloatCounter(name string, opts ...meter.Option) meter.FloatCounter { - return r.set.GetOrCreateFloatCounter(r.buildName(name, opts...)) +func (r *victoriametricsMeter) FloatCounter(name string, labels ...string) meter.FloatCounter { + return r.set.GetOrCreateFloatCounter(r.buildName(name, labels...)) } -func (r *victoriametricsMeter) Gauge(name string, f func() float64, opts ...meter.Option) meter.Gauge { - return r.set.GetOrCreateGauge(r.buildName(name, opts...), f) +func (r *victoriametricsMeter) Gauge(name string, f func() float64, labels ...string) meter.Gauge { + return r.set.GetOrCreateGauge(r.buildName(name, labels...), f) } -func (r *victoriametricsMeter) Histogram(name string, opts ...meter.Option) meter.Histogram { - return r.set.GetOrCreateHistogram(r.buildName(name, opts...)) +func (r *victoriametricsMeter) Histogram(name string, labels ...string) meter.Histogram { + return r.set.GetOrCreateHistogram(r.buildName(name, labels...)) } -func (r *victoriametricsMeter) Summary(name string, opts ...meter.Option) meter.Summary { - return r.set.GetOrCreateSummary(r.buildName(name, opts...)) +func (r *victoriametricsMeter) Summary(name string, labels ...string) meter.Summary { + return r.set.GetOrCreateSummary(r.buildName(name, labels...)) } -func (r *victoriametricsMeter) SummaryExt(name string, window time.Duration, quantiles []float64, opts ...meter.Option) meter.Summary { - return r.set.GetOrCreateSummaryExt(r.buildName(name, opts...), window, quantiles) +func (r *victoriametricsMeter) SummaryExt(name string, window time.Duration, quantiles []float64, labels ...string) meter.Summary { + return r.set.GetOrCreateSummaryExt(r.buildName(name, labels...), window, quantiles) } func (r *victoriametricsMeter) Set(opts ...meter.Option) meter.Meter { - m := &victoriametricsMeter{opts: meter.NewOptions(opts...), set: metrics.NewSet()} + m := &victoriametricsMeter{opts: r.opts} + for _, o := range opts { + o(&m.opts) + } + m.set = metrics.NewSet() return m } diff --git a/victoriametrics_test.go b/victoriametrics_test.go index 8b62f38..ba8cf87 100644 --- a/victoriametrics_test.go +++ b/victoriametrics_test.go @@ -6,7 +6,6 @@ import ( "github.com/unistack-org/micro/v3/client" "github.com/unistack-org/micro/v3/codec" - "github.com/unistack-org/micro/v3/meter" "github.com/unistack-org/micro/v3/meter/wrapper" ) @@ -14,12 +13,12 @@ func TestBuildName(t *testing.T) { m := NewMeter() im := m.(*victoriametricsMeter) check := `micro_foo{micro_aaa="b",micro_bar="baz"}` - name := im.buildName("foo", meter.Labels("bar", "baz", "aaa", "b")) + name := im.buildName("foo", "bar", "baz", "aaa", "b") if name != check { t.Fatalf("metric name error: %s != %s", name, check) } - cnt := m.Counter("counter", meter.Labels("key", "val")) + cnt := m.Counter("counter", "key", "val") cnt.Inc() //m.Write(os.Stdout, meter.WriteProcessMetrics(true), meter.WriteFDMetrics(true)) }