123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- // Copyright The OpenTelemetry Authors
- // SPDX-License-Identifier: Apache-2.0
- //go:build integration
- // +build integration
- package hostmetricsreceiver
- import (
- "os/exec"
- "path/filepath"
- "testing"
- "time"
- "github.com/stretchr/testify/require"
- "go.opentelemetry.io/collector/component"
- "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"
- )
- func Test_ProcessScrape(t *testing.T) {
- expectedFile := filepath.Join("testdata", "e2e", "expected_process.yaml")
- cmd := exec.Command("/bin/sleep", "300")
- require.NoError(t, cmd.Start())
- defer func() {
- require.NoError(t, cmd.Process.Kill())
- }()
- scraperinttest.NewIntegrationTest(
- NewFactory(),
- scraperinttest.WithCustomConfig(
- func(t *testing.T, cfg component.Config, ci *scraperinttest.ContainerInfo) {
- rCfg := cfg.(*Config)
- rCfg.CollectionInterval = time.Second
- pCfg := (&processscraper.Factory{}).CreateDefaultConfig().(*processscraper.Config)
- pCfg.Include = processscraper.MatchConfig{
- Config: filterset.Config{MatchType: filterset.Regexp},
- Names: []string{"sleep"},
- }
- rCfg.Scrapers = map[string]internal.Config{
- "process": pCfg,
- }
- }),
- scraperinttest.WithExpectedFile(expectedFile),
- scraperinttest.WithCompareOptions(
- pmetrictest.IgnoreResourceMetricsOrder(),
- pmetrictest.IgnoreMetricValues(),
- pmetrictest.IgnoreMetricDataPointsOrder(),
- pmetrictest.IgnoreStartTimestamp(),
- pmetrictest.IgnoreTimestamp(),
- ),
- ).Run(t)
- }
- func Test_ProcessScrapeWithCustomRootPath(t *testing.T) {
- expectedFile := filepath.Join("testdata", "e2e", "expected_process_separate_proc.yaml")
- scraperinttest.NewIntegrationTest(
- NewFactory(),
- scraperinttest.WithCustomConfig(
- func(t *testing.T, cfg component.Config, ci *scraperinttest.ContainerInfo) {
- rCfg := cfg.(*Config)
- rCfg.CollectionInterval = time.Second
- pCfg := (&processscraper.Factory{}).CreateDefaultConfig().(*processscraper.Config)
- pCfg.Include = processscraper.MatchConfig{
- Config: filterset.Config{MatchType: filterset.Regexp},
- Names: []string{"sleep"},
- }
- rCfg.Scrapers = map[string]internal.Config{
- "process": pCfg,
- }
- rCfg.RootPath = filepath.Join("testdata", "e2e")
- }),
- scraperinttest.WithExpectedFile(expectedFile),
- scraperinttest.WithCompareOptions(
- pmetrictest.IgnoreResourceMetricsOrder(),
- pmetrictest.IgnoreMetricValues(),
- pmetrictest.IgnoreMetricDataPointsOrder(),
- pmetrictest.IgnoreStartTimestamp(),
- pmetrictest.IgnoreTimestamp(),
- ),
- ).Run(t)
- }
- func Test_ProcessScrapeWithBadRootPathAndEnvVar(t *testing.T) {
- expectedFile := filepath.Join("testdata", "e2e", "expected_process_separate_proc.yaml")
- t.Setenv("HOST_PROC", filepath.Join("testdata", "e2e", "proc"))
- scraperinttest.NewIntegrationTest(
- NewFactory(),
- scraperinttest.WithCustomConfig(
- func(t *testing.T, cfg component.Config, ci *scraperinttest.ContainerInfo) {
- rCfg := cfg.(*Config)
- rCfg.CollectionInterval = time.Second
- pCfg := (&processscraper.Factory{}).CreateDefaultConfig().(*processscraper.Config)
- pCfg.Include = processscraper.MatchConfig{
- Config: filterset.Config{MatchType: filterset.Regexp},
- Names: []string{"sleep"},
- }
- rCfg.Scrapers = map[string]internal.Config{
- "process": pCfg,
- }
- rCfg.RootPath = filepath.Join("testdata", "NOT A VALID FOLDER")
- }),
- scraperinttest.WithExpectedFile(expectedFile),
- scraperinttest.WithCompareOptions(
- pmetrictest.IgnoreResourceMetricsOrder(),
- pmetrictest.IgnoreMetricValues(),
- pmetrictest.IgnoreMetricDataPointsOrder(),
- pmetrictest.IgnoreStartTimestamp(),
- pmetrictest.IgnoreTimestamp(),
- ),
- ).Run(t)
- }
|