Skip to content

Conversation

@maleki-it
Copy link
Contributor

@maleki-it maleki-it commented Oct 17, 2025

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]

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
Contributor Author

Related to #982

@SuperQ
Copy link
Member

SuperQ commented Oct 27, 2025

If you are going to use LLMs to write PRs, please include this information in the PR description.

@SuperQ
Copy link
Member

SuperQ commented Oct 27, 2025

I am unable to find any evidence in the MySQL documentation about why this happens. This smells like an LLM hallucination.

Regardless, it's clear that the column schema is int64 and we need to handle the negative case.

@maleki-it
Copy link
Contributor Author

maleki-it commented Oct 27, 2025

Thanks for reviewing.
I can find this in the MySQL documentation:
Maybe help
For lower estimates in summary tables other than memory_summary_global_by_event_name, it is possible for values to go negative if memory ownership is transferred between threads.

link url:
https://dev.mysql.com/doc/refman/8.0/en/performance-schema-memory-summary-tables.html

@SuperQ

@SuperQ
Copy link
Member

SuperQ commented Oct 27, 2025

That is for a completely different feature within the documentation. While it may be true that this is what is happening, the documentation does NOT make this conclusive or clear.

Please do not use LLMs to write PR descriptions. The statement of fact in the description is not written by you and is completely made up.

@SuperQ
Copy link
Member

SuperQ commented Oct 27, 2025

✅ Verified on MySQL 8.0.35 Enterprise with --collect.sys.user_summary flag

Did you actually test this? Or is this another made up LLM output?

@maleki-it
Copy link
Contributor Author

maleki-it commented Oct 27, 2025

After applying the fix, I’m currently using the fixed version without any issues.
sample metric after the fix version >
mysql_sys_current_memory_bytes{user="backup_user"} -15732
Because of these negative values main version does not work for me, and I had to change it to work in our environment
MySQL Version > Server version: 8.0.35-commercial MySQL Enterprise Server - Commercial
works with no issues with these flags >
docker compose file:
mysqld-exporter:
#image: quay.io/prometheus/mysqld-exporter:v0.18.0
image: myregXXXX/quay.io/prometheus/mysqld-exporter:v0.18.0-fix
Command:
- '--config.my-cnf=/.my.cnf'
- '--web.listen-address=0.0.0.0:9104'
- '--log.level=debug'
- '--collect.info_schema.userstats'
- '--collect.info_schema.tables'
- '--collect.perf_schema.eventsstatements'
- '--collect.perf_schema.eventswaits'
- '--collect.perf_schema.file_events'
- '--collect.perf_schema.file_instances'
- '--collect.sys.user_summary'

Am I misunderstanding something here? Is this not considered an issue, or should I proceed with submitting a new PR for this change, or would you prefer to handle the update on your side? @SuperQ

Again, I revert the version to show you the real error
mysqld-exporter | time=2025-10-27T10:18:19.451Z level=INFO source=tls_config.go:349 msg="TLS is disabled." http2=false address=[::]:9104
mysqld-exporter | time=2025-10-27T10:18:27.711Z level=ERROR source=exporter.go:183 msg="Error from scraper" scraper=sys.user_summary target=host.docker.internal:3306 err="sql: Scan error on column index 9, name "current_memory": converting driver.Value type []uint8 ("-15732") to a uint64: invalid syntax"

So I use my fix version to not get this error ^^^

@SuperQ
Copy link
Member

SuperQ commented Oct 27, 2025

Thanks for confirming. The issues is it's difficult to tell if the issue is really fixed because of your use of LLMs.

@SuperQ SuperQ changed the title Fix sys.user_summary scraper to handle negative current_memory values sys.user_summary: Fix handling of negative current_memory values Oct 27, 2025
@SuperQ SuperQ merged commit e149561 into prometheus:main Oct 27, 2025
13 checks passed
@maleki-it
Copy link
Contributor Author

Thanks for your time and review @SuperQ
This was my first PR here and merge too,❤️ so it means a lot to me :)

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.

2 participants