Skip to content

Commit

Permalink
Change carbonexporter to use pdata, remove dependency on opencensus (#…
Browse files Browse the repository at this point in the history
…14589)

Signed-off-by: Bogdan Drutu <[email protected]>

Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu authored Sep 30, 2022
1 parent def6d0b commit 3c9d8f5
Show file tree
Hide file tree
Showing 7 changed files with 289 additions and 385 deletions.
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

0 comments on commit 3c9d8f5

Please sign in to comment.