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 6381636 commit 1c5dea8
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 @@ -29,6 +29,7 @@ import (
"github.com/pingcap/tidb/util/memory"
"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 @@ -74,7 +75,7 @@ func getFeatureUsage(ctx context.Context, sctx sessionctx.Context) (*featureUsag
var err error
usage.NewClusterIndex, usage.ClusterIndex, err = getClusterIndexUsageInfo(ctx, sctx)
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 @@ -64,7 +64,7 @@ var (
func getSlowQueryStats() (*slowQueryStats, error) {
slowQueryBucket, err := getSlowQueryBucket()
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 @@ -255,7 +255,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 1c5dea8

Please sign in to comment.