Skip to content

Commit

Permalink
[receiver/hostmetrics] Migrate memory scraper to the new metrics builder
Browse files Browse the repository at this point in the history
  • Loading branch information
rogercoll committed Feb 7, 2022
1 parent e794616 commit a551925
Show file tree
Hide file tree
Showing 13 changed files with 279 additions and 180 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
- `postgresreceiver`: Update to mdatagen v2 (#7503)
- `nginxreceiver`: Update to mdatagen v2 (#7549)
- `datadogexporter`: Fix traces exporter's initialization log (#7564)
- `hostreceiver/memoryscraper`: Migrate the scraper to the mdatagen metrics builder (#7421)

## 🛑 Breaking changes 🛑

Expand Down
2 changes: 1 addition & 1 deletion receiver/hostmetricsreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func TestLoadConfig(t *testing.T) {
return cfg
})(),
filesystemscraper.TypeStr: &filesystemscraper.Config{},
memoryscraper.TypeStr: &memoryscraper.Config{},
memoryscraper.TypeStr: (&memoryscraper.Factory{}).CreateDefaultConfig(),
networkscraper.TypeStr: (func() internal.Config {
cfg := (&networkscraper.Factory{}).CreateDefaultConfig()
cfg.(*networkscraper.Config).Include = networkscraper.MatchConfig{
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 @@ -109,7 +109,7 @@ func TestGatherMetrics_EndToEnd(t *testing.T) {
diskscraper.TypeStr: scraperFactories[diskscraper.TypeStr].CreateDefaultConfig(),
filesystemscraper.TypeStr: &filesystemscraper.Config{},
loadscraper.TypeStr: scraperFactories[loadscraper.TypeStr].CreateDefaultConfig(),
memoryscraper.TypeStr: &memoryscraper.Config{},
memoryscraper.TypeStr: scraperFactories[memoryscraper.TypeStr].CreateDefaultConfig(),
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 @@ -14,9 +14,15 @@

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"
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 {
internal.ConfigSettings `mapstructure:",squash"` // squash ensures fields are correctly decoded in embedded struct

// Metrics allows to customize scraped metrics representation.
Metrics metadata.MetricsSettings `mapstructure:"metrics"`
}
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 memoryscraper // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/hostmetricsreceiver/internal/scraper/memoryscraper"
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/memoryscraper/internal/metadata"
)

// This file implements Factory for Memory 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 All @@ -48,5 +51,8 @@ func (f *Factory) CreateMetricsScraper(
cfg := config.(*Config)
s := newMemoryScraper(ctx, cfg)

return scraperhelper.NewScraper(TypeStr, s.Scrape)
return scraperhelper.NewScraper(TypeStr,
s.scrape,
scraperhelper.WithStart(s.start),
)
}

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a551925

Please sign in to comment.