From 1f6688e5c104e3223ce75a0d397a6d63c371352d Mon Sep 17 00:00:00 2001 From: Kevin Wan Date: Sat, 17 Sep 2022 20:06:23 +0800 Subject: [PATCH] chore: refactor the imports (#2406) --- core/metric/counter.go | 3 +-- core/metric/counter_test.go | 3 +-- core/metric/gauge.go | 3 +-- core/metric/histogram.go | 3 +-- core/stores/redis/hook.go | 6 +++--- core/stores/sqlx/metrics.go | 2 +- core/stores/sqlx/sqlconn.go | 4 ---- zrpc/internal/clientinterceptors/prometheusinterceptor.go | 1 - zrpc/internal/serverinterceptors/prometheusinterceptor.go | 1 - 9 files changed, 8 insertions(+), 18 deletions(-) diff --git a/core/metric/counter.go b/core/metric/counter.go index 578f91f9b05d..c95412f736e9 100644 --- a/core/metric/counter.go +++ b/core/metric/counter.go @@ -1,10 +1,9 @@ package metric import ( + prom "github.com/prometheus/client_golang/prometheus" "github.com/zeromicro/go-zero/core/proc" "github.com/zeromicro/go-zero/core/prometheus" - - prom "github.com/prometheus/client_golang/prometheus" ) type ( diff --git a/core/metric/counter_test.go b/core/metric/counter_test.go index 64cb5056d926..145d1b20c8bd 100644 --- a/core/metric/counter_test.go +++ b/core/metric/counter_test.go @@ -3,10 +3,9 @@ package metric import ( "testing" - "github.com/zeromicro/go-zero/core/prometheus" - "github.com/prometheus/client_golang/prometheus/testutil" "github.com/stretchr/testify/assert" + "github.com/zeromicro/go-zero/core/prometheus" ) func TestNewCounterVec(t *testing.T) { diff --git a/core/metric/gauge.go b/core/metric/gauge.go index 763bd4d97f27..52ff841de913 100644 --- a/core/metric/gauge.go +++ b/core/metric/gauge.go @@ -1,10 +1,9 @@ package metric import ( + prom "github.com/prometheus/client_golang/prometheus" "github.com/zeromicro/go-zero/core/proc" "github.com/zeromicro/go-zero/core/prometheus" - - prom "github.com/prometheus/client_golang/prometheus" ) type ( diff --git a/core/metric/histogram.go b/core/metric/histogram.go index 77cb5e39d2a3..4f0a1058bdb5 100644 --- a/core/metric/histogram.go +++ b/core/metric/histogram.go @@ -1,10 +1,9 @@ package metric import ( + prom "github.com/prometheus/client_golang/prometheus" "github.com/zeromicro/go-zero/core/proc" "github.com/zeromicro/go-zero/core/prometheus" - - prom "github.com/prometheus/client_golang/prometheus" ) type ( diff --git a/core/stores/redis/hook.go b/core/stores/redis/hook.go index 4cd8e97c380a..5229bd274425 100644 --- a/core/stores/redis/hook.go +++ b/core/stores/redis/hook.go @@ -57,7 +57,7 @@ func (h hook) AfterProcess(ctx context.Context, cmd red.Cmder) error { } metricReqDur.Observe(int64(duration/time.Millisecond), cmd.Name()) - if msg := errFormat(err); len(msg) > 0 { + if msg := formatError(err); len(msg) > 0 { metricReqErr.Inc(cmd.Name(), msg) } @@ -104,14 +104,14 @@ func (h hook) AfterProcessPipeline(ctx context.Context, cmds []red.Cmder) error } metricReqDur.Observe(int64(duration/time.Millisecond), "Pipeline") - if msg := errFormat(batchError.Err()); len(msg) > 0 { + if msg := formatError(batchError.Err()); len(msg) > 0 { metricReqErr.Inc("Pipeline", msg) } return nil } -func errFormat(err error) string { +func formatError(err error) string { if err == nil || err == red.Nil { return "" } diff --git a/core/stores/sqlx/metrics.go b/core/stores/sqlx/metrics.go index 3a4c7e0b801e..7c478012e7b2 100644 --- a/core/stores/sqlx/metrics.go +++ b/core/stores/sqlx/metrics.go @@ -2,7 +2,7 @@ package sqlx import "github.com/zeromicro/go-zero/core/metric" -const namespace = "mysql_client" +const namespace = "sql_client" var ( metricReqDur = metric.NewHistogramVec(&metric.HistogramVecOpts{ diff --git a/core/stores/sqlx/sqlconn.go b/core/stores/sqlx/sqlconn.go index e5771c54cca5..0118a38d090b 100644 --- a/core/stores/sqlx/sqlconn.go +++ b/core/stores/sqlx/sqlconn.go @@ -153,7 +153,6 @@ func (db *commonSqlConn) ExecCtx(ctx context.Context, q string, args ...interfac result, err = exec(ctx, conn, q, args...) return err }, db.acceptable) - if err == breaker.ErrServiceUnavailable { metricReqErr.Inc("Exec", "breaker") } @@ -190,7 +189,6 @@ func (db *commonSqlConn) PrepareCtx(ctx context.Context, query string) (stmt Stm } return nil }, db.acceptable) - if err == breaker.ErrServiceUnavailable { metricReqErr.Inc("Prepare", "breaker") } @@ -281,7 +279,6 @@ func (db *commonSqlConn) TransactCtx(ctx context.Context, fn func(context.Contex err = db.brk.DoWithAcceptable(func() error { return transact(ctx, db, db.beginTx, fn) }, db.acceptable) - if err == breaker.ErrServiceUnavailable { metricReqErr.Inc("Transact", "breaker") } @@ -315,7 +312,6 @@ func (db *commonSqlConn) queryRows(ctx context.Context, scanner func(*sql.Rows) }, func(err error) bool { return qerr == err || db.acceptable(err) }) - if err == breaker.ErrServiceUnavailable { metricReqErr.Inc("queryRows", "breaker") } diff --git a/zrpc/internal/clientinterceptors/prometheusinterceptor.go b/zrpc/internal/clientinterceptors/prometheusinterceptor.go index 56017053dc94..7b50144acd97 100644 --- a/zrpc/internal/clientinterceptors/prometheusinterceptor.go +++ b/zrpc/internal/clientinterceptors/prometheusinterceptor.go @@ -7,7 +7,6 @@ import ( "github.com/zeromicro/go-zero/core/metric" "github.com/zeromicro/go-zero/core/timex" - "google.golang.org/grpc" "google.golang.org/grpc/status" ) diff --git a/zrpc/internal/serverinterceptors/prometheusinterceptor.go b/zrpc/internal/serverinterceptors/prometheusinterceptor.go index 97ac073ee460..e6cce1a472d2 100644 --- a/zrpc/internal/serverinterceptors/prometheusinterceptor.go +++ b/zrpc/internal/serverinterceptors/prometheusinterceptor.go @@ -7,7 +7,6 @@ import ( "github.com/zeromicro/go-zero/core/metric" "github.com/zeromicro/go-zero/core/timex" - "google.golang.org/grpc" "google.golang.org/grpc/status" )