Skip to content

Commit

Permalink
Move scraper error outside of phase1 stable packages (#2580)
Browse files Browse the repository at this point in the history
Signed-off-by: Bogdan Drutu <bogdandrutu@gmail.com>
  • Loading branch information
bogdandrutu authored Mar 8, 2021
1 parent 68871bd commit 65c4c4a
Show file tree
Hide file tree
Showing 31 changed files with 85 additions and 78 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions obsreport/obsreport_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions obsreport/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -45,7 +45,7 @@ const (

var (
errFake = errors.New("errFake")
partialErrFake = consumererror.NewPartialScrapeError(errFake, 1)
partialErrFake = scrapererror.NewPartialScrapeError(errFake, 1)
)

type receiveTestParams struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -102,20 +102,20 @@ 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
logicalDiskObject.Filter(s.includeFS, s.excludeFS, false)

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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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)
}
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
Expand Down
Loading

0 comments on commit 65c4c4a

Please sign in to comment.