Skip to content

Commit

Permalink
chore: refactor the imports (#2406)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevwan authored Sep 17, 2022
1 parent ae7f1aa commit 1f6688e
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 18 deletions.
3 changes: 1 addition & 2 deletions core/metric/counter.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
3 changes: 1 addition & 2 deletions core/metric/counter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
3 changes: 1 addition & 2 deletions core/metric/gauge.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
3 changes: 1 addition & 2 deletions core/metric/histogram.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand Down
6 changes: 3 additions & 3 deletions core/stores/redis/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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 ""
}
Expand Down
2 changes: 1 addition & 1 deletion core/stores/sqlx/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
4 changes: 0 additions & 4 deletions core/stores/sqlx/sqlconn.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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")
}
Expand Down
1 change: 0 additions & 1 deletion zrpc/internal/clientinterceptors/prometheusinterceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down
1 change: 0 additions & 1 deletion zrpc/internal/serverinterceptors/prometheusinterceptor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down

0 comments on commit 1f6688e

Please sign in to comment.