update to latest micro
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
10
go.mod
10
go.mod
@@ -1,14 +1,16 @@
|
|||||||
module go.unistack.org/micro-meter-victoriametrics/v4
|
module go.unistack.org/micro-meter-victoriametrics/v4
|
||||||
|
|
||||||
go 1.20
|
go 1.22.0
|
||||||
|
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/VictoriaMetrics/metrics v1.24.0
|
github.com/VictoriaMetrics/metrics v1.35.2
|
||||||
go.unistack.org/micro/v4 v4.0.7
|
go.unistack.org/micro/v4 v4.1.2
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
github.com/spf13/cast v1.7.1 // indirect
|
||||||
github.com/valyala/fastrand v1.1.0 // indirect
|
github.com/valyala/fastrand v1.1.0 // indirect
|
||||||
github.com/valyala/histogram v1.2.0 // indirect
|
github.com/valyala/histogram v1.2.0 // indirect
|
||||||
golang.org/x/sys v0.11.0 // indirect
|
golang.org/x/sys v0.30.0 // indirect
|
||||||
)
|
)
|
||||||
|
14
go.sum
14
go.sum
@@ -1,6 +1,12 @@
|
|||||||
github.com/VictoriaMetrics/metrics v1.23.1 h1:/j8DzeJBxSpL2qSIdqnRFLvQQhbJyJbbEi22yMm7oL0=
|
github.com/VictoriaMetrics/metrics v1.23.1 h1:/j8DzeJBxSpL2qSIdqnRFLvQQhbJyJbbEi22yMm7oL0=
|
||||||
github.com/VictoriaMetrics/metrics v1.24.0 h1:ILavebReOjYctAGY5QU2F9X0MYvkcrG3aEn2RKa1Zkw=
|
github.com/VictoriaMetrics/metrics v1.24.0 h1:ILavebReOjYctAGY5QU2F9X0MYvkcrG3aEn2RKa1Zkw=
|
||||||
github.com/VictoriaMetrics/metrics v1.24.0/go.mod h1:eFT25kvsTidQFHb6U0oa0rTrDRdz4xTYjpL8+UPohys=
|
github.com/VictoriaMetrics/metrics v1.24.0/go.mod h1:eFT25kvsTidQFHb6U0oa0rTrDRdz4xTYjpL8+UPohys=
|
||||||
|
github.com/VictoriaMetrics/metrics v1.35.1 h1:o84wtBKQbzLdDy14XeskkCZih6anG+veZ1SwJHFGwrU=
|
||||||
|
github.com/VictoriaMetrics/metrics v1.35.1/go.mod h1:r7hveu6xMdUACXvB8TYdAj8WEsKzWB0EkpJN+RDtOf8=
|
||||||
|
github.com/VictoriaMetrics/metrics v1.35.2 h1:Bj6L6ExfnakZKYPpi7mGUnkJP4NGQz2v5wiChhXNyWQ=
|
||||||
|
github.com/VictoriaMetrics/metrics v1.35.2/go.mod h1:r7hveu6xMdUACXvB8TYdAj8WEsKzWB0EkpJN+RDtOf8=
|
||||||
|
github.com/spf13/cast v1.7.1 h1:cuNEagBQEHWN1FnbGEjCXL2szYEXqfJPbP2HNUaca9Y=
|
||||||
|
github.com/spf13/cast v1.7.1/go.mod h1:ancEpBxwJDODSW/UG4rDrAqiKolqNNh2DX3mk86cAdo=
|
||||||
github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8=
|
github.com/valyala/fastrand v1.1.0 h1:f+5HkLW4rsgzdNoleUOB69hyT9IlD2ZQh9GyDMfb5G8=
|
||||||
github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
|
github.com/valyala/fastrand v1.1.0/go.mod h1:HWqCzkrkg6QXT8V2EXWvXCoow7vLwOFN002oeRzjapQ=
|
||||||
github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ=
|
github.com/valyala/histogram v1.2.0 h1:wyYGAZZt3CpwUiIb9AU/Zbllg1llXyrtApRS815OLoQ=
|
||||||
@@ -9,5 +15,13 @@ go.unistack.org/micro/v4 v4.0.1 h1:xo1IxbVfgh8i0eY0VeYa3cbb13u5n/Mxnp3FOgWD4Jo=
|
|||||||
go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs=
|
go.unistack.org/micro/v4 v4.0.1/go.mod h1:p/J5UcSJjfHsWGT31uKoghQ5rUQZzQJBAFy+Z4+ZVMs=
|
||||||
go.unistack.org/micro/v4 v4.0.7 h1:2lwtZlHcSwgkahhFbkI4x1lOS79lw8uLHtcEhlFF+AM=
|
go.unistack.org/micro/v4 v4.0.7 h1:2lwtZlHcSwgkahhFbkI4x1lOS79lw8uLHtcEhlFF+AM=
|
||||||
go.unistack.org/micro/v4 v4.0.7/go.mod h1:bVEYTlPi0EsdgZZt311bIroDg9ict7ky3C87dSCCAGk=
|
go.unistack.org/micro/v4 v4.0.7/go.mod h1:bVEYTlPi0EsdgZZt311bIroDg9ict7ky3C87dSCCAGk=
|
||||||
|
go.unistack.org/micro/v4 v4.0.20 h1:+DzI0l4L3pItOPWrM5oqiJP/hSpfS5kKKePmWXzDw0I=
|
||||||
|
go.unistack.org/micro/v4 v4.0.20/go.mod h1:5+da5r835gP0WnNZbYUJDCvWpJ9Xc3IEGyp62e8o8R4=
|
||||||
|
go.unistack.org/micro/v4 v4.1.2 h1:9SOlPYyPNNFpg1A7BsvhDyQm3gysLH1AhWbDCp1hyoY=
|
||||||
|
go.unistack.org/micro/v4 v4.1.2/go.mod h1:lr3oYED8Ay1vjK68QqRw30QOtdk/ffpZqMFDasOUhKw=
|
||||||
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
golang.org/x/sys v0.11.0 h1:eG7RXZHdqOJ1i+0lgLgCpSXAp6M3LYlAo6osgSi0xOM=
|
||||||
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||||
|
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
|
||||||
|
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
|
||||||
|
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||||
|
@@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/VictoriaMetrics/metrics"
|
"github.com/VictoriaMetrics/metrics"
|
||||||
"go.unistack.org/micro/v4/meter"
|
"go.unistack.org/micro/v4/meter"
|
||||||
"go.unistack.org/micro/v4/options"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type victoriametricsMeter struct {
|
type victoriametricsMeter struct {
|
||||||
@@ -14,7 +13,7 @@ type victoriametricsMeter struct {
|
|||||||
opts meter.Options
|
opts meter.Options
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMeter(opts ...options.Option) meter.Meter {
|
func NewMeter(opts ...meter.Option) meter.Meter {
|
||||||
return &victoriametricsMeter{set: metrics.NewSet(), opts: meter.NewOptions(opts...)}
|
return &victoriametricsMeter{set: metrics.NewSet(), opts: meter.NewOptions(opts...)}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,7 +21,7 @@ func (r *victoriametricsMeter) Name() string {
|
|||||||
return r.opts.Name
|
return r.opts.Name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) Clone(opts ...options.Option) meter.Meter {
|
func (r *victoriametricsMeter) Clone(opts ...meter.Option) meter.Meter {
|
||||||
options := r.opts
|
options := r.opts
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
o(&options)
|
||||||
@@ -31,10 +30,6 @@ func (r *victoriametricsMeter) Clone(opts ...options.Option) meter.Meter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) buildName(name string, labels ...string) string {
|
func (r *victoriametricsMeter) buildName(name string, labels ...string) string {
|
||||||
if len(r.opts.MetricPrefix) > 0 {
|
|
||||||
name = r.opts.MetricPrefix + name
|
|
||||||
}
|
|
||||||
|
|
||||||
nl := len(r.opts.Labels) + len(labels)
|
nl := len(r.opts.Labels) + len(labels)
|
||||||
if nl == 0 {
|
if nl == 0 {
|
||||||
return name
|
return name
|
||||||
@@ -44,14 +39,6 @@ func (r *victoriametricsMeter) buildName(name string, labels ...string) string {
|
|||||||
nlabels = append(nlabels, r.opts.Labels...)
|
nlabels = append(nlabels, r.opts.Labels...)
|
||||||
nlabels = append(nlabels, labels...)
|
nlabels = append(nlabels, labels...)
|
||||||
|
|
||||||
if len(r.opts.LabelPrefix) == 0 {
|
|
||||||
return meter.BuildName(name, nlabels...)
|
|
||||||
}
|
|
||||||
|
|
||||||
for idx := 0; idx < nl; idx++ {
|
|
||||||
nlabels[idx] = r.opts.LabelPrefix + nlabels[idx]
|
|
||||||
idx++
|
|
||||||
}
|
|
||||||
return meter.BuildName(name, nlabels...)
|
return meter.BuildName(name, nlabels...)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +66,7 @@ func (r *victoriametricsMeter) SummaryExt(name string, window time.Duration, qua
|
|||||||
return r.set.GetOrCreateSummaryExt(r.buildName(name, labels...), window, quantiles)
|
return r.set.GetOrCreateSummaryExt(r.buildName(name, labels...), window, quantiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) Set(opts ...options.Option) meter.Meter {
|
func (r *victoriametricsMeter) Set(opts ...meter.Option) meter.Meter {
|
||||||
m := &victoriametricsMeter{opts: r.opts}
|
m := &victoriametricsMeter{opts: r.opts}
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&m.opts)
|
o(&m.opts)
|
||||||
@@ -88,7 +75,7 @@ func (r *victoriametricsMeter) Set(opts ...options.Option) meter.Meter {
|
|||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) Init(opts ...options.Option) error {
|
func (r *victoriametricsMeter) Init(opts ...meter.Option) error {
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&r.opts)
|
o(&r.opts)
|
||||||
}
|
}
|
||||||
@@ -96,7 +83,7 @@ func (r *victoriametricsMeter) Init(opts ...options.Option) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *victoriametricsMeter) Write(w io.Writer, opts ...options.Option) error {
|
func (r *victoriametricsMeter) Write(w io.Writer, opts ...meter.Option) error {
|
||||||
options := r.opts
|
options := r.opts
|
||||||
for _, o := range opts {
|
for _, o := range opts {
|
||||||
o(&options)
|
o(&options)
|
||||||
|
@@ -8,14 +8,13 @@ import (
|
|||||||
"go.unistack.org/micro/v4/client"
|
"go.unistack.org/micro/v4/client"
|
||||||
"go.unistack.org/micro/v4/codec"
|
"go.unistack.org/micro/v4/codec"
|
||||||
"go.unistack.org/micro/v4/meter"
|
"go.unistack.org/micro/v4/meter"
|
||||||
"go.unistack.org/micro/v4/meter/wrapper"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestBuildName(t *testing.T) {
|
func TestBuildName(t *testing.T) {
|
||||||
m := NewMeter()
|
m := NewMeter()
|
||||||
im := m.(*victoriametricsMeter)
|
im := m.(*victoriametricsMeter)
|
||||||
check := `micro_foo{micro_aaa="b",micro_bar="baz",micro_ccc="d"}`
|
check := `micro_foo{aaa="b",bar="baz",ccc="d"}`
|
||||||
name := im.buildName("foo", "bar", "baz", "aaa", "b", "ccc", "d")
|
name := im.buildName("micro_foo", "bar", "baz", "aaa", "b", "ccc", "d")
|
||||||
if name != check {
|
if name != check {
|
||||||
t.Fatalf("metric name error: %s != %s", name, check)
|
t.Fatalf("metric name error: %s != %s", name, check)
|
||||||
}
|
}
|
||||||
@@ -25,18 +24,13 @@ func TestBuildName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestWrapper(t *testing.T) {
|
func TestWrapper(t *testing.T) {
|
||||||
m := NewMeter() // meter.Labels("test_key", "test_val"))
|
m := NewMeter()
|
||||||
|
if err := m.Init(); err != nil {
|
||||||
w := wrapper.NewClientWrapper(
|
t.Fatal(err)
|
||||||
wrapper.ServiceName("svc1"),
|
}
|
||||||
wrapper.ServiceVersion("0.0.1"),
|
|
||||||
wrapper.ServiceID("12345"),
|
|
||||||
wrapper.Meter(m),
|
|
||||||
)
|
|
||||||
|
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
c := client.NewClient(client.Wrap(w))
|
c := client.NewClient(client.Meter(m))
|
||||||
if err := c.Init(); err != nil {
|
if err := c.Init(); err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
@@ -46,7 +40,7 @@ func TestWrapper(t *testing.T) {
|
|||||||
_, _ = rsp, err
|
_, _ = rsp, err
|
||||||
buf := bytes.NewBuffer(nil)
|
buf := bytes.NewBuffer(nil)
|
||||||
_ = m.Write(buf, meter.WriteProcessMetrics(false), meter.WriteFDMetrics(false))
|
_ = m.Write(buf, meter.WriteProcessMetrics(false), meter.WriteFDMetrics(false))
|
||||||
if !bytes.Contains(buf.Bytes(), []byte(`micro_client_request_inflight{micro_endpoint="svc2.Service.Method"} 0`)) {
|
if !bytes.Contains(buf.Bytes(), []byte(`micro_client_request_total{code="500",endpoint="Service.Method",status="failure"} 1`)) {
|
||||||
t.Fatalf("invalid metrics output: %s", buf.Bytes())
|
t.Fatalf("invalid metrics output: %s", buf.Bytes())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user