config.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // Copyright 2016 The etcd Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package clientv3
  15. import (
  16. "context"
  17. "crypto/tls"
  18. "time"
  19. "go.uber.org/zap"
  20. "google.golang.org/grpc"
  21. )
  22. type Config struct {
  23. // Endpoints is a list of URLs.
  24. Endpoints []string `json:"endpoints"`
  25. // AutoSyncInterval is the interval to update endpoints with its latest members.
  26. // 0 disables auto-sync. By default auto-sync is disabled.
  27. AutoSyncInterval time.Duration `json:"auto-sync-interval"`
  28. // DialTimeout is the timeout for failing to establish a connection.
  29. DialTimeout time.Duration `json:"dial-timeout"`
  30. // DialKeepAliveTime is the time after which client pings the server to see if
  31. // transport is alive.
  32. DialKeepAliveTime time.Duration `json:"dial-keep-alive-time"`
  33. // DialKeepAliveTimeout is the time that the client waits for a response for the
  34. // keep-alive probe. If the response is not received in this time, the connection is closed.
  35. DialKeepAliveTimeout time.Duration `json:"dial-keep-alive-timeout"`
  36. // MaxCallSendMsgSize is the client-side request send limit in bytes.
  37. // If 0, it defaults to 2.0 MiB (2 * 1024 * 1024).
  38. // Make sure that "MaxCallSendMsgSize" < server-side default send/recv limit.
  39. // ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes").
  40. MaxCallSendMsgSize int
  41. // MaxCallRecvMsgSize is the client-side response receive limit.
  42. // If 0, it defaults to "math.MaxInt32", because range response can
  43. // easily exceed request send limits.
  44. // Make sure that "MaxCallRecvMsgSize" >= server-side default send/recv limit.
  45. // ("--max-request-bytes" flag to etcd or "embed.Config.MaxRequestBytes").
  46. MaxCallRecvMsgSize int
  47. // TLS holds the client secure credentials, if any.
  48. TLS *tls.Config
  49. // Username is a user name for authentication.
  50. Username string `json:"username"`
  51. // Password is a password for authentication.
  52. Password string `json:"password"`
  53. // RejectOldCluster when set will refuse to create a client against an outdated cluster.
  54. RejectOldCluster bool `json:"reject-old-cluster"`
  55. // DialOptions is a list of dial options for the grpc client (e.g., for interceptors).
  56. DialOptions []grpc.DialOption
  57. // Context is the default client context; it can be used to cancel grpc dial out and
  58. // other operations that do not have an explicit context.
  59. Context context.Context
  60. // LogConfig configures client-side logger.
  61. // If nil, use the default logger.
  62. // TODO: configure gRPC logger
  63. LogConfig *zap.Config
  64. }
  65. // DefaultLogConfig is the default client logging configuration.
  66. // Default log level is "Warn". Use "zap.InfoLevel" for debugging.
  67. // Use "/dev/null" for output paths, to discard all logs.
  68. var DefaultLogConfig = zap.Config{
  69. Level: zap.NewAtomicLevelAt(zap.WarnLevel),
  70. Development: false,
  71. Sampling: &zap.SamplingConfig{
  72. Initial: 100,
  73. Thereafter: 100,
  74. },
  75. Encoding: "json",
  76. EncoderConfig: zap.NewProductionEncoderConfig(),
  77. // Use "/dev/null" to discard all
  78. OutputPaths: []string{"stderr"},
  79. ErrorOutputPaths: []string{"stderr"},
  80. }