diff --git a/go.mod b/go.mod index 054fe12c..cc44be45 100644 --- a/go.mod +++ b/go.mod @@ -1,17 +1,19 @@ module github.com/uber-go/tally/v7 -go 1.20 +go 1.26.0 require ( github.com/cactus/go-statsd-client/v5 v5.0.0 github.com/golang/mock v1.6.0 + github.com/open-telemetry/opentelemetry-collector-contrib/pkg/expohisto v0.163.0 github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.11.0 github.com/prometheus/client_model v0.2.0 - github.com/stretchr/testify v1.9.0 + github.com/stretchr/testify v1.12.1 github.com/twmb/murmur3 v1.1.8 go.uber.org/atomic v1.11.0 go.uber.org/goleak v1.3.0 + google.golang.org/protobuf v1.36.12 gopkg.in/validator.v2 v2.0.0-20200605151824-2b28d334fa05 gopkg.in/yaml.v2 v2.4.0 ) @@ -19,13 +21,10 @@ require ( require ( github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/golang/protobuf v1.4.3 // indirect + github.com/golang/protobuf v1.5.0 // indirect github.com/matttproud/golang_protobuf_extensions v1.0.1 // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/common v0.26.0 // indirect github.com/prometheus/procfs v0.6.0 // indirect + go.yaml.in/yaml/v3 v3.0.5 // indirect golang.org/x/sys v0.0.0-20210603081109-ebe580a85c40 // indirect - google.golang.org/protobuf v1.26.0-rc.1 // indirect - gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index fd2d328f..219d1171 100644 --- a/go.sum +++ b/go.sum @@ -10,12 +10,10 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/cactus/go-statsd-client/v5 v5.0.0 h1:KqvIQtc9qt34uq+nu4nd1PwingWfBt/IISgtUQ2nSJk= github.com/cactus/go-statsd-client/v5 v5.0.0/go.mod h1:COEvJ1E+/E2L4q6QE5CkjWPi4eeDw9maJBMIuMPBZbY= -github.com/cespare/xxhash/v2 v2.1.1 h1:6MnRN8NT7+YBpUIWxHtefFZOKTAPgGjpQSxqLNn0+qY= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -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/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= github.com/go-kit/kit v0.9.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as= @@ -36,14 +34,16 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= -github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0 h1:LUVKkCeviFUMKqHa4tXIIij/lbhnMbP7Fn5wKdKkRh4= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX5e0EB2j4= @@ -68,11 +68,12 @@ github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lN github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/expohisto v0.163.0 h1:A0ePxZDbW4AAf/A+b7SJ2Op/E1fJTcRI/Zc1lMNfqco= +github.com/open-telemetry/opentelemetry-collector-contrib/pkg/expohisto v0.163.0/go.mod h1:xFPRb3HfuJwOU/DKbIMF+xYMyF92AsOoqJouG9iXm+s= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= 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/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw= github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo= @@ -97,28 +98,20 @@ github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6Mwd github.com/sirupsen/logrus v1.6.0/go.mod h1:7uNnSEd1DgxDLC74fIahvMZmmYsHGZGEOFrfsX/uA88= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk= -github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= -github.com/twmb/murmur3 v1.1.5 h1:i9OLS9fkuLzBXjt6dptlAEyk58fJsSTXbRg3SgVyqgk= -github.com/twmb/murmur3 v1.1.5/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ= +github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= +github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= github.com/twmb/murmur3 v1.1.8 h1:8Yt9taO/WN3l08xErzjeschgZU2QSrwm1kclYq+0aRg= github.com/twmb/murmur3 v1.1.8/go.mod h1:Qq/R7NUyOfr65zD+6Q5IHKsJLwP7exErjN6lyyq3OSQ= github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k= -go.uber.org/atomic v1.7.0 h1:ADUqmZGgLDDfbSL9ZmPxKTybcoEYHgpYfELNoN+7hsw= -go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= -go.uber.org/goleak v1.2.1 h1:NBol2c7O1ZokfZ0LEU9K6Whx/KnwvepVetCUhtKja4A= -go.uber.org/goleak v1.2.1/go.mod h1:qlT2yGI9QafXHhZZLxlSuNsMw3FFLxBr+tBRlmO1xH4= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= +go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= @@ -164,7 +157,6 @@ golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= @@ -173,8 +165,9 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= -google.golang.org/protobuf v1.26.0-rc.1 h1:7QnIQpGRHE5RnLKnESfDoxm2dTapTZua5a0kS0A+VXQ= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= +google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo= @@ -188,6 +181,3 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= -gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/m3/reporter.go b/m3/reporter.go index 8b4676b4..498da690 100644 --- a/m3/reporter.go +++ b/m3/reporter.go @@ -94,6 +94,7 @@ const ( counterType metricType = iota + 1 timerType gaugeType + sketchType ) var ( @@ -457,16 +458,17 @@ func (r *reporter) AllocateHistogram( // AllocateNativeHistogram implements tally.CachedStatsReporter. // -// The M3 thrift wire format carries only count, gauge and timer values, so -// there is no field a serialized native histogram payload can travel in. -// Rather than silently discard them, the returned handle counts every dropped -// report into tally.internal.num-native-histograms-dropped. +// Each payload is sent as a SKETCH metric. maxBuckets is not used, because the +// accumulator that produces the payload already applies it. func (r *reporter) AllocateNativeHistogram( name string, tags map[string]string, maxBuckets int, ) tally.CachedNativeHistogram { - return cachedNativeHistogram{reporter: r} + return cachedNativeHistogram{ + metric: r.newMetric(name, tags, sketchType), + reporter: r, + } } func (r *reporter) valueBucketString(v float64) string { @@ -512,6 +514,8 @@ func (r *reporter) newMetric( case timerType: m.Value.MetricType = m3thrift.MetricType_TIMER m.Value.Timer = _maxInt64 + case sketchType: + m.Value.MetricType = m3thrift.MetricType_SKETCH } if len(tags) == 0 { @@ -679,9 +683,11 @@ func (r *reporter) flush(mets []m3thrift.Metric) []m3thrift.Metric { // n.b. In the event that we had allocated additional tag storage in // process(), clear it so that it can be reclaimed. This does not - // affect allocated metrics' tags. + // affect allocated metrics' tags. Sketch payloads are cleared for the + // same reason. for i := range mets { mets[i].Tags = nil + mets[i].Value.Sketch = nil } return mets[:0] } @@ -729,9 +735,9 @@ func (r *reporter) reportInternalMetrics() { r.numWriteErrorsCounter.ReportCount(writeErrors) r.numTagCacheCounter.ReportCount(int64(r.tagCache.Len())) - // Reported only when non-zero. Emitting it unconditionally would add a - // permanently-zero series to every m3 reporter in a fleet, since almost - // no caller uses native histograms with this reporter. + // Reported only when non-zero. Only a payload too large for one packet + // is dropped, so emitting it unconditionally would add a series that is + // almost always zero to every m3 reporter in a fleet. if dropped := r.numNativeHistogramsDropped.Swap(0); dropped > 0 { r.numNativeHistogramsDroppedCounter.ReportCount(dropped) } @@ -771,14 +777,30 @@ func (c cachedMetric) ReportTimer(interval time.Duration) { c.reporter.reportCopyMetric(c.metric, c.size, "", "") } -// cachedNativeHistogram discards native histogram payloads, which the M3 -// thrift wire format cannot represent, and counts the drops. +// cachedNativeHistogram sends each native histogram payload as a SKETCH +// metric. type cachedNativeHistogram struct { + metric m3thrift.Metric reporter *reporter } +// ReportNativeHistogram computes the size of each report separately, because +// the payload size changes from one interval to the next. A payload that does +// not fit in one packet is dropped and counted into +// tally.internal.num-native-histograms-dropped. func (c cachedNativeHistogram) ReportNativeHistogram(payload []byte, samples uint64) { - c.reporter.numNativeHistogramsDropped.Inc() + if len(payload) == 0 { + return + } + + c.metric.Value.Sketch = payload + size := c.reporter.calculateSize(c.metric) + if size > c.reporter.freeBytes { + c.reporter.numNativeHistogramsDropped.Inc() + return + } + + c.reporter.reportCopyMetric(c.metric, size, "", "") } type noopMetric struct{} diff --git a/m3/reporter_test.go b/m3/reporter_test.go index 6e163983..4bac4208 100644 --- a/m3/reporter_test.go +++ b/m3/reporter_test.go @@ -22,6 +22,7 @@ package m3 import ( "bytes" + "fmt" "math/rand" "net" "os" @@ -186,6 +187,137 @@ func TestMetricBatchClientLibraryNameRoundTrip(t *testing.T) { } } +func TestMetricValueSketchRoundTrip(t *testing.T) { + tests := []struct { + desc string + sketch []byte + }{ + {desc: "set", sketch: []byte{0x10, 0x01, 0x18, 0x01}}, + {desc: "unset", sketch: nil}, + } + + factories := map[string]thrift.TProtocolFactory{ + "binary": thrift.NewTBinaryProtocolFactoryDefault(), + "compact": thrift.NewTCompactProtocolFactory(), + } + + for protoName, factory := range factories { + for _, tt := range tests { + t.Run(protoName+"/"+tt.desc, func(t *testing.T) { + var ( + buf = thrift.NewTMemoryBuffer() + proto = factory.GetProtocol(buf) + in = m3thrift.MetricValue{ + MetricType: m3thrift.MetricType_SKETCH, + Sketch: tt.sketch, + } + out m3thrift.MetricValue + ) + require.NoError(t, in.Write(proto)) + require.NoError(t, out.Read(proto)) + require.Equal(t, m3thrift.MetricType_SKETCH, out.GetMetricType()) + require.Equal(t, tt.sketch != nil, out.IsSetSketch()) + require.Equal(t, tt.sketch, out.GetSketch()) + }) + } + } +} + +func TestReporterNativeHistogram(t *testing.T) { + for _, protocol := range protocols { + t.Run(fmt.Sprintf("protocol=%d", protocol), func(t *testing.T) { + var wg sync.WaitGroup + server := newFakeM3Server(t, &wg, false, protocol) + go server.Serve() + defer server.Close() + + r, err := NewReporter(Options{ + HostPorts: []string{server.Addr}, + Service: "test-service", + CommonTags: defaultCommonTags, + Protocol: protocol, + MaxQueueSize: queueSize, + MaxPacketSizeBytes: maxPacketSize, + }) + require.NoError(t, err) + defer func() { + assert.NoError(t, r.Close()) + }() + + tags := map[string]string{"testTag": "TestValue"} + h := r.AllocateNativeHistogram("my-native-histogram", tags, 160) + + // An empty payload is not sent. + h.ReportNativeHistogram(nil, 0) + + first := []byte{0x10, 0x02, 0x18, 0x02} + second := bytes.Repeat([]byte{0xab}, 300) + + // The payloads and the internal metrics can need more than one + // packet, so the test counts metrics and not batches. + wg.Add(2 + internalMetrics) + h.ReportNativeHistogram(first, 2) + h.ReportNativeHistogram(second, 7) + r.Flush() + wg.Wait() + + var sketches []m3thrift.Metric + for _, m := range server.Service.getMetrics() { + if m.GetName() == "my-native-histogram" { + sketches = append(sketches, m) + } + } + require.Len(t, sketches, 2) + + for i, want := range [][]byte{first, second} { + m := sketches[i] + require.Equal(t, m3thrift.MetricType_SKETCH, m.Value.MetricType) + require.Equal(t, want, m.Value.Sketch) + require.True(t, tagEquals(m.GetTags(), "testTag", "TestValue")) + } + }) + } +} + +func TestReporterNativeHistogramTooLargeIsDropped(t *testing.T) { + var wg sync.WaitGroup + server := newFakeM3Server(t, &wg, false, Compact) + go server.Serve() + defer server.Close() + + maxPacketSize := int32(1440) + r, err := NewReporter(Options{ + HostPorts: []string{server.Addr}, + Service: "test-service", + CommonTags: defaultCommonTags, + MaxQueueSize: queueSize, + MaxPacketSizeBytes: maxPacketSize, + }) + require.NoError(t, err) + defer r.Close() + + r.AllocateNativeHistogram("too-large", nil, 160). + ReportNativeHistogram(make([]byte, maxPacketSize), 1) + + wg.Add(internalMetrics + 1) + r.Flush() + wg.Wait() + + var dropped []m3thrift.Metric + for _, m := range server.Service.getMetrics() { + require.NotEqual(t, "too-large", m.GetName()) + if m.GetName() == "tally.internal.num-native-histograms-dropped" { + dropped = append(dropped, m) + } + } + require.Len(t, dropped, 1) + require.Equal(t, int64(1), dropped[0].Value.Count) + + for _, packet := range server.Packets() { + require.Less(t, len(packet), int(maxPacketSize)) + } +} + func TestMultiReporter(t *testing.T) { dests := []string{"127.0.0.1:9052", "127.0.0.1:9053"} commonTags := map[string]string{ @@ -422,6 +554,7 @@ func TestBatchSizes(t *testing.T) { counters = make(map[string]tally.CachedCount) gauges = make(map[string]tally.CachedGauge) timers = make(map[string]tally.CachedTimer) + sketches = make(map[string]tally.CachedNativeHistogram) randTags = func() map[string]string { return map[string]string{ "t1": "val" + strconv.Itoa(rand.Intn(10000)), @@ -429,7 +562,7 @@ func TestBatchSizes(t *testing.T) { } ) for atomic.LoadUint32(&stop) == 0 { - metTypeRand := rand.Intn(9) + metTypeRand := rand.Intn(12) name := "size.test.metric.name" + strconv.Itoa(rand.Intn(50)) if metTypeRand <= 2 { @@ -444,12 +577,19 @@ func TestBatchSizes(t *testing.T) { gauges[name] = r.AllocateGauge(name, randTags()) } gauges[name].ReportGauge(rand.Float64() * 10000) - } else { + } else if metTypeRand <= 8 { _, ok := timers[name] if !ok { timers[name] = r.AllocateTimer(name, randTags()) } timers[name].ReportTimer(time.Duration(rand.Int63n(10000))) + } else { + _, ok := sketches[name] + if !ok { + sketches[name] = r.AllocateNativeHistogram(name, randTags(), 160) + } + payload := make([]byte, 1+rand.Intn(600)) + sketches[name].ReportNativeHistogram(payload, 1) } } r.Close() diff --git a/m3/scope_test.go b/m3/scope_test.go index bca19460..6062f054 100644 --- a/m3/scope_test.go +++ b/m3/scope_test.go @@ -27,6 +27,7 @@ import ( "github.com/stretchr/testify/require" tally "github.com/uber-go/tally/v7" + m3thrift "github.com/uber-go/tally/v7/m3/thrift/v2" ) var commonTags = map[string]string{"env": "test"} @@ -113,6 +114,38 @@ func TestScopeCounter(t *testing.T) { require.Equal(t, "honk.foobar", emittedMetrics[cardinalityMetrics].GetName()) } +// TestScopeNativeHistogram tests that a scope with the default native +// histogram factory sends a SKETCH metric. +func TestScopeNativeHistogram(t *testing.T) { + var wg sync.WaitGroup + server := newFakeM3Server(t, &wg, false, Compact) + go server.Serve() + defer server.Close() + + tags := map[string]string{"testTag": "TestValue", "testTag2": "TestValue2"} + + _, scope, close := newTestReporterScope(t, server.Addr, "honk", tags) + + // The sketch payload pushes the final report over one packet, so the + // test counts metrics and not batches. + wg.Add(internalMetrics + cardinalityMetrics + 1) + h := scope.NativeDurationHistogram("latency") + h.RecordDuration(5 * time.Millisecond) + h.RecordDuration(50 * time.Millisecond) + close() + wg.Wait() + + var sketches []m3thrift.Metric + for _, m := range server.Service.getMetrics() { + if m.Value.MetricType == m3thrift.MetricType_SKETCH { + sketches = append(sketches, m) + } + } + require.Len(t, sketches, 1) + require.Equal(t, "honk.latency", sketches[0].GetName()) + require.NotEmpty(t, sketches[0].Value.Sketch) +} + // TestScopeGauge tests that scope works as expected func TestScopeGauge(t *testing.T) { var wg sync.WaitGroup diff --git a/m3/thrift/thrift.diff b/m3/thrift/thrift.diff index a45ec974..110af6dd 100644 --- a/m3/thrift/thrift.diff +++ b/m3/thrift/thrift.diff @@ -66,10 +66,10 @@ index f8a4434..0da14bd 100644 return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Batch), err) } diff --git a/m3/thrift/v2/ttypes.go b/m3/thrift/v2/ttypes.go -index 759107c..ae8b68c 100644 +index 4f6c63c..b381934 100644 --- a/m3/thrift/v2/ttypes.go +++ b/m3/thrift/v2/ttypes.go -@@ -429,10 +429,10 @@ func (p *MetricTag) String() string { +@@ -476,10 +476,10 @@ func (p *MetricTag) String() string { // - Timestamp // - Tags type Metric struct { @@ -84,7 +84,7 @@ index 759107c..ae8b68c 100644 } func NewMetric() *Metric { -@@ -443,9 +443,9 @@ func (p *Metric) GetName() string { +@@ -490,9 +490,9 @@ func (p *Metric) GetName() string { return p.Name } @@ -96,7 +96,7 @@ index 759107c..ae8b68c 100644 if !p.IsSetValue() { return Metric_Value_DEFAULT } -@@ -456,13 +456,13 @@ func (p *Metric) GetTimestamp() int64 { +@@ -503,13 +503,13 @@ func (p *Metric) GetTimestamp() int64 { return p.Timestamp } @@ -113,7 +113,7 @@ index 759107c..ae8b68c 100644 } func (p *Metric) IsSetTags() bool { -@@ -540,7 +540,7 @@ func (p *Metric) readField1(iprot thrift.TProtocol) error { +@@ -587,7 +587,7 @@ func (p *Metric) readField1(iprot thrift.TProtocol) error { } func (p *Metric) readField2(iprot thrift.TProtocol) error { @@ -122,7 +122,7 @@ index 759107c..ae8b68c 100644 if err := p.Value.Read(iprot); err != nil { return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", p.Value), err) } -@@ -561,10 +561,10 @@ func (p *Metric) readField4(iprot thrift.TProtocol) error { +@@ -608,10 +608,10 @@ func (p *Metric) readField4(iprot thrift.TProtocol) error { if err != nil { return thrift.PrependError("error reading list begin: ", err) } @@ -135,7 +135,7 @@ index 759107c..ae8b68c 100644 if err := _elem0.Read(iprot); err != nil { return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem0), err) } -@@ -675,22 +675,22 @@ func (p *Metric) String() string { +@@ -722,22 +722,22 @@ func (p *Metric) String() string { // - CommonTags // - ClientLibraryName type MetricBatch struct { @@ -164,7 +164,7 @@ index 759107c..ae8b68c 100644 return p.CommonTags } -@@ -762,10 +762,10 @@ func (p *MetricBatch) readField1(iprot thrift.TProtocol) error { +@@ -809,10 +809,10 @@ func (p *MetricBatch) readField1(iprot thrift.TProtocol) error { if err != nil { return thrift.PrependError("error reading list begin: ", err) } @@ -177,7 +177,7 @@ index 759107c..ae8b68c 100644 if err := _elem1.Read(iprot); err != nil { return thrift.PrependError(fmt.Sprintf("%T error reading struct: ", _elem1), err) } -@@ -782,10 +782,10 @@ func (p *MetricBatch) readField2(iprot thrift.TProtocol) error { +@@ -829,10 +829,10 @@ func (p *MetricBatch) readField2(iprot thrift.TProtocol) error { if err != nil { return thrift.PrependError("error reading list begin: ", err) } diff --git a/m3/thrift/v2/ttypes.go b/m3/thrift/v2/ttypes.go index ae8b68cc..b381934b 100644 --- a/m3/thrift/v2/ttypes.go +++ b/m3/thrift/v2/ttypes.go @@ -23,6 +23,7 @@ const ( MetricType_COUNTER MetricType = 1 MetricType_GAUGE MetricType = 2 MetricType_TIMER MetricType = 3 + MetricType_SKETCH MetricType = 4 ) func (p MetricType) String() string { @@ -35,6 +36,8 @@ func (p MetricType) String() string { return "GAUGE" case MetricType_TIMER: return "TIMER" + case MetricType_SKETCH: + return "SKETCH" } return "" } @@ -49,6 +52,8 @@ func MetricTypeFromString(s string) (MetricType, error) { return MetricType_GAUGE, nil case "TIMER": return MetricType_TIMER, nil + case "SKETCH": + return MetricType_SKETCH, nil } return MetricType(0), fmt.Errorf("not a valid MetricType string") } @@ -73,11 +78,13 @@ func (p *MetricType) UnmarshalText(text []byte) error { // - Count // - Gauge // - Timer +// - Sketch type MetricValue struct { MetricType MetricType `thrift:"metricType,1,required" json:"metricType"` Count int64 `thrift:"count,2,required" json:"count"` Gauge float64 `thrift:"gauge,3,required" json:"gauge"` Timer int64 `thrift:"timer,4,required" json:"timer"` + Sketch []byte `thrift:"sketch,5" json:"sketch,omitempty"` } func NewMetricValue() *MetricValue { @@ -99,6 +106,15 @@ func (p *MetricValue) GetGauge() float64 { func (p *MetricValue) GetTimer() int64 { return p.Timer } + +var MetricValue_Sketch_DEFAULT []byte + +func (p *MetricValue) GetSketch() []byte { + return p.Sketch +} +func (p *MetricValue) IsSetSketch() bool { + return p.Sketch != nil +} func (p *MetricValue) Read(iprot thrift.TProtocol) error { if _, err := iprot.ReadStructBegin(); err != nil { return thrift.PrependError(fmt.Sprintf("%T read error: ", p), err) @@ -138,6 +154,10 @@ func (p *MetricValue) Read(iprot thrift.TProtocol) error { return err } issetTimer = true + case 5: + if err := p.readField5(iprot); err != nil { + return err + } default: if err := iprot.Skip(fieldTypeId); err != nil { return err @@ -202,6 +222,15 @@ func (p *MetricValue) readField4(iprot thrift.TProtocol) error { return nil } +func (p *MetricValue) readField5(iprot thrift.TProtocol) error { + if v, err := iprot.ReadBinary(); err != nil { + return thrift.PrependError("error reading field 5: ", err) + } else { + p.Sketch = v + } + return nil +} + func (p *MetricValue) Write(oprot thrift.TProtocol) error { if err := oprot.WriteStructBegin("MetricValue"); err != nil { return thrift.PrependError(fmt.Sprintf("%T write struct begin error: ", p), err) @@ -218,6 +247,9 @@ func (p *MetricValue) Write(oprot thrift.TProtocol) error { if err := p.writeField4(oprot); err != nil { return err } + if err := p.writeField5(oprot); err != nil { + return err + } if err := oprot.WriteFieldStop(); err != nil { return thrift.PrependError("write field stop error: ", err) } @@ -279,6 +311,21 @@ func (p *MetricValue) writeField4(oprot thrift.TProtocol) (err error) { return err } +func (p *MetricValue) writeField5(oprot thrift.TProtocol) (err error) { + if p.IsSetSketch() { + if err := oprot.WriteFieldBegin("sketch", thrift.STRING, 5); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field begin error 5:sketch: ", p), err) + } + if err := oprot.WriteBinary(p.Sketch); err != nil { + return thrift.PrependError(fmt.Sprintf("%T.sketch (5) field write error: ", p), err) + } + if err := oprot.WriteFieldEnd(); err != nil { + return thrift.PrependError(fmt.Sprintf("%T write field end error 5:sketch: ", p), err) + } + } + return err +} + func (p *MetricValue) String() string { if p == nil { return "" diff --git a/m3/thrift/v2/v2.thrift b/m3/thrift/v2/v2.thrift index c122eb3c..bb3a7ac1 100644 --- a/m3/thrift/v2/v2.thrift +++ b/m3/thrift/v2/v2.thrift @@ -3,6 +3,7 @@ enum MetricType { COUNTER = 1 GAUGE = 2 TIMER = 3 + SKETCH = 4 } struct MetricValue { @@ -10,6 +11,7 @@ struct MetricValue { 2: required i64 count 3: required double gauge 4: required i64 timer + 5: optional binary sketch } struct MetricTag { diff --git a/native_histogram.go b/native_histogram.go index 66b5d012..a03a6a92 100644 --- a/native_histogram.go +++ b/native_histogram.go @@ -31,16 +31,20 @@ import ( // default max size. const DefaultNativeHistogramMaxBuckets = 160 -// ErrNativeHistogramBackendNotConfigured is returned by MarshalBinary when a -// scope has no ScopeOptions.NativeHistogramFactory. Values are still counted, -// but there is no encoder to serialize them with, so nothing is reported. +// ErrNativeHistogramBackendNotConfigured was returned by MarshalBinary when a +// scope had no ScopeOptions.NativeHistogramFactory. +// +// Deprecated: A scope without a NativeHistogramFactory now uses an +// OpenTelemetry exponential histogram, so nothing returns this error. var ErrNativeHistogramBackendNotConfigured = errors.New( "native histogram backend not configured: " + "set ScopeOptions.NativeHistogramFactory", ) -// NativeHistogramData is a mergeable accumulator backing a NativeHistogram, -// supplied by the application through ScopeOptions.NativeHistogramFactory. +// NativeHistogramData is a mergeable accumulator backing a NativeHistogram. +// The default is an OpenTelemetry base-2 exponential histogram that marshals +// to the proto3 ExponentialHistogram message. An application can supply a +// different one through ScopeOptions.NativeHistogramFactory. // // Implementations need not be safe for concurrent use; the owning scope // serializes every call. MarshalBinary is expected to produce a self-describing @@ -205,30 +209,3 @@ func (h nativeDurationHistogram) RecordStopwatch(stopwatchStart time.Time) { d := globalNow().Sub(stopwatchStart) h.RecordDuration(d) } - -// defaultNativeHistogramData counts observations but cannot serialize them. -// It is what a scope falls back to when no NativeHistogramFactory is set, so -// that the native histogram methods are safe to call but emit nothing. -type defaultNativeHistogramData struct { - count uint64 -} - -func defaultNativeHistogramFactory(maxBuckets int) NativeHistogramData { - return &defaultNativeHistogramData{} -} - -func (d *defaultNativeHistogramData) Update(value float64) { - d.count++ -} - -func (d *defaultNativeHistogramData) Count() uint64 { - return d.count -} - -func (d *defaultNativeHistogramData) Clear() { - d.count = 0 -} - -func (d *defaultNativeHistogramData) MarshalBinary() ([]byte, error) { - return nil, ErrNativeHistogramBackendNotConfigured -} diff --git a/native_histogram_expohisto.go b/native_histogram_expohisto.go new file mode 100644 index 00000000..81c695df --- /dev/null +++ b/native_histogram_expohisto.go @@ -0,0 +1,198 @@ +// Copyright (c) 2026 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package tally + +import ( + "errors" + "math" + + "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/expohisto/structure" + "google.golang.org/protobuf/encoding/protowire" +) + +const ( + // maxNativeHistogramBuckets caps the bucket budget of the default + // accumulator. m3collector rejects a payload with more buckets than this + // on either side. + maxNativeHistogramBuckets = 160 + + // minNativeHistogramScale is the coarsest scale m3collector accepts. The + // accumulator only goes below it when its bucket budget is very small. + minNativeHistogramScale = -4 +) + +var errNativeHistogramScaleTooLow = errors.New( + "native histogram scale is below the minimum the encoding allows", +) + +// Field numbers of the ExponentialHistogram proto3 message that the default +// accumulator marshals to: +// +// message ExponentialHistogram { +// int32 scale = 1; +// uint64 count = 2; +// uint64 zero_count = 3; +// double sum = 4; +// double min = 5; +// double max = 6; +// ExponentialBuckets positive = 7; +// ExponentialBuckets negative = 8; +// } +// +// message ExponentialBuckets { +// sint32 offset = 1; +// repeated uint64 bucket_counts = 2; +// } +const ( + expoFieldScale protowire.Number = 1 + expoFieldCount protowire.Number = 2 + expoFieldZeroCount protowire.Number = 3 + expoFieldSum protowire.Number = 4 + expoFieldMin protowire.Number = 5 + expoFieldMax protowire.Number = 6 + expoFieldPositive protowire.Number = 7 + expoFieldNegative protowire.Number = 8 + + bucketsFieldOffset protowire.Number = 1 + bucketsFieldCounts protowire.Number = 2 +) + +// expoHistogramData is the default NativeHistogramData. It accumulates into an +// OpenTelemetry base-2 exponential histogram and marshals it as the proto3 +// ExponentialHistogram message above, which is the payload m3collector +// decodes. +type expoHistogramData struct { + hist structure.Float64 +} + +func newExpoHistogramData(maxBuckets int) NativeHistogramData { + // Init raises a budget below structure.MinSize on its own, so only the + // upper bound needs a clamp here. + maxBuckets = min(maxBuckets, maxNativeHistogramBuckets) + + d := &expoHistogramData{} + d.hist.Init(structure.NewConfig(structure.WithMaxSize(int32(maxBuckets)))) + return d +} + +// Update drops NaN and infinities. The histogram has no bucket for them, and +// they would make the sum and the bucket indexes invalid, so the receiver +// would reject the whole payload. +func (d *expoHistogramData) Update(value float64) { + if math.IsNaN(value) || math.IsInf(value, 0) { + return + } + d.hist.Update(value) +} + +func (d *expoHistogramData) Count() uint64 { + return d.hist.Count() +} + +func (d *expoHistogramData) Clear() { + d.hist.Clear() +} + +// MarshalBinary encodes the histogram as proto3, so fields with a zero value +// are left out. +func (d *expoHistogramData) MarshalBinary() ([]byte, error) { + h := &d.hist + + scale := h.Scale() + if scale < minNativeHistogramScale { + return nil, errNativeHistogramScaleTooLow + } + + positive, negative := h.Positive(), h.Negative() + + // Each count is a varint of at most 10 bytes. The fixed fields need at + // most 11 bytes each. + b := make([]byte, 0, 8*11+10*int(positive.Len()+negative.Len())) + + if scale != 0 { + // An int32 is sign-extended to 64 bits on the wire. + b = appendVarintField(b, expoFieldScale, uint64(int64(scale))) + } + b = appendVarintField(b, expoFieldCount, h.Count()) + b = appendVarintField(b, expoFieldZeroCount, h.ZeroCount()) + b = appendDoubleField(b, expoFieldSum, h.Sum()) + b = appendDoubleField(b, expoFieldMin, h.Min()) + b = appendDoubleField(b, expoFieldMax, h.Max()) + b = appendBucketsField(b, expoFieldPositive, positive) + b = appendBucketsField(b, expoFieldNegative, negative) + + return b, nil +} + +func appendVarintField(b []byte, num protowire.Number, v uint64) []byte { + if v == 0 { + return b + } + b = protowire.AppendTag(b, num, protowire.VarintType) + return protowire.AppendVarint(b, v) +} + +func appendDoubleField(b []byte, num protowire.Number, v float64) []byte { + bits := math.Float64bits(v) + if bits == 0 { + return b + } + b = protowire.AppendTag(b, num, protowire.Fixed64Type) + return protowire.AppendFixed64(b, bits) +} + +// appendBucketsField appends an ExponentialBuckets message. It sizes the +// message first, so it can write the length prefix without a second buffer. +func appendBucketsField( + b []byte, + num protowire.Number, + buckets *structure.Buckets, +) []byte { + n := buckets.Len() + if n == 0 { + return b + } + + countsLen := 0 + for i := uint32(0); i < n; i++ { + countsLen += protowire.SizeVarint(buckets.At(i)) + } + + offset := protowire.EncodeZigZag(int64(buckets.Offset())) + + msgLen := protowire.SizeTag(bucketsFieldCounts) + protowire.SizeBytes(countsLen) + if offset != 0 { + msgLen += protowire.SizeTag(bucketsFieldOffset) + protowire.SizeVarint(offset) + } + + b = protowire.AppendTag(b, num, protowire.BytesType) + b = protowire.AppendVarint(b, uint64(msgLen)) + + b = appendVarintField(b, bucketsFieldOffset, offset) + + b = protowire.AppendTag(b, bucketsFieldCounts, protowire.BytesType) + b = protowire.AppendVarint(b, uint64(countsLen)) + for i := uint32(0); i < n; i++ { + b = protowire.AppendVarint(b, buckets.At(i)) + } + + return b +} diff --git a/native_histogram_expohisto_test.go b/native_histogram_expohisto_test.go new file mode 100644 index 00000000..ce397e49 --- /dev/null +++ b/native_histogram_expohisto_test.go @@ -0,0 +1,319 @@ +// Copyright (c) 2026 Uber Technologies, Inc. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +package tally + +import ( + "math" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "google.golang.org/protobuf/encoding/protowire" +) + +type decodedBuckets struct { + offset int32 + counts []uint64 +} + +type decodedExpoHistogram struct { + scale int32 + count uint64 + zeroCount uint64 + sum float64 + min float64 + max float64 + positive decodedBuckets + negative decodedBuckets +} + +// decodeExpoHistogram decodes an ExponentialHistogram payload independently of +// the encoder, so the tests check the wire format and not only a round trip. +func decodeExpoHistogram(t *testing.T, b []byte) decodedExpoHistogram { + t.Helper() + + var h decodedExpoHistogram + for len(b) > 0 { + num, typ, n := protowire.ConsumeTag(b) + require.GreaterOrEqual(t, n, 0, "invalid tag") + b = b[n:] + + switch typ { + case protowire.VarintType: + v, n := protowire.ConsumeVarint(b) + require.GreaterOrEqual(t, n, 0, "invalid varint") + b = b[n:] + + switch num { + case expoFieldScale: + h.scale = int32(v) + case expoFieldCount: + h.count = v + case expoFieldZeroCount: + h.zeroCount = v + default: + t.Fatalf("unexpected varint field %d", num) + } + case protowire.Fixed64Type: + v, n := protowire.ConsumeFixed64(b) + require.GreaterOrEqual(t, n, 0, "invalid fixed64") + b = b[n:] + + switch num { + case expoFieldSum: + h.sum = math.Float64frombits(v) + case expoFieldMin: + h.min = math.Float64frombits(v) + case expoFieldMax: + h.max = math.Float64frombits(v) + default: + t.Fatalf("unexpected fixed64 field %d", num) + } + case protowire.BytesType: + v, n := protowire.ConsumeBytes(b) + require.GreaterOrEqual(t, n, 0, "invalid bytes") + b = b[n:] + + switch num { + case expoFieldPositive: + h.positive = decodeBuckets(t, v) + case expoFieldNegative: + h.negative = decodeBuckets(t, v) + default: + t.Fatalf("unexpected bytes field %d", num) + } + default: + t.Fatalf("unexpected wire type %d for field %d", typ, num) + } + } + + return h +} + +func decodeBuckets(t *testing.T, b []byte) decodedBuckets { + t.Helper() + + var d decodedBuckets + for len(b) > 0 { + num, typ, n := protowire.ConsumeTag(b) + require.GreaterOrEqual(t, n, 0, "invalid tag") + b = b[n:] + + switch { + case num == bucketsFieldOffset && typ == protowire.VarintType: + v, n := protowire.ConsumeVarint(b) + require.GreaterOrEqual(t, n, 0, "invalid varint") + b = b[n:] + d.offset = int32(protowire.DecodeZigZag(v)) + case num == bucketsFieldCounts && typ == protowire.BytesType: + packed, n := protowire.ConsumeBytes(b) + require.GreaterOrEqual(t, n, 0, "invalid bytes") + b = b[n:] + for len(packed) > 0 { + v, n := protowire.ConsumeVarint(packed) + require.GreaterOrEqual(t, n, 0, "invalid packed varint") + packed = packed[n:] + d.counts = append(d.counts, v) + } + default: + t.Fatalf("unexpected field %d with wire type %d", num, typ) + } + } + + return d +} + +func sumCounts(counts []uint64) uint64 { + var total uint64 + for _, c := range counts { + total += c + } + return total +} + +// m3collector rejects a payload whose count does not equal the zero count plus +// the bucket counts. +func assertCountInvariant(t *testing.T, h decodedExpoHistogram) { + t.Helper() + assert.Equal( + t, + h.count, + h.zeroCount+sumCounts(h.positive.counts)+sumCounts(h.negative.counts), + "count must equal zero count plus bucket counts", + ) +} + +func marshalExpo(t *testing.T, maxBuckets int, values ...float64) []byte { + t.Helper() + + d := newExpoHistogramData(maxBuckets) + for _, v := range values { + d.Update(v) + } + payload, err := d.MarshalBinary() + require.NoError(t, err) + return payload +} + +func TestExpoHistogramDataGoldenBytes(t *testing.T) { + tests := []struct { + name string + values []float64 + want []byte + }{ + { + // Scale() is 0 when every sample is zero, and proto3 leaves out + // the zero sum, min and max. + name: "zeros only", + values: []float64{0, 0, 0}, + want: []byte{ + 0x10, 0x03, // count = 3 + 0x18, 0x03, // zero_count = 3 + }, + }, + { + // One sample keeps the histogram at its maximum scale, 20. 1.0 + // is an exact power of two, so it lands in bucket -1. + name: "single positive", + values: []float64{1}, + want: []byte{ + 0x08, 0x14, // scale = 20 + 0x10, 0x01, // count = 1 + 0x21, 0, 0, 0, 0, 0, 0, 0xf0, 0x3f, // sum = 1.0 + 0x29, 0, 0, 0, 0, 0, 0, 0xf0, 0x3f, // min = 1.0 + 0x31, 0, 0, 0, 0, 0, 0, 0xf0, 0x3f, // max = 1.0 + 0x3a, 0x05, // positive, 5 bytes + 0x08, 0x01, // offset = zigzag(-1) + 0x12, 0x01, 0x01, // bucket_counts = [1] + }, + }, + { + name: "single negative", + values: []float64{-1}, + want: []byte{ + 0x08, 0x14, // scale = 20 + 0x10, 0x01, // count = 1 + 0x21, 0, 0, 0, 0, 0, 0, 0xf0, 0xbf, // sum = -1.0 + 0x29, 0, 0, 0, 0, 0, 0, 0xf0, 0xbf, // min = -1.0 + 0x31, 0, 0, 0, 0, 0, 0, 0xf0, 0xbf, // max = -1.0 + 0x42, 0x05, // negative, 5 bytes + 0x08, 0x01, // offset = zigzag(-1) + 0x12, 0x01, 0x01, // bucket_counts = [1] + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := marshalExpo(t, DefaultNativeHistogramMaxBuckets, tt.values...) + assert.Equal(t, tt.want, got) + }) + } +} + +// The input matches TestSketchPayloadRoundTrip in m3collector. +func TestExpoHistogramDataMixedValues(t *testing.T) { + payload := marshalExpo( + t, + DefaultNativeHistogramMaxBuckets, + 0.5, 1, 1.5, 2, 8, 64, 1024, 0, -3, + ) + h := decodeExpoHistogram(t, payload) + + // The positive values span 11 octaves. Scale 3 uses 8 buckets per octave + // and is the finest scale that fits in 160 buckets. + assert.Equal(t, int32(3), h.scale) + assert.Equal(t, uint64(9), h.count) + assert.Equal(t, uint64(1), h.zeroCount) + assert.Equal(t, 1098.0, h.sum) + assert.Equal(t, -3.0, h.min) + assert.Equal(t, 1024.0, h.max) + + // At scale 3, 0.5 maps to bucket -9 and 1024 maps to bucket 79. + assert.Equal(t, int32(-9), h.positive.offset) + assert.Len(t, h.positive.counts, 89) + assert.Equal(t, uint64(7), sumCounts(h.positive.counts)) + + // 3 maps to bucket ceil(8*log2(3)) - 1 = 12. + assert.Equal(t, int32(12), h.negative.offset) + assert.Equal(t, []uint64{1}, h.negative.counts) + + assertCountInvariant(t, h) +} + +func TestExpoHistogramDataDropsNaNAndInf(t *testing.T) { + d := newExpoHistogramData(DefaultNativeHistogramMaxBuckets) + + d.Update(math.NaN()) + d.Update(math.Inf(1)) + d.Update(math.Inf(-1)) + assert.Equal(t, uint64(0), d.Count()) + + d.Update(2) + assert.Equal(t, uint64(1), d.Count()) + + payload, err := d.MarshalBinary() + require.NoError(t, err) + + h := decodeExpoHistogram(t, payload) + assert.Equal(t, 2.0, h.sum) + assertCountInvariant(t, h) +} + +func TestExpoHistogramDataClampsMaxBuckets(t *testing.T) { + // The values span 200 octaves. Without the clamp, a budget of 1000 keeps + // scale 2 and uses 800 buckets. + values := make([]float64, 0, 2001) + for i := 0; i <= 2000; i++ { + values = append(values, math.Pow(2, float64(i)/10)) + } + + h := decodeExpoHistogram(t, marshalExpo(t, 1000, values...)) + + assert.LessOrEqual(t, len(h.positive.counts), maxNativeHistogramBuckets) + assert.Equal(t, uint64(len(values)), h.count) + assertCountInvariant(t, h) +} + +func TestExpoHistogramDataRejectsScaleBelowMinimum(t *testing.T) { + // Two buckets cannot cover 1e-300 to 1e300 above scale -4. + d := newExpoHistogramData(2) + d.Update(1e-300) + d.Update(1e300) + + payload, err := d.MarshalBinary() + assert.Nil(t, payload) + assert.ErrorIs(t, err, errNativeHistogramScaleTooLow) +} + +func TestExpoHistogramDataClear(t *testing.T) { + d := newExpoHistogramData(DefaultNativeHistogramMaxBuckets) + d.Update(1) + d.Update(-1) + d.Clear() + assert.Equal(t, uint64(0), d.Count()) + + d.Update(0) + payload, err := d.MarshalBinary() + require.NoError(t, err) + assert.Equal(t, []byte{0x10, 0x01, 0x18, 0x01}, payload, + "nothing from before Clear is encoded") +} diff --git a/native_histogram_test.go b/native_histogram_test.go index 0f3ea517..0ca1cea9 100644 --- a/native_histogram_test.go +++ b/native_histogram_test.go @@ -298,40 +298,23 @@ func TestNativeHistogramSnapshot(t *testing.T) { assert.Equal(t, uint64(3), h.snapshot()) } -func TestDefaultNativeHistogramData(t *testing.T) { - data := defaultNativeHistogramFactory(DefaultNativeHistogramMaxBuckets) - - assert.Equal(t, uint64(0), data.Count()) - - data.Update(1) - data.Update(2) - assert.Equal(t, uint64(2), data.Count()) - - payload, err := data.MarshalBinary() - assert.Nil(t, payload) - assert.ErrorIs(t, err, ErrNativeHistogramBackendNotConfigured) - - data.Clear() - assert.Equal(t, uint64(0), data.Count()) -} - -// Without a NativeHistogramFactory a scope's native histograms must accumulate -// harmlessly and never report, rather than panicking or emitting nonsense. -func TestDefaultNativeHistogramDataIsInert(t *testing.T) { +// A scope's native histograms default to the exponential histogram, so a +// value recorded without a factory is reported as a decodable payload. +func TestDefaultNativeHistogramFactory(t *testing.T) { acc := newNativeHistogram( - defaultNativeHistogramFactory(DefaultNativeHistogramMaxBuckets), + newExpoHistogramData(DefaultNativeHistogramMaxBuckets), nil, ) r := newStatsTestReporter() - nativeValueHistogram{acc}.RecordValue(1) - nativeDurationHistogram{acc}.RecordDuration(time.Second) - assert.Equal(t, uint64(2), acc.snapshot(), "values are still counted") - + nativeValueHistogram{acc}.RecordValue(4) acc.report("nh", nil, r) - assert.Nil(t, r.nativeHistogramPayload, "but nothing is reported") - assert.Equal(t, uint64(0), acc.snapshot(), "and the failed marshal clears") + require.NotNil(t, r.nativeHistogramPayload) + h := decodeExpoHistogram(t, r.nativeHistogramPayload) + assert.Equal(t, uint64(1), h.count) + assert.Equal(t, 4.0, h.sum) + assert.Equal(t, uint64(0), acc.snapshot(), "report drains") } func TestDefaultNativeHistogramMaxBucketsValue(t *testing.T) { @@ -472,8 +455,8 @@ func TestScopeNativeHistogramMaxBuckets(t *testing.T) { } } -// A scope with no NativeHistogramFactory must stay usable: values are counted -// but nothing is ever reported. +// A scope with no NativeHistogramFactory reports exponential histogram +// payloads. Durations are recorded as milliseconds. func TestScopeNativeHistogramWithoutFactory(t *testing.T) { r := newTestStatsReporter() @@ -485,20 +468,24 @@ func TestScopeNativeHistogramWithoutFactory(t *testing.T) { s := root.(*scope) - values := s.NativeValueHistogram("payload_bytes").(nativeValueHistogram) - durations := s.NativeDurationHistogram("latency").(nativeDurationHistogram) - values.RecordValue(1) - durations.RecordDuration(time.Second) - - require.Equal(t, uint64(1), values.snapshot(), "values are counted") - require.Equal(t, uint64(1), durations.snapshot()) + s.NativeValueHistogram("payload_bytes").RecordValue(512) + s.NativeDurationHistogram("latency").RecordDuration(time.Second) + r.nhg.Add(2) s.report(r) r.WaitAll() - assert.Empty(t, r.getNativeHistograms(), "but nothing is reported") - assert.Equal(t, uint64(0), values.snapshot(), "and the failed marshal clears") - assert.Equal(t, uint64(0), durations.snapshot()) + got := r.getNativeHistograms() + require.Len(t, got, 2) + + values := decodeExpoHistogram(t, got["payload_bytes"].payload) + assert.Equal(t, uint64(1), got["payload_bytes"].samples) + assert.Equal(t, uint64(1), values.count) + assert.Equal(t, 512.0, values.sum) + + durations := decodeExpoHistogram(t, got["latency"].payload) + assert.Equal(t, uint64(1), got["latency"].samples) + assert.Equal(t, 1000.0, durations.sum, "durations are milliseconds") } func TestScopeNativeHistogramSubscopesInheritFactory(t *testing.T) { diff --git a/prometheus/reporter.go b/prometheus/reporter.go index 0cc9e694..11c294ce 100644 --- a/prometheus/reporter.go +++ b/prometheus/reporter.go @@ -577,8 +577,8 @@ func (r *reporter) AllocateHistogram( // AllocateNativeHistogram implements tally.CachedStatsReporter. // // Prometheus has native histograms of its own, but tally hands this method an -// already-serialized payload in whatever encoding the application chose via -// ScopeOptions.NativeHistogramFactory. An opaque blob cannot be turned into a +// already-serialized payload, in the default encoding or in whatever encoding +// the application chose via ScopeOptions.NativeHistogramFactory. An opaque blob cannot be turned into a // prometheus.Collector, so there is nothing to register and the metric is // dropped. func (r *reporter) AllocateNativeHistogram( diff --git a/scope.go b/scope.go index 0f9893b4..cb09785e 100644 --- a/scope.go +++ b/scope.go @@ -118,9 +118,9 @@ type ScopeOptions struct { CardinalityMetricsTags map[string]string // NativeHistogramFactory supplies the accumulator backing each native - // histogram created on this scope and its subscopes. Leaving it nil makes - // the native histogram methods safe to call, but values are merely counted and - // never reported. + // histogram created on this scope and its subscopes. If it is nil, the + // scope uses an OpenTelemetry exponential histogram that marshals to the + // proto3 ExponentialHistogram message. NativeHistogramFactory func(maxBuckets int) NativeHistogramData // DefaultNativeHistogramMaxBuckets is the bucket budget for every native @@ -185,7 +185,7 @@ func newRootScope(opts ScopeOptions, interval time.Duration) *scope { } if opts.NativeHistogramFactory == nil { - opts.NativeHistogramFactory = defaultNativeHistogramFactory + opts.NativeHistogramFactory = newExpoHistogramData } if opts.DefaultNativeHistogramMaxBuckets < 1 { opts.DefaultNativeHistogramMaxBuckets = DefaultNativeHistogramMaxBuckets diff --git a/thirdparty/github.com/apache/thrift/lib/go/thrift/protocol_test.go b/thirdparty/github.com/apache/thrift/lib/go/thrift/protocol_test.go index 8d0696d6..ce3be642 100644 --- a/thirdparty/github.com/apache/thrift/lib/go/thrift/protocol_test.go +++ b/thirdparty/github.com/apache/thrift/lib/go/thrift/protocol_test.go @@ -237,20 +237,20 @@ func ReadWriteByte(t testing.TB, p TProtocol, trans TTransport) { for k, v := range BYTE_VALUES { err = p.WriteByte(v) if err != nil { - t.Errorf("%s: %T %T %q Error writing byte in list at index %d: %q", "ReadWriteByte", p, trans, err, k, v) + t.Errorf("%s: %T %T %q Error writing byte in list at index %d: %v", "ReadWriteByte", p, trans, err, k, v) } } err = p.WriteListEnd() if err != nil { - t.Errorf("%s: %T %T %q Error writing list end: %q", "ReadWriteByte", p, trans, err, BYTE_VALUES) + t.Errorf("%s: %T %T %q Error writing list end: %v", "ReadWriteByte", p, trans, err, BYTE_VALUES) } err = p.Flush() if err != nil { - t.Errorf("%s: %T %T %q Error flushing list of bytes: %q", "ReadWriteByte", p, trans, err, BYTE_VALUES) + t.Errorf("%s: %T %T %q Error flushing list of bytes: %v", "ReadWriteByte", p, trans, err, BYTE_VALUES) } thetype2, thelen2, err := p.ReadListBegin() if err != nil { - t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteByte", p, trans, err, BYTE_VALUES) + t.Errorf("%s: %T %T %q Error reading list: %v", "ReadWriteByte", p, trans, err, BYTE_VALUES) } _, ok := p.(*TSimpleJSONProtocol) if !ok { @@ -264,7 +264,7 @@ func ReadWriteByte(t testing.TB, p TProtocol, trans TTransport) { for k, v := range BYTE_VALUES { value, err := p.ReadByte() if err != nil { - t.Errorf("%s: %T %T %q Error reading byte at index %d: %q", "ReadWriteByte", p, trans, err, k, v) + t.Errorf("%s: %T %T %q Error reading byte at index %d: %v", "ReadWriteByte", p, trans, err, k, v) } if v != value { t.Errorf("%s: %T %T %d != %d", "ReadWriteByte", p, trans, v, value) @@ -287,7 +287,7 @@ func ReadWriteI16(t testing.TB, p TProtocol, trans TTransport) { p.Flush() thetype2, thelen2, err := p.ReadListBegin() if err != nil { - t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteI16", p, trans, err, INT16_VALUES) + t.Errorf("%s: %T %T %q Error reading list: %v", "ReadWriteI16", p, trans, err, INT16_VALUES) } _, ok := p.(*TSimpleJSONProtocol) if !ok { @@ -301,7 +301,7 @@ func ReadWriteI16(t testing.TB, p TProtocol, trans TTransport) { for k, v := range INT16_VALUES { value, err := p.ReadI16() if err != nil { - t.Errorf("%s: %T %T %q Error reading int16 at index %d: %q", "ReadWriteI16", p, trans, err, k, v) + t.Errorf("%s: %T %T %q Error reading int16 at index %d: %v", "ReadWriteI16", p, trans, err, k, v) } if v != value { t.Errorf("%s: %T %T %d != %d", "ReadWriteI16", p, trans, v, value) @@ -360,7 +360,7 @@ func ReadWriteI64(t testing.TB, p TProtocol, trans TTransport) { p.Flush() thetype2, thelen2, err := p.ReadListBegin() if err != nil { - t.Errorf("%s: %T %T %q Error reading list: %q", "ReadWriteI64", p, trans, err, INT64_VALUES) + t.Errorf("%s: %T %T %q Error reading list: %v", "ReadWriteI64", p, trans, err, INT64_VALUES) } _, ok := p.(*TSimpleJSONProtocol) if !ok { @@ -374,10 +374,10 @@ func ReadWriteI64(t testing.TB, p TProtocol, trans TTransport) { for k, v := range INT64_VALUES { value, err := p.ReadI64() if err != nil { - t.Errorf("%s: %T %T %q Error reading int64 at index %d: %q", "ReadWriteI64", p, trans, err, k, v) + t.Errorf("%s: %T %T %q Error reading int64 at index %d: %v", "ReadWriteI64", p, trans, err, k, v) } if v != value { - t.Errorf("%s: %T %T %q != %q", "ReadWriteI64", p, trans, v, value) + t.Errorf("%s: %T %T %v != %v", "ReadWriteI64", p, trans, v, value) } } if err != nil { diff --git a/tools/go.mod b/tools/go.mod index 9636c360..de1ca33c 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -1,16 +1,16 @@ module github.com/uber-go/tally/tools -go 1.18 +go 1.26.0 require ( golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 - honnef.co/go/tools v0.3.2 + honnef.co/go/tools v0.8.2 ) require ( - github.com/BurntSushi/toml v1.1.0 // indirect - golang.org/x/exp/typeparams v0.0.0-20220613132600-b0d781184e0d // indirect - golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect - golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c // indirect - golang.org/x/tools v0.1.11 // indirect + github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c // indirect + golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 // indirect + golang.org/x/mod v0.41.0 // indirect + golang.org/x/sync v0.23.0 // indirect + golang.org/x/tools v0.51.0 // indirect ) diff --git a/tools/go.sum b/tools/go.sum index 7e6b2dc0..1793bb4c 100644 --- a/tools/go.sum +++ b/tools/go.sum @@ -1,25 +1,29 @@ -github.com/BurntSushi/toml v1.1.0 h1:ksErzDEI1khOiGPgpwuI7x2ebx/uXQNw7xJpn9Eq1+I= -github.com/BurntSushi/toml v1.1.0/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c h1:pxW6RcqyfI9/kWtOwnv/G+AzdKuy2ZrqINhenH4HyNs= +github.com/BurntSushi/toml v1.4.1-0.20240526193622-a339e1f7089c/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= +github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= +github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= -golang.org/x/exp/typeparams v0.0.0-20220613132600-b0d781184e0d h1:+W8Qf4iJtMGKkyAygcKohjxTk4JPsL9DpzApJ22m5Ic= -golang.org/x/exp/typeparams v0.0.0-20220613132600-b0d781184e0d/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= +golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678 h1:1P7xPZEwZMoBoz0Yze5Nx2/4pxj6nw9ZqHWXqP0iRgQ= +golang.org/x/exp/typeparams v0.0.0-20231108232855-2478ac86f678/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616 h1:VLliZ0d+/avPrXXH+OakdXhpJuEoBZuwh1m2j7U6Iug= golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s= -golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c= +golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.23.0 h1:KameEIfc1IkluZyXWLn39Wd4tURc6GbCiISGiZm2bQk= +golang.org/x/sync v0.23.0/go.mod h1:sUUOizhqBxiL6pEWpqNLUiaJn1ShEbZ6BBqskPbjZm0= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c h1:aFV+BgZ4svzjfabn8ERpuB4JI4N6/rdy1iusx77G3oU= -golang.org/x/sys v0.0.0-20220615213510-4f61da869c0c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= -golang.org/x/tools v0.1.11 h1:loJ25fNOEhSXfHrpoGj91eCUThwdNX6u24rO1xnNteY= -golang.org/x/tools v0.1.11/go.mod h1:SgwaegtQh8clINPpECJMqnxLv9I09HLqnW3RMqW0CA4= +golang.org/x/tools v0.51.0 h1:k4Xc/1Om9jwkBJBo4NVLMSARBoWtK10mx+W5BnXCeAI= +golang.org/x/tools v0.51.0/go.mod h1:9eEncMayCV6zRMGhR5eZEC2iBx98qWcF1HZ9Z7wJOoA= +golang.org/x/tools/go/expect v0.1.1-deprecated h1:jpBZDwmgPhXsKZC6WhL20P4b/wmnpsEAGHaNy0n/rJM= +golang.org/x/tools/go/expect v0.1.1-deprecated/go.mod h1:eihoPOH+FgIqa3FpoTwguz/bVUSGBlGQU67vpBeOrBY= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -honnef.co/go/tools v0.3.2 h1:ytYb4rOqyp1TSa2EPvNVwtPQJctSELKaMyLfqNP4+34= -honnef.co/go/tools v0.3.2/go.mod h1:jzwdWgg7Jdq75wlfblQxO4neNaFFSvgc1tD5Wv8U0Yw= +honnef.co/go/tools v0.8.2 h1:+jPbCzuYxYrcoOvCecYUFDj+XJQRmzIhJmlbpps21Zk= +honnef.co/go/tools v0.8.2/go.mod h1:xG1Q4n+mg3bKZrO6RWFA9jFlkqplflmDRHGeuexiLDs= diff --git a/types.go b/types.go index 055adac9..27657d1e 100644 --- a/types.go +++ b/types.go @@ -60,9 +60,7 @@ type Scope interface { // Unlike Histogram, bucket boundaries are derived from the observations // rather than declared up front, and the distribution is reported as a // single serialized payload. The bucket budget is - // ScopeOptions.DefaultNativeHistogramMaxBuckets. Requires - // ScopeOptions.NativeHistogramFactory to be set; without it the metric - // accumulates but is never reported. + // ScopeOptions.DefaultNativeHistogramMaxBuckets. NativeValueHistogram(name string) NativeValueHistogram // NativeDurationHistogram is NativeValueHistogram for durations, which it diff --git a/version.go b/version.go index bfa3ee63..d6c761d2 100644 --- a/version.go +++ b/version.go @@ -21,4 +21,4 @@ package tally // Version is the current version of the library. -const Version = "7.0.0" +const Version = "7.1.0"