From ba951bcdb8472db86bdfd764aaddb2fb08a0ca49 Mon Sep 17 00:00:00 2001 From: Bogdan Drutu Date: Thu, 9 Jan 2025 15:27:56 -0800 Subject: [PATCH] [chore] Make hostmetrics receiver scrapers closer to core scrapers Signed-off-by: Bogdan Drutu --- receiver/hostmetricsreceiver/config.go | 8 ++-- receiver/hostmetricsreceiver/config_test.go | 27 ++++++------ receiver/hostmetricsreceiver/factory.go | 2 +- receiver/hostmetricsreceiver/factory_test.go | 4 +- .../hostmetrics_linux_test.go | 4 +- .../hostmetrics_receiver_test.go | 43 ++++++++----------- .../hostmetricsreceiver/integration_test.go | 11 ++--- .../hostmetricsreceiver/internal/scraper.go | 12 +----- .../internal/scraper/cpuscraper/config.go | 2 - .../internal/scraper/cpuscraper/factory.go | 5 +-- .../internal/scraper/diskscraper/config.go | 2 - .../internal/scraper/diskscraper/factory.go | 5 +-- .../scraper/filesystemscraper/config.go | 8 +++- .../scraper/filesystemscraper/factory.go | 7 ++- .../filesystemscraper/filesystem_scraper.go | 2 +- .../internal/scraper/loadscraper/config.go | 2 - .../internal/scraper/loadscraper/factory.go | 5 +-- .../internal/scraper/memoryscraper/config.go | 2 - .../internal/scraper/memoryscraper/factory.go | 5 +-- .../internal/scraper/networkscraper/config.go | 2 - .../scraper/networkscraper/factory.go | 5 +-- .../internal/scraper/pagingscraper/config.go | 2 - .../internal/scraper/pagingscraper/factory.go | 5 +-- .../scraper/processesscraper/config.go | 2 - .../scraper/processesscraper/factory.go | 5 +-- .../internal/scraper/processscraper/config.go | 2 - .../scraper/processscraper/factory.go | 5 +-- .../internal/scraper/systemscraper/config.go | 2 - .../internal/scraper/systemscraper/factory.go | 5 +-- 29 files changed, 72 insertions(+), 119 deletions(-) diff --git a/receiver/hostmetricsreceiver/config.go b/receiver/hostmetricsreceiver/config.go index f4adbf86077a..5e6ba246d1c4 100644 --- a/receiver/hostmetricsreceiver/config.go +++ b/receiver/hostmetricsreceiver/config.go @@ -19,7 +19,7 @@ import ( // Config defines configuration for HostMetrics receiver. type Config struct { scraperhelper.ControllerConfig `mapstructure:",squash"` - Scrapers map[component.Type]internal.Config `mapstructure:"-"` + Scrapers map[component.Type]component.Config `mapstructure:"-"` // RootPath is the host's root directory (linux only). RootPath string `mapstructure:"root_path"` @@ -58,7 +58,7 @@ func (cfg *Config) Unmarshal(componentParser *confmap.Conf) error { // dynamically load the individual collector configs based on the key name - cfg.Scrapers = map[component.Type]internal.Config{} + cfg.Scrapers = map[component.Type]component.Config{} scrapersSection, err := componentParser.Sub("scrapers") if err != nil { @@ -84,7 +84,9 @@ func (cfg *Config) Unmarshal(componentParser *confmap.Conf) error { return fmt.Errorf("error reading settings for scraper type %q: %w", key, err) } - scraperCfg.SetRootPath(cfg.RootPath) + if iCfg, ok := scraperCfg.(internal.Config); ok { + iCfg.SetRootPath(cfg.RootPath) + } cfg.Scrapers[key] = scraperCfg } diff --git a/receiver/hostmetricsreceiver/config_test.go b/receiver/hostmetricsreceiver/config_test.go index 48d655eaa0c6..0e2f82727690 100644 --- a/receiver/hostmetricsreceiver/config_test.go +++ b/receiver/hostmetricsreceiver/config_test.go @@ -15,7 +15,6 @@ import ( "go.opentelemetry.io/collector/scraper/scraperhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/metadata" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/diskscraper" @@ -43,8 +42,8 @@ func TestLoadConfig(t *testing.T) { id: component.NewID(metadata.Type), expected: func() component.Config { cfg := createDefaultConfig().(*Config) - cfg.Scrapers = map[component.Type]internal.Config{ - cpuscraper.Type: func() internal.Config { + cfg.Scrapers = map[component.Type]component.Config{ + cpuscraper.Type: func() component.Config { cfg := (&cpuscraper.Factory{}).CreateDefaultConfig() return cfg }(), @@ -60,29 +59,29 @@ func TestLoadConfig(t *testing.T) { CollectionInterval: 30 * time.Second, InitialDelay: time.Second, }, - Scrapers: map[component.Type]internal.Config{ - cpuscraper.Type: func() internal.Config { + Scrapers: map[component.Type]component.Config{ + cpuscraper.Type: func() component.Config { cfg := (&cpuscraper.Factory{}).CreateDefaultConfig() return cfg }(), - diskscraper.Type: func() internal.Config { + diskscraper.Type: func() component.Config { cfg := (&diskscraper.Factory{}).CreateDefaultConfig() return cfg }(), - loadscraper.Type: (func() internal.Config { + loadscraper.Type: (func() component.Config { cfg := (&loadscraper.Factory{}).CreateDefaultConfig() cfg.(*loadscraper.Config).CPUAverage = true return cfg })(), - filesystemscraper.Type: func() internal.Config { + filesystemscraper.Type: func() component.Config { cfg := (&filesystemscraper.Factory{}).CreateDefaultConfig() return cfg }(), - memoryscraper.Type: func() internal.Config { + memoryscraper.Type: func() component.Config { cfg := (&memoryscraper.Factory{}).CreateDefaultConfig() return cfg }(), - networkscraper.Type: (func() internal.Config { + networkscraper.Type: (func() component.Config { cfg := (&networkscraper.Factory{}).CreateDefaultConfig() cfg.(*networkscraper.Config).Include = networkscraper.MatchConfig{ Interfaces: []string{"test1"}, @@ -90,15 +89,15 @@ func TestLoadConfig(t *testing.T) { } return cfg })(), - processesscraper.Type: func() internal.Config { + processesscraper.Type: func() component.Config { cfg := (&processesscraper.Factory{}).CreateDefaultConfig() return cfg }(), - pagingscraper.Type: func() internal.Config { + pagingscraper.Type: func() component.Config { cfg := (&pagingscraper.Factory{}).CreateDefaultConfig() return cfg }(), - processscraper.Type: (func() internal.Config { + processscraper.Type: (func() component.Config { cfg := (&processscraper.Factory{}).CreateDefaultConfig() cfg.(*processscraper.Config).Include = processscraper.MatchConfig{ Names: []string{"test2", "test3"}, @@ -106,7 +105,7 @@ func TestLoadConfig(t *testing.T) { } return cfg })(), - systemscraper.Type: (func() internal.Config { + systemscraper.Type: (func() component.Config { cfg := (&systemscraper.Factory{}).CreateDefaultConfig() return cfg })(), diff --git a/receiver/hostmetricsreceiver/factory.go b/receiver/hostmetricsreceiver/factory.go index 0fac30742796..e1af92a95d48 100644 --- a/receiver/hostmetricsreceiver/factory.go +++ b/receiver/hostmetricsreceiver/factory.go @@ -130,7 +130,7 @@ func createAddScraperOptions( return scraperControllerOptions, nil } -func createHostMetricsScraper(ctx context.Context, set receiver.Settings, key component.Type, cfg internal.Config, factories map[component.Type]internal.ScraperFactory) (s scraper.Metrics, ok bool, err error) { +func createHostMetricsScraper(ctx context.Context, set receiver.Settings, key component.Type, cfg component.Config, factories map[component.Type]internal.ScraperFactory) (s scraper.Metrics, ok bool, err error) { factory := factories[key] if factory == nil { ok = false diff --git a/receiver/hostmetricsreceiver/factory_test.go b/receiver/hostmetricsreceiver/factory_test.go index d9cd23736c4a..7a3ecb047728 100644 --- a/receiver/hostmetricsreceiver/factory_test.go +++ b/receiver/hostmetricsreceiver/factory_test.go @@ -14,8 +14,6 @@ import ( "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/pipeline" "go.opentelemetry.io/collector/receiver/receivertest" - - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" ) var creationSet = receivertest.NewNopSettings() @@ -48,7 +46,7 @@ func TestCreateReceiver_ScraperKeyConfigError(t *testing.T) { const errorKey string = "error" factory := NewFactory() - cfg := &Config{Scrapers: map[component.Type]internal.Config{component.MustNewType(errorKey): &mockConfig{}}} + cfg := &Config{Scrapers: map[component.Type]component.Config{component.MustNewType(errorKey): &mockConfig{}}} _, err := factory.CreateMetrics(context.Background(), creationSet, cfg, consumertest.NewNop()) assert.EqualError(t, err, fmt.Sprintf("host metrics scraper factory not found for key: %q", errorKey)) diff --git a/receiver/hostmetricsreceiver/hostmetrics_linux_test.go b/receiver/hostmetricsreceiver/hostmetrics_linux_test.go index 7722e0bd2b12..93288dcf383e 100644 --- a/receiver/hostmetricsreceiver/hostmetrics_linux_test.go +++ b/receiver/hostmetricsreceiver/hostmetrics_linux_test.go @@ -15,7 +15,6 @@ import ( "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/confmap/confmaptest" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper" ) @@ -45,8 +44,7 @@ func TestLoadConfigRootPath(t *testing.T) { expectedConfig := factory.CreateDefaultConfig().(*Config) expectedConfig.RootPath = "testdata" cpuScraperCfg := (&cpuscraper.Factory{}).CreateDefaultConfig() - cpuScraperCfg.SetRootPath("testdata") - expectedConfig.Scrapers = map[component.Type]internal.Config{cpuscraper.Type: cpuScraperCfg} + expectedConfig.Scrapers = map[component.Type]component.Config{cpuscraper.Type: cpuScraperCfg} assert.Equal(t, expectedConfig, cfg) expectedEnvMap := common.EnvMap{ common.HostDevEnvKey: "testdata/dev", diff --git a/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go b/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go index 482bd84bc461..071020e58d68 100644 --- a/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go +++ b/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go @@ -78,7 +78,7 @@ func TestGatherMetrics_EndToEnd(t *testing.T) { ControllerConfig: scraperhelper.ControllerConfig{ CollectionInterval: 100 * time.Millisecond, }, - Scrapers: map[component.Type]internal.Config{ + Scrapers: map[component.Type]component.Config{ cpuscraper.Type: scraperFactories[cpuscraper.Type].CreateDefaultConfig(), diskscraper.Type: scraperFactories[diskscraper.Type].CreateDefaultConfig(), filesystemscraper.Type: (&filesystemscraper.Factory{}).CreateDefaultConfig(), @@ -186,12 +186,10 @@ var mockType = component.MustNewType("mock") type mockConfig struct{} -func (m *mockConfig) SetRootPath(_ string) {} - type errFactory struct{} -func (m *errFactory) CreateDefaultConfig() internal.Config { return &mockConfig{} } -func (m *errFactory) CreateMetricsScraper(context.Context, receiver.Settings, internal.Config) (scraper.Metrics, error) { +func (m *errFactory) CreateDefaultConfig() component.Config { return &mockConfig{} } +func (m *errFactory) CreateMetricsScraper(context.Context, receiver.Settings, component.Config) (scraper.Metrics, error) { return nil, errors.New("err1") } @@ -202,7 +200,7 @@ func TestGatherMetrics_ScraperKeyConfigError(t *testing.T) { scraperFactories = tmp }() - cfg := &Config{Scrapers: map[component.Type]internal.Config{component.MustNewType("error"): &mockConfig{}}} + cfg := &Config{Scrapers: map[component.Type]component.Config{component.MustNewType("error"): &mockConfig{}}} _, err := NewFactory().CreateMetrics(context.Background(), creationSet, cfg, consumertest.NewNop()) require.Error(t, err) } @@ -215,7 +213,7 @@ func TestGatherMetrics_CreateMetricsScraperError(t *testing.T) { scraperFactories = tmp }() - cfg := &Config{Scrapers: map[component.Type]internal.Config{mockType: &mockConfig{}}} + cfg := &Config{Scrapers: map[component.Type]component.Config{mockType: &mockConfig{}}} _, err := NewFactory().CreateMetrics(context.Background(), creationSet, cfg, consumertest.NewNop()) require.Error(t, err) } @@ -267,7 +265,7 @@ func benchmarkScrapeMetrics(b *testing.B, cfg *Config) { func Benchmark_ScrapeCpuMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{cpuscraper.Type: (&cpuscraper.Factory{}).CreateDefaultConfig()}, + Scrapers: map[component.Type]component.Config{cpuscraper.Type: (&cpuscraper.Factory{}).CreateDefaultConfig()}, } benchmarkScrapeMetrics(b, cfg) @@ -276,7 +274,7 @@ func Benchmark_ScrapeCpuMetrics(b *testing.B) { func Benchmark_ScrapeDiskMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{diskscraper.Type: (&diskscraper.Factory{}).CreateDefaultConfig()}, + Scrapers: map[component.Type]component.Config{diskscraper.Type: (&diskscraper.Factory{}).CreateDefaultConfig()}, } benchmarkScrapeMetrics(b, cfg) @@ -285,7 +283,7 @@ func Benchmark_ScrapeDiskMetrics(b *testing.B) { func Benchmark_ScrapeFileSystemMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{filesystemscraper.Type: (&filesystemscraper.Factory{}).CreateDefaultConfig()}, + Scrapers: map[component.Type]component.Config{filesystemscraper.Type: (&filesystemscraper.Factory{}).CreateDefaultConfig()}, } benchmarkScrapeMetrics(b, cfg) @@ -294,7 +292,7 @@ func Benchmark_ScrapeFileSystemMetrics(b *testing.B) { func Benchmark_ScrapeLoadMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{loadscraper.Type: (&loadscraper.Factory{}).CreateDefaultConfig()}, + Scrapers: map[component.Type]component.Config{loadscraper.Type: (&loadscraper.Factory{}).CreateDefaultConfig()}, } benchmarkScrapeMetrics(b, cfg) @@ -303,7 +301,7 @@ func Benchmark_ScrapeLoadMetrics(b *testing.B) { func Benchmark_ScrapeMemoryMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{memoryscraper.Type: (&memoryscraper.Factory{}).CreateDefaultConfig()}, + Scrapers: map[component.Type]component.Config{memoryscraper.Type: (&memoryscraper.Factory{}).CreateDefaultConfig()}, } benchmarkScrapeMetrics(b, cfg) @@ -312,7 +310,7 @@ func Benchmark_ScrapeMemoryMetrics(b *testing.B) { func Benchmark_ScrapeNetworkMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{networkscraper.Type: (&networkscraper.Factory{}).CreateDefaultConfig()}, + Scrapers: map[component.Type]component.Config{networkscraper.Type: (&networkscraper.Factory{}).CreateDefaultConfig()}, } benchmarkScrapeMetrics(b, cfg) @@ -321,7 +319,7 @@ func Benchmark_ScrapeNetworkMetrics(b *testing.B) { func Benchmark_ScrapeProcessesMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{processesscraper.Type: (&processesscraper.Factory{}).CreateDefaultConfig()}, + Scrapers: map[component.Type]component.Config{processesscraper.Type: (&processesscraper.Factory{}).CreateDefaultConfig()}, } benchmarkScrapeMetrics(b, cfg) @@ -330,7 +328,7 @@ func Benchmark_ScrapeProcessesMetrics(b *testing.B) { func Benchmark_ScrapePagingMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{pagingscraper.Type: (&pagingscraper.Factory{}).CreateDefaultConfig()}, + Scrapers: map[component.Type]component.Config{pagingscraper.Type: (&pagingscraper.Factory{}).CreateDefaultConfig()}, } benchmarkScrapeMetrics(b, cfg) @@ -343,7 +341,7 @@ func Benchmark_ScrapeProcessMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{processscraper.Type: (&processscraper.Factory{}).CreateDefaultConfig()}, + Scrapers: map[component.Type]component.Config{processscraper.Type: (&processscraper.Factory{}).CreateDefaultConfig()}, } benchmarkScrapeMetrics(b, cfg) @@ -356,7 +354,7 @@ func Benchmark_ScrapeUptimeMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{systemscraper.Type: (&systemscraper.Factory{}).CreateDefaultConfig()}, + Scrapers: map[component.Type]component.Config{systemscraper.Type: (&systemscraper.Factory{}).CreateDefaultConfig()}, } benchmarkScrapeMetrics(b, cfg) @@ -365,7 +363,7 @@ func Benchmark_ScrapeUptimeMetrics(b *testing.B) { func Benchmark_ScrapeSystemMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{ + Scrapers: map[component.Type]component.Config{ cpuscraper.Type: (&cpuscraper.Factory{}).CreateDefaultConfig(), diskscraper.Type: (&diskscraper.Factory{}).CreateDefaultConfig(), filesystemscraper.Type: (&filesystemscraper.Factory{}).CreateDefaultConfig(), @@ -387,16 +385,9 @@ func Benchmark_ScrapeSystemAndProcessMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[component.Type]internal.Config{ - cpuscraper.Type: &cpuscraper.Config{}, - diskscraper.Type: &diskscraper.Config{}, + Scrapers: map[component.Type]component.Config{ filesystemscraper.Type: (&filesystemscraper.Factory{}).CreateDefaultConfig(), - loadscraper.Type: &loadscraper.Config{}, - memoryscraper.Type: &memoryscraper.Config{}, - networkscraper.Type: &networkscraper.Config{}, pagingscraper.Type: (&pagingscraper.Factory{}).CreateDefaultConfig(), - processesscraper.Type: &processesscraper.Config{}, - systemscraper.Type: &systemscraper.Config{}, }, } diff --git a/receiver/hostmetricsreceiver/integration_test.go b/receiver/hostmetricsreceiver/integration_test.go index 9e765e3714f7..a45968059f41 100644 --- a/receiver/hostmetricsreceiver/integration_test.go +++ b/receiver/hostmetricsreceiver/integration_test.go @@ -17,7 +17,6 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/scraperinttest" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest/pmetrictest" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper" ) @@ -41,7 +40,7 @@ func Test_ProcessScrape(t *testing.T) { Config: filterset.Config{MatchType: filterset.Regexp}, Names: []string{"sleep"}, } - rCfg.Scrapers = map[component.Type]internal.Config{ + rCfg.Scrapers = map[component.Type]component.Config{ processscraper.Type: pCfg, } }), @@ -71,8 +70,7 @@ func Test_ProcessScrapeWithCustomRootPath(t *testing.T) { rCfg.CollectionInterval = time.Second rCfg.RootPath = rootPath pCfg := (&processscraper.Factory{}).CreateDefaultConfig().(*processscraper.Config) - pCfg.SetRootPath(rootPath) - rCfg.Scrapers = map[component.Type]internal.Config{ + rCfg.Scrapers = map[component.Type]component.Config{ processscraper.Type: pCfg, } }), @@ -99,12 +97,11 @@ func Test_ProcessScrapeWithBadRootPathAndEnvVar(t *testing.T) { func(_ *testing.T, cfg component.Config, _ *scraperinttest.ContainerInfo) { rCfg := cfg.(*Config) rCfg.CollectionInterval = time.Second + rCfg.RootPath = badRootPath pCfg := (&processscraper.Factory{}).CreateDefaultConfig().(*processscraper.Config) - pCfg.SetRootPath(badRootPath) - rCfg.Scrapers = map[component.Type]internal.Config{ + rCfg.Scrapers = map[component.Type]component.Config{ processscraper.Type: pCfg, } - rCfg.RootPath = badRootPath }), scraperinttest.WithExpectedFile(expectedFile), scraperinttest.WithCompareOptions( diff --git a/receiver/hostmetricsreceiver/internal/scraper.go b/receiver/hostmetricsreceiver/internal/scraper.go index 7cbb8872df32..704faf32232c 100644 --- a/receiver/hostmetricsreceiver/internal/scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper.go @@ -16,11 +16,11 @@ import ( // ScraperFactory can create a MetricScraper. type ScraperFactory interface { // CreateDefaultConfig creates the default configuration for the Scraper. - CreateDefaultConfig() Config + CreateDefaultConfig() component.Config // CreateMetricsScraper creates a scraper based on this config. // If the config is not valid, error will be returned instead. - CreateMetricsScraper(ctx context.Context, settings receiver.Settings, cfg Config) (scraper.Metrics, error) + CreateMetricsScraper(ctx context.Context, settings receiver.Settings, cfg component.Config) (scraper.Metrics, error) } // Config is the configuration of a scraper. @@ -28,14 +28,6 @@ type Config interface { SetRootPath(rootPath string) } -type ScraperConfig struct { - RootPath string `mapstructure:"-"` -} - -func (p *ScraperConfig) SetRootPath(rootPath string) { - p.RootPath = rootPath -} - type EnvVarScraper struct { delegate scraper.Metrics envMap common.EnvMap diff --git a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/config.go b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/config.go index 1509f2606a9d..34adc2e4821e 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/config.go @@ -4,12 +4,10 @@ package cpuscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper" import ( - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/internal/metadata" ) // Config relating to CPU Metric Scraper. type Config struct { metadata.MetricsBuilderConfig `mapstructure:",squash"` - internal.ScraperConfig } diff --git a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/factory.go b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/factory.go index d072159c8a98..f0d0e182c427 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/factory.go +++ b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/factory.go @@ -10,7 +10,6 @@ import ( "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/scraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/internal/metadata" ) @@ -23,7 +22,7 @@ var Type = component.MustNewType("cpu") type Factory struct{} // CreateDefaultConfig creates the default configuration for the Scraper. -func (f *Factory) CreateDefaultConfig() internal.Config { +func (f *Factory) CreateDefaultConfig() component.Config { return &Config{ MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } @@ -33,7 +32,7 @@ func (f *Factory) CreateDefaultConfig() internal.Config { func (f *Factory) CreateMetricsScraper( ctx context.Context, settings receiver.Settings, - config internal.Config, + config component.Config, ) (scraper.Metrics, error) { cfg := config.(*Config) s := newCPUScraper(ctx, settings, cfg) diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/config.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/config.go index 29048bd3188e..b9121fb423c2 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/config.go @@ -5,7 +5,6 @@ package diskscraper // import "github.com/open-telemetry/opentelemetry-collector import ( "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/diskscraper/internal/metadata" ) @@ -13,7 +12,6 @@ import ( type Config struct { // MetricsbuilderConfig allows to customize scraped metrics/attributes representation. metadata.MetricsBuilderConfig `mapstructure:",squash"` - internal.ScraperConfig // Include specifies a filter on the devices that should be included from the generated metrics. // Exclude specifies a filter on the devices that should be excluded from the generated metrics. diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/factory.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/factory.go index f1e30bd378f6..064e2242bae6 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/factory.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/factory.go @@ -10,7 +10,6 @@ import ( "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/scraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/diskscraper/internal/metadata" ) @@ -23,7 +22,7 @@ var Type = component.MustNewType("disk") type Factory struct{} // CreateDefaultConfig creates the default configuration for the Scraper. -func (f *Factory) CreateDefaultConfig() internal.Config { +func (f *Factory) CreateDefaultConfig() component.Config { return &Config{ MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } @@ -33,7 +32,7 @@ func (f *Factory) CreateDefaultConfig() internal.Config { func (f *Factory) CreateMetricsScraper( ctx context.Context, settings receiver.Settings, - config internal.Config, + config component.Config, ) (scraper.Metrics, error) { cfg := config.(*Config) s, err := newDiskScraper(ctx, settings, cfg) diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/config.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/config.go index f8acc4e30b0a..f38adc5ff806 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/config.go @@ -7,7 +7,6 @@ import ( "fmt" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata" ) @@ -15,7 +14,6 @@ import ( type Config struct { // MetricsBuilderConfig allows to customize scraped metrics/attributes representation. metadata.MetricsBuilderConfig `mapstructure:",squash"` - internal.ScraperConfig // IncludeVirtualFS will also capture filesystems such as tmpfs, ramfs // and other filesystem types that do no have an associated physical device. @@ -37,6 +35,8 @@ type Config struct { // ExcludeMountPoints specifies a filter on the mount points that should be excluded from the generated metrics. // When `root_path` is set, the mount points must be from the host's perspective. ExcludeMountPoints MountPointMatchConfig `mapstructure:"exclude_mount_points"` + + rootPath string `mapstructure:"-"` } type DeviceMatchConfig struct { @@ -67,6 +67,10 @@ type fsFilter struct { filtersExist bool } +func (cfg *Config) SetRootPath(rootPath string) { + cfg.rootPath = rootPath +} + func (cfg *Config) createFilter() (*fsFilter, error) { var err error filter := fsFilter{} diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/factory.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/factory.go index 9702d63e1414..250060a9108a 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/factory.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/factory.go @@ -11,7 +11,6 @@ import ( "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/scraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/internal/metadata" ) @@ -24,7 +23,7 @@ var Type = component.MustNewType("filesystem") type Factory struct{} // CreateDefaultConfig creates the default configuration for the Scraper. -func (f *Factory) CreateDefaultConfig() internal.Config { +func (f *Factory) CreateDefaultConfig() component.Config { return &Config{ MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } @@ -34,11 +33,11 @@ func (f *Factory) CreateDefaultConfig() internal.Config { func (f *Factory) CreateMetricsScraper( ctx context.Context, settings receiver.Settings, - config internal.Config, + config component.Config, ) (scraper.Metrics, error) { cfg := config.(*Config) - if cfg.RootPath == "" { + if cfg.rootPath == "" { inContainer := os.Getpid() == 1 for _, p := range []string{ "/.dockerenv", // Mounted by dockerd when starting a container by default diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go index 0304b3ab9289..9c6cd943ba92 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go @@ -108,7 +108,7 @@ func (s *filesystemsScraper) scrape(ctx context.Context) (pmetric.Metrics, error if !s.fsFilter.includePartition(partition) { continue } - translatedMountpoint := translateMountpoint(ctx, s.config.RootPath, partition.Mountpoint) + translatedMountpoint := translateMountpoint(ctx, s.config.rootPath, partition.Mountpoint) usage, usageErr := s.usage(ctx, translatedMountpoint) if usageErr != nil { errors.AddPartial(0, fmt.Errorf("failed to read usage at %s: %w", translatedMountpoint, usageErr)) diff --git a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/config.go b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/config.go index 996952370448..fae25f263485 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/config.go @@ -4,7 +4,6 @@ package loadscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/loadscraper" import ( - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/loadscraper/internal/metadata" ) @@ -14,5 +13,4 @@ type Config struct { CPUAverage bool `mapstructure:"cpu_average"` // MetricsBuilderConfig allows to customize scraped metrics/attributes representation. metadata.MetricsBuilderConfig `mapstructure:",squash"` - internal.ScraperConfig } diff --git a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/factory.go b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/factory.go index 695884ba1097..79dc32a9d6bd 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/factory.go +++ b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/factory.go @@ -10,7 +10,6 @@ import ( "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/scraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/loadscraper/internal/metadata" ) @@ -23,7 +22,7 @@ var Type = component.MustNewType("load") type Factory struct{} // CreateDefaultConfig creates the default configuration for the Scraper. -func (f *Factory) CreateDefaultConfig() internal.Config { +func (f *Factory) CreateDefaultConfig() component.Config { return &Config{ MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } @@ -33,7 +32,7 @@ func (f *Factory) CreateDefaultConfig() internal.Config { func (f *Factory) CreateMetricsScraper( ctx context.Context, settings receiver.Settings, - config internal.Config, + config component.Config, ) (scraper.Metrics, error) { cfg := config.(*Config) s := newLoadScraper(ctx, settings, cfg) diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/config.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/config.go index c273c8dd8a85..ba8e5589993a 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/config.go @@ -4,12 +4,10 @@ package memoryscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/memoryscraper" import ( - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata" ) // Config relating to Memory Metric Scraper. type Config struct { metadata.MetricsBuilderConfig `mapstructure:",squash"` - internal.ScraperConfig } diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/factory.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/factory.go index 3a34a4013704..a966d478ec6b 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/factory.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/factory.go @@ -10,7 +10,6 @@ import ( "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/scraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/internal/metadata" ) @@ -23,7 +22,7 @@ var Type = component.MustNewType("memory") type Factory struct{} // CreateDefaultConfig creates the default configuration for the Scraper. -func (f *Factory) CreateDefaultConfig() internal.Config { +func (f *Factory) CreateDefaultConfig() component.Config { return &Config{ MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } @@ -33,7 +32,7 @@ func (f *Factory) CreateDefaultConfig() internal.Config { func (f *Factory) CreateMetricsScraper( ctx context.Context, settings receiver.Settings, - config internal.Config, + config component.Config, ) (scraper.Metrics, error) { cfg := config.(*Config) s := newMemoryScraper(ctx, settings, cfg) diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/config.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/config.go index b7fa0728c599..7c888564b5eb 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/config.go @@ -5,14 +5,12 @@ package networkscraper // import "github.com/open-telemetry/opentelemetry-collec import ( "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata" ) // Config relating to Network Metric Scraper. type Config struct { metadata.MetricsBuilderConfig `mapstructure:",squash"` - internal.ScraperConfig // Include specifies a filter on the network interfaces that should be included from the generated metrics. Include MatchConfig `mapstructure:"include"` // Exclude specifies a filter on the network interfaces that should be excluded from the generated metrics. diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/factory.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/factory.go index 1746fd3e93f1..307b12ba32f9 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/factory.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/factory.go @@ -10,7 +10,6 @@ import ( "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/scraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata" ) @@ -23,7 +22,7 @@ var Type = component.MustNewType("network") type Factory struct{} // CreateDefaultConfig creates the default configuration for the Scraper. -func (f *Factory) CreateDefaultConfig() internal.Config { +func (f *Factory) CreateDefaultConfig() component.Config { return &Config{ MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } @@ -33,7 +32,7 @@ func (f *Factory) CreateDefaultConfig() internal.Config { func (f *Factory) CreateMetricsScraper( ctx context.Context, settings receiver.Settings, - config internal.Config, + config component.Config, ) (scraper.Metrics, error) { cfg := config.(*Config) s, err := newNetworkScraper(ctx, settings, cfg) diff --git a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/config.go b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/config.go index ac64f83ae034..50bc880f73d6 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/config.go @@ -4,7 +4,6 @@ package pagingscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper" import ( - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/internal/metadata" ) @@ -12,5 +11,4 @@ import ( type Config struct { // MetricsBuilderConfig allows customizing scraped metrics/attributes representation. metadata.MetricsBuilderConfig `mapstructure:",squash"` - internal.ScraperConfig } diff --git a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/factory.go b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/factory.go index 1ec88b5fadff..b85d0278a75c 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/factory.go +++ b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/factory.go @@ -10,7 +10,6 @@ import ( "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/scraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/internal/metadata" ) @@ -23,7 +22,7 @@ var Type = component.MustNewType("paging") type Factory struct{} // CreateDefaultConfig creates the default configuration for the Scraper. -func (f *Factory) CreateDefaultConfig() internal.Config { +func (f *Factory) CreateDefaultConfig() component.Config { return &Config{ MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } @@ -33,7 +32,7 @@ func (f *Factory) CreateDefaultConfig() internal.Config { func (f *Factory) CreateMetricsScraper( ctx context.Context, settings receiver.Settings, - config internal.Config, + config component.Config, ) (scraper.Metrics, error) { cfg := config.(*Config) s := newPagingScraper(ctx, settings, cfg) diff --git a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/config.go b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/config.go index 712b769f52e9..ce5beab04d8e 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/config.go @@ -4,7 +4,6 @@ package processesscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper" import ( - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper/internal/metadata" ) @@ -12,5 +11,4 @@ import ( type Config struct { // MetricsBuilderConfig allows customizing scraped metrics/attributes representation. metadata.MetricsBuilderConfig `mapstructure:",squash"` - internal.ScraperConfig } diff --git a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/factory.go b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/factory.go index b5b6201a22b6..21e73d2835d2 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/factory.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/factory.go @@ -10,7 +10,6 @@ import ( "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/scraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper/internal/metadata" ) @@ -23,7 +22,7 @@ var Type = component.MustNewType("processes") type Factory struct{} // CreateDefaultConfig creates the default configuration for the Scraper. -func (f *Factory) CreateDefaultConfig() internal.Config { +func (f *Factory) CreateDefaultConfig() component.Config { return &Config{ MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } @@ -33,7 +32,7 @@ func (f *Factory) CreateDefaultConfig() internal.Config { func (f *Factory) CreateMetricsScraper( ctx context.Context, settings receiver.Settings, - config internal.Config, + config component.Config, ) (scraper.Metrics, error) { cfg := config.(*Config) s := newProcessesScraper(ctx, settings, cfg) diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/config.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/config.go index 60c3ea0b8535..246a025ece1f 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/config.go @@ -7,7 +7,6 @@ import ( "time" "github.com/open-telemetry/opentelemetry-collector-contrib/internal/filter/filterset" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/metadata" ) @@ -15,7 +14,6 @@ import ( type Config struct { // MetricsBuilderConfig allows to customize scraped metrics/attributes representation. metadata.MetricsBuilderConfig `mapstructure:",squash"` - internal.ScraperConfig // Include specifies a filter on the process names that should be included from the generated metrics. // Exclude specifies a filter on the process names that should be excluded from the generated metrics. // If neither `include` or `exclude` are set, process metrics will be generated for all processes. diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/factory.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/factory.go index 20971d017849..7b68429cd3dd 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/factory.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/factory.go @@ -13,7 +13,6 @@ import ( "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/scraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper/internal/metadata" ) @@ -37,7 +36,7 @@ var ( type Factory struct{} // CreateDefaultConfig creates the default configuration for the Scraper. -func (f *Factory) CreateDefaultConfig() internal.Config { +func (f *Factory) CreateDefaultConfig() component.Config { return &Config{ MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } @@ -47,7 +46,7 @@ func (f *Factory) CreateDefaultConfig() internal.Config { func (f *Factory) CreateMetricsScraper( _ context.Context, settings receiver.Settings, - cfg internal.Config, + cfg component.Config, ) (scraper.Metrics, error) { if runtime.GOOS != "linux" && runtime.GOOS != "windows" && runtime.GOOS != "darwin" { return nil, errors.New("process scraper only available on Linux, Windows, or MacOS") diff --git a/receiver/hostmetricsreceiver/internal/scraper/systemscraper/config.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/config.go index 9c101ad03347..8d902bbc6c1d 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/systemscraper/config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/config.go @@ -4,7 +4,6 @@ package systemscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper" import ( - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata" ) @@ -12,5 +11,4 @@ import ( type Config struct { // MetricsBuilderConfig allows to customize scraped metrics/attributes representation. metadata.MetricsBuilderConfig `mapstructure:",squash"` - internal.ScraperConfig } diff --git a/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory.go index c163bea26ec4..abd1994a2fd6 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory.go @@ -12,7 +12,6 @@ import ( "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/scraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata" ) @@ -25,7 +24,7 @@ var Type = component.MustNewType("system") type Factory struct{} // CreateDefaultConfig creates the default configuration for the Scraper. -func (f *Factory) CreateDefaultConfig() internal.Config { +func (f *Factory) CreateDefaultConfig() component.Config { return &Config{ MetricsBuilderConfig: metadata.DefaultMetricsBuilderConfig(), } @@ -35,7 +34,7 @@ func (f *Factory) CreateDefaultConfig() internal.Config { func (f *Factory) CreateMetricsScraper( ctx context.Context, settings receiver.Settings, - cfg internal.Config, + cfg component.Config, ) (scraper.Metrics, error) { if runtime.GOOS != "linux" && runtime.GOOS != "windows" && runtime.GOOS != "darwin" { return nil, errors.New("uptime scraper only available on Linux, Windows, or MacOS")