Skip to content

Commit

Permalink
Merge pull request #127 from circonus-labs/v3
Browse files Browse the repository at this point in the history
v3.4.5
  • Loading branch information
maier authored Jun 28, 2021
2 parents 90603b7 + 1209b08 commit d4b398a
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 37 deletions.
2 changes: 2 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ linters-settings:
# enable:
# - atomicalign
enable-all: true
disable:
- fieldalignment
# disable:
# - shadow
# disable-all: false
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# v3.4.5

* upd: set metric ts only when submit timestamp set by caller
* upd: dependencies
* fix: lint struct field alignment

# v3.4.4

* add: setting submission timestamp
Expand Down
2 changes: 1 addition & 1 deletion circonus-gometrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ type Config struct {
}

type prevMetrics struct {
metrics *Metrics
ts time.Time
metricsmu sync.Mutex
metrics *Metrics
}

// CirconusMetrics state
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/circonus-labs/circonus-gometrics/v3
go 1.14

require (
github.com/circonus-labs/go-apiclient v0.7.14
github.com/hashicorp/go-retryablehttp v0.6.8
github.com/openhistogram/circonusllhist v0.2.1
github.com/circonus-labs/go-apiclient v0.7.15
github.com/hashicorp/go-retryablehttp v0.7.0
github.com/openhistogram/circonusllhist v0.3.0
github.com/pkg/errors v0.9.1
github.com/tv42/httpunix v0.0.0-20191220191345-2ba4b9c3382c
)
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
github.com/circonus-labs/go-apiclient v0.7.14 h1:SWES4wUaNNCXuQJeKQ5EC+D/eeARFYbPjPMfjWAj+8M=
github.com/circonus-labs/go-apiclient v0.7.14/go.mod h1:RFgkvdYEkimzgu3V2vVYlS1bitjOz1SF6uw109ieNeY=
github.com/circonus-labs/go-apiclient v0.7.15 h1:r9sUdc+EDM0tL6Z6u03dac8fxYvlz1kPhxlNwkoIoqM=
github.com/circonus-labs/go-apiclient v0.7.15/go.mod h1:RFgkvdYEkimzgu3V2vVYlS1bitjOz1SF6uw109ieNeY=
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/hashicorp/go-cleanhttp v0.5.1 h1:dH3aiDG9Jvb5r5+bYHsikaOUIpcM0xvgMXVoDkXMzJM=
github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
github.com/hashicorp/go-hclog v0.9.2 h1:CG6TE5H9/JXsFWJCfoIVpKFIkFe6ysEuHirp4DxCsHI=
github.com/hashicorp/go-hclog v0.9.2/go.mod h1:5CU+agLiy3J7N7QjHK5d05KxGsuXiQLrjA0H7acj2lQ=
github.com/hashicorp/go-retryablehttp v0.6.8 h1:92lWxgpa+fF3FozM4B3UZtHZMJX8T5XT+TFdCxsPyWs=
github.com/hashicorp/go-retryablehttp v0.6.8/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/openhistogram/circonusllhist v0.2.1 h1:x3U4T8CL+RyLq+PNqZ4g9WMCEYuZ3qlD7m+zkIQ6QYI=
github.com/openhistogram/circonusllhist v0.2.1/go.mod h1:PfeYJ/RW2+Jfv3wTz0upbY2TRour/LLqIm2K2Kw5zg0=
github.com/hashicorp/go-retryablehttp v0.7.0 h1:eu1EI/mbirUgP5C8hVsTNaGZreBDlYiwC1FZWkvQPQ4=
github.com/hashicorp/go-retryablehttp v0.7.0/go.mod h1:vAew36LZh98gCBJNLH42IQ1ER/9wtLZZ8meHqQvEYWY=
github.com/openhistogram/circonusllhist v0.3.0 h1:CuEawy94hKEzjhSABdqkGirl6o67QrqtRoZg3CXBn6k=
github.com/openhistogram/circonusllhist v0.3.0/go.mod h1:PfeYJ/RW2+Jfv3wTz0upbY2TRour/LLqIm2K2Kw5zg0=
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=
Expand Down
2 changes: 1 addition & 1 deletion histogram.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (

// Histogram measures the distribution of a stream of values.
type Histogram struct {
rw sync.RWMutex
hist *circonusllhist.Histogram
name string
rw sync.RWMutex
}

// TimingWithTags adds a value to a histogram metric with tags
Expand Down
35 changes: 28 additions & 7 deletions metric_output.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@ func (m *CirconusMetrics) packageMetrics() (map[string]*apiclient.CheckBundleMet
// }

var ts uint64
if m.submitTimestamp == nil {
ts = makeTimestamp(time.Now())
} else {
// always submitting a timestamp forces the broker to treat the check as though
// it is "async" which doesn't work well for "group" checks with multiple submitters
// e.g. circonus-agent with a group statsd check
// if m.submitTimestamp == nil {
// ts = makeTimestamp(time.Now())
// } else {
if m.submitTimestamp != nil {
ts = makeTimestamp(*m.submitTimestamp)
m.Log.Printf("setting custom timestamp %v -> %v (UTC ms)", *m.submitTimestamp, ts)
}
Expand Down Expand Up @@ -57,7 +61,11 @@ func (m *CirconusMetrics) packageMetrics() (map[string]*apiclient.CheckBundleMet
}
}
if send {
output[name] = Metric{Type: "L", Value: value, Timestamp: ts}
metric := Metric{Type: "L", Value: value}
if ts > 0 {
metric.Timestamp = ts
}
output[name] = metric
}
}

Expand All @@ -72,7 +80,11 @@ func (m *CirconusMetrics) packageMetrics() (map[string]*apiclient.CheckBundleMet
}
}
if send {
output[name] = Metric{Type: m.getGaugeType(value), Value: value, Timestamp: ts}
metric := Metric{Type: m.getGaugeType(value), Value: value}
if ts > 0 {
metric.Timestamp = ts
}
output[name] = metric
}
}

Expand All @@ -91,7 +103,12 @@ func (m *CirconusMetrics) packageMetrics() (map[string]*apiclient.CheckBundleMet
if err := value.SerializeB64(buf); err != nil {
m.Log.Printf("[ERR] serializing histogram %s: %s", name, err)
} else {
output[name] = Metric{Type: "h", Value: buf.String(), Timestamp: ts} // histograms b64 serialized support timestamps
// histograms b64 serialized support timestamps
metric := Metric{Type: "h", Value: buf.String()}
if ts > 0 {
metric.Timestamp = ts
}
output[name] = metric
}
// output[name] = Metric{Type: "h", Value: value.DecStrings()} // histograms do NOT get timestamps
}
Expand All @@ -108,7 +125,11 @@ func (m *CirconusMetrics) packageMetrics() (map[string]*apiclient.CheckBundleMet
}
}
if send {
output[name] = Metric{Type: "s", Value: value, Timestamp: ts}
metric := Metric{Type: "s", Value: value}
if ts > 0 {
metric.Timestamp = ts
}
output[name] = metric
}
}

Expand Down
32 changes: 12 additions & 20 deletions metric_output_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
"testing"
)

func testHistResult() string {
return "AAEeAQAB"
}

func TestFlush(t *testing.T) {
server := testServer()
defer server.Close()
Expand Down Expand Up @@ -236,11 +240,8 @@ func TestFlushMetricsNoReset(t *testing.T) {
if m.Type != "h" {
t.Fatalf("'Type' not correct %v", m)
}
if len(m.Value.([]string)) != 1 {
t.Fatal("expected 1 value")
}
if m.Value.([]string)[0] != "H[3.0e+01]=1" {
t.Fatalf("'Value' not correct %v", m)
if m.Value.(string) != testHistResult() {
t.Fatalf("expected '%s' - got %v", testHistResult(), m.Value)
}

metrics = cm.FlushMetricsNoReset()
Expand All @@ -255,11 +256,8 @@ func TestFlushMetricsNoReset(t *testing.T) {
if m.Type != "h" {
t.Fatalf("'Type' not correct %v", m)
}
if len(m.Value.([]string)) != 1 {
t.Fatal("expected 1 value")
}
if m.Value.([]string)[0] != "H[3.0e+01]=1" {
t.Fatalf("'Value' not correct %v", m)
if m.Value.(string) != testHistResult() {
t.Fatalf("expected '%s' - got %v", testHistResult(), m.Value)
}
}

Expand Down Expand Up @@ -413,11 +411,8 @@ func TestFlushMetrics(t *testing.T) {
if m.Type != "h" {
t.Fatalf("'Type' not correct %v", m)
}
if len(m.Value.([]string)) != 1 {
t.Fatal("expected 1 value")
}
if m.Value.([]string)[0] != "H[3.0e+01]=1" {
t.Fatalf("'Value' not correct %v", m)
if m.Value.(string) != testHistResult() {
t.Fatalf("expected '%s' - got %v", testHistResult(), m.Value)
}
}

Expand Down Expand Up @@ -567,11 +562,8 @@ func TestPromOutput(t *testing.T) {
if m.Type != "h" {
t.Fatalf("'Type' not correct %v", m)
}
if len(m.Value.([]string)) != 1 {
t.Fatal("expected 1 value")
}
if m.Value.([]string)[0] != "H[3.0e+01]=1" {
t.Fatalf("'Value' not correct %v", m)
if m.Value.(string) != testHistResult() {
t.Fatalf("expected '%s' - got %v", testHistResult(), m.Value)
}

b, err := cm.PromOutput()
Expand Down

0 comments on commit d4b398a

Please sign in to comment.