fix default labels
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
28ebe788da
commit
ab247ef9c6
@ -34,19 +34,23 @@ func (r *victoriametricsMeter) buildName(name string, labels ...string) string {
|
||||
name = r.opts.MetricPrefix + name
|
||||
}
|
||||
|
||||
if len(labels) == 0 {
|
||||
nl := len(r.opts.Labels) + len(labels)
|
||||
if nl == 0 {
|
||||
return name
|
||||
}
|
||||
|
||||
nlabels := make([]string, 0, nl)
|
||||
nlabels = append(nlabels, r.opts.Labels...)
|
||||
nlabels = append(nlabels, labels...)
|
||||
|
||||
if len(r.opts.LabelPrefix) == 0 {
|
||||
return meter.BuildName(name, labels...)
|
||||
return meter.BuildName(name, nlabels...)
|
||||
}
|
||||
|
||||
nlabels := make([]string, len(labels))
|
||||
copy(nlabels, labels)
|
||||
for idx := 0; idx <= len(nlabels)/2; idx += 2 {
|
||||
nlabels[idx] = r.opts.LabelPrefix + nlabels[idx]
|
||||
}
|
||||
|
||||
return meter.BuildName(name, nlabels...)
|
||||
}
|
||||
|
||||
|
@ -25,7 +25,7 @@ func TestBuildName(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestWrapper(t *testing.T) {
|
||||
m := NewMeter()
|
||||
m := NewMeter() // meter.Labels("test_key", "test_val"))
|
||||
|
||||
w := wrapper.NewClientWrapper(
|
||||
wrapper.ServiceName("svc1"),
|
||||
@ -45,7 +45,7 @@ func TestWrapper(t *testing.T) {
|
||||
err := c.Call(ctx, c.NewRequest("svc2", "Service.Method", req), rsp)
|
||||
_, _ = rsp, err
|
||||
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`)) {
|
||||
t.Fatalf("invalid metrics output: %s", buf.Bytes())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user