Skip to content

Commit

Permalink
Convert temporality and monotonicity for deprecated sums
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Jul 27, 2021
1 parent 3256c98 commit 144b6b4
Show file tree
Hide file tree
Showing 2 changed files with 139 additions and 9 deletions.
20 changes: 11 additions & 9 deletions model/internal/otlp_wrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,15 @@ func intHistogramToHistogram(src *otlpmetrics.Metric_IntHistogram) *otlpmetrics.
}

func intGaugeToGauge(src *otlpmetrics.Metric_IntGauge) *otlpmetrics.Metric_Gauge {
datapoints := []*otlpmetrics.NumberDataPoint{}
for _, datapoint := range src.IntGauge.DataPoints {
datapoints = append(datapoints, &otlpmetrics.NumberDataPoint{
datapoints := make([]*otlpmetrics.NumberDataPoint, len(src.IntGauge.DataPoints))
for i, datapoint := range src.IntGauge.DataPoints {
datapoints[i] = &otlpmetrics.NumberDataPoint{
Labels: datapoint.Labels,
TimeUnixNano: datapoint.TimeUnixNano,
StartTimeUnixNano: datapoint.StartTimeUnixNano,
Exemplars: intExemplarToExemplar(datapoint.Exemplars),
Value: &otlpmetrics.NumberDataPoint_AsInt{AsInt: datapoint.Value},
})
}
}
return &otlpmetrics.Metric_Gauge{
Gauge: &otlpmetrics.Gauge{
Expand All @@ -162,19 +162,21 @@ func intGaugeToGauge(src *otlpmetrics.Metric_IntGauge) *otlpmetrics.Metric_Gauge
}

func intSumToSum(src *otlpmetrics.Metric_IntSum) *otlpmetrics.Metric_Sum {
datapoints := []*otlpmetrics.NumberDataPoint{}
for _, datapoint := range src.IntSum.DataPoints {
datapoints = append(datapoints, &otlpmetrics.NumberDataPoint{
datapoints := make([]*otlpmetrics.NumberDataPoint, len(src.IntSum.DataPoints))
for i, datapoint := range src.IntSum.DataPoints {
datapoints[i] = &otlpmetrics.NumberDataPoint{
Labels: datapoint.Labels,
TimeUnixNano: datapoint.TimeUnixNano,
StartTimeUnixNano: datapoint.StartTimeUnixNano,
Exemplars: intExemplarToExemplar(datapoint.Exemplars),
Value: &otlpmetrics.NumberDataPoint_AsInt{AsInt: datapoint.Value},
})
}
}
return &otlpmetrics.Metric_Sum{
Sum: &otlpmetrics.Sum{
DataPoints: datapoints,
AggregationTemporality: src.IntSum.AggregationTemporality,
DataPoints: datapoints,
IsMonotonic: src.IntSum.IsMonotonic,
},
}
}
Expand Down
128 changes: 128 additions & 0 deletions model/internal/otlp_wrappers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,50 @@ func TestDeprecatedIntHistogram(t *testing.T) {
},
}},
},
{
inputMetrics: []*otlpmetrics.Metric{{
Data: &otlpmetrics.Metric_IntHistogram{
IntHistogram: &otlpmetrics.IntHistogram{ //nolint:staticcheck // SA1019 ignore this!
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
DataPoints: []*otlpmetrics.IntHistogramDataPoint{ //nolint:staticcheck // SA1019 ignore this!
{
Labels: []otlpcommon.StringKeyValue{
{Key: "key2", Value: "value2"},
},
BucketCounts: []uint64{10, 15, 1},
ExplicitBounds: []float64{1, 2},
Sum: 10,
StartTimeUnixNano: 2,
TimeUnixNano: 3,
Count: 26,
Exemplars: []otlpmetrics.IntExemplar{}, //nolint:staticcheck // SA1019 ignore this!
},
},
},
},
}},
outputMetrics: []*otlpmetrics.Metric{{
Data: &otlpmetrics.Metric_Histogram{
Histogram: &otlpmetrics.Histogram{
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
DataPoints: []*otlpmetrics.HistogramDataPoint{
{
Labels: []otlpcommon.StringKeyValue{
{Key: "key2", Value: "value2"},
},
BucketCounts: []uint64{10, 15, 1},
ExplicitBounds: []float64{1, 2},
Sum: 10.0,
StartTimeUnixNano: 2,
TimeUnixNano: 3,
Count: 26,
Exemplars: []otlpmetrics.Exemplar{},
},
},
},
},
}},
},
}

