diff --git a/cmd/checkapi/allowlist.txt b/cmd/checkapi/allowlist.txt index 7866dce0ae2d..c784a1e659da 100644 --- a/cmd/checkapi/allowlist.txt +++ b/cmd/checkapi/allowlist.txt @@ -2,7 +2,6 @@ connector/servicegraphconnector extension/encoding extension/observer processor/servicegraphprocessor -receiver/dockerstatsreceiver receiver/journaldreceiver receiver/kafkareceiver receiver/windowseventlogreceiver diff --git a/receiver/dockerstatsreceiver/factory.go b/receiver/dockerstatsreceiver/factory.go index f6537250387c..f86bea25ab10 100644 --- a/receiver/dockerstatsreceiver/factory.go +++ b/receiver/dockerstatsreceiver/factory.go @@ -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" @@ -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 { @@ -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 { diff --git a/receiver/dockerstatsreceiver/receiver.go b/receiver/dockerstatsreceiver/receiver.go index 847305e54525..e848a4914420 100644 --- a/receiver/dockerstatsreceiver/receiver.go +++ b/receiver/dockerstatsreceiver/receiver.go @@ -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" @@ -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 @@ -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)) @@ -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) @@ -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)) @@ -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) @@ -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 } @@ -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)) @@ -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)) @@ -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 diff --git a/receiver/dockerstatsreceiver/receiver_test.go b/receiver/dockerstatsreceiver/receiver_test.go index b84ecb1d3fc5..a13b16c06dcf 100644 --- a/receiver/dockerstatsreceiver/receiver_test.go +++ b/receiver/dockerstatsreceiver/receiver_test.go @@ -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) } @@ -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" @@ -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) @@ -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)