chore: refactor the imports (#2406)
This commit is contained in:
@@ -1,10 +1,9 @@
|
|||||||
package metric
|
package metric
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
prom "github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/zeromicro/go-zero/core/proc"
|
"github.com/zeromicro/go-zero/core/proc"
|
||||||
"github.com/zeromicro/go-zero/core/prometheus"
|
"github.com/zeromicro/go-zero/core/prometheus"
|
||||||
|
|
||||||
prom "github.com/prometheus/client_golang/prometheus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|||||||
@@ -3,10 +3,9 @@ package metric
|
|||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/prometheus"
|
|
||||||
|
|
||||||
"github.com/prometheus/client_golang/prometheus/testutil"
|
"github.com/prometheus/client_golang/prometheus/testutil"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
|
"github.com/zeromicro/go-zero/core/prometheus"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestNewCounterVec(t *testing.T) {
|
func TestNewCounterVec(t *testing.T) {
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package metric
|
package metric
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
prom "github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/zeromicro/go-zero/core/proc"
|
"github.com/zeromicro/go-zero/core/proc"
|
||||||
"github.com/zeromicro/go-zero/core/prometheus"
|
"github.com/zeromicro/go-zero/core/prometheus"
|
||||||
|
|
||||||
prom "github.com/prometheus/client_golang/prometheus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package metric
|
package metric
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
prom "github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/zeromicro/go-zero/core/proc"
|
"github.com/zeromicro/go-zero/core/proc"
|
||||||
"github.com/zeromicro/go-zero/core/prometheus"
|
"github.com/zeromicro/go-zero/core/prometheus"
|
||||||
|
|
||||||
prom "github.com/prometheus/client_golang/prometheus"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type (
|
type (
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func (h hook) AfterProcess(ctx context.Context, cmd red.Cmder) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
metricReqDur.Observe(int64(duration/time.Millisecond), cmd.Name())
|
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)
|
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")
|
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)
|
metricReqErr.Inc("Pipeline", msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func errFormat(err error) string {
|
func formatError(err error) string {
|
||||||
if err == nil || err == red.Nil {
|
if err == nil || err == red.Nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ package sqlx
|
|||||||
|
|
||||||
import "github.com/zeromicro/go-zero/core/metric"
|
import "github.com/zeromicro/go-zero/core/metric"
|
||||||
|
|
||||||
const namespace = "mysql_client"
|
const namespace = "sql_client"
|
||||||
|
|
||||||
var (
|
var (
|
||||||
metricReqDur = metric.NewHistogramVec(&metric.HistogramVecOpts{
|
metricReqDur = metric.NewHistogramVec(&metric.HistogramVecOpts{
|
||||||
|
|||||||
@@ -153,7 +153,6 @@ func (db *commonSqlConn) ExecCtx(ctx context.Context, q string, args ...interfac
|
|||||||
result, err = exec(ctx, conn, q, args...)
|
result, err = exec(ctx, conn, q, args...)
|
||||||
return err
|
return err
|
||||||
}, db.acceptable)
|
}, db.acceptable)
|
||||||
|
|
||||||
if err == breaker.ErrServiceUnavailable {
|
if err == breaker.ErrServiceUnavailable {
|
||||||
metricReqErr.Inc("Exec", "breaker")
|
metricReqErr.Inc("Exec", "breaker")
|
||||||
}
|
}
|
||||||
@@ -190,7 +189,6 @@ func (db *commonSqlConn) PrepareCtx(ctx context.Context, query string) (stmt Stm
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}, db.acceptable)
|
}, db.acceptable)
|
||||||
|
|
||||||
if err == breaker.ErrServiceUnavailable {
|
if err == breaker.ErrServiceUnavailable {
|
||||||
metricReqErr.Inc("Prepare", "breaker")
|
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 {
|
err = db.brk.DoWithAcceptable(func() error {
|
||||||
return transact(ctx, db, db.beginTx, fn)
|
return transact(ctx, db, db.beginTx, fn)
|
||||||
}, db.acceptable)
|
}, db.acceptable)
|
||||||
|
|
||||||
if err == breaker.ErrServiceUnavailable {
|
if err == breaker.ErrServiceUnavailable {
|
||||||
metricReqErr.Inc("Transact", "breaker")
|
metricReqErr.Inc("Transact", "breaker")
|
||||||
}
|
}
|
||||||
@@ -315,7 +312,6 @@ func (db *commonSqlConn) queryRows(ctx context.Context, scanner func(*sql.Rows)
|
|||||||
}, func(err error) bool {
|
}, func(err error) bool {
|
||||||
return qerr == err || db.acceptable(err)
|
return qerr == err || db.acceptable(err)
|
||||||
})
|
})
|
||||||
|
|
||||||
if err == breaker.ErrServiceUnavailable {
|
if err == breaker.ErrServiceUnavailable {
|
||||||
metricReqErr.Inc("queryRows", "breaker")
|
metricReqErr.Inc("queryRows", "breaker")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/metric"
|
"github.com/zeromicro/go-zero/core/metric"
|
||||||
"github.com/zeromicro/go-zero/core/timex"
|
"github.com/zeromicro/go-zero/core/timex"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import (
|
|||||||
|
|
||||||
"github.com/zeromicro/go-zero/core/metric"
|
"github.com/zeromicro/go-zero/core/metric"
|
||||||
"github.com/zeromicro/go-zero/core/timex"
|
"github.com/zeromicro/go-zero/core/timex"
|
||||||
|
|
||||||
"google.golang.org/grpc"
|
"google.golang.org/grpc"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user