Skip to content

Commit

Permalink
[receiver/mysql] int64 overflows with time (#36879)
Browse files Browse the repository at this point in the history
  • Loading branch information
atoulme authored Dec 18, 2024
1 parent 2ab75f3 commit ad60f51
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 34 deletions.
27 changes: 27 additions & 0 deletions .chloggen/smaller_numbers.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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: Divide large values directly in SQL queries to avoid int overflows

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

# 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: []
14 changes: 7 additions & 7 deletions receiver/mysqlreceiver/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ func (c *mySQLClient) getTableStats() ([]TableStats, error) {
func (c *mySQLClient) getTableIoWaitsStats() ([]TableIoWaitsStats, error) {
query := "SELECT OBJECT_SCHEMA, OBJECT_NAME, " +
"COUNT_DELETE, COUNT_FETCH, COUNT_INSERT, COUNT_UPDATE," +
"SUM_TIMER_DELETE, SUM_TIMER_FETCH, SUM_TIMER_INSERT, SUM_TIMER_UPDATE " +
"SUM_TIMER_DELETE/1000, SUM_TIMER_FETCH/1000, SUM_TIMER_INSERT/1000, SUM_TIMER_UPDATE/1000 " +
"FROM performance_schema.table_io_waits_summary_by_table " +
"WHERE OBJECT_SCHEMA NOT IN ('mysql', 'performance_schema');"
rows, err := c.client.Query(query)
Expand All @@ -319,7 +319,7 @@ func (c *mySQLClient) getTableIoWaitsStats() ([]TableIoWaitsStats, error) {
func (c *mySQLClient) getIndexIoWaitsStats() ([]IndexIoWaitsStats, error) {
query := "SELECT OBJECT_SCHEMA, OBJECT_NAME, ifnull(INDEX_NAME, 'NONE') as INDEX_NAME," +
"COUNT_FETCH, COUNT_INSERT, COUNT_UPDATE, COUNT_DELETE," +
"SUM_TIMER_FETCH, SUM_TIMER_INSERT, SUM_TIMER_UPDATE, SUM_TIMER_DELETE " +
"SUM_TIMER_FETCH/1000, SUM_TIMER_INSERT/1000, SUM_TIMER_UPDATE/1000, SUM_TIMER_DELETE/1000 " +
"FROM performance_schema.table_io_waits_summary_by_index_usage " +
"WHERE OBJECT_SCHEMA NOT IN ('mysql', 'performance_schema');"

Expand All @@ -345,7 +345,7 @@ func (c *mySQLClient) getIndexIoWaitsStats() ([]IndexIoWaitsStats, error) {

func (c *mySQLClient) getStatementEventsStats() ([]StatementEventStats, error) {
query := fmt.Sprintf("SELECT ifnull(SCHEMA_NAME, 'NONE') as SCHEMA_NAME, DIGEST,"+
"LEFT(DIGEST_TEXT, %d) as DIGEST_TEXT, SUM_TIMER_WAIT, SUM_ERRORS,"+
"LEFT(DIGEST_TEXT, %d) as DIGEST_TEXT, SUM_TIMER_WAIT/1000, SUM_ERRORS,"+
"SUM_WARNINGS, SUM_ROWS_AFFECTED, SUM_ROWS_SENT, SUM_ROWS_EXAMINED,"+
"SUM_CREATED_TMP_DISK_TABLES, SUM_CREATED_TMP_TABLES, SUM_SORT_MERGE_PASSES,"+
"SUM_SORT_ROWS, SUM_NO_INDEX_USED "+
Expand Down Expand Up @@ -384,10 +384,10 @@ func (c *mySQLClient) getTableLockWaitEventStats() ([]tableLockWaitEventStats, e
query := "SELECT OBJECT_SCHEMA, OBJECT_NAME, COUNT_READ_NORMAL, COUNT_READ_WITH_SHARED_LOCKS," +
"COUNT_READ_HIGH_PRIORITY, COUNT_READ_NO_INSERT, COUNT_READ_EXTERNAL, COUNT_WRITE_ALLOW_WRITE," +
"COUNT_WRITE_CONCURRENT_INSERT, COUNT_WRITE_LOW_PRIORITY, COUNT_WRITE_NORMAL," +
"COUNT_WRITE_EXTERNAL, SUM_TIMER_READ_NORMAL, SUM_TIMER_READ_WITH_SHARED_LOCKS," +
"SUM_TIMER_READ_HIGH_PRIORITY, SUM_TIMER_READ_NO_INSERT, SUM_TIMER_READ_EXTERNAL," +
"SUM_TIMER_WRITE_ALLOW_WRITE, SUM_TIMER_WRITE_CONCURRENT_INSERT, SUM_TIMER_WRITE_LOW_PRIORITY," +
"SUM_TIMER_WRITE_NORMAL, SUM_TIMER_WRITE_EXTERNAL " +
"COUNT_WRITE_EXTERNAL, SUM_TIMER_READ_NORMAL/1000, SUM_TIMER_READ_WITH_SHARED_LOCKS/1000," +
"SUM_TIMER_READ_HIGH_PRIORITY/1000, SUM_TIMER_READ_NO_INSERT/1000, SUM_TIMER_READ_EXTERNAL/1000," +
"SUM_TIMER_WRITE_ALLOW_WRITE/1000, SUM_TIMER_WRITE_CONCURRENT_INSERT/1000, SUM_TIMER_WRITE_LOW_PRIORITY/1000," +
"SUM_TIMER_WRITE_NORMAL/1000, SUM_TIMER_WRITE_EXTERNAL/1000 " +
"FROM performance_schema.table_lock_waits_summary_by_table " +
"WHERE OBJECT_SCHEMA NOT IN ('mysql', 'performance_schema', 'information_schema')"

Expand Down
42 changes: 19 additions & 23 deletions receiver/mysqlreceiver/scraper.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ import (
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver/internal/metadata"
)

const (
picosecondsInNanoseconds int64 = 1000
)

type mySQLScraper struct {
sqlclient client
logger *zap.Logger
Expand Down Expand Up @@ -451,16 +447,16 @@ func (m *mySQLScraper) scrapeTableIoWaitsStats(now pcommon.Timestamp, errs *scra

// times
m.mb.RecordMysqlTableIoWaitTimeDataPoint(
now, s.timeDelete/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsDelete, s.name, s.schema,
now, s.timeDelete, metadata.AttributeIoWaitsOperationsDelete, s.name, s.schema,
)
m.mb.RecordMysqlTableIoWaitTimeDataPoint(
now, s.timeFetch/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsFetch, s.name, s.schema,
now, s.timeFetch, metadata.AttributeIoWaitsOperationsFetch, s.name, s.schema,
)
m.mb.RecordMysqlTableIoWaitTimeDataPoint(
now, s.timeInsert/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsInsert, s.name, s.schema,
now, s.timeInsert, metadata.AttributeIoWaitsOperationsInsert, s.name, s.schema,
)
m.mb.RecordMysqlTableIoWaitTimeDataPoint(
now, s.timeUpdate/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsUpdate, s.name, s.schema,
now, s.timeUpdate, metadata.AttributeIoWaitsOperationsUpdate, s.name, s.schema,
)
}
}
Expand All @@ -483,16 +479,16 @@ func (m *mySQLScraper) scrapeIndexIoWaitsStats(now pcommon.Timestamp, errs *scra

// times
m.mb.RecordMysqlIndexIoWaitTimeDataPoint(
now, s.timeDelete/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsDelete, s.name, s.schema, s.index,
now, s.timeDelete, metadata.AttributeIoWaitsOperationsDelete, s.name, s.schema, s.index,
)
m.mb.RecordMysqlIndexIoWaitTimeDataPoint(
now, s.timeFetch/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsFetch, s.name, s.schema, s.index,
now, s.timeFetch, metadata.AttributeIoWaitsOperationsFetch, s.name, s.schema, s.index,
)
m.mb.RecordMysqlIndexIoWaitTimeDataPoint(
now, s.timeInsert/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsInsert, s.name, s.schema, s.index,
now, s.timeInsert, metadata.AttributeIoWaitsOperationsInsert, s.name, s.schema, s.index,
)
m.mb.RecordMysqlIndexIoWaitTimeDataPoint(
now, s.timeUpdate/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsUpdate, s.name, s.schema, s.index,
now, s.timeUpdate, metadata.AttributeIoWaitsOperationsUpdate, s.name, s.schema, s.index,
)
}
}
Expand All @@ -518,7 +514,7 @@ func (m *mySQLScraper) scrapeStatementEventsStats(now pcommon.Timestamp, errs *s
m.mb.RecordMysqlStatementEventCountDataPoint(now, s.countSortRows, s.schema, s.digest, s.digestText, metadata.AttributeEventStateSortRows)
m.mb.RecordMysqlStatementEventCountDataPoint(now, s.countWarnings, s.schema, s.digest, s.digestText, metadata.AttributeEventStateWarnings)

m.mb.RecordMysqlStatementEventWaitTimeDataPoint(now, s.sumTimerWait/picosecondsInNanoseconds, s.schema, s.digest, s.digestText)
m.mb.RecordMysqlStatementEventWaitTimeDataPoint(now, s.sumTimerWait, s.schema, s.digest, s.digestText)
}
}

Expand All @@ -540,11 +536,11 @@ func (m *mySQLScraper) scrapeTableLockWaitEventStats(now pcommon.Timestamp, errs
m.mb.RecordMysqlTableLockWaitReadCountDataPoint(now, s.countReadExternal, s.schema, s.name, metadata.AttributeReadLockTypeExternal)

// read time data points
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadNormal/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeReadLockTypeNormal)
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadWithSharedLocks/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeReadLockTypeWithSharedLocks)
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadHighPriority/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeReadLockTypeHighPriority)
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadNoInsert/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeReadLockTypeNoInsert)
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadExternal/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeReadLockTypeExternal)
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadNormal, s.schema, s.name, metadata.AttributeReadLockTypeNormal)
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadWithSharedLocks, s.schema, s.name, metadata.AttributeReadLockTypeWithSharedLocks)
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadHighPriority, s.schema, s.name, metadata.AttributeReadLockTypeHighPriority)
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadNoInsert, s.schema, s.name, metadata.AttributeReadLockTypeNoInsert)
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadExternal, s.schema, s.name, metadata.AttributeReadLockTypeExternal)

