Skip to content

Conversation

@isopropylcyanide
Copy link

@isopropylcyanide isopropylcyanide commented Jul 13, 2021

Summary

PR Status Type Impact level
Ready Feature Request #151 Medium

Description

This PR adds / changes the following

  • Upgrades cactus-statsd-client to v5
  • Support tags in StatsD Reporter.
  • Update README

Motivation & Context

How was this tested?

  • Master on Statsd Example Reporter
❯ nc 8125 -l -u                                                                                                            ▼
my-stats.my-service.test-counter:1
  • This branch on Statsd Example Reporter with two tags offset=-34.34 and dev=local
❯ nc 8125 -l -u                                                                                                            ▼
my-stats.my-service.test-counter,offset=-34.34,dev=local:2

Pasted Graphic

Bench stats

Here's the benchstat between old (master) and new (this branch)

name                               old time/op    new time/op    delta
pkg:github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift goos:darwin goarch:amd64
BinaryBool_0-12                       161ns ± 0%     146ns ± 0%   ~     (p=1.000 n=1+1)
BinaryByte_0-12                       170ns ± 0%     172ns ± 0%   ~     (p=1.000 n=1+1)
BinaryI16_0-12                        320ns ± 0%     327ns ± 0%   ~     (p=1.000 n=1+1)
BinaryI32_0-12                        353ns ± 0%     351ns ± 0%   ~     (p=1.000 n=1+1)
BinaryI64_0-12                        491ns ± 0%     480ns ± 0%   ~     (p=1.000 n=1+1)
BinaryDouble_0-12                     553ns ± 0%     539ns ± 0%   ~     (p=1.000 n=1+1)
BinaryString_0-12                     683ns ± 0%     679ns ± 0%   ~     (p=1.000 n=1+1)
BinaryBinary_0-12                     222ns ± 0%     195ns ± 0%   ~     (p=1.000 n=1+1)
BinaryBool_1-12                       358ns ± 0%     302ns ± 0%   ~     (p=1.000 n=1+1)
pkg:github.com/uber-go/tally goos:darwin goarch:amd64
BucketsEqual/same_20_values-12       13.2ns ± 0%    12.7ns ± 0%   ~     (p=1.000 n=1+1)
BucketsEqual/same_20_durations-12    11.0ns ± 0%    10.5ns ± 0%   ~     (p=1.000 n=1+1)
NameGeneration-12                    22.1ns ± 0%    20.9ns ± 0%   ~     (p=1.000 n=1+1)
CounterAllocation-12                  576ns ± 0%     586ns ± 0%   ~     (p=1.000 n=1+1)
SanitizedCounterAllocation-12         620ns ± 0%     645ns ± 0%   ~     (p=1.000 n=1+1)
NameGenerationTagged-12              23.5ns ± 0%    21.9ns ± 0%   ~     (p=1.000 n=1+1)
ScopeTaggedCachedSubscopes-12        1.22µs ± 0%    1.24µs ± 0%   ~     (p=1.000 n=1+1)
ScopeTaggedNoCachedSubscopes-12      3.62µs ± 0%    3.65µs ± 0%   ~     (p=1.000 n=1+1)
NameGenerationNoPrefix-12            0.38ns ± 0%    0.38ns ± 0%   ~     (p=1.000 n=1+1)
HistogramAllocation-12               1.40µs ± 0%    1.48µs ± 0%   ~     (p=1.000 n=1+1)
HistogramExisting-12                 25.1ns ± 0%    24.2ns ± 0%   ~     (p=1.000 n=1+1)
ScopeReporting/size1-12              35.0ns ± 0%    34.9ns ± 0%   ~     (p=1.000 n=1+1)
ScopeReporting/size10-12             50.1ns ± 0%    49.3ns ± 0%   ~     (p=1.000 n=1+1)
ScopeReporting/size100-12             204ns ± 0%     214ns ± 0%   ~     (p=1.000 n=1+1)
ScopeReporting/size1000-12           1.89µs ± 0%    1.96µs ± 0%   ~     (p=1.000 n=1+1)
ScopeReporting/size10000-12          19.4µs ± 0%    20.1µs ± 0%   ~     (p=1.000 n=1+1)
ScopeReporting/size100000-12          205µs ± 0%     201µs ± 0%   ~     (p=1.000 n=1+1)
ScopeReporting/size1000000-12        3.38ms ± 0%    3.38ms ± 0%   ~     (p=1.000 n=1+1)
CounterInc-12                        4.51ns ± 0%    4.39ns ± 0%   ~     (p=1.000 n=1+1)
ReportCounterNoData-12               2.21ns ± 0%    2.21ns ± 0%   ~     (all equal)
ReportCounterWithData-12             15.3ns ± 0%    15.3ns ± 0%   ~     (p=1.000 n=1+1)
GaugeSet-12                          8.48ns ± 0%    8.58ns ± 0%   ~     (p=1.000 n=1+1)
ReportGaugeNoData-12                 7.11ns ± 0%    7.34ns ± 0%   ~     (p=1.000 n=1+1)
ReportGaugeWithData-12               18.0ns ± 0%    17.5ns ± 0%   ~     (p=1.000 n=1+1)
TimerStopwatch-12                     157ns ± 0%     152ns ± 0%   ~     (p=1.000 n=1+1)
TimerReport-12                        109ns ± 0%     105ns ± 0%   ~     (p=1.000 n=1+1)

