Skip to content

Commit

Permalink
[receiver/mysql] fix oob overflow for Innodb_buffer_pool_pages_misc
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme committed Dec 20, 2024
1 parent 96368fa commit b79be3b
Show file tree
Hide file tree
Showing 5 changed files with 1,202 additions and 1 deletion.
29 changes: 29 additions & 0 deletions .chloggen/mysql_oob_misc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Use this changelog template to create an entry for release notes.

# 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: mysqlreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Avoid recording a value for the MysqlBufferPoolPages metric when out-of-bounds.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [35495]

# (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: |
When using compressed tables, Innodb_buffer_pool_pages_misc may report an out-of-bounds value.
See https://bugs.mysql.com/bug.php?id=59550 for context.
# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: []
6 changes: 5 additions & 1 deletion receiver/mysqlreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,13 @@ func (m *mySQLScraper) scrapeGlobalStats(now pcommon.Timestamp, errs *scrapererr
addPartialIfError(errs, m.mb.RecordMysqlBufferPoolPagesDataPoint(now, v,
metadata.AttributeBufferPoolPagesFree))
case "Innodb_buffer_pool_pages_misc":
_, err := strconv.ParseInt(v, 10, 64)
if err != nil {
m.logger.Warn("Innodb_buffer_pool_pages_misc reports an out-of-bounds value and will be ignored. See https://bugs.mysql.com/bug.php?id=59550.")
continue
}
addPartialIfError(errs, m.mb.RecordMysqlBufferPoolPagesDataPoint(now, v,
metadata.AttributeBufferPoolPagesMisc))

// buffer_pool.page_flushes
case "Innodb_buffer_pool_pages_flushed":
addPartialIfError(errs, m.mb.RecordMysqlBufferPoolPageFlushesDataPoint(now, v))
Expand Down
31 changes: 31 additions & 0 deletions receiver/mysqlreceiver/scraper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,37 @@ func TestScrape(t *testing.T) {
})
}

func TestScrapeBufferPoolPagesMiscOutOfBounds(t *testing.T) {

expectedFile := filepath.Join("testdata", "scraper", "expected_oob.yaml")
expectedMetrics, err := golden.ReadMetrics(expectedFile)
require.NoError(t, err)

cfg := createDefaultConfig().(*Config)
cfg.Username = "otel"
cfg.Password = "otel"
cfg.AddrConfig = confignet.AddrConfig{Endpoint: "localhost:3306"}

scraper := newMySQLScraper(receivertest.NewNopSettings(), cfg)
scraper.sqlclient = &mockClient{
globalStatsFile: "global_stats_oob",
innodbStatsFile: "innodb_stats_empty",
tableIoWaitsFile: "table_io_waits_stats_empty",
indexIoWaitsFile: "index_io_waits_stats_empty",
tableStatsFile: "table_stats_empty",
statementEventsFile: "statement_events_empty",
tableLockWaitEventStatsFile: "table_lock_wait_event_stats_empty",
replicaStatusFile: "replica_stats_empty",
}

scraper.renameCommands = true

actualMetrics, err := scraper.scrape(context.Background())
require.NoError(t, err)
require.NoError(t, pmetrictest.CompareMetrics(actualMetrics, expectedMetrics,
pmetrictest.IgnoreMetricDataPointsOrder(), pmetrictest.IgnoreStartTimestamp(), pmetrictest.IgnoreTimestamp()))
}

var _ client = (*mockClient)(nil)

type mockClient struct {
Expand Down
Loading

0 comments on commit b79be3b

Please sign in to comment.