From 71a2bf888e5adb588df72ac73a60dd5bdab886d4 Mon Sep 17 00:00:00 2001 From: shunki-fujita Date: Mon, 17 Jun 2024 09:14:03 +0000 Subject: [PATCH] support MySQL 8.4.0 --- containers/mysqld_exporter/.dockerignore | 1 + containers/mysqld_exporter/Dockerfile | 3 ++ containers/mysqld_exporter/TAG | 2 +- containers/mysqld_exporter/mysql84.patch | 63 ++++++++++++++++++++++++ 4 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 containers/mysqld_exporter/mysql84.patch diff --git a/containers/mysqld_exporter/.dockerignore b/containers/mysqld_exporter/.dockerignore index 72e8ffc0d..c253e29c8 100644 --- a/containers/mysqld_exporter/.dockerignore +++ b/containers/mysqld_exporter/.dockerignore @@ -1 +1,2 @@ * +!mysql84.patch diff --git a/containers/mysqld_exporter/Dockerfile b/containers/mysqld_exporter/Dockerfile index fe98972a3..10756d96a 100644 --- a/containers/mysqld_exporter/Dockerfile +++ b/containers/mysqld_exporter/Dockerfile @@ -5,7 +5,10 @@ FROM ghcr.io/cybozu/golang:1.22-jammy AS build ARG MYSQLD_EXPORTER_VERSION=v0.15.1 +COPY mysql84.patch . + RUN git clone -b ${MYSQLD_EXPORTER_VERSION} --depth 1 https://github.com/prometheus/mysqld_exporter \ + && patch -d mysqld_exporter -Np1 < mysql84.patch \ && make -C mysqld_exporter build # Stage2: setup runtime container diff --git a/containers/mysqld_exporter/TAG b/containers/mysqld_exporter/TAG index a2f9311ca..a6508758c 100644 --- a/containers/mysqld_exporter/TAG +++ b/containers/mysqld_exporter/TAG @@ -1 +1 @@ -0.15.1.1 +0.15.1.2 diff --git a/containers/mysqld_exporter/mysql84.patch b/containers/mysqld_exporter/mysql84.patch new file mode 100644 index 000000000..72707809b --- /dev/null +++ b/containers/mysqld_exporter/mysql84.patch @@ -0,0 +1,63 @@ +patch for MySQL 8.4 +https://github.com/prometheus/mysqld_exporter/commit/f6a64d768c6d0e182ab70733c07f6d8781d4fa0c?diff=split&w=0 + +diff --git a/collector/slave_hosts.go b/collector/slave_hosts.go +index d473c3c..b95110e 100644 +--- a/collector/slave_hosts.go ++++ b/collector/slave_hosts.go +@@ -31,7 +31,8 @@ const ( + // timestamps. %s will be replaced by the database and table name. + // The second column allows gets the server timestamp at the exact same + // time the query is run. +- slaveHostsQuery = "SHOW SLAVE HOSTS" ++ slaveHostsQuery = "SHOW SLAVE HOSTS" ++ showReplicasQuery = "SHOW REPLICAS" + ) + + // Metric descriptors. +@@ -63,9 +64,15 @@ func (ScrapeSlaveHosts) Version() float64 { + + // Scrape collects data from database connection and sends it over channel as prometheus metric. + func (ScrapeSlaveHosts) Scrape(ctx context.Context, db *sql.DB, ch chan<- prometheus.Metric, logger log.Logger) error { +- slaveHostsRows, err := db.QueryContext(ctx, slaveHostsQuery) +- if err != nil { +- return err ++ var ( ++ slaveHostsRows *sql.Rows ++ err error ++ ) ++ // Try the both syntax for MySQL 8.0 and MySQL 8.4 ++ if slaveHostsRows, err = db.QueryContext(ctx, slaveHostsQuery); err != nil { ++ if slaveHostsRows, err = db.QueryContext(ctx, showReplicasQuery); err != nil { ++ return err ++ } + } + defer slaveHostsRows.Close() + +diff --git a/collector/slave_status.go b/collector/slave_status.go +index 36dda33..b798465 100644 +--- a/collector/slave_status.go ++++ b/collector/slave_status.go +@@ -30,7 +30,7 @@ const ( + slaveStatus = "slave_status" + ) + +-var slaveStatusQueries = [2]string{"SHOW ALL SLAVES STATUS", "SHOW SLAVE STATUS"} ++var slaveStatusQueries = [3]string{"SHOW ALL SLAVES STATUS", "SHOW SLAVE STATUS", "SHOW REPLICA STATUS"} + var slaveStatusQuerySuffixes = [3]string{" NONBLOCKING", " NOLOCK", ""} + + func columnIndex(slaveCols []string, colName string) int { +@@ -113,7 +113,13 @@ func (ScrapeSlaveStatus) Scrape(ctx context.Context, db *sql.DB, ch chan<- prome + } + + masterUUID := columnValue(scanArgs, slaveCols, "Master_UUID") ++ if masterUUID == "" { ++ masterUUID = columnValue(scanArgs, slaveCols, "Source_UUID") ++ } + masterHost := columnValue(scanArgs, slaveCols, "Master_Host") ++ if masterHost == "" { ++ masterHost = columnValue(scanArgs, slaveCols, "Source_Host") ++ } + channelName := columnValue(scanArgs, slaveCols, "Channel_Name") // MySQL & Percona + connectionName := columnValue(scanArgs, slaveCols, "Connection_name") // MariaDB +