name                               old alloc/op   new alloc/op   delta
pkg:github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift goos:darwin goarch:amd64
BinaryBool_0-12                       0.00B          0.00B        ~     (all equal)
BinaryByte_0-12                       0.00B          0.00B        ~     (all equal)
BinaryI16_0-12                        0.00B          0.00B        ~     (all equal)
BinaryI32_0-12                        0.00B          0.00B        ~     (all equal)
BinaryI64_0-12                        0.00B          0.00B        ~     (all equal)
BinaryDouble_0-12                     0.00B          0.00B        ~     (all equal)
BinaryString_0-12                      352B ± 0%      352B ± 0%   ~     (all equal)
BinaryBinary_0-12                      160B ± 0%      160B ± 0%   ~     (all equal)
BinaryBool_1-12                       0.00B          0.00B        ~     (all equal)
pkg:github.com/uber-go/tally goos:darwin goarch:amd64
BucketsEqual/same_20_values-12        0.00B          0.00B        ~     (all equal)
BucketsEqual/same_20_durations-12     0.00B          0.00B        ~     (all equal)
NameGeneration-12                     0.00B          0.00B        ~     (all equal)
CounterAllocation-12                   192B ± 0%      191B ± 0%   ~     (p=1.000 n=1+1)
SanitizedCounterAllocation-12          246B ± 0%      249B ± 0%   ~     (p=1.000 n=1+1)
NameGenerationTagged-12               0.00B          0.00B        ~     (all equal)
ScopeTaggedCachedSubscopes-12          816B ± 0%      816B ± 0%   ~     (all equal)
ScopeTaggedNoCachedSubscopes-12      2.35kB ± 0%    2.35kB ± 0%   ~     (p=1.000 n=1+1)
NameGenerationNoPrefix-12             0.00B          0.00B        ~     (all equal)
HistogramAllocation-12               1.20kB ± 0%    1.19kB ± 0%   ~     (p=1.000 n=1+1)
HistogramExisting-12                  0.00B          0.00B        ~     (all equal)
ScopeReporting/size1-12               0.00B          0.00B        ~     (all equal)
ScopeReporting/size10-12              0.00B          0.00B        ~     (all equal)
ScopeReporting/size100-12             0.00B          0.00B        ~     (all equal)
ScopeReporting/size1000-12            0.00B          0.00B        ~     (all equal)
ScopeReporting/size10000-12           0.00B          0.00B        ~     (all equal)
ScopeReporting/size100000-12          0.00B          0.00B        ~     (all equal)
ScopeReporting/size1000000-12         0.00B          0.00B        ~     (all equal)
CounterInc-12                         0.00B          0.00B        ~     (all equal)
ReportCounterNoData-12                0.00B          0.00B        ~     (all equal)
ReportCounterWithData-12              0.00B          0.00B        ~     (all equal)
GaugeSet-12                           0.00B          0.00B        ~     (all equal)
ReportGaugeNoData-12                  0.00B          0.00B        ~     (all equal)
ReportGaugeWithData-12                0.00B          0.00B        ~     (all equal)
TimerStopwatch-12                     0.00B          0.00B        ~     (all equal)
TimerReport-12                        0.00B          0.00B        ~     (all equal)

