Skip to content

Commit

Permalink
[chore][receiver/mysql]: extract handling global stats to another fun…
Browse files Browse the repository at this point in the history
…ction (#14458)

Global stats have been extracted to another function to handle the errors properly.
  • Loading branch information
aboguszewski-sumo committed Sep 23, 2022
1 parent 7677ba7 commit 1e2a266
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions receiver/mysqlreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,19 @@ func (m *mySQLScraper) scrape(context.Context) (pmetric.Metrics, error) {
m.scrapeIndexIoWaitsStats(now, errs)

// collect global status metrics.
m.scrapeGlobalStats(now, errs)

m.mb.EmitForResource(metadata.WithMysqlInstanceEndpoint(m.config.Endpoint))

return m.mb.Emit(), errs.Combine()
}

func (m *mySQLScraper) scrapeGlobalStats(now pcommon.Timestamp, errs *scrapererror.ScrapeErrors) {
globalStats, err := m.sqlclient.getGlobalStats()
if err != nil {
m.logger.Error("Failed to fetch global stats", zap.Error(err))
return pmetric.Metrics{}, err
errs.AddPartial(66, err)
return
}

m.recordDataPages(now, globalStats, errs)
Expand Down Expand Up @@ -278,10 +287,6 @@ func (m *mySQLScraper) scrape(context.Context) (pmetric.Metrics, error) {
addPartialIfError(errs, m.mb.RecordMysqlThreadsDataPoint(now, v, metadata.AttributeThreadsRunning))
}
}

m.mb.EmitForResource(metadata.WithMysqlInstanceEndpoint(m.config.Endpoint))

return m.mb.Emit(), errs.Combine()
}

func (m *mySQLScraper) scrapeTableIoWaitsStats(now pcommon.Timestamp, errs *scrapererror.ScrapeErrors) {
Expand Down

0 comments on commit 1e2a266

Please sign in to comment.