Skip to content

Commit 5d5825a

Browse files
atoulmeAkhigbeEromo
authored andcommitted
[receiver/mysql] int64 overflows with time (open-telemetry#36879)
1 parent 840ff55 commit 5d5825a

File tree

7 files changed

+57
-34
lines changed

7 files changed

+57
-34
lines changed

.chloggen/smaller_numbers.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: bug_fix
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: mysqlreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Divide large values directly in SQL queries to avoid int overflows
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [35495]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

receiver/mysqlreceiver/client.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ func (c *mySQLClient) getTableStats() ([]TableStats, error) {
292292
func (c *mySQLClient) getTableIoWaitsStats() ([]TableIoWaitsStats, error) {
293293
query := "SELECT OBJECT_SCHEMA, OBJECT_NAME, " +
294294
"COUNT_DELETE, COUNT_FETCH, COUNT_INSERT, COUNT_UPDATE," +
295-
"SUM_TIMER_DELETE, SUM_TIMER_FETCH, SUM_TIMER_INSERT, SUM_TIMER_UPDATE " +
295+
"SUM_TIMER_DELETE/1000, SUM_TIMER_FETCH/1000, SUM_TIMER_INSERT/1000, SUM_TIMER_UPDATE/1000 " +
296296
"FROM performance_schema.table_io_waits_summary_by_table " +
297297
"WHERE OBJECT_SCHEMA NOT IN ('mysql', 'performance_schema');"
298298
rows, err := c.client.Query(query)
@@ -319,7 +319,7 @@ func (c *mySQLClient) getTableIoWaitsStats() ([]TableIoWaitsStats, error) {
319319
func (c *mySQLClient) getIndexIoWaitsStats() ([]IndexIoWaitsStats, error) {
320320
query := "SELECT OBJECT_SCHEMA, OBJECT_NAME, ifnull(INDEX_NAME, 'NONE') as INDEX_NAME," +
321321
"COUNT_FETCH, COUNT_INSERT, COUNT_UPDATE, COUNT_DELETE," +
322-
"SUM_TIMER_FETCH, SUM_TIMER_INSERT, SUM_TIMER_UPDATE, SUM_TIMER_DELETE " +
322+
"SUM_TIMER_FETCH/1000, SUM_TIMER_INSERT/1000, SUM_TIMER_UPDATE/1000, SUM_TIMER_DELETE/1000 " +
323323
"FROM performance_schema.table_io_waits_summary_by_index_usage " +
324324
"WHERE OBJECT_SCHEMA NOT IN ('mysql', 'performance_schema');"
325325

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

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

receiver/mysqlreceiver/scraper.go

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,6 @@ import (
1919
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/mysqlreceiver/internal/metadata"
2020
)
2121

22-
const (
23-
picosecondsInNanoseconds int64 = 1000
24-
)
25-
2622
type mySQLScraper struct {
2723
sqlclient client
2824
logger *zap.Logger
@@ -451,16 +447,16 @@ func (m *mySQLScraper) scrapeTableIoWaitsStats(now pcommon.Timestamp, errs *scra
451447

452448
// times
453449
m.mb.RecordMysqlTableIoWaitTimeDataPoint(
454-
now, s.timeDelete/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsDelete, s.name, s.schema,
450+
now, s.timeDelete, metadata.AttributeIoWaitsOperationsDelete, s.name, s.schema,
455451
)
456452
m.mb.RecordMysqlTableIoWaitTimeDataPoint(
457-
now, s.timeFetch/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsFetch, s.name, s.schema,
453+
now, s.timeFetch, metadata.AttributeIoWaitsOperationsFetch, s.name, s.schema,
458454
)
459455
m.mb.RecordMysqlTableIoWaitTimeDataPoint(
460-
now, s.timeInsert/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsInsert, s.name, s.schema,
456+
now, s.timeInsert, metadata.AttributeIoWaitsOperationsInsert, s.name, s.schema,
461457
)
462458
m.mb.RecordMysqlTableIoWaitTimeDataPoint(
463-
now, s.timeUpdate/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsUpdate, s.name, s.schema,
459+
now, s.timeUpdate, metadata.AttributeIoWaitsOperationsUpdate, s.name, s.schema,
464460
)
465461
}
466462
}
@@ -483,16 +479,16 @@ func (m *mySQLScraper) scrapeIndexIoWaitsStats(now pcommon.Timestamp, errs *scra
483479

484480
// times
485481
m.mb.RecordMysqlIndexIoWaitTimeDataPoint(
486-
now, s.timeDelete/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsDelete, s.name, s.schema, s.index,
482+
now, s.timeDelete, metadata.AttributeIoWaitsOperationsDelete, s.name, s.schema, s.index,
487483
)
488484
m.mb.RecordMysqlIndexIoWaitTimeDataPoint(
489-
now, s.timeFetch/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsFetch, s.name, s.schema, s.index,
485+
now, s.timeFetch, metadata.AttributeIoWaitsOperationsFetch, s.name, s.schema, s.index,
490486
)
491487
m.mb.RecordMysqlIndexIoWaitTimeDataPoint(
492-
now, s.timeInsert/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsInsert, s.name, s.schema, s.index,
488+
now, s.timeInsert, metadata.AttributeIoWaitsOperationsInsert, s.name, s.schema, s.index,
493489
)
494490
m.mb.RecordMysqlIndexIoWaitTimeDataPoint(
495-
now, s.timeUpdate/picosecondsInNanoseconds, metadata.AttributeIoWaitsOperationsUpdate, s.name, s.schema, s.index,
491+
now, s.timeUpdate, metadata.AttributeIoWaitsOperationsUpdate, s.name, s.schema, s.index,
496492
)
497493
}
498494
}
@@ -518,7 +514,7 @@ func (m *mySQLScraper) scrapeStatementEventsStats(now pcommon.Timestamp, errs *s
518514
m.mb.RecordMysqlStatementEventCountDataPoint(now, s.countSortRows, s.schema, s.digest, s.digestText, metadata.AttributeEventStateSortRows)
519515
m.mb.RecordMysqlStatementEventCountDataPoint(now, s.countWarnings, s.schema, s.digest, s.digestText, metadata.AttributeEventStateWarnings)
520516

521-
m.mb.RecordMysqlStatementEventWaitTimeDataPoint(now, s.sumTimerWait/picosecondsInNanoseconds, s.schema, s.digest, s.digestText)
517+
m.mb.RecordMysqlStatementEventWaitTimeDataPoint(now, s.sumTimerWait, s.schema, s.digest, s.digestText)
522518
}
523519
}
524520

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

542538
// read time data points
543-
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadNormal/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeReadLockTypeNormal)
544-
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadWithSharedLocks/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeReadLockTypeWithSharedLocks)
545-
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadHighPriority/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeReadLockTypeHighPriority)
546-
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadNoInsert/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeReadLockTypeNoInsert)
547-
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadExternal/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeReadLockTypeExternal)
539+
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadNormal, s.schema, s.name, metadata.AttributeReadLockTypeNormal)
540+
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadWithSharedLocks, s.schema, s.name, metadata.AttributeReadLockTypeWithSharedLocks)
541+
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadHighPriority, s.schema, s.name, metadata.AttributeReadLockTypeHighPriority)
542+
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadNoInsert, s.schema, s.name, metadata.AttributeReadLockTypeNoInsert)
543+
m.mb.RecordMysqlTableLockWaitReadTimeDataPoint(now, s.sumTimerReadExternal, s.schema, s.name, metadata.AttributeReadLockTypeExternal)
548544

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

556552
// write time data points
557-
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteAllowWrite/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeWriteLockTypeAllowWrite)
558-
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteConcurrentInsert/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeWriteLockTypeConcurrentInsert)
559-
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteLowPriority/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeWriteLockTypeLowPriority)
560-
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteNormal/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeWriteLockTypeNormal)
561-
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteExternal/picosecondsInNanoseconds, s.schema, s.name, metadata.AttributeWriteLockTypeExternal)
553+
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteAllowWrite, s.schema, s.name, metadata.AttributeWriteLockTypeAllowWrite)
554+
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteConcurrentInsert, s.schema, s.name, metadata.AttributeWriteLockTypeConcurrentInsert)
555+
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteLowPriority, s.schema, s.name, metadata.AttributeWriteLockTypeLowPriority)
556+
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteNormal, s.schema, s.name, metadata.AttributeWriteLockTypeNormal)
557+
m.mb.RecordMysqlTableLockWaitWriteTimeDataPoint(now, s.sumTimerWriteExternal, s.schema, s.name, metadata.AttributeWriteLockTypeExternal)
562558
}
563559
}
564560

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

0 commit comments

Comments
 (0)