Skip to content

Commit

Permalink
[receiver/hostmetrics] Migrate network scraper to new metrics builder (
Browse files Browse the repository at this point in the history
…#7048)

* [receiver/hostmetrics] Migrate network scraper to new metrics builder

* Fix review comments

- Add CHANGELOG
- Fix lint failures

* Uncomment networkscraper config.yaml

* Fix review comments

* Address review comments

* Fix unit test failures
  • Loading branch information
abhide authored Jan 21, 2022
1 parent d22de4b commit 5ea0161
Show file tree
Hide file tree
Showing 10 changed files with 504 additions and 259 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
OpenCensus conversion path.
- `extension/observers`: Correctly set image and tag on container endpoints (#7279)
- `tanzuobservabilityexporter`: Document how to enable memory_limiter (#7286)
- `hostreceiver/networkscraper`: Migrate the scraper to the mdatagen metrics builder (#7048)

## 🛑 Breaking changes 🛑

Expand Down
10 changes: 6 additions & 4 deletions receiver/hostmetricsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@ func TestLoadConfig(t *testing.T) {
loadscraper.TypeStr: &loadscraper.Config{},
filesystemscraper.TypeStr: &filesystemscraper.Config{},
memoryscraper.TypeStr: &memoryscraper.Config{},
networkscraper.TypeStr: &networkscraper.Config{
Include: networkscraper.MatchConfig{
networkscraper.TypeStr: (func() internal.Config {
cfg := (&networkscraper.Factory{}).CreateDefaultConfig()
cfg.(*networkscraper.Config).Include = networkscraper.MatchConfig{
Interfaces: []string{"test1"},
Config: filterset.Config{MatchType: "strict"},
},
},
}
return cfg
})(),
processesscraper.TypeStr: &processesscraper.Config{},
pagingscraper.TypeStr: &pagingscraper.Config{},
processscraper.TypeStr: &processscraper.Config{
Expand Down
2 changes: 1 addition & 1 deletion receiver/hostmetricsreceiver/hostmetrics_receiver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func TestGatherMetrics_EndToEnd(t *testing.T) {
filesystemscraper.TypeStr: &filesystemscraper.Config{},
loadscraper.TypeStr: &loadscraper.Config{},
memoryscraper.TypeStr: &memoryscraper.Config{},
networkscraper.TypeStr: &networkscraper.Config{},
networkscraper.TypeStr: scraperFactories[networkscraper.TypeStr].CreateDefaultConfig(),
pagingscraper.TypeStr: &pagingscraper.Config{},
processesscraper.TypeStr: &processesscraper.Config{},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
//go:build !windows
// +build !windows

//go:generate mdatagen metadata.yaml
//go:generate mdatagen --experimental-gen metadata.yaml

package networkscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/networkscraper"
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ package networkscraper // import "github.com/open-telemetry/opentelemetry-collec
import (
"github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal/processor/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 {
internal.ConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct

Metrics metadata.MetricsSettings `mapstructure:"metrics"`
// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"go.uber.org/zap"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/networkscraper/internal/metadata"
)

// This file implements Factory for Network scraper.
Expand All @@ -36,7 +37,9 @@ type Factory struct {

// CreateDefaultConfig creates the default configuration for the Scraper.
func (f *Factory) CreateDefaultConfig() internal.Config {
return &Config{}
return &Config{
Metrics: metadata.DefaultMetricsSettings(),
}
}

// CreateMetricsScraper creates a scraper based on provided config.
Expand Down

This file was deleted.

Loading

0 comments on commit 5ea0161

Please sign in to comment.