Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
chore(mysql): improve tests (#769)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyam8 authored Aug 18, 2022
1 parent dee191d commit 6ff8777
Show file tree
Hide file tree
Showing 48 changed files with 3,689 additions and 10,831 deletions.
88 changes: 50 additions & 38 deletions modules/mysql/charts.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,9 +94,6 @@ var baseCharts = module.Charts{
chartInnoDBIOOperations.Copy(),
chartInnoDBPendingIOOperations.Copy(),
chartInnoDBLogOperations.Copy(),
chartInnoDBOSLogPendingOperations.Copy(),
chartInnoDBOSLogOperations.Copy(),
chartInnoDBOSLogIO.Copy(),
chartInnoDBCurrentRowLocks.Copy(),
chartInnoDBRowsOperations.Copy(),
chartInnoDBBufferPoolPages.Copy(),
Expand Down Expand Up @@ -348,41 +345,6 @@ var (
{ID: "innodb_log_writes", Name: "writes", Algo: module.Incremental, Mul: -1},
},
}
chartInnoDBOSLogPendingOperations = module.Chart{
ID: "innodb_os_log",
Title: "InnoDB OS Log Pending Operations",
Units: "operations",
Fam: "innodb",
Ctx: "mysql.innodb_os_log",
Priority: prioInnoDBOSLog,
Dims: module.Dims{
{ID: "innodb_os_log_pending_fsyncs", Name: "fsyncs"},
{ID: "innodb_os_log_pending_writes", Name: "writes", Mul: -1},
},
}
chartInnoDBOSLogOperations = module.Chart{
ID: "innodb_os_log_fsync_writes",
Title: "InnoDB OS Log Operations",
Units: "operations/s",
Fam: "innodb",
Ctx: "mysql.innodb_os_log_fsync_writes",
Priority: prioInnoDBOSLogFsyncWrites,
Dims: module.Dims{
{ID: "innodb_os_log_fsyncs", Name: "fsyncs", Algo: module.Incremental},
},
}
chartInnoDBOSLogIO = module.Chart{
ID: "innodb_os_log_io",
Title: "InnoDB OS Log Bandwidth",
Units: "KiB/s",
Fam: "innodb",
Ctx: "mysql.innodb_os_log_io",
Type: module.Area,
Priority: prioInnoDBOSLogIO,
Dims: module.Dims{
{ID: "innodb_os_log_written", Name: "write", Algo: module.Incremental, Mul: -1, Div: 1024},
},
}
chartInnoDBCurrentRowLocks = module.Chart{
ID: "innodb_cur_row_lock",
Title: "InnoDB Current Row Locks",
Expand Down Expand Up @@ -585,6 +547,50 @@ var (
}
)

var chartsInnoDBOSLog = module.Charts{
chartInnoDBOSLogPendingOperations.Copy(),
chartInnoDBOSLogOperations.Copy(),
chartInnoDBOSLogIO.Copy(),
}

var (
chartInnoDBOSLogPendingOperations = module.Chart{
ID: "innodb_os_log",
Title: "InnoDB OS Log Pending Operations",
Units: "operations",
Fam: "innodb",
Ctx: "mysql.innodb_os_log",
Priority: prioInnoDBOSLog,
Dims: module.Dims{
{ID: "innodb_os_log_pending_fsyncs", Name: "fsyncs"},
{ID: "innodb_os_log_pending_writes", Name: "writes", Mul: -1},
},
}
chartInnoDBOSLogOperations = module.Chart{
ID: "innodb_os_log_fsync_writes",
Title: "InnoDB OS Log Operations",
Units: "operations/s",
Fam: "innodb",
Ctx: "mysql.innodb_os_log_fsync_writes",
Priority: prioInnoDBOSLogFsyncWrites,
Dims: module.Dims{
{ID: "innodb_os_log_fsyncs", Name: "fsyncs", Algo: module.Incremental},
},
}
chartInnoDBOSLogIO = module.Chart{
ID: "innodb_os_log_io",
Title: "InnoDB OS Log Bandwidth",
Units: "KiB/s",
Fam: "innodb",
Ctx: "mysql.innodb_os_log_io",
Type: module.Area,
Priority: prioInnoDBOSLogIO,
Dims: module.Dims{
{ID: "innodb_os_log_written", Name: "write", Algo: module.Incremental, Mul: -1, Div: 1024},
},
}
)

var chartInnoDBDeadlocks = module.Chart{
ID: "innodb_deadlocks",
Title: "InnoDB Deadlocks",
Expand Down Expand Up @@ -1046,6 +1052,12 @@ func (m *MySQL) addUserStatisticsCharts(user string) {
}
}

func (m *MySQL) addInnoDBOSLogCharts() {
if err := m.Charts().Add(*chartsInnoDBOSLog.Copy()...); err != nil {
m.Warning(err)
}
}

func (m *MySQL) addMyISAMCharts() {
if err := m.Charts().Add(*chartsMyISAM.Copy()...); err != nil {
m.Warning(err)
Expand Down
10 changes: 10 additions & 0 deletions modules/mysql/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ func (m *MySQL) collect() (map[string]int64, error) {
return nil, fmt.Errorf("error on collecting global status: %v", err)
}

if hasInnodbOSLog(mx) {
m.addInnoDBOSLogOnce.Do(m.addInnoDBOSLogCharts)
}
if hasInnodbDeadlocks(mx) {
m.addInnodbDeadlocksOnce.Do(m.addInnodbDeadlocksChart)
}
Expand All @@ -64,6 +67,7 @@ func (m *MySQL) collect() (map[string]int64, error) {
m.addBinlogOnce.Do(m.addBinlogCharts)
}

// TODO: perhaps make a decisions based on privileges? (SHOW GRANTS FOR CURRENT_USER();)
if m.doSlaveStatus {
if err := m.collectSlaveStatus(mx); err != nil {
m.Errorf("error on collecting slave status: %v", err)
Expand Down Expand Up @@ -117,6 +121,12 @@ func calcThreadCacheMisses(collected map[string]int64) {
}
}

func hasInnodbOSLog(collected map[string]int64) bool {
// removed in MariaDB 10.8 (https://mariadb.com/kb/en/innodb-status-variables/#innodb_os_log_fsyncs)
_, ok := collected["innodb_os_log_fsyncs"]
return ok
}

func hasInnodbDeadlocks(collected map[string]int64) bool {
_, ok := collected["innodb_deadlocks"]
return ok
Expand Down
Loading

0 comments on commit 6ff8777

Please sign in to comment.