diff --git a/metrics/go.mod b/metrics/go.mod index 40360d9f7..e7f8f9e7a 100644 --- a/metrics/go.mod +++ b/metrics/go.mod @@ -3,10 +3,10 @@ module github.com/palantir/pkg/metrics go 1.24.0 require ( - github.com/palantir/go-metrics v1.1.1 + github.com/palantir/go-metrics v1.1.2-0.20250702225129-c6f3e150f585 github.com/palantir/pkg v1.1.0 github.com/palantir/pkg/objmatcher v1.1.0 - github.com/pkg/errors v0.8.1 + github.com/pkg/errors v0.9.1 github.com/stretchr/testify v1.10.0 ) diff --git a/metrics/go.sum b/metrics/go.sum index 78de4eecc..c36e6490a 100644 --- a/metrics/go.sum +++ b/metrics/go.sum @@ -1,13 +1,13 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/palantir/go-metrics v1.1.1 h1:YL/UmptBjrC6iSCTVr7vfuIcjL0M359Da3/gBGNny10= -github.com/palantir/go-metrics v1.1.1/go.mod h1:fRkuipBnsI4nD8Vd9UNcrUJvD8Y0wOJMSbicygcBrGs= +github.com/palantir/go-metrics v1.1.2-0.20250702225129-c6f3e150f585 h1:zMElUPb/81H1n/iCWohy8FJ74O6rNe7o5r9OYz8Lqnc= +github.com/palantir/go-metrics v1.1.2-0.20250702225129-c6f3e150f585/go.mod h1:fRkuipBnsI4nD8Vd9UNcrUJvD8Y0wOJMSbicygcBrGs= github.com/palantir/pkg v1.1.0 h1:0EhrSUP8oeeh3MUvk7V/UU7WmsN1UiJNTvNj0sN9Cpo= github.com/palantir/pkg v1.1.0/go.mod h1:KC9srP/9ssWRxBxFCIqhUGC4Jt7OJkWRz0Iqehup1/c= github.com/palantir/pkg/objmatcher v1.1.0 h1:bh/Set1mIL3sEJKIBbNr3afPg0PrvhPKY6deyGwGhZs= github.com/palantir/pkg/objmatcher v1.1.0/go.mod h1:sUFipHgtqogNOs9uir4Fbu8Nu+n3qTAEL2vfghIiwZ0= -github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I= -github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= +github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stathat/go v1.0.0/go.mod h1:+9Eg2szqkcOGWv6gfheJmBBsmq9Qf5KDbzy8/aYYR0c= diff --git a/metrics/registry.go b/metrics/registry.go index 7cbe84684..dd78cf00d 100644 --- a/metrics/registry.go +++ b/metrics/registry.go @@ -6,6 +6,7 @@ package metrics import ( "context" + "fmt" "strings" "sync" "time" @@ -261,6 +262,9 @@ func (r *childRegistry) Each(f MetricVisitor) { } func (r *childRegistry) Unregister(name string, tags ...Tag) { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Unregistering Metric...", name, tags) + } r.root.Unregister(r.prefix+name, append(r.tags, tags...)...) } @@ -324,6 +328,9 @@ func (r *rootRegistry) Unregister(name string, tags ...Tag) { // This must happen after the registry Unregister() above to preserve the correctness guarantees in Each() r.idToMetricMutex.Lock() + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Unregistering Metric from idToMetricWithTags...", name, tags, metricID) + } delete(r.idToMetricWithTags, metricID) r.idToMetricMutex.Unlock() } @@ -333,6 +340,9 @@ func (r *rootRegistry) Counter(name string, tags ...Tag) metrics.Counter { } func (r *rootRegistry) Gauge(name string, tags ...Tag) metrics.Gauge { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Registering Gauge...", name, tags) + } return metrics.GetOrRegisterGauge(r.registerMetric(name, tags), r.registry) } @@ -374,6 +384,9 @@ func getOrRegisterHistogram(name string, r metrics.Registry) metrics.Histogram { } func (r *rootRegistry) registerMetric(name string, tags Tags) string { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Registering Metric...", name, tags) + } sortedTags := newSortedTags(tags) metricID := toMetricTagsID(name, sortedTags) r.idToMetricMutex.Lock() @@ -382,6 +395,9 @@ func (r *rootRegistry) registerMetric(name string, tags Tags) string { tags: sortedTags, } r.idToMetricMutex.Unlock() + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Metric registered...", name, tags, metricID) + } return string(metricID) } diff --git a/metrics/vendor/github.com/palantir/go-metrics/.travis.yml b/metrics/vendor/github.com/palantir/go-metrics/.travis.yml index 3135e08f1..ce9afeaee 100644 --- a/metrics/vendor/github.com/palantir/go-metrics/.travis.yml +++ b/metrics/vendor/github.com/palantir/go-metrics/.travis.yml @@ -12,6 +12,8 @@ go: - "1.11" - "1.12" - "1.13" + - "1.14" + - "1.15" script: - ./validate.sh diff --git a/metrics/vendor/github.com/palantir/go-metrics/gauge.go b/metrics/vendor/github.com/palantir/go-metrics/gauge.go index cb57a9388..61858315a 100644 --- a/metrics/vendor/github.com/palantir/go-metrics/gauge.go +++ b/metrics/vendor/github.com/palantir/go-metrics/gauge.go @@ -1,6 +1,10 @@ package metrics -import "sync/atomic" +import ( + "fmt" + "strings" + "sync/atomic" +) // Gauges hold an int64 value that can be set arbitrarily. type Gauge interface { @@ -12,7 +16,11 @@ type Gauge interface { // GetOrRegisterGauge returns an existing Gauge or constructs and registers a // new StandardGauge. func GetOrRegisterGauge(name string, r Registry) Gauge { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Entering GetOrRegisterGauge", name) + } if nil == r { + fmt.Println("Nil registry, setting to default") r = DefaultRegistry } return r.GetOrRegister(name, NewGauge).(Gauge) diff --git a/metrics/vendor/github.com/palantir/go-metrics/registry.go b/metrics/vendor/github.com/palantir/go-metrics/registry.go index a8e67228a..2a1c7866c 100644 --- a/metrics/vendor/github.com/palantir/go-metrics/registry.go +++ b/metrics/vendor/github.com/palantir/go-metrics/registry.go @@ -83,24 +83,44 @@ func (r *StandardRegistry) Get(name string) interface{} { // The interface can be the metric to register if not found in registry, // or a function returning the metric for lazy instantiation. func (r *StandardRegistry) GetOrRegister(name string, i interface{}) interface{} { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Entering GetOrRegister", name) + } // access the read lock first which should be re-entrant r.mutex.RLock() metric, ok := r.metrics[name] r.mutex.RUnlock() if ok { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Found metric -- Round 1", name, metric) + } return metric } - + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Did not find metric -- Round 1", name) + } // only take the write lock if we'll be modifying the metrics map r.mutex.Lock() defer r.mutex.Unlock() if metric, ok := r.metrics[name]; ok { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Found metric -- Round 2", name, metric) + } return metric } + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Did not find metric -- Round 2", name) + } if v := reflect.ValueOf(i); v.Kind() == reflect.Func { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Calling function", name) + } i = v.Call(nil)[0].Interface() } r.register(name, i) + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Finished registering metric", name, i) + } return i } @@ -186,10 +206,16 @@ func (r *StandardRegistry) GetAll() map[string]map[string]interface{} { // Unregister the metric with the given name. func (r *StandardRegistry) Unregister(name string) { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Unregistering metric in StandardRegistry", name) + } r.mutex.Lock() defer r.mutex.Unlock() r.stop(name) delete(r.metrics, name) + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Finished unregistering metric", name) + } } // Unregister all metrics. (Mostly for testing.) @@ -203,11 +229,20 @@ func (r *StandardRegistry) UnregisterAll() { } func (r *StandardRegistry) register(name string, i interface{}) error { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Registering metric", name) + } if _, ok := r.metrics[name]; ok { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Duplicate metric error", name) + } return DuplicateMetric(name) } switch i.(type) { case Counter, Gauge, GaugeFloat64, Healthcheck, Histogram, Meter, Timer: + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Adding metric to map", name, i) + } r.metrics[name] = i } return nil @@ -232,8 +267,17 @@ func (r *StandardRegistry) registered() []metricKV { } func (r *StandardRegistry) stop(name string) { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Stopping metric", name) + } if i, ok := r.metrics[name]; ok { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Found metric to stop", name, i) + } if s, ok := i.(Stoppable); ok { + if strings.Contains(name, "signals.expected-state.beta.healthstatus.node.value.status") && strings.Contains(name, "rubix-node-agent") { + fmt.Println("Metric is stoppable. Going to stop", name) + } s.Stop() } } diff --git a/metrics/vendor/github.com/pkg/errors/.travis.yml b/metrics/vendor/github.com/pkg/errors/.travis.yml index d4b92663b..9159de03e 100644 --- a/metrics/vendor/github.com/pkg/errors/.travis.yml +++ b/metrics/vendor/github.com/pkg/errors/.travis.yml @@ -1,15 +1,10 @@ language: go go_import_path: github.com/pkg/errors go: - - 1.4.x - - 1.5.x - - 1.6.x - - 1.7.x - - 1.8.x - - 1.9.x - - 1.10.x - 1.11.x + - 1.12.x + - 1.13.x - tip script: - - go test -v ./... + - make check diff --git a/metrics/vendor/github.com/pkg/errors/README.md b/metrics/vendor/github.com/pkg/errors/README.md index 6483ba2af..54dfdcb12 100644 --- a/metrics/vendor/github.com/pkg/errors/README.md +++ b/metrics/vendor/github.com/pkg/errors/README.md @@ -41,11 +41,18 @@ default: [Read the package documentation for more information](https://godoc.org/github.com/pkg/errors). +## Roadmap + +With the upcoming [Go2 error proposals](https://go.googlesource.com/proposal/+/master/design/go2draft.md) this package is moving into maintenance mode. The roadmap for a 1.0 release is as follows: + +- 0.9. Remove pre Go 1.9 and Go 1.10 support, address outstanding pull requests (if possible) +- 1.0. Final release. + ## Contributing -We welcome pull requests, bug fixes and issue reports. With that said, the bar for adding new symbols to this package is intentionally set high. +Because of the Go2 errors changes, this package is not accepting proposals for new functionality. With that said, we welcome pull requests, bug fixes and issue reports. -Before proposing a change, please discuss your change by raising an issue. +Before sending a PR, please discuss your change by raising an issue. ## License diff --git a/metrics/vendor/github.com/pkg/errors/errors.go b/metrics/vendor/github.com/pkg/errors/errors.go index 7421f326f..161aea258 100644 --- a/metrics/vendor/github.com/pkg/errors/errors.go +++ b/metrics/vendor/github.com/pkg/errors/errors.go @@ -82,7 +82,7 @@ // // if err, ok := err.(stackTracer); ok { // for _, f := range err.StackTrace() { -// fmt.Printf("%+s:%d", f) +// fmt.Printf("%+s:%d\n", f, f) // } // } // @@ -159,6 +159,9 @@ type withStack struct { func (w *withStack) Cause() error { return w.error } +// Unwrap provides compatibility for Go 1.13 error chains. +func (w *withStack) Unwrap() error { return w.error } + func (w *withStack) Format(s fmt.State, verb rune) { switch verb { case 'v': @@ -241,6 +244,9 @@ type withMessage struct { func (w *withMessage) Error() string { return w.msg + ": " + w.cause.Error() } func (w *withMessage) Cause() error { return w.cause } +// Unwrap provides compatibility for Go 1.13 error chains. +func (w *withMessage) Unwrap() error { return w.cause } + func (w *withMessage) Format(s fmt.State, verb rune) { switch verb { case 'v': diff --git a/metrics/vendor/github.com/pkg/errors/stack.go b/metrics/vendor/github.com/pkg/errors/stack.go index 2874a048c..779a8348f 100644 --- a/metrics/vendor/github.com/pkg/errors/stack.go +++ b/metrics/vendor/github.com/pkg/errors/stack.go @@ -5,10 +5,13 @@ import ( "io" "path" "runtime" + "strconv" "strings" ) // Frame represents a program counter inside a stack frame. +// For historical reasons if Frame is interpreted as a uintptr +// its value represents the program counter + 1. type Frame uintptr // pc returns the program counter for this frame; @@ -37,6 +40,15 @@ func (f Frame) line() int { return line } +// name returns the name of this function, if known. +func (f Frame) name() string { + fn := runtime.FuncForPC(f.pc()) + if fn == nil { + return "unknown" + } + return fn.Name() +} + // Format formats the frame according to the fmt.Formatter interface. // // %s source file @@ -54,22 +66,16 @@ func (f Frame) Format(s fmt.State, verb rune) { case 's': switch { case s.Flag('+'): - pc := f.pc() - fn := runtime.FuncForPC(pc) - if fn == nil { - io.WriteString(s, "unknown") - } else { - file, _ := fn.FileLine(pc) - fmt.Fprintf(s, "%s\n\t%s", fn.Name(), file) - } + io.WriteString(s, f.name()) + io.WriteString(s, "\n\t") + io.WriteString(s, f.file()) default: io.WriteString(s, path.Base(f.file())) } case 'd': - fmt.Fprintf(s, "%d", f.line()) + io.WriteString(s, strconv.Itoa(f.line())) case 'n': - name := runtime.FuncForPC(f.pc()).Name() - io.WriteString(s, funcname(name)) + io.WriteString(s, funcname(f.name())) case 'v': f.Format(s, 's') io.WriteString(s, ":") @@ -77,6 +83,16 @@ func (f Frame) Format(s fmt.State, verb rune) { } } +// MarshalText formats a stacktrace Frame as a text string. The output is the +// same as that of fmt.Sprintf("%+v", f), but without newlines or tabs. +func (f Frame) MarshalText() ([]byte, error) { + name := f.name() + if name == "unknown" { + return []byte(name), nil + } + return []byte(fmt.Sprintf("%s %s:%d", name, f.file(), f.line())), nil +} + // StackTrace is stack of Frames from innermost (newest) to outermost (oldest). type StackTrace []Frame @@ -94,16 +110,30 @@ func (st StackTrace) Format(s fmt.State, verb rune) { switch { case s.Flag('+'): for _, f := range st { - fmt.Fprintf(s, "\n%+v", f) + io.WriteString(s, "\n") + f.Format(s, verb) } case s.Flag('#'): fmt.Fprintf(s, "%#v", []Frame(st)) default: - fmt.Fprintf(s, "%v", []Frame(st)) + st.formatSlice(s, verb) } case 's': - fmt.Fprintf(s, "%s", []Frame(st)) + st.formatSlice(s, verb) + } +} + +// formatSlice will format this StackTrace into the given buffer as a slice of +// Frame, only valid when called with '%s' or '%v'. +func (st StackTrace) formatSlice(s fmt.State, verb rune) { + io.WriteString(s, "[") + for i, f := range st { + if i > 0 { + io.WriteString(s, " ") + } + f.Format(s, verb) } + io.WriteString(s, "]") } // stack represents a stack of program counters. diff --git a/metrics/vendor/modules.txt b/metrics/vendor/modules.txt index aca6f24bf..967916270 100644 --- a/metrics/vendor/modules.txt +++ b/metrics/vendor/modules.txt @@ -1,7 +1,7 @@ # github.com/davecgh/go-spew v1.1.1 ## explicit github.com/davecgh/go-spew/spew -# github.com/palantir/go-metrics v1.1.1 +# github.com/palantir/go-metrics v1.1.2-0.20250702225129-c6f3e150f585 ## explicit; go 1.13 github.com/palantir/go-metrics # github.com/palantir/pkg v1.1.0 @@ -10,7 +10,7 @@ github.com/palantir/pkg # github.com/palantir/pkg/objmatcher v1.1.0 ## explicit; go 1.19 github.com/palantir/pkg/objmatcher -# github.com/pkg/errors v0.8.1 +# github.com/pkg/errors v0.9.1 ## explicit github.com/pkg/errors # github.com/pmezard/go-difflib v1.0.0