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

Remove old metrics internal structs #1710

Merged
merged 1 commit into from
Sep 1, 2020
Merged
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
39 changes: 0 additions & 39 deletions consumer/pdatautil/pdatautil.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import (
"go.opentelemetry.io/collector/consumer/consumerdata"
"go.opentelemetry.io/collector/consumer/pdata"
"go.opentelemetry.io/collector/internal/data"
"go.opentelemetry.io/collector/internal/dataold"
"go.opentelemetry.io/collector/translator/internaldata"
)

Expand All @@ -36,9 +35,6 @@ func MetricsToMetricsData(md pdata.Metrics) []consumerdata.MetricsData {
if cmd, ok := md.InternalOpaque.([]consumerdata.MetricsData); ok {
return cmd
}
if ims, ok := md.InternalOpaque.(dataold.MetricData); ok {
return internaldata.MetricDataToOC(ims)
}
if ims, ok := md.InternalOpaque.(data.MetricData); ok {
return internaldata.MetricsToOC(ims)
}
Expand All @@ -52,39 +48,13 @@ func MetricsFromMetricsData(ocmds []consumerdata.MetricsData) pdata.Metrics {
return pdata.Metrics{InternalOpaque: ocmds}
}

// MetricsToOldInternalMetrics returns the `dataold.MetricData` representation of the `pdata.Metrics`.
//
// This is a temporary function that will be removed when the new internal pdata.Metrics will be finalized.
func MetricsToOldInternalMetrics(md pdata.Metrics) dataold.MetricData {
if ims, ok := md.InternalOpaque.(data.MetricData); ok {
return internaldata.OCSliceToMetricData(internaldata.MetricsToOC(ims))
}
if ims, ok := md.InternalOpaque.(dataold.MetricData); ok {
return ims
}
if cmd, ok := md.InternalOpaque.([]consumerdata.MetricsData); ok {
return internaldata.OCSliceToMetricData(cmd)
}
panic("Unsupported metrics type.")
}

// MetricsFromOldInternalMetrics returns the `pdata.Metrics` representation of the `dataold.MetricData`.
//
// This is a temporary function that will be removed when the new internal pdata.Metrics will be finalized.
func MetricsFromOldInternalMetrics(md dataold.MetricData) pdata.Metrics {
return pdata.Metrics{InternalOpaque: md}
}

// MetricsToInternalMetrics returns the `data.MetricData` representation of the `pdata.Metrics`.
//
// This is a temporary function that will be removed when the new internal pdata.Metrics will be finalized.
func MetricsToInternalMetrics(md pdata.Metrics) data.MetricData {
if ims, ok := md.InternalOpaque.(data.MetricData); ok {
return ims
}
if ims, ok := md.InternalOpaque.(dataold.MetricData); ok {
return internaldata.OCSliceToMetrics(internaldata.MetricDataToOC(ims))
}
if cmd, ok := md.InternalOpaque.([]consumerdata.MetricsData); ok {
return internaldata.OCSliceToMetrics(cmd)
}
Expand All @@ -102,9 +72,6 @@ func MetricsFromInternalMetrics(md data.MetricData) pdata.Metrics {
//
// This is a temporary function that will be removed when the new internal pdata.Metrics will be finalized.
func CloneMetrics(md pdata.Metrics) pdata.Metrics {
if ims, ok := md.InternalOpaque.(dataold.MetricData); ok {
return pdata.Metrics{InternalOpaque: ims.Clone()}
}
if ims, ok := md.InternalOpaque.(data.MetricData); ok {
return pdata.Metrics{InternalOpaque: ims.Clone()}
}
Expand All @@ -119,9 +86,6 @@ func CloneMetrics(md pdata.Metrics) pdata.Metrics {
}

func MetricCount(md pdata.Metrics) int {
if ims, ok := md.InternalOpaque.(dataold.MetricData); ok {
return ims.MetricCount()
}
if ims, ok := md.InternalOpaque.(data.MetricData); ok {
return ims.MetricCount()
}
Expand All @@ -136,9 +100,6 @@ func MetricCount(md pdata.Metrics) int {
}

func MetricAndDataPointCount(md pdata.Metrics) (int, int) {
if ims, ok := md.InternalOpaque.(dataold.MetricData); ok {
return ims.MetricAndDataPointCount()
}
if ims, ok := md.InternalOpaque.(data.MetricData); ok {
return ims.MetricAndDataPointCount()
}
Expand Down
24 changes: 6 additions & 18 deletions consumer/pdatautil/pdatautil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ import (

"go.opentelemetry.io/collector/consumer/consumerdata"
"go.opentelemetry.io/collector/internal/data/testdata"
"go.opentelemetry.io/collector/internal/dataold/testdataold"
)

func TestMetricCount(t *testing.T) {
metrics := MetricsFromOldInternalMetrics(testdataold.GenerateMetricDataTwoMetrics())
metrics := MetricsFromInternalMetrics(testdata.GenerateMetricsTwoMetrics())
assert.Equal(t, 2, MetricCount(metrics))
}

func TestMetricCountOld(t *testing.T) {
metrics := MetricsFromInternalMetrics(testdata.GenerateMetricsOneMetric())
assert.Equal(t, 1, MetricCount(metrics))

metrics = MetricsFromMetricsData([]consumerdata.MetricsData{
{
Expand All @@ -56,13 +50,6 @@ func TestMetricCountOld(t *testing.T) {
assert.Equal(t, 1, MetricCount(metrics))
}

func TestMetricAndDataPointCountOld(t *testing.T) {
metrics := MetricsFromOldInternalMetrics(testdataold.GenerateMetricDataTwoMetrics())
metricsCount, dataPointsCount := MetricAndDataPointCount(metrics)
assert.Equal(t, 2, metricsCount)
assert.Equal(t, 4, dataPointsCount)
}

func TestMetricAndDataPointCount(t *testing.T) {
metrics := MetricsFromInternalMetrics(testdata.GenerateMetricsOneMetric())
metricsCount, dataPointsCount := MetricAndDataPointCount(metrics)
Expand Down Expand Up @@ -91,11 +78,12 @@ func TestMetricAndDataPointCount(t *testing.T) {
assert.Equal(t, 3, dataPointsCount)
}

func TestMetricConvertInternalToFromOld(t *testing.T) {
func TestMetricConvertInternalToFromOC(t *testing.T) {
metrics := MetricsFromInternalMetrics(testdata.GenerateMetricsOneMetric())
mdOld := MetricsToOldInternalMetrics(metrics)
assert.Equal(t, 1, mdOld.MetricCount())
oldMetrics := MetricsFromOldInternalMetrics(mdOld)
mdOc := MetricsToMetricsData(metrics)
assert.Len(t, mdOc, 1)
assert.Len(t, mdOc[0].Metrics, 1)
oldMetrics := MetricsFromMetricsData(mdOc)
assert.Equal(t, 1, MetricCount(oldMetrics))
mdNew := MetricsToInternalMetrics(oldMetrics)
assert.Equal(t, 1, mdNew.MetricCount())
Expand Down
Loading