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

Add fixture with a histogram exemplar, and implement exemplar attachments in SDK #813

Merged
merged 6 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
75 changes: 75 additions & 0 deletions exporter/collector/integrationtest/testcases/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,22 @@
}

func convertHistogram(h pmetric.Histogram) metricdata.Aggregation {
for i := 0; i < h.DataPoints().Len(); i++ {
pt := h.DataPoints().At(i)
for j := 0; j < pt.Exemplars().Len(); j++ {
switch pt.Exemplars().At(j).ValueType() {
case pmetric.ExemplarValueTypeDouble:
return convertFloatHistogram(h)
case pmetric.ExemplarValueTypeInt:
return convertIntHistogram(h)
}
}
}
// The sum is always a float, so default to treating it as a float histogram.
return convertFloatHistogram(h)
}

func convertFloatHistogram(h pmetric.Histogram) metricdata.Aggregation {
if h.DataPoints().Len() == 0 {
return nil
}
Expand All @@ -166,11 +182,70 @@
Sum: pt.Sum(),
Bounds: pt.ExplicitBounds().AsRaw(),
BucketCounts: pt.BucketCounts().AsRaw(),
Exemplars: convertFloatExemplars(pt.Exemplars()),
}
}
return agg
}

func convertIntHistogram(h pmetric.Histogram) metricdata.Aggregation {
if h.DataPoints().Len() == 0 {
return nil
}

Check warning on line 194 in exporter/collector/integrationtest/testcases/conversion.go

View check run for this annotation

Codecov / codecov/patch

exporter/collector/integrationtest/testcases/conversion.go#L193-L194

Added lines #L193 - L194 were not covered by tests
agg := metricdata.Histogram[int64]{
Temporality: convertTemporality(h.AggregationTemporality()),
DataPoints: make([]metricdata.HistogramDataPoint[int64], h.DataPoints().Len()),
}
for i := 0; i < h.DataPoints().Len(); i++ {
pt := h.DataPoints().At(i)
agg.DataPoints[i] = metricdata.HistogramDataPoint[int64]{
Attributes: attribute.NewSet(convertAttributes(pt.Attributes())...),
StartTime: pt.StartTimestamp().AsTime(),
Time: pt.Timestamp().AsTime(),
Count: pt.Count(),
Sum: int64(pt.Sum()),
Bounds: pt.ExplicitBounds().AsRaw(),
BucketCounts: pt.BucketCounts().AsRaw(),
Exemplars: convertIntExemplars(pt.Exemplars()),
}
}
return agg
}

func convertIntExemplars(es pmetric.ExemplarSlice) []metricdata.Exemplar[int64] {
exemplars := make([]metricdata.Exemplar[int64], es.Len())
for i := 0; i < es.Len(); i++ {
e := es.At(i)
traceID := e.TraceID()
spanID := e.SpanID()
dashpole marked this conversation as resolved.
Show resolved Hide resolved
exemplars[i] = metricdata.Exemplar[int64]{
FilteredAttributes: convertAttributes(e.FilteredAttributes()),
Time: e.Timestamp().AsTime(),
TraceID: []byte(traceID[:]),
SpanID: []byte(spanID[:]),
Value: e.IntValue(),
}
}
return exemplars
}

func convertFloatExemplars(es pmetric.ExemplarSlice) []metricdata.Exemplar[float64] {
exemplars := make([]metricdata.Exemplar[float64], es.Len())
for i := 0; i < es.Len(); i++ {
e := es.At(i)
traceID := e.TraceID()
spanID := e.SpanID()
dashpole marked this conversation as resolved.
Show resolved Hide resolved
exemplars[i] = metricdata.Exemplar[float64]{
FilteredAttributes: convertAttributes(e.FilteredAttributes()),
Time: e.Timestamp().AsTime(),
TraceID: []byte(traceID[:]),
SpanID: []byte(spanID[:]),
Value: e.DoubleValue(),
}
}
return exemplars
}

func convertAttributes(attrs pcommon.Map) []attribute.KeyValue {
var kvs []attribute.KeyValue
attrs.Range(func(k string, v pcommon.Value) bool {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,110 @@
"scope": {},
"metrics": [
{
"name": "simple.histogram",
"name": "simple.float64.histogram",
"unit": "s",
"histogram": {
"dataPoints": [
{
"attributes": [
{
"key": "some.lemons",
"value": {
"stringValue": "13"
}
}
],
"startTimeUnixNano": "1649443516286000000",
"timeUnixNano": "1649443516286000000",
"count": "1",
"sum": 2.5,
"bucketCounts": [
"0",
"0",
"1",
"0",
"0",
"0",
"0"
],
"explicitBounds": [
1,
2,
5,
10,
20,
50
],
"exemplars": [
{
"asDouble": 4.1,
"timeUnixNano": "1649443516286000000",
"traceId": "2499d13df7b35ae93dfa3d6ddc01da74",
"spanId": "84f9e8929bb1cd5b",
"filteredAttributes": [
{
"key": "filtered.attribute",
"value": {
"stringValue": "foobar"
}
}
]
}
]
},
{
"attributes": [
{
"key": "some.lemons",
"value": {
"stringValue": "10"
}
}
],
"startTimeUnixNano": "1649443516286000000",
"timeUnixNano": "1649443516286000000",
"count": "2",
"sum": 14.3,
"bucketCounts": [
"0",
"0",
"1",
"0",
"1",
"0",
"0"
],
"explicitBounds": [
1,
2,
5,
10,
20,
50
],
"exemplars": [
{
"asDouble": 15.5,
"timeUnixNano": "1649443516286000000",
"traceId": "2499d13df7b35ae93dfa3d6ddc01da74",
"spanId": "84f9e8929bb1cd5b",
"filteredAttributes": [
{
"key": "filtered.attribute",
"value": {
"stringValue": "foobar"
}
}
]
}
]
}
],
"aggregationTemporality": "AGGREGATION_TEMPORALITY_CUMULATIVE"
}
},
{
"name": "simple.int64.histogram",
"unit": "s",
"histogram": {
"dataPoints": [
Expand Down Expand Up @@ -61,6 +164,22 @@
10,
20,
50
],
"exemplars": [
{
"asInt": 4,
"timeUnixNano": "1649443516286000000",
"traceId": "2499d13df7b35ae93dfa3d6ddc01da74",
"spanId": "84f9e8929bb1cd5b",
"filteredAttributes": [
{
"key": "filtered.attribute",
"value": {
"stringValue": "foobar"
}
}
]
}
]
},
{
Expand Down Expand Up @@ -92,6 +211,22 @@
10,
20,
50
],
"exemplars": [
{
"asInt": 12,
"timeUnixNano": "1649443516286000000",
"traceId": "2499d13df7b35ae93dfa3d6ddc01da74",
"spanId": "84f9e8929bb1cd5b",
"filteredAttributes": [
{
"key": "filtered.attribute",
"value": {
"stringValue": "foobar"
}
}
]
}
]
}
],
Expand Down
Loading
Loading