diff --git a/CHANGELOG.md b/CHANGELOG.md index e50ca40b516..6bedcfa0439 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ - Remove `consumerdata.TraceData` (#2551) - Move `consumerdata.MetricsData` to `internaldata.MetricsData` (#2512) - Remove custom OpenCensus sematic conventions that have equivalent in otel (#2552) +- Move ScrapeErrors and PartialScrapeError to `scrapererror` (#2580) - Remove support for deprecated unmarshaler `CustomUnmarshaler`, only `Unmarshal` is supported (#2591) - Remove deprecated componenterror.CombineErrors (#2598) diff --git a/obsreport/obsreport_scraper.go b/obsreport/obsreport_scraper.go index ee02acb78a8..8d24223ef35 100644 --- a/obsreport/obsreport_scraper.go +++ b/obsreport/obsreport_scraper.go @@ -23,7 +23,7 @@ import ( "go.opentelemetry.io/collector/config/configmodels" "go.opentelemetry.io/collector/config/configtelemetry" - "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const ( @@ -100,7 +100,7 @@ func EndMetricsScrapeOp( ) { numErroredMetrics := 0 if err != nil { - if partialErr, isPartial := err.(consumererror.PartialScrapeError); isPartial { + if partialErr, isPartial := err.(scrapererror.PartialScrapeError); isPartial { numErroredMetrics = partialErr.Failed } else { numErroredMetrics = numScrapedMetrics diff --git a/obsreport/obsreport_test.go b/obsreport/obsreport_test.go index 59733c72fc5..500d99fafd5 100644 --- a/obsreport/obsreport_test.go +++ b/obsreport/obsreport_test.go @@ -29,9 +29,9 @@ import ( "go.opencensus.io/trace" "go.opentelemetry.io/collector/config/configtelemetry" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/obsreport" "go.opentelemetry.io/collector/obsreport/obsreporttest" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const ( @@ -45,7 +45,7 @@ const ( var ( errFake = errors.New("errFake") - partialErrFake = consumererror.NewPartialScrapeError(errFake, 1) + partialErrFake = scrapererror.NewPartialScrapeError(errFake, 1) ) type receiveTestParams struct { diff --git a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper.go index 3e6fec28f0b..82c3639919d 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper.go @@ -22,9 +22,9 @@ import ( "github.com/shirou/gopsutil/host" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const metricsLen = 1 @@ -60,7 +60,7 @@ func (s *scraper) scrape(_ context.Context) (pdata.MetricSlice, error) { now := pdata.TimestampFromTime(time.Now()) cpuTimes, err := s.times( /*percpu=*/ true) if err != nil { - return metrics, consumererror.NewPartialScrapeError(err, metricsLen) + return metrics, scrapererror.NewPartialScrapeError(err, metricsLen) } metrics.Resize(metricsLen) diff --git a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_test.go index 38af8be4cb0..26e8c211eaa 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/cpuscraper/cpu_scraper_test.go @@ -25,10 +25,10 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) func TestScrape(t *testing.T) { @@ -83,10 +83,10 @@ func TestScrape(t *testing.T) { if test.expectedErr != "" { assert.EqualError(t, err, test.expectedErr) - isPartial := consumererror.IsPartialScrapeError(err) + isPartial := scrapererror.IsPartialScrapeError(err) assert.True(t, isPartial) if isPartial { - assert.Equal(t, 1, err.(consumererror.PartialScrapeError).Failed) + assert.Equal(t, 1, err.(scrapererror.PartialScrapeError).Failed) } return diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_others.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_others.go index 9cbb7c01dbd..fc180366536 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_others.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_others.go @@ -25,10 +25,10 @@ import ( "github.com/shirou/gopsutil/host" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/internal/processor/filterset" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const ( @@ -87,7 +87,7 @@ func (s *scraper) scrape(_ context.Context) (pdata.MetricSlice, error) { now := pdata.TimestampFromTime(time.Now()) ioCounters, err := s.ioCounters() if err != nil { - return metrics, consumererror.NewPartialScrapeError(err, metricsLen) + return metrics, scrapererror.NewPartialScrapeError(err, metricsLen) } // filter devices by name diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_others_test.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_others_test.go index 516e233e634..c53dbbc9daf 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_others_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_others_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/receiver/scrapererror" ) func TestScrape_Others(t *testing.T) { @@ -59,10 +59,10 @@ func TestScrape_Others(t *testing.T) { _, err = scraper.scrape(context.Background()) assert.EqualError(t, err, test.expectedErr) - isPartial := consumererror.IsPartialScrapeError(err) + isPartial := scrapererror.IsPartialScrapeError(err) assert.True(t, isPartial) if isPartial { - assert.Equal(t, metricsLen, err.(consumererror.PartialScrapeError).Failed) + assert.Equal(t, metricsLen, err.(scrapererror.PartialScrapeError).Failed) } }) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_windows.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_windows.go index f35fe98cf1d..e01ecd36a5a 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_windows.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_windows.go @@ -22,11 +22,11 @@ import ( "github.com/shirou/gopsutil/host" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/internal/processor/filterset" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/perfcounters" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const ( @@ -102,12 +102,12 @@ func (s *scraper) scrape(ctx context.Context) (pdata.MetricSlice, error) { counters, err := s.perfCounterScraper.Scrape() if err != nil { - return metrics, consumererror.NewPartialScrapeError(err, metricsLen) + return metrics, scrapererror.NewPartialScrapeError(err, metricsLen) } logicalDiskObject, err := counters.GetObject(logicalDisk) if err != nil { - return metrics, consumererror.NewPartialScrapeError(err, metricsLen) + return metrics, scrapererror.NewPartialScrapeError(err, metricsLen) } // filter devices by name @@ -115,7 +115,7 @@ func (s *scraper) scrape(ctx context.Context) (pdata.MetricSlice, error) { logicalDiskCounterValues, err := logicalDiskObject.GetValues(readsPerSec, writesPerSec, readBytesPerSec, writeBytesPerSec, idleTime, avgDiskSecsPerRead, avgDiskSecsPerWrite, queueLength) if err != nil { - return metrics, consumererror.NewPartialScrapeError(err, metricsLen) + return metrics, scrapererror.NewPartialScrapeError(err, metricsLen) } if len(logicalDiskCounterValues) > 0 { diff --git a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_windows_test.go b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_windows_test.go index e6940fda432..b9241a1ae20 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_windows_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/diskscraper/disk_scraper_windows_test.go @@ -25,8 +25,8 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/perfcounters" + "go.opentelemetry.io/collector/receiver/scrapererror" ) func TestScrape_Error(t *testing.T) { @@ -69,10 +69,10 @@ func TestScrape_Error(t *testing.T) { _, err = scraper.scrape(context.Background()) assert.EqualError(t, err, test.expectedErr) - isPartial := consumererror.IsPartialScrapeError(err) + isPartial := scrapererror.IsPartialScrapeError(err) assert.True(t, isPartial) if isPartial { - assert.Equal(t, metricsLen, err.(consumererror.PartialScrapeError).Failed) + assert.Equal(t, metricsLen, err.(scrapererror.PartialScrapeError).Failed) } }) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go index efb37da1452..45c1835d073 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper.go @@ -21,9 +21,9 @@ import ( "github.com/shirou/gopsutil/disk" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const ( @@ -66,10 +66,10 @@ func (s *scraper) Scrape(_ context.Context) (pdata.MetricSlice, error) { // omit logical (virtual) filesystems (not relevant for windows) partitions, err := s.partitions( /*all=*/ false) if err != nil { - return metrics, consumererror.NewPartialScrapeError(err, metricsLen) + return metrics, scrapererror.NewPartialScrapeError(err, metricsLen) } - var errors consumererror.ScrapeErrors + var errors scrapererror.ScrapeErrors usages := make([]*deviceUsage, 0, len(partitions)) for _, partition := range partitions { if !s.fsFilter.includePartition(partition) { @@ -92,7 +92,7 @@ func (s *scraper) Scrape(_ context.Context) (pdata.MetricSlice, error) { err = errors.Combine() if err != nil && len(usages) == 0 { - err = consumererror.NewPartialScrapeError(err, metricsLen) + err = scrapererror.NewPartialScrapeError(err, metricsLen) } return metrics, err diff --git a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_test.go index 7e92ca82554..69f700dc1ef 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/filesystemscraper/filesystem_scraper_test.go @@ -24,11 +24,11 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/internal/processor/filterset" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) func TestScrape(t *testing.T) { @@ -197,10 +197,10 @@ func TestScrape(t *testing.T) { if test.expectedErr != "" { assert.Contains(t, err.Error(), test.expectedErr) - isPartial := consumererror.IsPartialScrapeError(err) + isPartial := scrapererror.IsPartialScrapeError(err) assert.True(t, isPartial) if isPartial { - assert.Equal(t, metricsLen, err.(consumererror.PartialScrapeError).Failed) + assert.Equal(t, metricsLen, err.(scrapererror.PartialScrapeError).Failed) } return diff --git a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper.go index 689c61133f2..f91bc8f0423 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper.go @@ -22,9 +22,9 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const metricsLen = 3 @@ -60,7 +60,7 @@ func (s *scraper) scrape(_ context.Context) (pdata.MetricSlice, error) { now := pdata.TimestampFromTime(time.Now()) avgLoadValues, err := s.load() if err != nil { - return metrics, consumererror.NewPartialScrapeError(err, metricsLen) + return metrics, scrapererror.NewPartialScrapeError(err, metricsLen) } metrics.Resize(metricsLen) diff --git a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper_test.go index 89d1548bff8..a459149410d 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/loadscraper/load_scraper_test.go @@ -25,10 +25,10 @@ import ( "go.uber.org/zap" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) func TestScrape(t *testing.T) { @@ -64,10 +64,10 @@ func TestScrape(t *testing.T) { if test.expectedErr != "" { assert.EqualError(t, err, test.expectedErr) - isPartial := consumererror.IsPartialScrapeError(err) + isPartial := scrapererror.IsPartialScrapeError(err) assert.True(t, isPartial) if isPartial { - assert.Equal(t, metricsLen, err.(consumererror.PartialScrapeError).Failed) + assert.Equal(t, metricsLen, err.(scrapererror.PartialScrapeError).Failed) } return diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper.go index b35711bb784..6a999e24368 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper.go @@ -20,9 +20,9 @@ import ( "github.com/shirou/gopsutil/mem" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const metricsLen = 1 @@ -47,7 +47,7 @@ func (s *scraper) Scrape(_ context.Context) (pdata.MetricSlice, error) { now := pdata.TimestampFromTime(time.Now()) memInfo, err := s.virtualMemory() if err != nil { - return metrics, consumererror.NewPartialScrapeError(err, metricsLen) + return metrics, scrapererror.NewPartialScrapeError(err, metricsLen) } metrics.Resize(metricsLen) diff --git a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go index 8b2b1a6a0c7..a7767a3b69b 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/memoryscraper/memory_scraper_test.go @@ -24,10 +24,10 @@ import ( "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) func TestScrape(t *testing.T) { @@ -59,10 +59,10 @@ func TestScrape(t *testing.T) { if test.expectedErr != "" { assert.EqualError(t, err, test.expectedErr) - isPartial := consumererror.IsPartialScrapeError(err) + isPartial := scrapererror.IsPartialScrapeError(err) assert.True(t, isPartial) if isPartial { - assert.Equal(t, metricsLen, err.(consumererror.PartialScrapeError).Failed) + assert.Equal(t, metricsLen, err.(scrapererror.PartialScrapeError).Failed) } return diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go index b402b991f5c..b9c94a0e236 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper.go @@ -23,10 +23,10 @@ import ( "github.com/shirou/gopsutil/net" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/internal/processor/filterset" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const ( @@ -83,7 +83,7 @@ func (s *scraper) start(context.Context, component.Host) error { func (s *scraper) scrape(_ context.Context) (pdata.MetricSlice, error) { metrics := pdata.NewMetricSlice() - var errors consumererror.ScrapeErrors + var errors scrapererror.ScrapeErrors err := s.scrapeAndAppendNetworkCounterMetrics(metrics, s.startTime) if err != nil { diff --git a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go index 501cf9a77b8..c1a7dd98a09 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/networkscraper/network_scraper_test.go @@ -24,11 +24,11 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/internal/processor/filterset" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) func TestScrape(t *testing.T) { @@ -122,10 +122,10 @@ func TestScrape(t *testing.T) { if test.expectedErr != "" { assert.EqualError(t, err, test.expectedErr) - isPartial := consumererror.IsPartialScrapeError(err) + isPartial := scrapererror.IsPartialScrapeError(err) assert.True(t, isPartial) if isPartial { - assert.Equal(t, test.expectedErrCount, err.(consumererror.PartialScrapeError).Failed) + assert.Equal(t, test.expectedErrCount, err.(scrapererror.PartialScrapeError).Failed) } return diff --git a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_others.go b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_others.go index 349a3e6d666..4c2a6c500f2 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_others.go +++ b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_others.go @@ -24,9 +24,9 @@ import ( "github.com/shirou/gopsutil/mem" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const ( @@ -63,7 +63,7 @@ func (s *scraper) start(context.Context, component.Host) error { func (s *scraper) scrape(_ context.Context) (pdata.MetricSlice, error) { metrics := pdata.NewMetricSlice() - var errors consumererror.ScrapeErrors + var errors scrapererror.ScrapeErrors err := s.scrapeAndAppendPagingUsageMetric(metrics) if err != nil { diff --git a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_others_test.go b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_others_test.go index 7688d336f3c..9433dc9804f 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_others_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_others_test.go @@ -26,7 +26,7 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/consumer/consumererror" + "go.opentelemetry.io/collector/receiver/scrapererror" ) func TestScrape_Errors(t *testing.T) { @@ -76,10 +76,10 @@ func TestScrape_Errors(t *testing.T) { _, err = scraper.scrape(context.Background()) assert.EqualError(t, err, test.expectedError) - isPartial := consumererror.IsPartialScrapeError(err) + isPartial := scrapererror.IsPartialScrapeError(err) assert.True(t, isPartial) if isPartial { - assert.Equal(t, test.expectedErrCount, err.(consumererror.PartialScrapeError).Failed) + assert.Equal(t, test.expectedErrCount, err.(scrapererror.PartialScrapeError).Failed) } }) } diff --git a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_windows.go b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_windows.go index de17dd46074..0a88cf82ef6 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_windows.go +++ b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_windows.go @@ -24,10 +24,10 @@ import ( "github.com/shirou/gopsutil/host" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/perfcounters" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const ( @@ -80,7 +80,7 @@ func (s *scraper) start(context.Context, component.Host) error { func (s *scraper) scrape(context.Context) (pdata.MetricSlice, error) { metrics := pdata.NewMetricSlice() - var errors consumererror.ScrapeErrors + var errors scrapererror.ScrapeErrors err := s.scrapeAndAppendPagingUsageMetric(metrics) if err != nil { diff --git a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_windows_test.go b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_windows_test.go index cd06bd0281b..2f3d432a6b8 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_windows_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/pagingscraper/paging_scraper_windows_test.go @@ -25,8 +25,8 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/perfcounters" + "go.opentelemetry.io/collector/receiver/scrapererror" ) func TestScrape_Errors(t *testing.T) { @@ -110,10 +110,10 @@ func TestScrape_Errors(t *testing.T) { if test.expectedErr != "" { assert.EqualError(t, err, test.expectedErr) - isPartial := consumererror.IsPartialScrapeError(err) + isPartial := scrapererror.IsPartialScrapeError(err) assert.True(t, isPartial) if isPartial { - assert.Equal(t, test.expectedErrCount, err.(consumererror.PartialScrapeError).Failed) + assert.Equal(t, test.expectedErrCount, err.(scrapererror.PartialScrapeError).Failed) } return diff --git a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_scraper_test.go index ba7e609e83d..80bbde4d373 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_scraper_test.go @@ -25,10 +25,10 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) func TestScrape(t *testing.T) { @@ -75,10 +75,10 @@ func TestScrape(t *testing.T) { if (expectProcessesCountMetric || expectProcessesCreatedMetric) && test.expectedErr != "" { assert.EqualError(t, err, test.expectedErr) - isPartial := consumererror.IsPartialScrapeError(err) + isPartial := scrapererror.IsPartialScrapeError(err) assert.True(t, isPartial) if isPartial { - assert.Equal(t, expectedMetricCount, err.(consumererror.PartialScrapeError).Failed) + assert.Equal(t, expectedMetricCount, err.(scrapererror.PartialScrapeError).Failed) } return diff --git a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_scraper_unix.go b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_scraper_unix.go index 70cff619f6b..17b1e7c3a4d 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_scraper_unix.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processesscraper/processes_scraper_unix.go @@ -21,9 +21,9 @@ import ( "github.com/shirou/gopsutil/load" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const ( @@ -35,7 +35,7 @@ func appendSystemSpecificProcessesMetrics(metrics pdata.MetricSlice, startIndex now := pdata.TimestampFromTime(time.Now()) misc, err := miscFunc() if err != nil { - return consumererror.NewPartialScrapeError(err, unixMetricsLen) + return scrapererror.NewPartialScrapeError(err, unixMetricsLen) } metrics.Resize(startIndex + unixMetricsLen) diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper.go index b6fc8914793..ee65f888165 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper.go @@ -24,10 +24,10 @@ import ( "github.com/shirou/gopsutil/process" "go.opentelemetry.io/collector/component" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/internal/processor/filterset" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" ) const ( @@ -86,11 +86,11 @@ func (s *scraper) start(context.Context, component.Host) error { func (s *scraper) scrape(_ context.Context) (pdata.ResourceMetricsSlice, error) { rms := pdata.NewResourceMetricsSlice() - var errs consumererror.ScrapeErrors + var errs scrapererror.ScrapeErrors metadata, err := s.getProcessMetadata() if err != nil { - partialErr, isPartial := err.(consumererror.PartialScrapeError) + partialErr, isPartial := err.(scrapererror.PartialScrapeError) if !isPartial { return rms, err } @@ -135,7 +135,7 @@ func (s *scraper) getProcessMetadata() ([]*processMetadata, error) { return nil, err } - var errs consumererror.ScrapeErrors + var errs scrapererror.ScrapeErrors metadata := make([]*processMetadata, 0, handles.Len()) for i := 0; i < handles.Len(); i++ { diff --git a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_test.go b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_test.go index 26ec9f81abc..756e5c4f209 100644 --- a/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_test.go +++ b/receiver/hostmetricsreceiver/internal/scraper/processscraper/process_scraper_test.go @@ -28,11 +28,11 @@ import ( "github.com/stretchr/testify/require" "go.opentelemetry.io/collector/component/componenttest" - "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/internal/processor/filterset" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal" "go.opentelemetry.io/collector/receiver/hostmetricsreceiver/internal/metadata" + "go.opentelemetry.io/collector/receiver/scrapererror" "go.opentelemetry.io/collector/translator/conventions" ) @@ -62,9 +62,9 @@ func TestScrape(t *testing.T) { // // so validate that we have at some errors & some valid data if err != nil { - require.True(t, consumererror.IsPartialScrapeError(err)) + require.True(t, scrapererror.IsPartialScrapeError(err)) noProcessesScraped := resourceMetrics.Len() - noProcessesErrored := err.(consumererror.PartialScrapeError).Failed + noProcessesErrored := err.(scrapererror.PartialScrapeError).Failed require.Lessf(t, 0, noProcessesErrored, "Failed to scrape metrics - : error, but 0 failed process %v", err) require.Lessf(t, 0, noProcessesScraped, "Failed to scrape metrics - : 0 successful scrapes %v", err) } @@ -174,7 +174,7 @@ func TestScrapeMetrics_GetProcessesError(t *testing.T) { metrics, err := scraper.scrape(context.Background()) assert.EqualError(t, err, "err1") assert.Equal(t, 0, metrics.Len()) - assert.False(t, consumererror.IsPartialScrapeError(err)) + assert.False(t, scrapererror.IsPartialScrapeError(err)) } type processHandlesMock struct { @@ -447,11 +447,11 @@ func TestScrapeMetrics_ProcessErrors(t *testing.T) { assert.Equal(t, expectedMetricsLen, md.MetricCount()) assert.EqualError(t, err, test.expectedError) - isPartial := consumererror.IsPartialScrapeError(err) + isPartial := scrapererror.IsPartialScrapeError(err) assert.True(t, isPartial) if isPartial { expectedFailures := getExpectedScrapeFailures(test.nameError, test.exeError, test.timesError, test.memoryInfoError, test.ioCountersError) - assert.Equal(t, expectedFailures, err.(consumererror.PartialScrapeError).Failed) + assert.Equal(t, expectedFailures, err.(scrapererror.PartialScrapeError).Failed) } }) } diff --git a/consumer/consumererror/partialscrapeerror.go b/receiver/scrapererror/partialscrapeerror.go similarity index 98% rename from consumer/consumererror/partialscrapeerror.go rename to receiver/scrapererror/partialscrapeerror.go index a3980d3c0bf..2b23bed620c 100644 --- a/consumer/consumererror/partialscrapeerror.go +++ b/receiver/scrapererror/partialscrapeerror.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package consumererror +package scrapererror import "errors" diff --git a/consumer/consumererror/partialscrapeerror_test.go b/receiver/scrapererror/partialscrapeerror_test.go similarity index 98% rename from consumer/consumererror/partialscrapeerror_test.go rename to receiver/scrapererror/partialscrapeerror_test.go index 58d6cae5bea..85ee7d7ca2e 100644 --- a/consumer/consumererror/partialscrapeerror_test.go +++ b/receiver/scrapererror/partialscrapeerror_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package consumererror +package scrapererror import ( "errors" diff --git a/consumer/consumererror/scrapeerrors.go b/receiver/scrapererror/scrapeerrors.go similarity index 86% rename from consumer/consumererror/scrapeerrors.go rename to receiver/scrapererror/scrapeerrors.go index 1bd0b6de12a..a8131332448 100644 --- a/consumer/consumererror/scrapeerrors.go +++ b/receiver/scrapererror/scrapeerrors.go @@ -12,7 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. -package consumererror +package scrapererror + +import ( + "go.opentelemetry.io/collector/consumer/consumererror" +) // ScrapeErrors contains multiple PartialScrapeErrors and can also contain generic errors. type ScrapeErrors struct { @@ -42,8 +46,8 @@ func (s *ScrapeErrors) Combine() error { } if !partialScrapeErr { - return CombineErrors(s.errs) + return consumererror.CombineErrors(s.errs) } - return NewPartialScrapeError(CombineErrors(s.errs), s.failedScrapeCount) + return NewPartialScrapeError(consumererror.CombineErrors(s.errs), s.failedScrapeCount) } diff --git a/consumer/consumererror/scrapeerrors_test.go b/receiver/scrapererror/scrapeerrors_test.go similarity index 99% rename from consumer/consumererror/scrapeerrors_test.go rename to receiver/scrapererror/scrapeerrors_test.go index dd3c3df945e..44a4beaf7d1 100644 --- a/consumer/consumererror/scrapeerrors_test.go +++ b/receiver/scrapererror/scrapeerrors_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package consumererror +package scrapererror import ( "errors" diff --git a/receiver/scraperhelper/scrapercontroller.go b/receiver/scraperhelper/scrapercontroller.go index c0ea0409dc6..5d07ffb9740 100644 --- a/receiver/scraperhelper/scrapercontroller.go +++ b/receiver/scraperhelper/scrapercontroller.go @@ -28,6 +28,7 @@ import ( "go.opentelemetry.io/collector/consumer/consumererror" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/obsreport" + "go.opentelemetry.io/collector/receiver/scrapererror" ) // ScraperControllerSettings defines common settings for a scraper controller @@ -204,7 +205,7 @@ func (sc *controller) scrapeMetricsAndReport(ctx context.Context) { if err != nil { sc.logger.Error("Error scraping metrics", zap.Error(err)) - if !consumererror.IsPartialScrapeError(err) { + if !scrapererror.IsPartialScrapeError(err) { continue } } @@ -260,11 +261,11 @@ func (mms *multiMetricScraper) Scrape(ctx context.Context, receiverName string) ilms.Resize(1) ilm := ilms.At(0) - var errs consumererror.ScrapeErrors + var errs scrapererror.ScrapeErrors for _, scraper := range mms.scrapers { metrics, err := scraper.Scrape(ctx, receiverName) if err != nil { - partialErr, isPartial := err.(consumererror.PartialScrapeError) + partialErr, isPartial := err.(scrapererror.PartialScrapeError) if isPartial { errs.AddPartial(partialErr.Failed, partialErr) } diff --git a/receiver/scraperhelper/scrapercontroller_test.go b/receiver/scraperhelper/scrapercontroller_test.go index d8ebc78325e..f2ef6a3863d 100644 --- a/receiver/scraperhelper/scrapercontroller_test.go +++ b/receiver/scraperhelper/scrapercontroller_test.go @@ -33,6 +33,7 @@ import ( "go.opentelemetry.io/collector/consumer/consumertest" "go.opentelemetry.io/collector/consumer/pdata" "go.opentelemetry.io/collector/obsreport/obsreporttest" + "go.opentelemetry.io/collector/receiver/scrapererror" ) type testInitialize struct { @@ -387,7 +388,7 @@ func assertScraperViews(t *testing.T, expectedErr error, sink *consumertest.Metr expectedScraped := int64(sink.MetricsCount()) expectedErrored := int64(0) if expectedErr != nil { - if partialError, isPartial := expectedErr.(consumererror.PartialScrapeError); isPartial { + if partialError, isPartial := expectedErr.(scrapererror.PartialScrapeError); isPartial { expectedErrored = int64(partialError.Failed) } else { expectedScraped = int64(0)