Skip to content

Conversation

@maleki-it
Copy link

Summary

Fixes the sys.user_summary scraper failing when the current_memory column contains negative values in MySQL 8.0 Enterprise.

Problem

The scraper attempts to parse current_memory as uint64 (unsigned integer), which fails when MySQL returns negative values. According to MySQL documentation, negative memory values can occur when:

  • Memory is freed faster than it is allocated
  • Threads terminate and release memory asynchronously

This causes the scraper to fail with the following error:

sql: Scan error on column index 9, name "current_memory": 
converting driver.Value type []uint8 ("-16360") to a uint64: invalid syntax

Solution

  • Changed current_memory variable type from uint64 to int64 in collector/sys_user_summary.go
  • This allows the scraper to handle both positive and negative values
  • Values are still converted to float64 for Prometheus metrics (no breaking changes)
  • Added test case in collector/sys_user_summary_test.go with negative value (-16360) to prevent regression

Changes

  • File: collector/sys_user_summary.go (Line 121)

    • Changed: current_memory uint64current_memory int64
  • File: collector/sys_user_summary_test.go (Lines 80-92)

    • Added: Test case with current_memory = "-16360"

Testing

  • ✅ All existing tests pass
  • ✅ New test case covers negative memory values
  • ✅ Verified on MySQL 8.0.35 Enterprise with --collect.sys.user_summary flag
  • ✅ Confirmed metrics export correctly with both positive and negative values
  • ✅ No breaking changes - backward compatible with existing deployments

Environment Tested

  • MySQL Version: 8.0.35 Enterprise
  • Exporter Version: 0.18.0
  • Platform: linux/amd64
  • Flags Used: --collect.sys.user_summary, --log.level=debug

Impact

  • Breaking Changes: None
  • Backward Compatibility: 100% - positive values work exactly as before
  • Performance Impact: None - both uint64 and int64 are 64-bit types
  • Security Impact: None - read-only operation

Related

This issue affects users running MySQL 8.0 Enterprise with the sys.user_summary collector enabled.

MySQL's sys.user_summary.current_memory column can contain negative values
when memory is freed faster than allocated. This is valid MySQL behavior.

Changes:
- Changed current_memory type from uint64 to int64
- Added test case with negative current_memory value (-16360)

Fixes scan error: 'converting driver.Value type []uint8 to uint64: invalid syntax'

Signed-off-by: Ali Maleki <[email protected]>
@maleki-it
Copy link
Author

Related to #982

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant