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

[connector/datadog] Allow export to traces pipelines #4796

Merged
merged 17 commits into from
Oct 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
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
27 changes: 27 additions & 0 deletions .chloggen/awscwl_noisypusher.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: awscloudwatchlogsexporter/awsemfexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Reduce noisy logs emitted by CloudWatch Logs Pusher.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [27774]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext: The Collector logger will now write successful CloudWatch API writes at the Debug level instead of Info level.

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
27 changes: 27 additions & 0 deletions .chloggen/datadog-connector-traces.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: datadogconnector

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Allow datadogconnector to be used as a traces-to-traces connector

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [27846]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
27 changes: 27 additions & 0 deletions .chloggen/double-converter.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: 'enhancement'

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: doubleconverter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Adding a double converter into pkg/ottl"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [22056]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
22 changes: 22 additions & 0 deletions .chloggen/feat_top_n_file_sorting.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: "enhancement"

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: filelogreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Add a new "top_n" option to specify the number of files to track when using ordering criteria

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [23788]

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: ["user"]
27 changes: 27 additions & 0 deletions .chloggen/ptracetest-ignore-spanid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/pdatatest

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "support ignore span ID in span comparisons for ptracetest"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [27685]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
27 changes: 27 additions & 0 deletions .chloggen/ptracetest-ignore-traceid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/pdatatest

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "support ignore trace ID in span comparisons for ptracetest"

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [27687]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: pkg/stanza

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: When async is enabled for udp receiver, separate logic into readers (only read logs from udp port and push to channel), and processors (read logs from channel and process; decode, split, add attributes, and push downstream), allowing to change concurrency level for both readers and processors separately.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [27613]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
18 changes: 15 additions & 3 deletions cmd/otelcontribcol/exporters_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,11 +606,23 @@ func verifyExporterLifecycle(t *testing.T, factory exporter.Factory, getConfigFn
assert.NotPanics(t, func() {
switch e := exp.(type) {
case exporter.Logs:
err = e.ConsumeLogs(ctx, testdata.GenerateLogsManyLogRecordsSameResource(2))
logs := testdata.GenerateLogsManyLogRecordsSameResource(2)
if !e.Capabilities().MutatesData {
logs.MarkReadOnly()
}
err = e.ConsumeLogs(ctx, logs)
case exporter.Metrics:
err = e.ConsumeMetrics(ctx, testdata.GenerateMetricsTwoMetrics())
metrics := testdata.GenerateMetricsTwoMetrics()
if !e.Capabilities().MutatesData {
metrics.MarkReadOnly()
}
err = e.ConsumeMetrics(ctx, metrics)
case exporter.Traces:
err = e.ConsumeTraces(ctx, testdata.GenerateTracesTwoSpansSameResource())
traces := testdata.GenerateTracesTwoSpansSameResource()
if !e.Capabilities().MutatesData {
traces.MarkReadOnly()
}
err = e.ConsumeTraces(ctx, traces)
}
})
if !expectErr {
Expand Down
3 changes: 2 additions & 1 deletion connector/datadogconnector/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
| [Exporter Pipeline Type] | [Receiver Pipeline Type] | [Stability Level] |
| ------------------------ | ------------------------ | ----------------- |
| traces | metrics | [beta] |
| traces | traces | [beta] |

[Exporter Pipeline Type]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/connector/README.md#exporter-pipeline-type
[Receiver Pipeline Type]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/connector/README.md#receiver-pipeline-type
Expand Down Expand Up @@ -91,7 +92,7 @@ service:
exporters: [datadog/connector]

traces/2: # this pipeline uses sampling
receivers: [otlp]
receivers: [datadog/connector]
processors: [batch, probabilistic_sampler]
exporters: [datadog]

Expand Down
15 changes: 11 additions & 4 deletions connector/datadogconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (

// connectorImp is the schema for connector
type connectorImp struct {
metricsConsumer consumer.Metrics // the next component in the pipeline to ingest data after connector
metricsConsumer consumer.Metrics // the next component in the pipeline to ingest metrics after connector
tracesConsumer consumer.Traces // the next component in the pipeline to ingest traces after connector
logger *zap.Logger

// agent specifies the agent used to ingest traces and output APM Stats.
Expand All @@ -40,7 +41,7 @@ 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, nextConsumer consumer.Metrics) (*connectorImp, error) {
func newConnector(logger *zap.Logger, _ component.Config, metricsConsumer consumer.Metrics, tracesConsumer consumer.Traces) (*connectorImp, error) {
logger.Info("Building datadog connector")

in := make(chan *pb.StatsPayload, 100)
Expand All @@ -55,7 +56,8 @@ func newConnector(logger *zap.Logger, _ component.Config, nextConsumer consumer.
agent: datadog.NewAgent(ctx, in),
translator: trans,
in: in,
metricsConsumer: nextConsumer,
metricsConsumer: metricsConsumer,
tracesConsumer: tracesConsumer,
exit: make(chan struct{}),
}, nil
}
Expand All @@ -64,7 +66,9 @@ func newConnector(logger *zap.Logger, _ component.Config, nextConsumer consumer.
func (c *connectorImp) Start(_ context.Context, _ component.Host) error {
c.logger.Info("Starting datadogconnector")
c.agent.Start()
go c.run()
if c.metricsConsumer != nil {
go c.run()
}
return nil
}

Expand All @@ -85,6 +89,9 @@ func (c *connectorImp) Capabilities() consumer.Capabilities {

func (c *connectorImp) ConsumeTraces(ctx context.Context, traces ptrace.Traces) error {
c.agent.Ingest(ctx, traces)
if c.tracesConsumer != nil {
return c.tracesConsumer.ConsumeTraces(ctx, traces)
}
return nil
}

Expand Down
10 changes: 8 additions & 2 deletions connector/datadogconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ func TestNewConnector(t *testing.T) {
creationParams := connectortest.NewNopCreateSettings()
cfg := factory.CreateDefaultConfig().(*Config)

traceConnector, err := factory.CreateTracesToMetrics(context.Background(), creationParams, cfg, consumertest.NewNop())
traceToMetricsConnector, err := factory.CreateTracesToMetrics(context.Background(), creationParams, cfg, consumertest.NewNop())
assert.NoError(t, err)

_, ok := traceConnector.(*connectorImp)
_, ok := traceToMetricsConnector.(*connectorImp)
assert.True(t, ok) // checks if the created connector implements the connectorImp struct

traceToTracesConnector, err := factory.CreateTracesToTraces(context.Background(), creationParams, cfg, consumertest.NewNop())
assert.NoError(t, err)

_, ok = traceToTracesConnector.(*connectorImp)
assert.True(t, ok) // checks if the created connector implements the connectorImp struct
}
13 changes: 11 additions & 2 deletions connector/datadogconnector/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ func NewFactory() connector.Factory {
return connector.NewFactory(
metadata.Type,
createDefaultConfig,
connector.WithTracesToMetrics(createTracesToMetricsConnector, metadata.TracesToMetricsStability))
connector.WithTracesToMetrics(createTracesToMetricsConnector, metadata.TracesToMetricsStability),
connector.WithTracesToTraces(createTracesToTracesConnector, metadata.TracesToTracesStability))
}

var _ component.Config = (*Config)(nil)
Expand All @@ -35,7 +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)
c, err := newConnector(params.Logger, 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)
if err != nil {
return nil, err
}
Expand Down

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

2 changes: 1 addition & 1 deletion connector/datadogconnector/metadata.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ type: datadog
status:
class: connector
stability:
beta: [traces_to_metrics]
beta: [traces_to_metrics, traces_to_traces]
distributions: [contrib]
codeowners:
active: [mx-psi, gbbr, dineshg13]
5 changes: 2 additions & 3 deletions exporter/fileexporter/buffered_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@ package fileexporter // import "github.com/open-telemetry/opentelemetry-collecto

import (
"bufio"
"errors"
"io"

"go.uber.org/multierr"
)

// bufferedWriteCloser is intended to use more memory
Expand All @@ -33,7 +32,7 @@ func (bwc *bufferedWriteCloser) Write(p []byte) (n int, err error) {
}

func (bwc *bufferedWriteCloser) Close() error {
return multierr.Combine(
return errors.Join(
bwc.buffered.Flush(),
bwc.wrapped.Close(),
)
Expand Down
4 changes: 2 additions & 2 deletions exporter/fileexporter/buffered_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package fileexporter

import (
"bytes"
"errors"
"fmt"
"io"
"os"
Expand All @@ -13,7 +14,6 @@ import (

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/multierr"
)

const (
Expand Down Expand Up @@ -83,7 +83,7 @@ func BenchmarkWriter(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err = w.Write(payload)
}
errBenchmark = multierr.Combine(err, w.Close())
errBenchmark = errors.Join(err, w.Close())
})
}
}
Expand Down
Loading
Loading