Skip to content
This repository has been archived by the owner on Jul 12, 2024. It is now read-only.

Commit

Permalink
Add an extra test for Summary metric marshaling
Browse files Browse the repository at this point in the history
  • Loading branch information
Toni Reina committed Jun 5, 2020
1 parent db4be85 commit ec7ecd6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions telemetry/metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,30 @@ func TestMetricPayload(t *testing.T) {
// attributes correctly marshals into JSON.
now := time.Date(2014, time.November, 28, 1, 1, 0, 0, time.UTC)
h, _ := NewHarvester(ConfigCommonAttributes(map[string]interface{}{"zop": "zup"}), configTesting)
// Use a single metric to avoid sorting.
h.RecordMetric(Gauge{
Name: "metric",
Attributes: map[string]interface{}{"zip": "zap"},
Timestamp: now,
Value: 1.0,
})
h.RecordMetric(Summary{
Name: "another-metric",
Name: "summary-metric-nan-min",
Attributes: map[string]interface{}{"zip": "zap"},
Timestamp: now,
Count: 4.0,
Sum: 1.0,
Min: math.NaN(),
Max: 3.0,
})
h.RecordMetric(Summary{
Name: "summary-metric-nan-max",
Attributes: map[string]interface{}{"zip": "zap"},
Timestamp: now,
Count: 4.0,
Sum: 1.0,
Min: 10,
Max: math.NaN(),
})
h.lastHarvest = now
end := h.lastHarvest.Add(5 * time.Second)
reqs := h.swapOutMetrics(end)
Expand All @@ -47,7 +55,8 @@ func TestMetricPayload(t *testing.T) {
},
"metrics":[
{"name":"metric","type":"gauge","value":1,"timestamp":1417136460000,"attributes":{"zip":"zap"}},
{"name":"another-metric","type":"summary","value":{"sum":1,"count":4,"min":null,"max":3},"timestamp":1417136460000,"attributes":{"zip":"zap"}}
{"name":"summary-metric-nan-min","type":"summary","value":{"sum":1,"count":4,"min":null,"max":3},"timestamp":1417136460000,"attributes":{"zip":"zap"}},
{"name":"summary-metric-nan-max","type":"summary","value":{"sum":1,"count":4,"min":10,"max":null},"timestamp":1417136460000,"attributes":{"zip":"zap"}}
]
}]`
compactExpect := compactJSONString(expect)
Expand Down

0 comments on commit ec7ecd6

Please sign in to comment.