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

Change carbonexporter to use pdata, remove dependency on opencensus #14589

Merged
merged 1 commit into from
Sep 30, 2022
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
12 changes: 1 addition & 11 deletions exporter/carbonexporter/exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,9 @@ import (
"sync"
"time"

agentmetricspb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/metrics/v1"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter/exporterhelper"
"go.opentelemetry.io/collector/pdata/pmetric"

internaldata "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus"
)

// newCarbonExporter returns a new Carbon exporter.
Expand Down Expand Up @@ -62,14 +59,7 @@ type carbonSender struct {
}

func (cs *carbonSender) pushMetricsData(_ context.Context, md pmetric.Metrics) error {
rms := md.ResourceMetrics()
mds := make([]*agentmetricspb.ExportMetricsServiceRequest, 0, rms.Len())
for i := 0; i < rms.Len(); i++ {
emsr := &agentmetricspb.ExportMetricsServiceRequest{}
emsr.Node, emsr.Resource, emsr.Metrics = internaldata.ResourceMetricsToOC(rms.At(i))
mds = append(mds, emsr)
}
lines, _, _ := metricDataToPlaintext(mds)
lines := metricDataToPlaintext(md)

if _, err := cs.connPool.Write([]byte(lines)); err != nil {
// Use the sum of converted and dropped since the write failed for all.
Expand Down
60 changes: 23 additions & 37 deletions exporter/carbonexporter/exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,16 @@ import (
"testing"
"time"

commonpb "github.com/census-instrumentation/opencensus-proto/gen-go/agent/common/v1"
metricspb "github.com/census-instrumentation/opencensus-proto/gen-go/metrics/v1"
resourcepb "github.com/census-instrumentation/opencensus-proto/gen-go/resource/v1"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
conventions "go.opentelemetry.io/collector/semconv/v1.9.0"
"go.uber.org/atomic"
"google.golang.org/protobuf/types/known/timestamppb"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/metricstestutil/ocmetricstestutil"
internaldata "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus"
)

func TestNew(t *testing.T) {
Expand Down Expand Up @@ -87,16 +83,14 @@ func TestNew(t *testing.T) {

func TestConsumeMetricsData(t *testing.T) {
t.Skip("skipping flaky test, see https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/396")
smallBatch := internaldata.OCToMetrics(nil, nil, []*metricspb.Metric{
ocmetricstestutil.Gauge(
"test_gauge",
[]string{"k0", "k1"},
ocmetricstestutil.Timeseries(
time.Now(),
[]string{"v0", "v1"},
ocmetricstestutil.Double(time.Now(), 123))),
})

smallBatch := pmetric.NewMetrics()
m := smallBatch.ResourceMetrics().AppendEmpty().ScopeMetrics().AppendEmpty().Metrics().AppendEmpty()
m.SetName("test_gauge")
dp := m.SetEmptyGauge().DataPoints().AppendEmpty()
dp.Attributes().PutString("k0", "v0")
dp.Attributes().PutString("k1", "v1")
dp.SetTimestamp(pcommon.NewTimestampFromTime(time.Now()))
dp.SetDoubleValue(123)
largeBatch := generateLargeBatch()

tests := []struct {
Expand Down Expand Up @@ -284,29 +278,21 @@ func Test_connPool_Concurrency(t *testing.T) {
}

func generateLargeBatch() pmetric.Metrics {
var metrics []*metricspb.Metric
ts := time.Now()
metrics := pmetric.NewMetrics()
rm := metrics.ResourceMetrics().AppendEmpty()
rm.Resource().Attributes().PutString(conventions.AttributeServiceName, "test_carbon")
ms := rm.ScopeMetrics().AppendEmpty().Metrics()

for i := 0; i < 65000; i++ {
metrics = append(metrics,
ocmetricstestutil.Gauge(
"test_"+strconv.Itoa(i),
[]string{"k0", "k1"},
ocmetricstestutil.Timeseries(
time.Now(),
[]string{"v0", "v1"},
&metricspb.Point{
Timestamp: timestamppb.New(ts),
Value: &metricspb.Point_Int64Value{Int64Value: int64(i)},
},
),
),
)
m := ms.AppendEmpty()
m.SetName("test_" + strconv.Itoa(i))
dp := m.SetEmptyGauge().DataPoints().AppendEmpty()
dp.Attributes().PutString("k0", "v0")
dp.Attributes().PutString("k1", "v1")
dp.SetTimestamp(pcommon.NewTimestampFromTime(ts))
dp.SetIntValue(int64(i))
}

return internaldata.OCToMetrics(
&commonpb.Node{
ServiceInfo: &commonpb.ServiceInfo{Name: "test_carbon"},
},
&resourcepb.Resource{Type: "test"},
metrics)
return metrics
}
17 changes: 5 additions & 12 deletions exporter/carbonexporter/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,31 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/exporter/carbon
go 1.18

require (
github.com/census-instrumentation/opencensus-proto v0.4.1
github.com/open-telemetry/opentelemetry-collector-contrib/internal/common v0.61.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.61.0
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus v0.61.0
github.com/stretchr/testify v1.8.0
go.opentelemetry.io/collector v0.61.0
go.opentelemetry.io/collector/pdata v0.61.0
go.opentelemetry.io/collector/semconv v0.61.0
go.uber.org/atomic v1.10.0
google.golang.org/protobuf v1.28.1

)

require (
github.com/cenkalti/backoff/v4 v4.1.3 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.5.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.2 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.3 // indirect
github.com/google/go-cmp v0.5.9 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/knadh/koanf v1.4.3 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/mapstructure v1.5.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pelletier/go-toml v1.9.4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
go.opencensus.io v0.23.0 // indirect
go.opentelemetry.io/collector/semconv v0.61.0 // indirect
go.opentelemetry.io/otel v1.10.0 // indirect
go.opentelemetry.io/otel/metric v0.32.1 // indirect
go.opentelemetry.io/otel/trace v1.10.0 // indirect
Expand All @@ -42,11 +38,8 @@ require (
golang.org/x/text v0.3.7 // indirect
google.golang.org/genproto v0.0.0-20220822174746-9e6da59bd2fc // indirect
google.golang.org/grpc v1.49.0 // indirect
google.golang.org/protobuf v1.28.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/opencensus => ../../pkg/translator/opencensus

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/common => ../../internal/common

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../internal/coreinternal
10 changes: 4 additions & 6 deletions exporter/carbonexporter/go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading