Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

switch int64 to uint64 #90

Merged
merged 1 commit into from
May 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
module github.com/Netflix/spectator-go

go 1.21

require (
github.com/json-iterator/go v1.1.12
github.com/klauspost/compress v1.15.12
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/pkg/errors v0.9.1
golang.org/x/sync v0.1.0
)
22 changes: 0 additions & 22 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,22 +0,0 @@
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/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/klauspost/compress v1.15.12 h1:YClS/PImqYbn+UILDnqxQCZ3RehC9N318SU3kElDUEM=
github.com/klauspost/compress v1.15.12/go.mod h1:QPwzmACJjUTFsnSHH934V6woptycfrDDJnH7hvFVbGM=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9Gz0M=
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
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/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
8 changes: 3 additions & 5 deletions spectator/meter/age_gauge.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ func (g *AgeGauge) MeterId() *Id {
}

// Set records the current value.
func (g *AgeGauge) Set(value int64) {
if value >= 0 {
var line = fmt.Sprintf("%s:%s:%d", g.meterTypeSymbol, g.id.spectatordId, value)
g.writer.Write(line)
}
func (g *AgeGauge) Set(value uint64) {
var line = fmt.Sprintf("%s:%s:%d", g.meterTypeSymbol, g.id.spectatordId, value)
g.writer.Write(line)
}

// Now records the current time in epoch seconds in spectatord.
Expand Down
11 changes: 0 additions & 11 deletions spectator/meter/age_gauge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,6 @@ func TestAgeGauge_Now(t *testing.T) {
}
}

func TestAgeGauge_SetNegative(t *testing.T) {
id := NewId("setNegative", nil)
w := writer.MemoryWriter{}
g := NewAgeGauge(id, &w)
g.Set(-100)

if len(w.Lines) != 0 {
t.Error("Negative values should be ignored")
}
}

func TestAgeGauge_SetMultipleValues(t *testing.T) {
id := NewId("setMultiple", nil)
w := writer.MemoryWriter{}
Expand Down
10 changes: 4 additions & 6 deletions spectator/meter/counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,8 @@ func (c *Counter) AddFloat(delta float64) {
}
}

// Add is to add a specific int64 delta to the current measurement.
func (c *Counter) Add(delta int64) {
if delta > 0 {
var line = fmt.Sprintf("%s:%s:%d", c.meterTypeSymbol, c.id.spectatordId, delta)
c.writer.Write(line)
}
// Add is to add a specific uint64 delta to the current measurement.
func (c *Counter) Add(delta uint64) {
var line = fmt.Sprintf("%s:%s:%d", c.meterTypeSymbol, c.id.spectatordId, delta)
c.writer.Write(line)
}
5 changes: 0 additions & 5 deletions spectator/meter/counter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,4 @@ func TestCounter_Add(t *testing.T) {
if w.Lines[0] != expected {
t.Error("Expected ", expected, " got ", w.Lines[0])
}

c.Add(-1)
if len(w.Lines) != 1 {
t.Error("Negative deltas should be ignored")
}
}
8 changes: 3 additions & 5 deletions spectator/meter/dist_summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ func (d *DistributionSummary) MeterId() *Id {
}

// Record records a new value to track within the distribution.
func (d *DistributionSummary) Record(amount int64) {
if amount >= 0 {
var line = fmt.Sprintf("%s:%s:%d", d.meterTypeSymbol, d.id.spectatordId, amount)
d.writer.Write(line)
}
func (d *DistributionSummary) Record(amount uint64) {
var line = fmt.Sprintf("%s:%s:%d", d.meterTypeSymbol, d.id.spectatordId, amount)
d.writer.Write(line)
}
11 changes: 0 additions & 11 deletions spectator/meter/dist_summary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,6 @@ func TestDistributionSummary_RecordZeroValue(t *testing.T) {
}
}

func TestDistributionSummary_RecordNegativeValue(t *testing.T) {
id := NewId("recordNegative", nil)
w := writer.MemoryWriter{}
ds := NewDistributionSummary(id, &w)
ds.Record(-100)

if len(w.Lines) != 0 {
t.Errorf("Expected no lines, got %d", len(w.Lines))
}
}

func TestDistributionSummary_RecordMultipleValues(t *testing.T) {
id := NewId("recordMultiple", nil)
w := writer.MemoryWriter{}
Expand Down
10 changes: 4 additions & 6 deletions spectator/meter/monotonic_counter.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,8 @@ func (c *MonotonicCounter) MeterId() *Id {
return c.id
}

// Set is to set a specific int64 delta as the current measurement.
func (c *MonotonicCounter) Set(delta int64) {
if delta > 0 {
var line = fmt.Sprintf("%s:%s:%d", c.meterTypeSymbol, c.id.spectatordId, delta)
c.writer.Write(line)
}
// Set is to set a specific uint64 value as the current measurement - spectatord will calculate the delta.
func (c *MonotonicCounter) Set(value uint64) {
var line = fmt.Sprintf("%s:%s:%d", c.meterTypeSymbol, c.id.spectatordId, value)
c.writer.Write(line)
}
5 changes: 0 additions & 5 deletions spectator/meter/monotonic_counter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,4 @@ func TestMonotonicCounter_Set(t *testing.T) {
if w.Lines[0] != expected {
t.Error("Expected ", expected, " got ", w.Lines[0])
}

c.Set(-1)
if len(w.Lines) != 1 {
t.Error("Negative deltas should be ignored")
}
}
8 changes: 3 additions & 5 deletions spectator/meter/percentile_distsummary.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ func NewPercentileDistributionSummary(id *Id, writer writer.Writer) *PercentileD
}

// Record records a new value to track within the distribution.
func (p *PercentileDistributionSummary) Record(amount int64) {
if amount >= 0 {
var line = fmt.Sprintf("%s:%s:%d", p.meterTypeSymbol, p.id.spectatordId, amount)
p.writer.Write(line)
}
func (p *PercentileDistributionSummary) Record(amount uint64) {
var line = fmt.Sprintf("%s:%s:%d", p.meterTypeSymbol, p.id.spectatordId, amount)
p.writer.Write(line)
}
11 changes: 0 additions & 11 deletions spectator/meter/percentile_distsummary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,6 @@ func TestPercentileDistributionSummary_RecordZero(t *testing.T) {
}
}

func TestPercentileDistributionSummary_RecordNegative(t *testing.T) {
id := NewId("recordPercentileNegative", nil)
w := writer.MemoryWriter{}
ds := NewPercentileDistributionSummary(id, &w)
ds.Record(-100)

if len(w.Lines) != 0 {
t.Errorf("Expected no lines to be written, got %d", len(w.Lines))
}
}

func TestPercentileDistributionSummary_RecordMultipleValues(t *testing.T) {
id := NewId("recordPercentileMultiple", nil)
w := writer.MemoryWriter{}
Expand Down