Skip to content

Commit

Permalink
Hide unnecessary public API
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <[email protected]>
  • Loading branch information
bogdandrutu committed Dec 14, 2023
1 parent 0af7fce commit 881c74a
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 68 deletions.
22 changes: 22 additions & 0 deletions .chloggen/carbonreceiver.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: 'breaking'

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

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Hide unnecessary public API

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

# 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: [api]
8 changes: 8 additions & 0 deletions receiver/carbonreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package carbonreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver"

import (
"errors"
"fmt"
"time"

Expand Down Expand Up @@ -35,6 +36,13 @@ type Config struct {
Parser *protocol.Config `mapstructure:"parser"`
}

func (cfg *Config) Validate() error {
if cfg.TCPIdleTimeout < 0 {
return errors.New("'tcp_idle_timeout' must be non-negative")
}
return nil
}

func (cfg *Config) Unmarshal(componentParser *confmap.Conf) error {
if componentParser == nil {
// The section is empty nothing to do, using the default config.
Expand Down
9 changes: 7 additions & 2 deletions receiver/carbonreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package carbonreceiver // import "github.com/open-telemetry/opentelemetry-collec

import (
"context"
"time"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/config/confignet"
Expand All @@ -13,7 +14,11 @@ import (

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/internal/metadata"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/protocol"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/transport"
)

const (
// TCPIdleTimeoutDefault is the default timeout for idle TCP connections.
TCPIdleTimeoutDefault = 30 * time.Second
)

// This file implements factory for Carbon receiver.
Expand All @@ -32,7 +37,7 @@ func createDefaultConfig() component.Config {
Endpoint: "localhost:2003",
Transport: "tcp",
},
TCPIdleTimeout: transport.TCPIdleTimeoutDefault,
TCPIdleTimeout: TCPIdleTimeoutDefault,
Parser: &protocol.Config{
Type: "plaintext",
Config: &protocol.PlaintextConfig{},
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package transport

import (
"context"
"runtime"
"sync"
"testing"
Expand All @@ -14,8 +15,8 @@ import (
"go.opentelemetry.io/collector/consumer/consumertest"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/internal/client"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/protocol"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/transport/client"
)

func Test_Server_ListenAndServe(t *testing.T) {
Expand Down Expand Up @@ -52,7 +53,8 @@ func Test_Server_ListenAndServe(t *testing.T) {
mc := new(consumertest.MetricsSink)
p, err := (&protocol.PlaintextConfig{}).BuildParser()
require.NoError(t, err)
mr := NewMockReporter(1)
mr := &mockReporter{}
mr.wgMetricsProcessed.Add(1)

wgListenAndServe := sync.WaitGroup{}
wgListenAndServe.Add(1)
Expand All @@ -76,7 +78,7 @@ func Test_Server_ListenAndServe(t *testing.T) {
err = gc.Disconnect()
assert.NoError(t, err)

mr.WaitAllOnMetricsProcessedCalls()
mr.wgMetricsProcessed.Wait()

// Keep trying until we're timed out or got a result
assert.Eventually(t, func() bool {
Expand All @@ -96,3 +98,21 @@ func Test_Server_ListenAndServe(t *testing.T) {
})
}
}

// mockReporter provides a Reporter that provides some useful functionalities for
// tests (eg.: wait for certain number of messages).
type mockReporter struct {
wgMetricsProcessed sync.WaitGroup
}

func (m *mockReporter) OnDataReceived(ctx context.Context) context.Context {
return ctx
}

func (m *mockReporter) OnTranslationError(context.Context, error) {}

func (m *mockReporter) OnMetricsProcessed(context.Context, int, error) {
m.wgMetricsProcessed.Done()
}

func (m *mockReporter) OnDebugf(string, ...any) {}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"bufio"
"context"
"errors"
"fmt"
"io"
"net"
"strings"
Expand All @@ -21,11 +20,6 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/protocol"
)

const (
// TCPIdleTimeoutDefault is the default timeout for idle TCP connections.
TCPIdleTimeoutDefault = 30 * time.Second
)

type tcpServer struct {
ln net.Listener
wg sync.WaitGroup
Expand All @@ -40,14 +34,6 @@ func NewTCPServer(
addr string,
idleTimeout time.Duration,
) (Server, error) {
if idleTimeout < 0 {
return nil, fmt.Errorf("invalid idle timeout: %v", idleTimeout)
}

if idleTimeout == 0 {
idleTimeout = TCPIdleTimeoutDefault
}

ln, err := net.Listen("tcp", addr)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion receiver/carbonreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/internal/transport"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/protocol"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/transport"
)

var (
Expand Down
2 changes: 1 addition & 1 deletion receiver/carbonreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ import (
"go.opentelemetry.io/otel/sdk/trace/tracetest"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/common/testutil"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/internal/client"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/protocol"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/transport/client"
)

func Test_carbonreceiver_New(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion receiver/carbonreceiver/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"go.opentelemetry.io/collector/receiver/receiverhelper"
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/transport"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/internal/transport"
)

// reporter struct implements the transport.Reporter interface to give consistent
Expand Down
44 changes: 0 additions & 44 deletions receiver/carbonreceiver/transport/mock_reporter.go

This file was deleted.

8 changes: 8 additions & 0 deletions receiver/wavefrontreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package wavefrontreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/wavefrontreceiver"

import (
"errors"
"time"

"go.opentelemetry.io/collector/config/confignet"
Expand All @@ -20,3 +21,10 @@ type Config struct {
// tags in the CollectD format from the metric name. The default is false.
ExtractCollectdTags bool `mapstructure:"extract_collectd_tags"`
}

func (cfg *Config) Validate() error {
if cfg.TCPIdleTimeout < 0 {
return errors.New("'tcp_idle_timeout' must be non-negative")
}
return nil
}
4 changes: 2 additions & 2 deletions receiver/wavefrontreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver/transport"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/carbonreceiver"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/wavefrontreceiver/internal/metadata"
)

Expand All @@ -31,7 +31,7 @@ func createDefaultConfig() component.Config {
TCPAddr: confignet.TCPAddr{
Endpoint: "localhost:2003",
},
TCPIdleTimeout: transport.TCPIdleTimeoutDefault,
TCPIdleTimeout: carbonreceiver.TCPIdleTimeoutDefault,
}
}

Expand Down

0 comments on commit 881c74a

Please sign in to comment.