Skip to content

Commit

Permalink
Fix all breakage
Browse files Browse the repository at this point in the history
  • Loading branch information
songy23 committed Dec 12, 2023
1 parent 1aae21f commit edd2fa7
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 32 deletions.
8 changes: 4 additions & 4 deletions connector/datadogconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,18 @@ type connectorImp struct {
var _ component.Component = (*connectorImp)(nil) // testing that the connectorImp properly implements the type Component interface

// function to create a new connector
func newConnector(logger *zap.Logger, _ component.Config, metricsConsumer consumer.Metrics, tracesConsumer consumer.Traces) (*connectorImp, error) {
logger.Info("Building datadog connector")
func newConnector(set component.TelemetrySettings, _ component.Config, metricsConsumer consumer.Metrics, tracesConsumer consumer.Traces) (*connectorImp, error) {
set.Logger.Info("Building datadog connector")

in := make(chan *pb.StatsPayload, 100)
trans, err := metrics.NewTranslator(logger)
trans, err := metrics.NewTranslator(set)

ctx := context.Background()
if err != nil {
return nil, err
}
return &connectorImp{
logger: logger,
logger: set.Logger,
agent: datadog.NewAgent(ctx, in),
translator: trans,
in: in,
Expand Down
4 changes: 2 additions & 2 deletions connector/datadogconnector/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ func createDefaultConfig() component.Config {
// defines the consumer type of the connector
// we want to consume traces and export metrics therefore define nextConsumer as metrics, consumer is the next component in the pipeline
func createTracesToMetricsConnector(_ context.Context, params connector.CreateSettings, cfg component.Config, nextConsumer consumer.Metrics) (connector.Traces, error) {
c, err := newConnector(params.Logger, cfg, nextConsumer, nil)
c, err := newConnector(params.TelemetrySettings, cfg, nextConsumer, nil)
if err != nil {
return nil, err
}
return c, nil
}

func createTracesToTracesConnector(_ context.Context, params connector.CreateSettings, cfg component.Config, nextConsumer consumer.Traces) (connector.Traces, error) {
c, err := newConnector(params.Logger, cfg, nil, nextConsumer)
c, err := newConnector(params.TelemetrySettings, cfg, nil, nextConsumer)
if err != nil {
return nil, err
}
Expand Down
5 changes: 4 additions & 1 deletion exporter/datadogexporter/internal/metrics/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/pdata/pmetric"
conventions "go.opentelemetry.io/collector/semconv/v1.6.1"
"go.uber.org/zap"
Expand All @@ -28,7 +29,9 @@ func (t testProvider) Source(context.Context) (source.Source, error) {
}

func newTranslator(t *testing.T, logger *zap.Logger) *metrics.Translator {
tr, err := metrics.NewTranslator(logger,
set := componenttest.NewNopTelemetrySettings()
set.Logger = logger
tr, err := metrics.NewTranslator(set,
metrics.WithHistogramMode(metrics.HistogramModeDistributions),
metrics.WithNumberMode(metrics.NumberModeCumulativeToDelta),
metrics.WithFallbackSourceProvider(testProvider("fallbackHostname")),
Expand Down
17 changes: 9 additions & 8 deletions exporter/datadogexporter/logs_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"encoding/binary"
"fmt"
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -21,6 +20,8 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/traceutil"
)

const timeFormatString = "2006-01-02T15:04:05.000Z07:00"

func TestLogsExporter(t *testing.T) {
lr := testdata.GenerateLogsOneLogRecord()
ld := lr.ResourceLogs().At(0).ScopeLogs().At(0).LogRecords().At(0)
Expand All @@ -44,7 +45,7 @@ func TestLogsExporter(t *testing.T) {
"message": ld.Body().AsString(),
"app": "server",
"instance_num": "1",
"@timestamp": testdata.TestLogTime.Format(time.RFC3339),
"@timestamp": testdata.TestLogTime.Format(timeFormatString),
"status": "Info",
"dd.span_id": fmt.Sprintf("%d", spanIDToUint64(ld.SpanID())),
"dd.trace_id": fmt.Sprintf("%d", traceIDToUint64(ld.TraceID())),
Expand Down Expand Up @@ -74,7 +75,7 @@ func TestLogsExporter(t *testing.T) {
"message": "hello",
"app": "server",
"instance_num": "1",
"@timestamp": testdata.TestLogTime.Format(time.RFC3339),
"@timestamp": testdata.TestLogTime.Format(timeFormatString),
"status": "Info",
"dd.span_id": fmt.Sprintf("%d", spanIDToUint64(ld.SpanID())),
"dd.trace_id": fmt.Sprintf("%d", traceIDToUint64(ld.TraceID())),
Expand Down Expand Up @@ -104,7 +105,7 @@ func TestLogsExporter(t *testing.T) {
"message": ld.Body().AsString(),
"app": "server",
"instance_num": "1",
"@timestamp": testdata.TestLogTime.Format(time.RFC3339),
"@timestamp": testdata.TestLogTime.Format(timeFormatString),
"status": "Info",
"dd.span_id": fmt.Sprintf("%d", spanIDToUint64(ld.SpanID())),
"dd.trace_id": fmt.Sprintf("%d", traceIDToUint64(ld.TraceID())),
Expand Down Expand Up @@ -136,7 +137,7 @@ func TestLogsExporter(t *testing.T) {
"message": ld.Body().AsString(),
"app": "server",
"instance_num": "1",
"@timestamp": testdata.TestLogTime.Format(time.RFC3339),
"@timestamp": testdata.TestLogTime.Format(timeFormatString),
"status": "Info",
"dd.span_id": fmt.Sprintf("%d", spanIDToUint64(ld.SpanID())),
"dd.trace_id": fmt.Sprintf("%d", traceIDToUint64(ld.TraceID())),
Expand All @@ -152,7 +153,7 @@ func TestLogsExporter(t *testing.T) {
"message": "something happened",
"env": "dev",
"customer": "acme",
"@timestamp": testdata.TestLogTime.Format(time.RFC3339),
"@timestamp": testdata.TestLogTime.Format(timeFormatString),
"status": "Info",
"ddtags": "tag1:true,otel_source:datadog_exporter",
"otel.severity_text": "Info",
Expand Down Expand Up @@ -180,7 +181,7 @@ func TestLogsExporter(t *testing.T) {
"message": ld.Body().AsString(),
"app": "server",
"instance_num": "1",
"@timestamp": testdata.TestLogTime.Format(time.RFC3339),
"@timestamp": testdata.TestLogTime.Format(timeFormatString),
"status": "Info",
"dd.span_id": fmt.Sprintf("%d", spanIDToUint64(ld.SpanID())),
"dd.trace_id": fmt.Sprintf("%d", traceIDToUint64(ld.TraceID())),
Expand All @@ -196,7 +197,7 @@ func TestLogsExporter(t *testing.T) {
"message": "something happened",
"env": "dev",
"customer": "acme",
"@timestamp": testdata.TestLogTime.Format(time.RFC3339),
"@timestamp": testdata.TestLogTime.Format(timeFormatString),
"status": "Info",
"ddtags": "tag2:true,otel_source:datadog_exporter",
"otel.severity_text": "Info",
Expand Down
7 changes: 4 additions & 3 deletions exporter/datadogexporter/metrics_exporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/DataDog/opentelemetry-mapping-go/pkg/inframetadata"
"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/attributes/source"
otlpmetrics "github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
Expand Down Expand Up @@ -50,7 +51,7 @@ type metricsExporter struct {
}

// translatorFromConfig creates a new metrics translator from the exporter
func translatorFromConfig(logger *zap.Logger, cfg *Config, sourceProvider source.Provider) (*otlpmetrics.Translator, error) {
func translatorFromConfig(set component.TelemetrySettings, cfg *Config, sourceProvider source.Provider) (*otlpmetrics.Translator, error) {
options := []otlpmetrics.TranslatorOption{
otlpmetrics.WithDeltaTTL(cfg.Metrics.DeltaTTL),
otlpmetrics.WithFallbackSourceProvider(sourceProvider),
Expand Down Expand Up @@ -82,7 +83,7 @@ func translatorFromConfig(logger *zap.Logger, cfg *Config, sourceProvider source
options = append(options, otlpmetrics.WithInitialCumulMonoValueMode(
otlpmetrics.InitialCumulMonoValueMode(cfg.Metrics.SumConfig.InitialCumulativeMonotonicMode)))

return otlpmetrics.NewTranslator(logger, options...)
return otlpmetrics.NewTranslator(set, options...)
}

func newMetricsExporter(
Expand All @@ -94,7 +95,7 @@ func newMetricsExporter(
apmStatsProcessor api.StatsProcessor,
metadataReporter *inframetadata.Reporter,
) (*metricsExporter, error) {
tr, err := translatorFromConfig(params.Logger, cfg, sourceProvider)
tr, err := translatorFromConfig(params.TelemetrySettings, cfg, sourceProvider)
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions exporter/datadogexporter/metrics_exporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/DataDog/opentelemetry-mapping-go/pkg/otlp/metrics"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/config/confignet"
"go.opentelemetry.io/collector/exporter/exportertest"
"go.opentelemetry.io/collector/pdata/pcommon"
Expand Down Expand Up @@ -750,8 +751,9 @@ func createTestMetricsWithStats() pmetric.Metrics {
"custom_attribute": "custom_value",
})
dest := md.ResourceMetrics()
logger, _ := zap.NewDevelopment()
trans, err := metrics.NewTranslator(logger)
set := componenttest.NewNopTelemetrySettings()
set.Logger, _ = zap.NewDevelopment()
trans, err := metrics.NewTranslator(set)
if err != nil {
panic(err)
}
Expand Down
2 changes: 1 addition & 1 deletion processor/datadogprocessor/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ func NewFactory() processor.Factory {
}

func createTracesProcessor(ctx context.Context, params processor.CreateSettings, cfg component.Config, nextConsumer consumer.Traces) (processor.Traces, error) {
return newProcessor(ctx, params.Logger, cfg, nextConsumer)
return newProcessor(ctx, params.TelemetrySettings, cfg, nextConsumer)
}
8 changes: 4 additions & 4 deletions processor/datadogprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ type datadogProcessor struct {
exit chan struct{}
}

func newProcessor(ctx context.Context, logger *zap.Logger, config component.Config, nextConsumer consumer.Traces) (*datadogProcessor, error) {
func newProcessor(ctx context.Context, set component.TelemetrySettings, config component.Config, nextConsumer consumer.Traces) (*datadogProcessor, error) {
cfg := config.(*Config)
in := make(chan *pb.StatsPayload, 100)
trans, err := metrics.NewTranslator(logger)
trans, err := metrics.NewTranslator(set)
if err != nil {
return nil, err
}
logger.Warn(
set.Logger.Warn(
"The datadogprocessor has been deprecated in favor of the datadogconnector",
zap.String(
"documentation",
"https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/datadogprocessor/README.md#deprecated-in-favor-of-datadogconnector",
),
)
return &datadogProcessor{
logger: logger,
logger: set.Logger,
nextConsumer: nextConsumer,
agent: datadog.NewAgent(ctx, in),
translator: trans,
Expand Down
14 changes: 7 additions & 7 deletions processor/datadogprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ import (
"github.com/DataDog/sketches-go/ddsketch"
"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/exporter"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/pdata/pmetric"
"go.opentelemetry.io/collector/pdata/ptrace"
"go.uber.org/zap"
"google.golang.org/protobuf/proto"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog"
Expand All @@ -29,7 +29,7 @@ func TestProcessorStart(t *testing.T) {
ctx := context.Background()

t.Run("fail", func(t *testing.T) {
p, err := newProcessor(ctx, zap.NewNop(), createDefaultConfig(), &mockTracesConsumer{})
p, err := newProcessor(ctx, componenttest.NewNopTelemetrySettings(), createDefaultConfig(), &mockTracesConsumer{})
require.NoError(t, err)
defer p.Shutdown(ctx) //nolint:errcheck
require.True(t, p.Capabilities().MutatesData)
Expand All @@ -42,7 +42,7 @@ func TestProcessorStart(t *testing.T) {
})

t.Run("fail/2", func(t *testing.T) {
p, err := newProcessor(ctx, zap.NewNop(), createDefaultConfig(), &mockTracesConsumer{})
p, err := newProcessor(ctx, componenttest.NewNopTelemetrySettings(), createDefaultConfig(), &mockTracesConsumer{})
require.NoError(t, err)
defer p.Shutdown(ctx) //nolint:errcheck
err = p.Start(ctx, &mockHost{
Expand All @@ -56,7 +56,7 @@ func TestProcessorStart(t *testing.T) {
})

t.Run("succeed/0", func(t *testing.T) {
p, err := newProcessor(ctx, zap.NewNop(), createDefaultConfig(), &mockTracesConsumer{})
p, err := newProcessor(ctx, componenttest.NewNopTelemetrySettings(), createDefaultConfig(), &mockTracesConsumer{})
require.NoError(t, err)
defer p.Shutdown(ctx) //nolint:errcheck
err = p.Start(ctx, &mockHost{
Expand All @@ -69,7 +69,7 @@ func TestProcessorStart(t *testing.T) {
})

t.Run("succeed/1", func(t *testing.T) {
p, err := newProcessor(ctx, zap.NewNop(), createDefaultConfig(), &mockTracesConsumer{})
p, err := newProcessor(ctx, componenttest.NewNopTelemetrySettings(), createDefaultConfig(), &mockTracesConsumer{})
require.NoError(t, err)
defer p.Shutdown(ctx) //nolint:errcheck
err = p.Start(ctx, &mockHost{
Expand All @@ -82,7 +82,7 @@ func TestProcessorStart(t *testing.T) {
})

t.Run("succeed/2", func(t *testing.T) {
lp, err := newProcessor(ctx, zap.NewNop(), &Config{MetricsExporter: component.NewIDWithName("datadog", "2")}, &mockTracesConsumer{})
lp, err := newProcessor(ctx, componenttest.NewNopTelemetrySettings(), &Config{MetricsExporter: component.NewIDWithName("datadog", "2")}, &mockTracesConsumer{})
require.NoError(t, err)
defer lp.Shutdown(ctx) //nolint:errcheck
err = lp.Start(ctx, &mockHost{
Expand All @@ -99,7 +99,7 @@ func TestProcessorStart(t *testing.T) {
func TestProcessorIngest(t *testing.T) {
var mockConsumer mockTracesConsumer
ctx := context.Background()
p, err := newProcessor(ctx, zap.NewNop(), createDefaultConfig(), &mockConsumer)
p, err := newProcessor(ctx, componenttest.NewNopTelemetrySettings(), createDefaultConfig(), &mockConsumer)
require.NoError(t, err)
out := make(chan *pb.StatsPayload, 1)
ing := &mockIngester{Out: out}
Expand Down

0 comments on commit edd2fa7

Please sign in to comment.