From dfef28535d59c498a0dc6cf3fdca4e206d0583af Mon Sep 17 00:00:00 2001 From: braydonk Date: Thu, 31 Oct 2024 22:09:00 +0000 Subject: [PATCH 1/3] change uptime scraper to system scraper This PR makes some changes that I had hoped to suggest on the PR that introduced the uptime scraper, however I was unable to make my comment in time before the PR was merged. * The `uptime` scraper is changed to be named `system` * The scraper is registered using the scraper name when adding to the scrapercontroller --- .chloggen/add-hostmetric-system-uptime.yaml | 4 ++-- receiver/hostmetricsreceiver/README.md | 12 +++++------ receiver/hostmetricsreceiver/config_test.go | 6 +++--- receiver/hostmetricsreceiver/factory.go | 4 ++-- receiver/hostmetricsreceiver/go.mod | 1 + receiver/hostmetricsreceiver/go.sum | 4 ++++ .../hostmetrics_receiver_test.go | 7 ++++--- .../config.go | 4 ++-- .../{uptimescraper => systemscraper}/doc.go | 2 +- .../documentation.md | 2 +- .../factory.go | 17 ++++++++++------ .../scraper/systemscraper/factory_test.go | 20 +++++++++++++++++++ .../internal/metadata/generated_config.go | 4 ++-- .../metadata/generated_config_test.go | 0 .../internal/metadata/generated_metrics.go | 2 +- .../metadata/generated_metrics_test.go | 0 .../internal/metadata/testdata/config.yaml | 0 .../metadata.yaml | 2 +- .../package_test.go | 2 +- .../system_scraper.go} | 4 ++-- .../system_scraper_test.go} | 4 ++-- .../hostmetricsreceiver/testdata/config.yaml | 2 +- 22 files changed, 67 insertions(+), 36 deletions(-) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper => systemscraper}/config.go (78%) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper => systemscraper}/doc.go (67%) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper => systemscraper}/documentation.md (93%) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper => systemscraper}/factory.go (76%) create mode 100644 receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper => systemscraper}/internal/metadata/generated_config.go (91%) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper => systemscraper}/internal/metadata/generated_config_test.go (100%) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper => systemscraper}/internal/metadata/generated_metrics.go (98%) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper => systemscraper}/internal/metadata/generated_metrics_test.go (100%) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper => systemscraper}/internal/metadata/testdata/config.yaml (100%) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper => systemscraper}/metadata.yaml (86%) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper => systemscraper}/package_test.go (89%) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper/uptime.go => systemscraper/system_scraper.go} (91%) rename receiver/hostmetricsreceiver/internal/scraper/{uptimescraper/uptime_test.go => systemscraper/system_scraper_test.go} (94%) diff --git a/.chloggen/add-hostmetric-system-uptime.yaml b/.chloggen/add-hostmetric-system-uptime.yaml index 296b5a311edc..a4d3bbafc52a 100644 --- a/.chloggen/add-hostmetric-system-uptime.yaml +++ b/.chloggen/add-hostmetric-system-uptime.yaml @@ -5,7 +5,7 @@ change_type: enhancement component: hostmetricsreceiver # A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). -note: Add an uptime scraper in the hostmetrics receiver +note: Add the system.uptime metric in the hostmetrics receiver # Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. issues: [31627] @@ -13,7 +13,7 @@ issues: [31627] # (Optional) One or more lines of additional information to render under the primary note. # These lines will be padded with 2 spaces and then inserted directly into the document. # Use pipe (|) for multiline entries. -subtext: +subtext: This metric is provided by the new `system` scraper. # 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. diff --git a/receiver/hostmetricsreceiver/README.md b/receiver/hostmetricsreceiver/README.md index 398b30a9ae1d..a56fbbda3617 100644 --- a/receiver/hostmetricsreceiver/README.md +++ b/receiver/hostmetricsreceiver/README.md @@ -17,7 +17,7 @@ The Host Metrics receiver generates metrics about the host system scraped -from various sources and host entity event as log. This is intended to be +from various sources and host entity event as log. This is intended to be used when the collector is deployed as an agent. ## Getting Started @@ -49,7 +49,7 @@ The available scrapers are: | [paging] | All | Paging/Swap space utilization and I/O metrics | | [processes] | Linux, Mac | Process count metrics | | [process] | Linux, Windows, Mac | Per process CPU, Memory, and Disk I/O metrics | -| [uptime] | Linux, Windows, Mac | Uptime metric | +| [system] | Linux, Windows, Mac | Miscellaneous system metrics | [cpu]: ./internal/scraper/cpuscraper/documentation.md [disk]: ./internal/scraper/diskscraper/documentation.md @@ -60,7 +60,7 @@ The available scrapers are: [paging]: ./internal/scraper/pagingscraper/documentation.md [processes]: ./internal/scraper/processesscraper/documentation.md [process]: ./internal/scraper/processscraper/documentation.md -[uptime]: ./internal/scraper/uptimescraper/documentation.md +[system]: ./internal/scraper/systemscraper/documentation.md ### Notes @@ -172,14 +172,14 @@ service: Host metrics are collected from the Linux system directories on the filesystem. You likely want to collect metrics about the host system and not the container. -This is achievable by following these steps: +This is achievable by following these steps: #### 1. Bind mount the host filesystem -The simplest configuration is to mount the entire host filesystem when running +The simplest configuration is to mount the entire host filesystem when running the container. e.g. `docker run -v /:/hostfs ...`. -You can also choose which parts of the host filesystem to mount, if you know +You can also choose which parts of the host filesystem to mount, if you know exactly what you'll need. e.g. `docker run -v /proc:/hostfs/proc`. #### 2. Configure `root_path` diff --git a/receiver/hostmetricsreceiver/config_test.go b/receiver/hostmetricsreceiver/config_test.go index 2d00dab4b738..4b30d09a9622 100644 --- a/receiver/hostmetricsreceiver/config_test.go +++ b/receiver/hostmetricsreceiver/config_test.go @@ -27,7 +27,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper" ) func TestLoadConfig(t *testing.T) { @@ -119,8 +119,8 @@ func TestLoadConfig(t *testing.T) { cfg.SetEnvMap(common.EnvMap{}) return cfg })(), - uptimescraper.TypeStr: (func() internal.Config { - cfg := (&uptimescraper.Factory{}).CreateDefaultConfig() + systemscraper.TypeStr: (func() internal.Config { + cfg := (&systemscraper.Factory{}).CreateDefaultConfig() cfg.SetEnvMap(common.EnvMap{}) return cfg })(), diff --git a/receiver/hostmetricsreceiver/factory.go b/receiver/hostmetricsreceiver/factory.go index 227ef00862d1..dbd7458f4233 100644 --- a/receiver/hostmetricsreceiver/factory.go +++ b/receiver/hostmetricsreceiver/factory.go @@ -27,7 +27,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper" ) const ( @@ -46,7 +46,7 @@ var ( pagingscraper.TypeStr: &pagingscraper.Factory{}, processesscraper.TypeStr: &processesscraper.Factory{}, processscraper.TypeStr: &processscraper.Factory{}, - uptimescraper.TypeStr: &uptimescraper.Factory{}, + systemscraper.TypeStr: &systemscraper.Factory{}, } ) diff --git a/receiver/hostmetricsreceiver/go.mod b/receiver/hostmetricsreceiver/go.mod index 212133b6fb35..835ab3e2c428 100644 --- a/receiver/hostmetricsreceiver/go.mod +++ b/receiver/hostmetricsreceiver/go.mod @@ -12,6 +12,7 @@ require ( github.com/prometheus/procfs v0.15.1 github.com/shirou/gopsutil/v4 v4.24.9 github.com/stretchr/testify v1.9.0 + github.com/tj/assert v0.0.3 github.com/yusufpapurcu/wmi v1.2.4 go.opentelemetry.io/collector/component v0.112.0 go.opentelemetry.io/collector/confmap v1.18.0 diff --git a/receiver/hostmetricsreceiver/go.sum b/receiver/hostmetricsreceiver/go.sum index bddb1259e22b..be2ccb8df7c1 100644 --- a/receiver/hostmetricsreceiver/go.sum +++ b/receiver/hostmetricsreceiver/go.sum @@ -164,11 +164,14 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= +github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/testcontainers/testcontainers-go v0.31.0 h1:W0VwIhcEVhRflwL9as3dhY6jXjVCA27AkmbnZ+UTh3U= github.com/testcontainers/testcontainers-go v0.31.0/go.mod h1:D2lAoA0zUFiSY+eAflqK5mcUx/A5hrrORaEQrd0SefI= +github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk= +github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= @@ -383,6 +386,7 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY= diff --git a/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go b/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go index 6919a4fe5e2f..993b08f95b7b 100644 --- a/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go +++ b/receiver/hostmetricsreceiver/hostmetrics_receiver_test.go @@ -34,7 +34,7 @@ import ( "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/pagingscraper" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processesscraper" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/processscraper" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper" ) var allMetrics = []string{ @@ -82,7 +82,7 @@ var factories = map[string]internal.ScraperFactory{ pagingscraper.TypeStr: &pagingscraper.Factory{}, processesscraper.TypeStr: &processesscraper.Factory{}, processscraper.TypeStr: &processscraper.Factory{}, - uptimescraper.TypeStr: &uptimescraper.Factory{}, + systemscraper.TypeStr: &systemscraper.Factory{}, } type testEnv struct { @@ -404,7 +404,7 @@ func Benchmark_ScrapeUptimeMetrics(b *testing.B) { cfg := &Config{ ControllerConfig: scraperhelper.NewDefaultControllerConfig(), - Scrapers: map[string]internal.Config{uptimescraper.TypeStr: (&uptimescraper.Factory{}).CreateDefaultConfig()}, + Scrapers: map[string]internal.Config{systemscraper.TypeStr: (&systemscraper.Factory{}).CreateDefaultConfig()}, } benchmarkScrapeMetrics(b, cfg) @@ -444,6 +444,7 @@ func Benchmark_ScrapeSystemAndProcessMetrics(b *testing.B) { networkscraper.TypeStr: &networkscraper.Config{}, pagingscraper.TypeStr: (&pagingscraper.Factory{}).CreateDefaultConfig(), processesscraper.TypeStr: &processesscraper.Config{}, + systemscraper.TypeStr: &systemscraper.Config{}, }, } diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/config.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/config.go similarity index 78% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/config.go rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/config.go index 00bdcff6722d..9c101ad03347 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/config.go @@ -1,11 +1,11 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package uptimescraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper" +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/uptimescraper/internal/metadata" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata" ) // Config relating to Uptime Metric Scraper. diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/doc.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/doc.go similarity index 67% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/doc.go rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/doc.go index 256a95de192a..0ccd665b954d 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/doc.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/doc.go @@ -3,4 +3,4 @@ //go:generate mdatagen metadata.yaml -package uptimescraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper" +package systemscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper" diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/documentation.md b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/documentation.md similarity index 93% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/documentation.md rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/documentation.md index ce38e605d291..1238dd9db1db 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/documentation.md +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/documentation.md @@ -1,6 +1,6 @@ [comment]: <> (Code generated by mdatagen. DO NOT EDIT.) -# hostmetricsreceiver/uptime +# hostmetricsreceiver/system **Parent Component:** hostmetrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/factory.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory.go similarity index 76% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/factory.go rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory.go index 9f957c33b2fb..bb7d540c7526 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/factory.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory.go @@ -1,26 +1,31 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package uptimescraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper" +package systemscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper" import ( "context" "errors" "runtime" + "go.opentelemetry.io/collector/component" "go.opentelemetry.io/collector/receiver" "go.opentelemetry.io/collector/receiver/scraperhelper" "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal" - hostmeta "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/metadata" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata" ) -// This file implements Factory for Uptime scraper. +// This file implements Factory for System scraper. const ( // TypeStr the value of "type" key in configuration. - TypeStr = "uptime" + TypeStr = "system" +) + +var ( + // scraperType is the component type used for the built scraper. + scraperType component.Type = component.MustNewType(TypeStr) ) // Factory is the Factory for scraper. @@ -47,7 +52,7 @@ func (f *Factory) CreateMetricsScraper( uptimeScraper := newUptimeScraper(ctx, settings, cfg.(*Config)) return scraperhelper.NewScraper( - hostmeta.Type, + scraperType, uptimeScraper.scrape, scraperhelper.WithStart(uptimeScraper.start), ) diff --git a/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go new file mode 100644 index 000000000000..8df4e287ca48 --- /dev/null +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go @@ -0,0 +1,20 @@ +package systemscraper + +import ( + "context" + "testing" + + "github.com/tj/assert" + "go.opentelemetry.io/collector/receiver/receivertest" +) + +func TestCreateSystemScraper(t *testing.T) { + factory := &Factory{} + cfg := &Config{} + + scraper, err := factory.CreateMetricsScraper(context.Background(), receivertest.NewNopSettings(), cfg) + + assert.NoError(t, err) + assert.NotNil(t, scraper) + assert.Equal(t, scraperType.String(), scraper.ID().String()) +} diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_config.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_config.go similarity index 91% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_config.go rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_config.go index f41b077ee334..f3a6f0c2be34 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_config.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_config.go @@ -25,7 +25,7 @@ func (ms *MetricConfig) Unmarshal(parser *confmap.Conf) error { return nil } -// MetricsConfig provides config for hostmetricsreceiver/uptime metrics. +// MetricsConfig provides config for hostmetricsreceiver/system metrics. type MetricsConfig struct { SystemUptime MetricConfig `mapstructure:"system.uptime"` } @@ -38,7 +38,7 @@ func DefaultMetricsConfig() MetricsConfig { } } -// MetricsBuilderConfig is a configuration for hostmetricsreceiver/uptime metrics builder. +// MetricsBuilderConfig is a configuration for hostmetricsreceiver/system metrics builder. type MetricsBuilderConfig struct { Metrics MetricsConfig `mapstructure:"metrics"` } diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_config_test.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_config_test.go similarity index 100% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_config_test.go rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_config_test.go diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_metrics.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_metrics.go similarity index 98% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_metrics.go rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_metrics.go index b586215338e1..653a4230e08f 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_metrics.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_metrics.go @@ -160,7 +160,7 @@ func (mb *MetricsBuilder) EmitForResource(options ...ResourceMetricsOption) { rm := pmetric.NewResourceMetrics() rm.SetSchemaUrl(conventions.SchemaURL) ils := rm.ScopeMetrics().AppendEmpty() - ils.Scope().SetName("github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper") + ils.Scope().SetName("github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper") ils.Scope().SetVersion(mb.buildInfo.Version) ils.Metrics().EnsureCapacity(mb.metricsCapacity) mb.metricSystemUptime.emit(ils.Metrics()) diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_metrics_test.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_metrics_test.go similarity index 100% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/generated_metrics_test.go rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/generated_metrics_test.go diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/testdata/config.yaml b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/testdata/config.yaml similarity index 100% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata/testdata/config.yaml rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata/testdata/config.yaml diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/metadata.yaml b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/metadata.yaml similarity index 86% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/metadata.yaml rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/metadata.yaml index 311077a1af94..f58a53420ba7 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/metadata.yaml +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/metadata.yaml @@ -1,4 +1,4 @@ -type: hostmetricsreceiver/uptime +type: hostmetricsreceiver/system parent: hostmetrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/package_test.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/package_test.go similarity index 89% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/package_test.go rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/package_test.go index 6de26a8152d0..337c65274c8b 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/package_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/package_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package uptimescraper +package systemscraper import ( "testing" diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/uptime.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/system_scraper.go similarity index 91% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/uptime.go rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/system_scraper.go index db6d307c53c5..3d441eb0bc2b 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/uptime.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/system_scraper.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package uptimescraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper" +package systemscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper" import ( "context" @@ -14,7 +14,7 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata" ) // scraper for Uptime Metrics diff --git a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/uptime_test.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/system_scraper_test.go similarity index 94% rename from receiver/hostmetricsreceiver/internal/scraper/uptimescraper/uptime_test.go rename to receiver/hostmetricsreceiver/internal/scraper/systemscraper/system_scraper_test.go index 1ceeebdd117c..38171c5a8cf1 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/uptime_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/system_scraper_test.go @@ -1,7 +1,7 @@ // Copyright The OpenTelemetry Authors // SPDX-License-Identifier: Apache-2.0 -package uptimescraper +package systemscraper import ( "context" @@ -14,7 +14,7 @@ import ( "go.opentelemetry.io/collector/pdata/pmetric" "go.opentelemetry.io/collector/receiver/receivertest" - "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/uptimescraper/internal/metadata" + "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/systemscraper/internal/metadata" ) func TestScrape(t *testing.T) { diff --git a/receiver/hostmetricsreceiver/testdata/config.yaml b/receiver/hostmetricsreceiver/testdata/config.yaml index 2128c3dcbc41..fd882c9e6465 100644 --- a/receiver/hostmetricsreceiver/testdata/config.yaml +++ b/receiver/hostmetricsreceiver/testdata/config.yaml @@ -21,7 +21,7 @@ receivers: include: names: ["test2", "test3"] match_type: "regexp" - uptime: + system: processors: nop: From fc04bce64eda7b8f0bb1510550c002ac78fba649 Mon Sep 17 00:00:00 2001 From: braydonk Date: Thu, 31 Oct 2024 23:02:14 +0000 Subject: [PATCH 2/3] fix bad assert import --- receiver/hostmetricsreceiver/go.mod | 1 - receiver/hostmetricsreceiver/go.sum | 4 ---- .../internal/scraper/systemscraper/factory_test.go | 2 +- 3 files changed, 1 insertion(+), 6 deletions(-) diff --git a/receiver/hostmetricsreceiver/go.mod b/receiver/hostmetricsreceiver/go.mod index 835ab3e2c428..212133b6fb35 100644 --- a/receiver/hostmetricsreceiver/go.mod +++ b/receiver/hostmetricsreceiver/go.mod @@ -12,7 +12,6 @@ require ( github.com/prometheus/procfs v0.15.1 github.com/shirou/gopsutil/v4 v4.24.9 github.com/stretchr/testify v1.9.0 - github.com/tj/assert v0.0.3 github.com/yusufpapurcu/wmi v1.2.4 go.opentelemetry.io/collector/component v0.112.0 go.opentelemetry.io/collector/confmap v1.18.0 diff --git a/receiver/hostmetricsreceiver/go.sum b/receiver/hostmetricsreceiver/go.sum index be2ccb8df7c1..bddb1259e22b 100644 --- a/receiver/hostmetricsreceiver/go.sum +++ b/receiver/hostmetricsreceiver/go.sum @@ -164,14 +164,11 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= -github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/testcontainers/testcontainers-go v0.31.0 h1:W0VwIhcEVhRflwL9as3dhY6jXjVCA27AkmbnZ+UTh3U= github.com/testcontainers/testcontainers-go v0.31.0/go.mod h1:D2lAoA0zUFiSY+eAflqK5mcUx/A5hrrORaEQrd0SefI= -github.com/tj/assert v0.0.3 h1:Df/BlaZ20mq6kuai7f5z2TvPFiwC3xaWJSDQNiIS3Rk= -github.com/tj/assert v0.0.3/go.mod h1:Ne6X72Q+TB1AteidzQncjw9PabbMp4PBMZ1k+vd1Pvk= github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU= github.com/tklauser/go-sysconf v0.3.12/go.mod h1:Ho14jnntGE1fpdOqQEEaiKRpvIavV0hSfmBq8nJbHYI= github.com/tklauser/numcpus v0.6.1 h1:ng9scYS7az0Bk4OZLvrNXNSAO2Pxr1XXRAPyjhIx+Fk= @@ -386,7 +383,6 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8 gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gotest.tools/v3 v3.5.0 h1:Ljk6PdHdOhAb5aDMWXjDLMMhph+BpztA4v1QdqEW2eY= diff --git a/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go index 8df4e287ca48..8f689ffbb8be 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go @@ -4,7 +4,7 @@ import ( "context" "testing" - "github.com/tj/assert" + "github.com/stretchr/testify/assert" "go.opentelemetry.io/collector/receiver/receivertest" ) From 938f03c219e4a191d293d04939923857a15d263d Mon Sep 17 00:00:00 2001 From: braydonk Date: Fri, 1 Nov 2024 12:47:31 +0000 Subject: [PATCH 3/3] added license to new test file --- .../internal/scraper/systemscraper/factory_test.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go index 8f689ffbb8be..5567d875bce2 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/systemscraper/factory_test.go @@ -1,3 +1,6 @@ +// Copyright The OpenTelemetry Authors +// SPDX-License-Identifier: Apache-2.0 + package systemscraper import (