Skip to content

Commit

Permalink
telemetry: Use zap.Error() instead of err.Error()
Browse files Browse the repository at this point in the history
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"
}
```
  • Loading branch information
dveeden authored and ti-chi-bot committed Feb 7, 2023
1 parent 61e2c09 commit d1103c8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 3 deletions.
3 changes: 2 additions & 1 deletion telemetry/data_feature_usage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion telemetry/data_slow_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion telemetry/data_window.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d1103c8

Please sign in to comment.