fixup golang std metrics
Some checks failed
build / test (push) Failing after 1m23s
codeql / analyze (go) (push) Failing after 2m37s
build / lint (push) Successful in 9m31s

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2024-04-04 16:36:48 +03:00
parent e02f291db2
commit 439d5cf125
2 changed files with 17 additions and 2 deletions

View File

@ -4,6 +4,7 @@ import (
"fmt" "fmt"
"hash/fnv" "hash/fnv"
"io" "io"
"regexp"
"sync" "sync"
"time" "time"
@ -279,8 +280,10 @@ func (m *prometheusMeter) Write(w io.Writer, opts ...meter.Option) error {
} }
if options.WriteProcessMetrics || options.WriteFDMetrics { if options.WriteProcessMetrics || options.WriteFDMetrics {
c := collectors.NewProcessCollector(collectors.ProcessCollectorOpts{}) pc := collectors.NewProcessCollector(collectors.ProcessCollectorOpts{})
_ = m.set.Register(c) _ = m.set.Register(pc)
gc := collectors.NewGoCollector(collectors.WithGoCollectorRuntimeMetrics(collectors.GoRuntimeMetricsRule{Matcher: regexp.MustCompile("/.*")}))
_ = m.set.Register(gc)
} }
g, ok := m.set.(prometheus.Gatherer) g, ok := m.set.(prometheus.Gatherer)

View File

@ -11,6 +11,18 @@ import (
"go.unistack.org/micro/v3/meter/wrapper" "go.unistack.org/micro/v3/meter/wrapper"
) )
func TestStd(t *testing.T) {
m := NewMeter(meter.WriteProcessMetrics(true), meter.WriteFDMetrics(true))
if err := m.Init(); err != nil {
t.Fatal(err)
}
buf := bytes.NewBuffer(nil)
_ = m.Write(buf)
if !bytes.Contains(buf.Bytes(), []byte(`go_goroutine`)) {
t.Fatalf("invalid metrics output: %s", buf.Bytes())
}
}
func TestBuildName(t *testing.T) { func TestBuildName(t *testing.T) {
m := NewMeter() m := NewMeter()
check := `micro_foo{micro_aaa="b",micro_bar="baz",micro_ccc="d"}` check := `micro_foo{micro_aaa="b",micro_bar="baz",micro_ccc="d"}`