From 61e2c093380d17a9b60fff05f45c868fcc62ae29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Thu, 26 Jan 2023 10:59:31 +0100 Subject: [PATCH 1/2] telemetry: Log error reason for failure to get SQL Metric --- telemetry/data_window.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/telemetry/data_window.go b/telemetry/data_window.go index 0945326075083..9d64d39cf740a 100644 --- a/telemetry/data_window.go +++ b/telemetry/data_window.go @@ -25,6 +25,7 @@ import ( promv1 "github.com/prometheus/client_golang/api/prometheus/v1" pmodel "github.com/prometheus/common/model" "go.uber.org/atomic" + "go.uber.org/zap" ) var ( @@ -246,7 +247,8 @@ func RotateSubWindow() { err := readSQLMetric(time.Now(), &thisSubWindow.SQLUsage) if err != nil { - logutil.BgLogger().Info("Error exists when getting the SQL Metric.") + logutil.BgLogger().Info("Error exists when getting the SQL Metric.", + zap.String("error", err.Error())) } thisSubWindow.SQLUsage.SQLTotal = getSQLSum(&thisSubWindow.SQLUsage.SQLType) From d1103c8666ec94abb8b023602a948dea9022923f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Eeden?= Date: Fri, 27 Jan 2023 10:03:22 +0100 Subject: [PATCH 2/2] telemetry: Use `zap.Error()` instead of `err.Error()` With JSON formatted logs: ``` $ jq 'select(.error) | select(.error | contains("Prometheus"))' tidb.log { "level": "INFO", "time": "2023/01/27 10:00:35.554 +01:00", "caller": "data_slow_query.go:67", "message": "Failed to get Slow Query Stats", "error": "[domain:9009]Prometheus address is not set in PD and etcd" } { "level": "INFO", "time": "2023/01/27 10:01:36.223 +01:00", "caller": "data_window.go:257", "message": "Error exists when getting the SQL Metric.", "error": "[domain:9009]Prometheus address is not set in PD and etcd" } { "level": "INFO", "time": "2023/01/27 10:02:36.225 +01:00", "caller": "data_window.go:257", "message": "Error exists when getting the SQL Metric.", "error": "[domain:9009]Prometheus address is not set in PD and etcd" } ``` --- telemetry/data_feature_usage.go | 3 ++- telemetry/data_slow_query.go | 2 +- telemetry/data_window.go | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/telemetry/data_feature_usage.go b/telemetry/data_feature_usage.go index 622f25c4b2430..b9a22291d74e4 100644 --- a/telemetry/data_feature_usage.go +++ b/telemetry/data_feature_usage.go @@ -27,6 +27,7 @@ import ( "github.com/pingcap/tidb/util/logutil" "github.com/pingcap/tidb/util/sqlexec" "github.com/tikv/client-go/v2/metrics" + "go.uber.org/zap" ) // emptyClusterIndexUsage is empty ClusterIndexUsage, deprecated. @@ -61,7 +62,7 @@ func getFeatureUsage(ctx sessionctx.Context) (*featureUsage, error) { var err error usage.NewClusterIndex, usage.ClusterIndex, err = getClusterIndexUsageInfo(ctx) if err != nil { - logutil.BgLogger().Info(err.Error()) + logutil.BgLogger().Info("Failed to get feature usage", zap.Error(err)) return nil, err } diff --git a/telemetry/data_slow_query.go b/telemetry/data_slow_query.go index e32940e09be6a..1e77ae9f21948 100644 --- a/telemetry/data_slow_query.go +++ b/telemetry/data_slow_query.go @@ -65,7 +65,7 @@ var ( func getSlowQueryStats(ctx sessionctx.Context) (*slowQueryStats, error) { slowQueryBucket, err := getSlowQueryBucket(ctx) if err != nil { - logutil.BgLogger().Info(err.Error()) + logutil.BgLogger().Info("Failed to get Slow Query Stats", zap.Error(err)) return nil, err } diff --git a/telemetry/data_window.go b/telemetry/data_window.go index 9d64d39cf740a..4ca77a274cdce 100644 --- a/telemetry/data_window.go +++ b/telemetry/data_window.go @@ -248,7 +248,7 @@ func RotateSubWindow() { err := readSQLMetric(time.Now(), &thisSubWindow.SQLUsage) if err != nil { logutil.BgLogger().Info("Error exists when getting the SQL Metric.", - zap.String("error", err.Error())) + zap.Error(err)) } thisSubWindow.SQLUsage.SQLTotal = getSQLSum(&thisSubWindow.SQLUsage.SQLType)