From b28c7f2b6a3d4c9086dbefaac956d50850e4dedc Mon Sep 17 00:00:00 2001 From: sakulali Date: Fri, 3 Nov 2023 00:08:58 +0800 Subject: [PATCH] [chore][testbed] Do not use export function `carbonreceiver.New` (#28858) **Description:** Do not use export function `carbonreceiver.New` and replace with `factory.CreateMetricsReceiver`, then we can chore carbonreceiver to make it pass checkapi tool. **Link to tracking Issue:** https://github.com/open-telemetry/opentelemetry-collector-contrib/issues/28857 --- testbed/datareceivers/carbon.go | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/testbed/datareceivers/carbon.go b/testbed/datareceivers/carbon.go index f0667e011d31..6f7794a631b8 100644 --- a/testbed/datareceivers/carbon.go +++ b/testbed/datareceivers/carbon.go @@ -8,13 +8,11 @@ import ( "fmt" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/config/confignet" "go.opentelemetry.io/collector/consumer" "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/receiver/receivertest" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/protocol" "github.com/open-telemetry/opentelemetry-collector-contrib/testbed/testbed" ) @@ -35,18 +33,13 @@ func NewCarbonDataReceiver(port int) *CarbonDataReceiver { // Start the receiver. func (cr *CarbonDataReceiver) Start(_ consumer.Traces, mc consumer.Metrics, _ consumer.Logs) error { - addr := fmt.Sprintf("127.0.0.1:%d", cr.Port) - config := carbonreceiver.Config{ - NetAddr: confignet.NetAddr{ - Endpoint: addr, - }, - Parser: &protocol.Config{ - Type: "plaintext", - Config: &protocol.PlaintextConfig{}, - }, - } + factory := carbonreceiver.NewFactory() + cfg := factory.CreateDefaultConfig().(*carbonreceiver.Config) + cfg.Endpoint = fmt.Sprintf("127.0.0.1:%d", cr.Port) + + set := receivertest.NewNopCreateSettings() var err error - cr.receiver, err = carbonreceiver.New(receivertest.NewNopCreateSettings(), config, mc) + cr.receiver, err = factory.CreateMetricsReceiver(context.Background(), set, cfg, mc) if err != nil { return err }