Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Instrument obsreport.Scraper #19

Merged
merged 6 commits into from
Nov 1, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
address review feedback
  • Loading branch information
moh-osman3 committed Nov 1, 2022
commit 3292407d4e7d9f11c1597adff73c134a8fc2100d
25 changes: 14 additions & 11 deletions obsreport/obsreport_scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@ func newScraper(cfg ScraperSettings, registry *featuregate.Registry) *Scraper {
}

func (s *Scraper) createOtelMetrics(cfg ScraperSettings) {
meter := cfg.ReceiverCreateSettings.MeterProvider.Meter(scraperScope)
if !s.useOtelForMetrics {
return
}
meter := cfg.ReceiverCreateSettings.MeterProvider.Meter(scraperScope)

var err error
handleError := func(metricName string, err error) {
Expand All @@ -117,7 +117,6 @@ func (s *Scraper) createOtelMetrics(cfg ScraperSettings) {
instrument.WithUnit(unit.Dimensionless),
)
handleError(obsmetrics.ScraperPrefix+obsmetrics.ErroredMetricPointsKey, err)

}

// StartMetricsOp is called when a scrape operation is started. The
Expand Down Expand Up @@ -152,15 +151,7 @@ func (s *Scraper) EndMetricsOp(
span := trace.SpanFromContext(scraperCtx)

if s.level != configtelemetry.LevelNone {
if s.useOtelForMetrics {
s.scrapedMetricsPoints.Add(scraperCtx, int64(numScrapedMetrics), s.otelAttrs...)
s.erroredMetricsPoints.Add(scraperCtx, int64(numErroredMetrics), s.otelAttrs...)
} else { // OC for metrics
stats.Record(
scraperCtx,
obsmetrics.ScraperScrapedMetricPoints.M(int64(numScrapedMetrics)),
obsmetrics.ScraperErroredMetricPoints.M(int64(numErroredMetrics)))
}
s.recordMetrics(scraperCtx, numScrapedMetrics, numErroredMetrics)
}

// end span according to errors
Expand All @@ -175,3 +166,15 @@ func (s *Scraper) EndMetricsOp(

span.End()
}

func (s *Scraper) recordMetrics(scraperCtx context.Context, numScrapedMetrics, numErroredMetrics int) {
if s.useOtelForMetrics {
s.scrapedMetricsPoints.Add(scraperCtx, int64(numScrapedMetrics), s.otelAttrs...)
s.erroredMetricsPoints.Add(scraperCtx, int64(numErroredMetrics), s.otelAttrs...)
} else { // OC for metrics
stats.Record(
scraperCtx,
obsmetrics.ScraperScrapedMetricPoints.M(int64(numScrapedMetrics)),
obsmetrics.ScraperErroredMetricPoints.M(int64(numErroredMetrics)))
}
}
4 changes: 2 additions & 2 deletions obsreport/obsreport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ func TestScrapeMetricsDataOp(t *testing.T) {
{items: 15, err: nil},
}
for i := range params {
scrp := NewScraper(ScraperSettings{
scrp := newScraper(ScraperSettings{
ReceiverID: receiver,
Scraper: scraper,
ReceiverCreateSettings: tt.ToReceiverCreateSettings(),
})
}, registry)
ctx := scrp.StartMetricsOp(parentCtx)
assert.NotNil(t, ctx)
scrp.EndMetricsOp(ctx, params[i].items, params[i].err)
Expand Down
8 changes: 0 additions & 8 deletions obsreport/obsreporttest/obsreporttest.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,6 @@ func checkValueForView(wantTags []tag.Tag, value int64, vName string) error {
return fmt.Errorf("[%s]: could not find tags, wantTags: %s in rows %v", vName, wantTags, rows)
}

// tagsForScraperView returns the tags that are needed for the scraper views.
func tagsForScraperView(receiver config.ComponentID, scraper config.ComponentID) []tag.Tag {
return []tag.Tag{
{Key: receiverTag, Value: receiver.String()},
{Key: scraperTag, Value: scraper.String()},
}
}

// tagsForProcessorView returns the tags that are needed for the processor views.
func tagsForProcessorView(processor config.ComponentID) []tag.Tag {
return []tag.Tag{
Expand Down