Skip to content

Commit

Permalink
PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
dineshg13 committed Feb 5, 2024
1 parent 3b5ad49 commit 7459120
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions .chloggen/dinesh.gurumurthy_fix-connector.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ change_type: bug_fix
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: datadog/connector
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: A new struct for trace-to-trace pipeline in datadog connector
note: Create a separate connector in the Datadog connector for the trace-to-metrics and trace-to-trace pipelines. It should reduce the number of conversions we do and help with Datadog connector performance.
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [30828]
# (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: Simplify datadog/connector in trace-trace pipeline
subtext: Simplify datadog/connector with two separate connectors in trace-to-metrics pipeline and trace-to-trace pipeline.
# 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.
Expand Down
20 changes: 10 additions & 10 deletions connector/datadogconnector/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/datadog"
)

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

Expand All @@ -42,10 +42,10 @@ type connectorImp struct {
exit chan struct{}
}

var _ component.Component = (*connectorImp)(nil) // testing that the connectorImp properly implements the type Component interface
var _ component.Component = (*traceToMetricConnector)(nil) // testing that the connectorImp properly implements the type Component interface

// function to create a new connector
func newConnector(set component.TelemetrySettings, cfg component.Config, metricsConsumer consumer.Metrics) (*connectorImp, error) {
func newTraceToMetricConnector(set component.TelemetrySettings, cfg component.Config, metricsConsumer consumer.Metrics) (*traceToMetricConnector, error) {
set.Logger.Info("Building datadog connector for traces to metrics")
in := make(chan *pb.StatsPayload, 100)
set.MeterProvider = noop.NewMeterProvider() // disable metrics for the connector
Expand All @@ -59,7 +59,7 @@ func newConnector(set component.TelemetrySettings, cfg component.Config, metrics
}

ctx := context.Background()
return &connectorImp{
return &traceToMetricConnector{
logger: set.Logger,
agent: datadog.NewAgentWithConfig(ctx, getTraceAgentCfg(cfg.(*Config).Traces), in),
translator: trans,
Expand All @@ -83,15 +83,15 @@ func getTraceAgentCfg(cfg TracesConfig) *traceconfig.AgentConfig {
}

// Start implements the component.Component interface.
func (c *connectorImp) Start(_ context.Context, _ component.Host) error {
func (c *traceToMetricConnector) Start(_ context.Context, _ component.Host) error {
c.logger.Info("Starting datadogconnector")
c.agent.Start()
go c.run()
return nil
}

// Shutdown implements the component.Component interface.
func (c *connectorImp) Shutdown(context.Context) error {
func (c *traceToMetricConnector) Shutdown(context.Context) error {
c.logger.Info("Shutting down datadog connector")
c.logger.Info("Stopping datadog agent")
// stop the agent and wait for the run loop to exit
Expand All @@ -103,18 +103,18 @@ func (c *connectorImp) Shutdown(context.Context) error {

// Capabilities implements the consumer interface.
// tells use whether the component(connector) will mutate the data passed into it. if set to true the connector does modify the data
func (c *connectorImp) Capabilities() consumer.Capabilities {
func (c *traceToMetricConnector) Capabilities() consumer.Capabilities {
return consumer.Capabilities{MutatesData: false}
}

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

// run awaits incoming stats resulting from the agent's ingestion, converts them
// to metrics and flushes them using the configured metrics exporter.
func (c *connectorImp) run() {
func (c *traceToMetricConnector) run() {
defer close(c.exit)
for {
select {
Expand Down
4 changes: 2 additions & 2 deletions connector/datadogconnector/connector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"go.opentelemetry.io/collector/consumer/consumertest"
)

var _ component.Component = (*connectorImp)(nil) // testing that the connectorImp properly implements the type Component interface
var _ component.Component = (*traceToMetricConnector)(nil) // testing that the connectorImp properly implements the type Component interface

// create test to create a connector, check that basic code compiles
func TestNewConnector(t *testing.T) {
Expand All @@ -25,7 +25,7 @@ func TestNewConnector(t *testing.T) {
traceToMetricsConnector, err := factory.CreateTracesToMetrics(context.Background(), creationParams, cfg, consumertest.NewNop())
assert.NoError(t, err)

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

Expand Down
2 changes: 1 addition & 1 deletion connector/datadogconnector/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ 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.TelemetrySettings, cfg, nextConsumer)
c, err := newTraceToMetricConnector(params.TelemetrySettings, cfg, nextConsumer)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 7459120

Please sign in to comment.