// write data points
m.mb.RecordMysqlTableLockWaitWriteCountDataPoint(now, s.countWriteAllowWrite, s.schema, s.name, metadata.AttributeWriteLockTypeAllowWrite)
Expand All @@ -554,11 +550,11 @@ func (m *mySQLScraper) scrapeTableLockWaitEventStats(now pcommon.Timestamp, errs
m.mb.RecordMysqlTableLockWaitWriteCountDataPoint(now, s.countWriteExternal, s.schema, s.name, metadata.AttributeWriteLockTypeExternal)

// write time data points
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteAllowWrite/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeWriteLockTypeAllowWrite)
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteConcurrentInsert/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeWriteLockTypeConcurrentInsert)
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteLowPriority/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeWriteLockTypeLowPriority)
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteNormal/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeWriteLockTypeNormal)
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteExternal/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeWriteLockTypeExternal)
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteAllowWrite, s.schema, s.name, metadata.AttributeWriteLockTypeAllowWrite)
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteConcurrentInsert, s.schema, s.name, metadata.AttributeWriteLockTypeConcurrentInsert)
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteLowPriority, s.schema, s.name, metadata.AttributeWriteLockTypeLowPriority)
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteNormal, s.schema, s.name, metadata.AttributeWriteLockTypeNormal)
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteExternal, s.schema, s.name, metadata.AttributeWriteLockTypeExternal)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a_schema a_table an_index 9 10 11 12 13000 14000 15000 16000
a_schema a_table an_index 9 10 11 12 13 14 15 16
Original file line number Diff line number Diff line change
@@ -1 +1 @@
otel 070e38632eb4444e50cdcbf0b17474ba801e203add89783a24584951442a2317 SHOW GLOBAL STATUS 2000 3 4 5 6 7 8 9 10 11 12
otel 070e38632eb4444e50cdcbf0b17474ba801e203add89783a24584951442a2317 SHOW GLOBAL STATUS 2 3 4 5 6 7 8 9 10 11 12
Original file line number Diff line number Diff line change
@@ -1 +1 @@
a_schema a_table 1 2 3 4 5000 6000 7000 8000
a_schema a_table 1 2 3 4 5 6 7 8
Original file line number Diff line number Diff line change
@@ -1 +1 @@
otel otel 0 1 2 3 4 5 6 7 8 9 10000 11000 12000 13000 14000 15000 16000 17000 18000 19000
otel otel 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19

0 comments on commit ad60f51

Please sign in to comment.