name                               old allocs/op  new allocs/op  delta
pkg:github.com/uber-go/tally/thirdparty/github.com/apache/thrift/lib/go/thrift goos:darwin goarch:amd64
BinaryBool_0-12                        0.00           0.00        ~     (all equal)
BinaryByte_0-12                        0.00           0.00        ~     (all equal)
BinaryI16_0-12                         0.00           0.00        ~     (all equal)
BinaryI32_0-12                         0.00           0.00        ~     (all equal)
BinaryI64_0-12                         0.00           0.00        ~     (all equal)
BinaryDouble_0-12                      0.00           0.00        ~     (all equal)
BinaryString_0-12                      7.00 ± 0%      7.00 ± 0%   ~     (all equal)
BinaryBinary_0-12                      1.00 ± 0%      1.00 ± 0%   ~     (all equal)
BinaryBool_1-12                        0.00           0.00        ~     (all equal)
pkg:github.com/uber-go/tally goos:darwin goarch:amd64
BucketsEqual/same_20_values-12         0.00           0.00        ~     (all equal)
BucketsEqual/same_20_durations-12      0.00           0.00        ~     (all equal)
NameGeneration-12                      0.00           0.00        ~     (all equal)
CounterAllocation-12                   1.00 ± 0%      1.00 ± 0%   ~     (all equal)
SanitizedCounterAllocation-12          4.00 ± 0%      4.00 ± 0%   ~     (all equal)
NameGenerationTagged-12                0.00           0.00        ~     (all equal)
ScopeTaggedCachedSubscopes-12          8.00 ± 0%      8.00 ± 0%   ~     (all equal)
ScopeTaggedNoCachedSubscopes-12        19.0 ± 0%      19.0 ± 0%   ~     (all equal)
NameGenerationNoPrefix-12              0.00           0.00        ~     (all equal)
HistogramAllocation-12                 20.0 ± 0%      20.0 ± 0%   ~     (all equal)
HistogramExisting-12                   0.00           0.00        ~     (all equal)
ScopeReporting/size1-12                0.00           0.00        ~     (all equal)
ScopeReporting/size10-12               0.00           0.00        ~     (all equal)
ScopeReporting/size100-12              0.00           0.00        ~     (all equal)
ScopeReporting/size1000-12             0.00           0.00        ~     (all equal)
ScopeReporting/size10000-12            0.00           0.00        ~     (all equal)
ScopeReporting/size100000-12           0.00           0.00        ~     (all equal)
ScopeReporting/size1000000-12          0.00           0.00        ~     (all equal)
CounterInc-12                          0.00           0.00        ~     (all equal)
ReportCounterNoData-12                 0.00           0.00        ~     (all equal)
ReportCounterWithData-12               0.00           0.00        ~     (all equal)
GaugeSet-12                            0.00           0.00        ~     (all equal)
ReportGaugeNoData-12                   0.00           0.00        ~     (all equal)
ReportGaugeWithData-12                 0.00           0.00        ~     (all equal)
TimerStopwatch-12                      0.00           0.00        ~     (all equal)
TimerReport-12                         0.00           0.00        ~     (all equal)

@CLAassistant
Copy link

CLAassistant commented Jul 13, 2021

CLA assistant check
All committers have signed the CLA.

// To view statsd emitted metrics locally you can use
// netcat with "nc 8125 -l -u"
func main() {
statter, err := statsd.NewBufferedClient("127.0.0.1:8125",
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is deprecated now

defer closer.Close()

counter := scope.Counter("test-counter")
defer func(closer io.Closer) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

closer.close returns an error

// no-op
}

func getStatsdTagPairs(tags map[string]string) []statsd.Tag {
Copy link
Author

@isopropylcyanide isopropylcyanide Jul 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Keeping it as a func and not a method.

  • 1 obvious allocation here. Open for feedback.
    image

~/gocode/src/github.com/uber-go/tally/statsd master !4 ?1 ❯ go test . -run none -bench BenchmarkGetStatsdTagPairs --benchtime 3s -benchmem      ▼
goos: darwin
goarch: amd64
pkg: github.com/uber-go/tally/statsd
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
BenchmarkGetStatsdTagPairs-12    	31455973	       105.0 ns/op	      64 B/op	       1 allocs/op
PASS
ok  	github.com/uber-go/tally/statsd	3.943s
  • Benchmark

func BenchmarkGetStatsdTagPairs(b *testing.B) {
	tags := map[string]string{
		"K1": "V1",
		"K2": "V2",
	}
	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		_ = getStatsdTagPairs(tags)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants