Skip to content

Commit

Permalink
Merge pull request #155 from hashicorp/biazmoreira/addgaugefloat64-sink
Browse files Browse the repository at this point in the history
Add PrecisionGauge to Circonus
  • Loading branch information
biazmoreira authored Jun 9, 2023
2 parents aee7470 + 94aba96 commit 25a7551
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions circonus/circonus.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ func (s *CirconusSink) SetGaugeWithLabels(key []string, val float32, labels []me
s.metrics.SetGauge(flatKey, int64(val))
}

// SetPrecisionGauge sets value for a gauge metric with float64 precision
func (s *CirconusSink) SetPrecisionGauge(key []string, val float64) {
flatKey := s.flattenKey(key)
s.metrics.SetGauge(flatKey, val)
}

// SetPrecisionGaugeWithLabels sets value for a gauge metric with the given labels with float64 precision
func (s *CirconusSink) SetPrecisionGaugeWithLabels(key []string, val float64, labels []metrics.Label) {
flatKey := s.flattenKeyLabels(key, labels)
s.metrics.SetGauge(flatKey, val)
}

// EmitKey is not implemented in circonus
func (s *CirconusSink) EmitKey(key []string, val float32) {
// NOP
Expand Down
28 changes: 28 additions & 0 deletions circonus/circonus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,34 @@ func TestSetGauge(t *testing.T) {
}
}

func TestSetPrecisionGauge(t *testing.T) {
q := make(chan string)

server := fakeBroker(q)
defer server.Close()

cfg := &Config{}
cfg.CheckManager.Check.SubmissionURL = server.URL

cs, err := NewCirconusSink(cfg)
if err != nil {
t.Errorf("Expected no error, got '%v'", err)
}

go func() {
cs.SetPrecisionGauge([]string{"foo", "bar"}, 1)
cs.Flush()
}()

expect := "{\"foo`bar\":{\"_type\":\"n\",\"_value\":1}}"
actual := <-q

if actual != expect {
t.Errorf("Expected '%s', got '%s'", expect, actual)

}
}

func TestIncrCounter(t *testing.T) {
q := make(chan string)

Expand Down

0 comments on commit 25a7551

Please sign in to comment.