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

[receiver/dockerstats] rename struct and function to keep expected receiver.Factory and pass checkapi #27086

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 0 additions & 1 deletion cmd/checkapi/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ connector/servicegraphconnector
extension/encoding
extension/observer
processor/servicegraphprocessor
receiver/dockerstatsreceiver
receiver/journaldreceiver
receiver/kafkareceiver
receiver/windowseventlogreceiver
14 changes: 7 additions & 7 deletions receiver/dockerstatsreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/consumer"
"go.opentelemetry.io/collector/featuregate"
rcvr "go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scraperhelper"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/dockerstatsreceiver/internal/metadata"
Expand All @@ -24,11 +24,11 @@ var _ = featuregate.GlobalRegistry().MustRegister(
featuregate.WithRegisterToVersion("0.74.0"),
)

func NewFactory() rcvr.Factory {
return rcvr.NewFactory(
func NewFactory() receiver.Factory {
return receiver.NewFactory(
metadata.Type,
createDefaultConfig,
rcvr.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
receiver.WithMetrics(createMetricsReceiver, metadata.MetricsStability))
}

func createDefaultConfig() component.Config {
Expand All @@ -45,12 +45,12 @@ func createDefaultConfig() component.Config {

func createMetricsReceiver(
_ context.Context,
params rcvr.CreateSettings,
params receiver.CreateSettings,
config component.Config,
consumer consumer.Metrics,
) (rcvr.Metrics, error) {
) (receiver.Metrics, error) {
dockerConfig := config.(*Config)
dsr := newReceiver(params, dockerConfig)
dsr := newMetricsReceiver(params, dockerConfig)

scrp, err := scraperhelper.NewScraper(metadata.Type, dsr.scrapeV2, scraperhelper.WithStart(dsr.start))
if err != nil {
Expand Down
28 changes: 14 additions & 14 deletions receiver/dockerstatsreceiver/receiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/pcommon"
"go.opentelemetry.io/collector/pdata/pmetric"
rcvr "go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver"
"go.opentelemetry.io/collector/receiver/scrapererror"
"go.uber.org/multierr"

Expand All @@ -35,22 +35,22 @@ type resultV2 struct {
err error
}

type receiver struct {
type metricsReceiver struct {
config *Config
settings rcvr.CreateSettings
settings receiver.CreateSettings
client *docker.Client
mb *metadata.MetricsBuilder
}

func newReceiver(set rcvr.CreateSettings, config *Config) *receiver {
return &receiver{
func newMetricsReceiver(set receiver.CreateSettings, config *Config) *metricsReceiver {
return &metricsReceiver{
config: config,
settings: set,
mb: metadata.NewMetricsBuilder(config.MetricsBuilderConfig, set),
}
}

func (r *receiver) start(ctx context.Context, _ component.Host) error {
func (r *metricsReceiver) start(ctx context.Context, _ component.Host) error {
dConfig, err := docker.NewConfig(r.config.Endpoint, r.config.Timeout, r.config.ExcludedImages, r.config.DockerAPIVersion)
if err != nil {
return err
Expand All @@ -69,7 +69,7 @@ func (r *receiver) start(ctx context.Context, _ component.Host) error {
return nil
}

func (r *receiver) scrapeV2(ctx context.Context) (pmetric.Metrics, error) {
func (r *metricsReceiver) scrapeV2(ctx context.Context) (pmetric.Metrics, error) {
containers := r.client.Containers()
results := make(chan resultV2, len(containers))

Expand Down Expand Up @@ -111,7 +111,7 @@ func (r *receiver) scrapeV2(ctx context.Context) (pmetric.Metrics, error) {
return r.mb.Emit(), errs
}

func (r *receiver) recordContainerStats(now pcommon.Timestamp, containerStats *dtypes.StatsJSON, container *docker.Container) error {
func (r *metricsReceiver) recordContainerStats(now pcommon.Timestamp, containerStats *dtypes.StatsJSON, container *docker.Container) error {
var errs error
r.recordCPUMetrics(now, &containerStats.CPUStats, &containerStats.PreCPUStats)
r.recordMemoryMetrics(now, &containerStats.MemoryStats)
Expand Down Expand Up @@ -148,7 +148,7 @@ func (r *receiver) recordContainerStats(now pcommon.Timestamp, containerStats *d
return errs
}

func (r *receiver) recordMemoryMetrics(now pcommon.Timestamp, memoryStats *dtypes.MemoryStats) {
func (r *metricsReceiver) recordMemoryMetrics(now pcommon.Timestamp, memoryStats *dtypes.MemoryStats) {
totalUsage := calculateMemUsageNoCache(memoryStats)
r.mb.RecordContainerMemoryUsageTotalDataPoint(now, int64(totalUsage))

Expand Down Expand Up @@ -204,7 +204,7 @@ func (r *receiver) recordMemoryMetrics(now pcommon.Timestamp, memoryStats *dtype

type blkioRecorder func(now pcommon.Timestamp, val int64, devMaj string, devMin string, operation string)

func (r *receiver) recordBlkioMetrics(now pcommon.Timestamp, blkioStats *dtypes.BlkioStats) {
func (r *metricsReceiver) recordBlkioMetrics(now pcommon.Timestamp, blkioStats *dtypes.BlkioStats) {
recordSingleBlkioStat(now, blkioStats.IoMergedRecursive, r.mb.RecordContainerBlockioIoMergedRecursiveDataPoint)
recordSingleBlkioStat(now, blkioStats.IoQueuedRecursive, r.mb.RecordContainerBlockioIoQueuedRecursiveDataPoint)
recordSingleBlkioStat(now, blkioStats.IoServiceBytesRecursive, r.mb.RecordContainerBlockioIoServiceBytesRecursiveDataPoint)
Expand All @@ -226,7 +226,7 @@ func recordSingleBlkioStat(now pcommon.Timestamp, statEntries []dtypes.BlkioStat
}
}

func (r *receiver) recordNetworkMetrics(now pcommon.Timestamp, networks *map[string]dtypes.NetworkStats) {
func (r *metricsReceiver) recordNetworkMetrics(now pcommon.Timestamp, networks *map[string]dtypes.NetworkStats) {
if networks == nil || *networks == nil {
return
}
Expand All @@ -243,7 +243,7 @@ func (r *receiver) recordNetworkMetrics(now pcommon.Timestamp, networks *map[str
}
}

func (r *receiver) recordCPUMetrics(now pcommon.Timestamp, cpuStats *dtypes.CPUStats, prevStats *dtypes.CPUStats) {
func (r *metricsReceiver) recordCPUMetrics(now pcommon.Timestamp, cpuStats *dtypes.CPUStats, prevStats *dtypes.CPUStats) {
r.mb.RecordContainerCPUUsageSystemDataPoint(now, int64(cpuStats.SystemUsage))
r.mb.RecordContainerCPUUsageTotalDataPoint(now, int64(cpuStats.CPUUsage.TotalUsage))
r.mb.RecordContainerCPUUsageKernelmodeDataPoint(now, int64(cpuStats.CPUUsage.UsageInKernelmode))
Expand All @@ -258,7 +258,7 @@ func (r *receiver) recordCPUMetrics(now pcommon.Timestamp, cpuStats *dtypes.CPUS
}
}

func (r *receiver) recordPidsMetrics(now pcommon.Timestamp, pidsStats *dtypes.PidsStats) {
func (r *metricsReceiver) recordPidsMetrics(now pcommon.Timestamp, pidsStats *dtypes.PidsStats) {
// pidsStats are available when kernel version is >= 4.3 and pids_cgroup is supported, it is empty otherwise.
if pidsStats.Current != 0 {
r.mb.RecordContainerPidsCountDataPoint(now, int64(pidsStats.Current))
Expand All @@ -268,7 +268,7 @@ func (r *receiver) recordPidsMetrics(now pcommon.Timestamp, pidsStats *dtypes.Pi
}
}

func (r *receiver) recordBaseMetrics(now pcommon.Timestamp, base *types.ContainerJSONBase) error {
func (r *metricsReceiver) recordBaseMetrics(now pcommon.Timestamp, base *types.ContainerJSONBase) error {
t, err := time.Parse(time.RFC3339, base.State.StartedAt)
if err != nil {
// value not available or invalid
Expand Down
8 changes: 4 additions & 4 deletions receiver/dockerstatsreceiver/receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func TestNewReceiver(t *testing.T) {
Endpoint: "unix:///run/some.sock",
DockerAPIVersion: defaultDockerAPIVersion,
}
mr := newReceiver(receivertest.NewNopCreateSettings(), cfg)
mr := newMetricsReceiver(receivertest.NewNopCreateSettings(), cfg)
assert.NotNil(t, mr)
}

Expand All @@ -136,7 +136,7 @@ func TestErrorsInStart(t *testing.T) {
Endpoint: unreachable,
DockerAPIVersion: defaultDockerAPIVersion,
}
recv := newReceiver(receivertest.NewNopCreateSettings(), cfg)
recv := newMetricsReceiver(receivertest.NewNopCreateSettings(), cfg)
assert.NotNil(t, recv)

cfg.Endpoint = "..not/a/valid/endpoint"
Expand Down Expand Up @@ -277,7 +277,7 @@ func TestScrapeV2(t *testing.T) {
mockDockerEngine := tc.mockDockerEngine(t)
defer mockDockerEngine.Close()

receiver := newReceiver(
receiver := newMetricsReceiver(
receivertest.NewNopCreateSettings(), tc.cfgBuilder.withEndpoint(mockDockerEngine.URL).build())
err := receiver.start(context.Background(), componenttest.NewNopHost())
require.NoError(t, err)
Expand Down Expand Up @@ -309,7 +309,7 @@ func TestRecordBaseMetrics(t *testing.T) {
cfg.MetricsBuilderConfig.Metrics = metadata.MetricsConfig{
ContainerUptime: metricEnabled,
}
r := newReceiver(receivertest.NewNopCreateSettings(), cfg)
r := newMetricsReceiver(receivertest.NewNopCreateSettings(), cfg)
now := time.Now()
started := now.Add(-2 * time.Second).Format(time.RFC3339)

Expand Down