Skip to content

Commit

Permalink
[receiver/apachereceiver] Pass pointer to ScrapeErrors instead of by …
Browse files Browse the repository at this point in the history
…value (open-telemetry#13135)

fixes issue where partial errors are not recorded due to passing the ScrapeErrors struct by value
rename errors -> errs to avoid possible shadowing of the errors package
  • Loading branch information
JonathanWamsley authored Aug 10, 2022
1 parent f89ffbd commit 9654a43
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
20 changes: 10 additions & 10 deletions receiver/apachereceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,26 +70,26 @@ func (r *apacheScraper) scrape(context.Context) (pmetric.Metrics, error) {
return pmetric.Metrics{}, err
}

var errors scrapererror.ScrapeErrors
errs := &scrapererror.ScrapeErrors{}
now := pcommon.NewTimestampFromTime(time.Now())
for metricKey, metricValue := range parseStats(stats) {
switch metricKey {
case "ServerUptimeSeconds":
addPartialIfError(errors, r.mb.RecordApacheUptimeDataPoint(now, metricValue, r.cfg.serverName))
addPartialIfError(errs, r.mb.RecordApacheUptimeDataPoint(now, metricValue, r.cfg.serverName))
case "ConnsTotal":
addPartialIfError(errors, r.mb.RecordApacheCurrentConnectionsDataPoint(now, metricValue, r.cfg.serverName))
addPartialIfError(errs, r.mb.RecordApacheCurrentConnectionsDataPoint(now, metricValue, r.cfg.serverName))
case "BusyWorkers":
addPartialIfError(errors, r.mb.RecordApacheWorkersDataPoint(now, metricValue, r.cfg.serverName,
addPartialIfError(errs, r.mb.RecordApacheWorkersDataPoint(now, metricValue, r.cfg.serverName,
metadata.AttributeWorkersStateBusy))
case "IdleWorkers":
addPartialIfError(errors, r.mb.RecordApacheWorkersDataPoint(now, metricValue, r.cfg.serverName,
addPartialIfError(errs, r.mb.RecordApacheWorkersDataPoint(now, metricValue, r.cfg.serverName,
metadata.AttributeWorkersStateIdle))
case "Total Accesses":
addPartialIfError(errors, r.mb.RecordApacheRequestsDataPoint(now, metricValue, r.cfg.serverName))
addPartialIfError(errs, r.mb.RecordApacheRequestsDataPoint(now, metricValue, r.cfg.serverName))
case "Total kBytes":
i, err := strconv.ParseInt(metricValue, 10, 64)
if err != nil {
errors.AddPartial(1, err)
errs.AddPartial(1, err)
} else {
r.mb.RecordApacheTrafficDataPoint(now, kbytesToBytes(i), r.cfg.serverName)
}
Expand All @@ -101,12 +101,12 @@ func (r *apacheScraper) scrape(context.Context) (pmetric.Metrics, error) {
}
}

return r.mb.Emit(), errors.Combine()
return r.mb.Emit(), errs.Combine()
}

func addPartialIfError(errors scrapererror.ScrapeErrors, err error) {
func addPartialIfError(errs *scrapererror.ScrapeErrors, err error) {
if err != nil {
errors.AddPartial(1, err)
errs.AddPartial(1, err)
}
}

Expand Down
16 changes: 16 additions & 0 deletions unreleased/apachereceiver-fix-partial-error.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: bug_fix

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: apachereceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Fix some partial errors not being correctly reported

# One or more tracking issues related to the change
issues: [13133]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

0 comments on commit 9654a43

Please sign in to comment.