From 55df5341e3b8edd9532f6ea59e360ca1441e3e1a Mon Sep 17 00:00:00 2001 From: hateeyan Date: Tue, 21 Dec 2021 09:37:29 +0800 Subject: [PATCH] compatible with mysql<=5.7 Signed-off-by: hateeyan --- collector/global_variables.go | 9 +++++++-- collector/global_variables_test.go | 1 + 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/collector/global_variables.go b/collector/global_variables.go index 55b35c3..b2717fb 100644 --- a/collector/global_variables.go +++ b/collector/global_variables.go @@ -153,6 +153,7 @@ func (ScrapeGlobalVariables) Scrape(ctx context.Context, db *sql.DB, ch chan<- p "version_comment": "", "wsrep_cluster_name": "", "wsrep_provider_options": "", + "tx_isolation": "", "transaction_isolation": "", } @@ -206,12 +207,16 @@ func (ScrapeGlobalVariables) Scrape(ctx context.Context, db *sql.DB, ch chan<- p } // mysql_transaction_isolation metric. - if textItems["transaction_isolation"] != "" { + if textItems["transaction_isolation"] != "" || textItems["tx_isolation"] != "" { + level := textItems["transaction_isolation"] + if level == "" { + level = textItems["tx_isolation"] + } ch <- prometheus.MustNewConstMetric( prometheus.NewDesc(prometheus.BuildFQName(namespace, "transaction", "isolation"), "MySQL transaction isolation.", []string{"level"}, nil), prometheus.GaugeValue, - 1, textItems["transaction_isolation"], + 1, level, ) } diff --git a/collector/global_variables_test.go b/collector/global_variables_test.go index 7395961..4f0ab36 100644 --- a/collector/global_variables_test.go +++ b/collector/global_variables_test.go @@ -69,6 +69,7 @@ func TestScrapeGlobalVariables(t *testing.T) { {labels: labelMap{"innodb_version": "5.6.30-76.3", "version": "5.6.30-76.3-56", "version_comment": "Percona XtraDB Cluster..."}, value: 1, metricType: dto.MetricType_GAUGE}, {labels: labelMap{"wsrep_cluster_name": "supercluster"}, value: 1, metricType: dto.MetricType_GAUGE}, {labels: labelMap{}, value: 134217728, metricType: dto.MetricType_GAUGE}, + {labels: labelMap{"level": "REPEATABLE-READ"}, value: 1, metricType: dto.MetricType_GAUGE}, } convey.Convey("Metrics comparison", t, func() { for _, expect := range counterExpected {