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

Changes demonstrating ScalarDataPoint #46

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions exporters/otlp/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module go.opentelemetry.io/otel/exporters/otlp

replace go.opentelemetry.io/otel => ../..

replace github.com/open-telemetry/opentelemetry-proto => ../../../github.com/open-telemetry/opentelemetry-proto

require (
github.com/gogo/protobuf v1.3.1
github.com/google/go-cmp v0.5.0
Expand Down
33 changes: 12 additions & 21 deletions exporters/otlp/internal/transform/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,11 +185,8 @@ func sink(ctx context.Context, in <-chan result) ([]*metricpb.ResourceMetrics, e
mb[mID] = res.Metric
continue
}
if len(res.Metric.Int64DataPoints) > 0 {
m.Int64DataPoints = append(m.Int64DataPoints, res.Metric.Int64DataPoints...)
}
if len(res.Metric.DoubleDataPoints) > 0 {
m.DoubleDataPoints = append(m.DoubleDataPoints, res.Metric.DoubleDataPoints...)
if len(res.Metric.ScalarDataPoints) > 0 {
m.ScalarDataPoints = append(m.ScalarDataPoints, res.Metric.ScalarDataPoints...)
}
if len(res.Metric.HistogramDataPoints) > 0 {
m.HistogramDataPoints = append(m.HistogramDataPoints, res.Metric.HistogramDataPoints...)
Expand Down Expand Up @@ -261,27 +258,21 @@ func sum(record export.Record, a aggregation.Sum) (*metricpb.Metric, error) {
},
}

m.ScalarDataPoints = []*metricpb.ScalarDataPoint{
{
Labels: stringKeyValues(labels.Iter()),
StartTimeUnixNano: uint64(record.StartTime().UnixNano()),
TimeUnixNano: uint64(record.EndTime().UnixNano()),
},
}

switch n := desc.NumberKind(); n {
case metric.Int64NumberKind:
m.MetricDescriptor.Type = metricpb.MetricDescriptor_INT64
m.Int64DataPoints = []*metricpb.Int64DataPoint{
{
Value: sum.CoerceToInt64(n),
Labels: stringKeyValues(labels.Iter()),
StartTimeUnixNano: uint64(record.StartTime().UnixNano()),
TimeUnixNano: uint64(record.EndTime().UnixNano()),
},
}
m.ScalarDataPoints[0].ValueInt64 = sum.CoerceToInt64(n)
case metric.Float64NumberKind:
m.MetricDescriptor.Type = metricpb.MetricDescriptor_DOUBLE
m.DoubleDataPoints = []*metricpb.DoubleDataPoint{
{
Value: sum.CoerceToFloat64(n),
Labels: stringKeyValues(labels.Iter()),
StartTimeUnixNano: uint64(record.StartTime().UnixNano()),
TimeUnixNano: uint64(record.EndTime().UnixNano()),
},
}
m.ScalarDataPoints[0].ValueDouble = sum.CoerceToFloat64(n)
default:
return nil, fmt.Errorf("%w: %v", ErrUnknownValueType, n)
}
Expand Down
17 changes: 7 additions & 10 deletions exporters/otlp/internal/transform/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,7 @@ func TestMinMaxSumCountDatapoints(t *testing.T) {
record := export.NewRecord(&desc, &labels, nil, ckpt.Aggregation(), intervalStart, intervalEnd)
m, err := minMaxSumCount(record, ckpt.(aggregation.MinMaxSumCount))
if assert.NoError(t, err) {
assert.Equal(t, []*metricpb.Int64DataPoint(nil), m.Int64DataPoints)
assert.Equal(t, []*metricpb.DoubleDataPoint(nil), m.DoubleDataPoints)
assert.Equal(t, []*metricpb.ScalarDataPoint(nil), m.ScalarDataPoints)
assert.Equal(t, []*metricpb.HistogramDataPoint(nil), m.HistogramDataPoints)
assert.Equal(t, expected, m.SummaryDataPoints)
}
Expand Down Expand Up @@ -280,12 +279,11 @@ func TestSumInt64DataPoints(t *testing.T) {
require.NoError(t, s.SynchronizedMove(ckpt, &desc))
record := export.NewRecord(&desc, &labels, nil, ckpt.Aggregation(), intervalStart, intervalEnd)
if m, err := sum(record, ckpt.(aggregation.Sum)); assert.NoError(t, err) {
assert.Equal(t, []*metricpb.Int64DataPoint{{
Value: 1,
assert.Equal(t, []*metricpb.ScalarDataPoint{{
ValueInt64: 1,
StartTimeUnixNano: uint64(intervalStart.UnixNano()),
TimeUnixNano: uint64(intervalEnd.UnixNano()),
}}, m.Int64DataPoints)
assert.Equal(t, []*metricpb.DoubleDataPoint(nil), m.DoubleDataPoints)
}}, m.ScalarDataPoints)
assert.Equal(t, []*metricpb.HistogramDataPoint(nil), m.HistogramDataPoints)
assert.Equal(t, []*metricpb.SummaryDataPoint(nil), m.SummaryDataPoints)
}
Expand All @@ -299,12 +297,11 @@ func TestSumFloat64DataPoints(t *testing.T) {
require.NoError(t, s.SynchronizedMove(ckpt, &desc))
record := export.NewRecord(&desc, &labels, nil, ckpt.Aggregation(), intervalStart, intervalEnd)
if m, err := sum(record, ckpt.(aggregation.Sum)); assert.NoError(t, err) {
assert.Equal(t, []*metricpb.Int64DataPoint(nil), m.Int64DataPoints)
assert.Equal(t, []*metricpb.DoubleDataPoint{{
Value: 1,
assert.Equal(t, []*metricpb.ScalarDataPoint{{
ValueDouble: 1,
StartTimeUnixNano: uint64(intervalStart.UnixNano()),
TimeUnixNano: uint64(intervalEnd.UnixNano()),
}}, m.DoubleDataPoints)
}}, m.ScalarDataPoints)
assert.Equal(t, []*metricpb.HistogramDataPoint(nil), m.HistogramDataPoints)
assert.Equal(t, []*metricpb.SummaryDataPoint(nil), m.SummaryDataPoints)
}
Expand Down
8 changes: 4 additions & 4 deletions exporters/otlp/otlp_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,13 +243,13 @@ func newExporterEndToEndTest(t *testing.T, additionalOpts []otlp.ExporterOption)
switch data.nKind {
case metricapi.Int64NumberKind:
assert.Equal(t, metricpb.MetricDescriptor_INT64.String(), desc.GetType().String())
if dp := m.GetInt64DataPoints(); assert.Len(t, dp, 1) {
assert.Equal(t, data.val, dp[0].Value, "invalid value for %q", desc.Name)
if dp := m.GetScalarDataPoints(); assert.Len(t, dp, 1) {
assert.Equal(t, data.val, dp[0].ValueInt64, "invalid value for %q", desc.Name)
}
case metricapi.Float64NumberKind:
assert.Equal(t, metricpb.MetricDescriptor_DOUBLE.String(), desc.GetType().String())
if dp := m.GetDoubleDataPoints(); assert.Len(t, dp, 1) {
assert.Equal(t, float64(data.val), dp[0].Value, "invalid value for %q", desc.Name)
if dp := m.GetScalarDataPoints(); assert.Len(t, dp, 1) {
assert.Equal(t, float64(data.val), dp[0].ValueDouble, "invalid value for %q", desc.Name)
}
default:
assert.Failf(t, "invalid number kind", data.nKind.String())
Expand Down
53 changes: 26 additions & 27 deletions exporters/otlp/otlp_metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,15 +189,15 @@ func TestNoGroupingExport(t *testing.T) {
Metrics: []*metricpb.Metric{
{
MetricDescriptor: md,
Int64DataPoints: []*metricpb.Int64DataPoint{
ScalarDataPoints: []*metricpb.ScalarDataPoint{
{
Value: 11,
ValueInt64: 11,
Labels: cpu1Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
},
{
Value: 11,
ValueInt64: 11,
Labels: cpu2Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
Expand Down Expand Up @@ -318,15 +318,15 @@ func TestCountInt64MetricGroupingExport(t *testing.T) {
Metrics: []*metricpb.Metric{
{
MetricDescriptor: md,
Int64DataPoints: []*metricpb.Int64DataPoint{
ScalarDataPoints: []*metricpb.ScalarDataPoint{
{
Value: 11,
ValueInt64: 11,
Labels: cpu1Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
},
{
Value: 11,
ValueInt64: 11,
Labels: cpu1Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
Expand Down Expand Up @@ -364,9 +364,9 @@ func TestCountFloat64MetricGroupingExport(t *testing.T) {
Name: "float64-count",
Type: metricpb.MetricDescriptor_DOUBLE,
},
DoubleDataPoints: []*metricpb.DoubleDataPoint{
ScalarDataPoints: []*metricpb.ScalarDataPoint{
{
Value: 11,
ValueDouble: 11,
Labels: []*commonpb.StringKeyValue{
{
Key: "CPU",
Expand All @@ -381,7 +381,7 @@ func TestCountFloat64MetricGroupingExport(t *testing.T) {
TimeUnixNano: pointTime(),
},
{
Value: 11,
ValueDouble: 11,
Labels: []*commonpb.StringKeyValue{
{
Key: "CPU",
Expand Down Expand Up @@ -450,21 +450,21 @@ func TestResourceMetricGroupingExport(t *testing.T) {
Metrics: []*metricpb.Metric{
{
MetricDescriptor: md,
Int64DataPoints: []*metricpb.Int64DataPoint{
ScalarDataPoints: []*metricpb.ScalarDataPoint{
{
Value: 11,
ValueInt64: 11,
Labels: cpu1Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
},
{
Value: 11,
ValueInt64: 11,
Labels: cpu1Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
},
{
Value: 11,
ValueInt64: 11,
Labels: cpu2Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
Expand All @@ -482,9 +482,9 @@ func TestResourceMetricGroupingExport(t *testing.T) {
Metrics: []*metricpb.Metric{
{
MetricDescriptor: md,
Int64DataPoints: []*metricpb.Int64DataPoint{
ScalarDataPoints: []*metricpb.ScalarDataPoint{
{
Value: 11,
ValueInt64: 11,
Labels: cpu1Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
Expand Down Expand Up @@ -575,21 +575,21 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
Metrics: []*metricpb.Metric{
{
MetricDescriptor: md,
Int64DataPoints: []*metricpb.Int64DataPoint{
ScalarDataPoints: []*metricpb.ScalarDataPoint{
{
Value: 11,
ValueInt64: 11,
Labels: cpu1Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
},
{
Value: 11,
ValueInt64: 11,
Labels: cpu1Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
},
{
Value: 11,
ValueInt64: 11,
Labels: cpu2Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
Expand All @@ -606,9 +606,9 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
Metrics: []*metricpb.Metric{
{
MetricDescriptor: md,
Int64DataPoints: []*metricpb.Int64DataPoint{
ScalarDataPoints: []*metricpb.ScalarDataPoint{
{
Value: 11,
ValueInt64: 11,
Labels: cpu1Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
Expand All @@ -624,9 +624,9 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
Metrics: []*metricpb.Metric{
{
MetricDescriptor: md,
Int64DataPoints: []*metricpb.Int64DataPoint{
ScalarDataPoints: []*metricpb.ScalarDataPoint{
{
Value: 11,
ValueInt64: 11,
Labels: cpu1Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
Expand All @@ -648,9 +648,9 @@ func TestResourceInstLibMetricGroupingExport(t *testing.T) {
Metrics: []*metricpb.Metric{
{
MetricDescriptor: md,
Int64DataPoints: []*metricpb.Int64DataPoint{
ScalarDataPoints: []*metricpb.ScalarDataPoint{
{
Value: 11,
ValueInt64: 11,
Labels: cpu1Labels,
StartTimeUnixNano: startTime(),
TimeUnixNano: pointTime(),
Expand Down Expand Up @@ -754,8 +754,7 @@ func runMetricExportTest(t *testing.T, exp *Exporter, rs []record, expected []me
// Compare each list directly because there is no order
// guarantee with the concurrent processing design of the exporter
// and ElementsMatch does not apply to contained slices.
assert.ElementsMatch(t, expected.GetInt64DataPoints(), g[i].GetInt64DataPoints())
assert.ElementsMatch(t, expected.GetDoubleDataPoints(), g[i].GetDoubleDataPoints())
assert.ElementsMatch(t, expected.GetScalarDataPoints(), g[i].GetScalarDataPoints())
assert.ElementsMatch(t, expected.GetHistogramDataPoints(), g[i].GetHistogramDataPoints())
assert.ElementsMatch(t, expected.GetSummaryDataPoints(), g[i].GetSummaryDataPoints())
}
Expand Down