Skip to content

Commit

Permalink
domain: add prometheus interceptor to etcd client's grpc dial option (p…
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored Sep 27, 2017
1 parent 7ac9504 commit 0548911
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/coreos/etcd/clientv3"
"github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/juju/errors"
"github.com/ngaut/pools"
"github.com/pingcap/tidb/context"
Expand All @@ -35,6 +36,7 @@ import (
"github.com/pingcap/tidb/statistics"
"github.com/pingcap/tidb/terror"
goctx "golang.org/x/net/context"
"google.golang.org/grpc"
)

// Domain represents a storage space. Different domains can use the same database name.
Expand Down Expand Up @@ -424,6 +426,10 @@ func NewDomain(store kv.Storage, ddlLease time.Duration, statsLease time.Duratio
cli, err = clientv3.New(clientv3.Config{
Endpoints: addrs,
DialTimeout: 5 * time.Second,
DialOptions: []grpc.DialOption{
grpc.WithUnaryInterceptor(grpc_prometheus.UnaryClientInterceptor),
grpc.WithStreamInterceptor(grpc_prometheus.StreamClientInterceptor),
},
})
if err != nil {
return nil, errors.Trace(err)
Expand Down
6 changes: 6 additions & 0 deletions store/tikv/kv.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (

log "github.com/Sirupsen/logrus"
"github.com/coreos/etcd/clientv3"
"github.com/grpc-ecosystem/go-grpc-prometheus"
"github.com/juju/errors"
"github.com/pingcap/kvproto/pkg/kvrpcpb"
"github.com/pingcap/pd/pd-client"
Expand All @@ -33,6 +34,7 @@ import (
"github.com/pingcap/tidb/store/tikv/oracle/oracles"
"github.com/pingcap/tidb/store/tikv/tikvrpc"
goctx "golang.org/x/net/context"
"google.golang.org/grpc"
)

type storeCache struct {
Expand All @@ -50,6 +52,10 @@ func createEtcdKV(addrs []string) (*clientv3.Client, error) {
cli, err := clientv3.New(clientv3.Config{
Endpoints: addrs,
DialTimeout: 5 * time.Second,
DialOptions: []grpc.DialOption{
grpc.WithUnaryInterceptor(grpc_prometheus.UnaryClientInterceptor),
grpc.WithStreamInterceptor(grpc_prometheus.StreamClientInterceptor),
},
})
if err != nil {
return nil, errors.Trace(err)
Expand Down

0 comments on commit 0548911

Please sign in to comment.