Skip to content

Commit

Permalink
autoid_service,server: handle TLS config of the etcd client (#38975) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-chi-bot authored Nov 9, 2022
1 parent 7e1e04f commit 786e3b4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
2 changes: 2 additions & 0 deletions autoid_service/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ go_library(
importpath = "github.com/pingcap/tidb/autoid_service",
visibility = ["//visibility:public"],
deps = [
"//config",
"//kv",
"//meta",
"//metrics",
Expand All @@ -16,6 +17,7 @@ go_library(
"@com_github_pingcap_kvproto//pkg/autoid",
"@io_etcd_go_etcd_client_v3//:client",
"@org_golang_google_grpc//:grpc",
"@org_golang_google_grpc//keepalive",
"@org_uber_go_zap//:zap",
],
)
21 changes: 18 additions & 3 deletions autoid_service/autoid.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ package autoid

import (
"context"
"crypto/tls"
"math"
"sync"
"time"

"github.com/pingcap/errors"
"github.com/pingcap/kvproto/pkg/autoid"
"github.com/pingcap/tidb/config"
"github.com/pingcap/tidb/kv"
"github.com/pingcap/tidb/meta"
"github.com/pingcap/tidb/metrics"
Expand All @@ -31,6 +33,7 @@ import (
clientv3 "go.etcd.io/etcd/client/v3"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/keepalive"
)

var (
Expand Down Expand Up @@ -245,10 +248,22 @@ type Service struct {
}

// New return a Service instance.
func New(selfAddr string, etcdAddr []string, store kv.Storage) *Service {
func New(selfAddr string, etcdAddr []string, store kv.Storage, tlsConfig *tls.Config) *Service {
cfg := config.GetGlobalConfig()
etcdLogCfg := zap.NewProductionConfig()
cli, err := clientv3.New(clientv3.Config{
Endpoints: etcdAddr,
DialTimeout: time.Second,
LogConfig: &etcdLogCfg,
Endpoints: etcdAddr,
AutoSyncInterval: 30 * time.Second,
DialTimeout: 5 * time.Second,
DialOptions: []grpc.DialOption{
grpc.WithBackoffMaxDelay(time.Second * 3),
grpc.WithKeepaliveParams(keepalive.ClientParameters{
Time: time.Duration(cfg.TiKVClient.GrpcKeepAliveTime) * time.Second,
Timeout: time.Duration(cfg.TiKVClient.GrpcKeepAliveTimeout) * time.Second,
}),
},
TLS: tlsConfig,
})
if err != nil {
panic(err)
Expand Down
2 changes: 1 addition & 1 deletion server/http_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ func (s *Server) startStatusServerAndRPCServer(serverMux *http.ServeMux) {
logutil.BgLogger().Error("tikv store not etcd background", zap.Error(err))
break
}
service := autoid.New(s.statusListener.Addr().String(), etcdAddr, store)
service := autoid.New(s.statusListener.Addr().String(), etcdAddr, store, ebd.TLSConfig())
pb.RegisterAutoIDAllocServer(grpcServer, service)
s.autoIDService = service
break
Expand Down

0 comments on commit 786e3b4

Please sign in to comment.