for _, test := range tests {
Expand Down Expand Up @@ -338,6 +382,8 @@ func TestDeprecatedIntSum(t *testing.T) {
inputMetrics: []*otlpmetrics.Metric{{
Data: &otlpmetrics.Metric_Sum{
Sum: &otlpmetrics.Sum{
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
DataPoints: []*otlpmetrics.NumberDataPoint{
{
Labels: []otlpcommon.StringKeyValue{
Expand All @@ -355,6 +401,8 @@ func TestDeprecatedIntSum(t *testing.T) {
outputMetrics: []*otlpmetrics.Metric{{
Data: &otlpmetrics.Metric_Sum{
Sum: &otlpmetrics.Sum{
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
DataPoints: []*otlpmetrics.NumberDataPoint{
{
Labels: []otlpcommon.StringKeyValue{
Expand All @@ -370,6 +418,86 @@ func TestDeprecatedIntSum(t *testing.T) {
},
}},
},
{
inputMetrics: []*otlpmetrics.Metric{{
Data: &otlpmetrics.Metric_IntSum{
IntSum: &otlpmetrics.IntSum{ //nolint:staticcheck // SA1019 ignore this!
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
DataPoints: []*otlpmetrics.IntDataPoint{ //nolint:staticcheck // SA1019 ignore this!
{
Labels: []otlpcommon.StringKeyValue{
{Key: "IntSumKey", Value: "IntSumValue"},
},
StartTimeUnixNano: 22,
TimeUnixNano: 23,
Value: 201,
Exemplars: []otlpmetrics.IntExemplar{}, //nolint:staticcheck // SA1019 ignore this!
},
},
},
},
}},
outputMetrics: []*otlpmetrics.Metric{{
Data: &otlpmetrics.Metric_Sum{
Sum: &otlpmetrics.Sum{
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_CUMULATIVE,
IsMonotonic: true,
DataPoints: []*otlpmetrics.NumberDataPoint{
{
Labels: []otlpcommon.StringKeyValue{
{Key: "IntSumKey", Value: "IntSumValue"},
},
StartTimeUnixNano: 22,
TimeUnixNano: 23,
Value: &otlpmetrics.NumberDataPoint_AsInt{AsInt: 201},
Exemplars: []otlpmetrics.Exemplar{},
},
},
},
},
}},
},
{
inputMetrics: []*otlpmetrics.Metric{{
Data: &otlpmetrics.Metric_IntSum{
IntSum: &otlpmetrics.IntSum{ //nolint:staticcheck // SA1019 ignore this!
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA,
IsMonotonic: false,
DataPoints: []*otlpmetrics.IntDataPoint{ //nolint:staticcheck // SA1019 ignore this!
{
Labels: []otlpcommon.StringKeyValue{
{Key: "IntSumKey", Value: "IntSumValue"},
},
StartTimeUnixNano: 22,
TimeUnixNano: 23,
Value: 201,
Exemplars: []otlpmetrics.IntExemplar{}, //nolint:staticcheck // SA1019 ignore this!
},
},
},
},
}},
outputMetrics: []*otlpmetrics.Metric{{
Data: &otlpmetrics.Metric_Sum{
Sum: &otlpmetrics.Sum{
AggregationTemporality: otlpmetrics.AggregationTemporality_AGGREGATION_TEMPORALITY_DELTA,
IsMonotonic: false,
DataPoints: []*otlpmetrics.NumberDataPoint{
{
Labels: []otlpcommon.StringKeyValue{
{Key: "IntSumKey", Value: "IntSumValue"},
},
StartTimeUnixNano: 22,
TimeUnixNano: 23,
Value: &otlpmetrics.NumberDataPoint_AsInt{AsInt: 201},
Exemplars: []otlpmetrics.Exemplar{},
},
},
},
},
}},
},
{
inputMetrics: []*otlpmetrics.Metric{{
Data: &otlpmetrics.Metric_IntSum{
Expand Down

0 comments on commit 144b6b4

Please sign in to comment.