github.com/m3db/m3@v1.5.0/src/cluster/client/etcd/types.go (about)

     1  // Copyright (c) 2016 Uber Technologies, Inc.
     2  //
     3  // Permission is hereby granted, free of charge, to any person obtaining a copy
     4  // of this software and associated documentation files (the "Software"), to deal
     5  // in the Software without restriction, including without limitation the rights
     6  // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     7  // copies of the Software, and to permit persons to whom the Software is
     8  // furnished to do so, subject to the following conditions:
     9  //
    10  // The above copyright notice and this permission notice shall be included in
    11  // all copies or substantial portions of the Software.
    12  //
    13  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    14  // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    15  // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    16  // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    17  // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    18  // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    19  // THE SOFTWARE.
    20  
    21  package etcd
    22  
    23  import (
    24  	"crypto/tls"
    25  	"os"
    26  	"time"
    27  
    28  	"google.golang.org/grpc"
    29  
    30  	"github.com/m3db/m3/src/cluster/client"
    31  	"github.com/m3db/m3/src/cluster/services"
    32  	"github.com/m3db/m3/src/x/instrument"
    33  	"github.com/m3db/m3/src/x/retry"
    34  )
    35  
    36  // Options is the Options to create a config service client.
    37  type Options interface {
    38  	// RequestTimeout is the timeout for etcd requests
    39  	RequestTimeout() time.Duration
    40  	// SetRequestTimeout sets the RequestTimeout
    41  	SetRequestTimeout(t time.Duration) Options
    42  
    43  	Env() string
    44  	SetEnv(e string) Options
    45  
    46  	Zone() string
    47  	SetZone(z string) Options
    48  
    49  	Service() string
    50  	SetService(id string) Options
    51  
    52  	CacheDir() string
    53  	SetCacheDir(dir string) Options
    54  
    55  	ServicesOptions() services.Options
    56  	SetServicesOptions(opts services.Options) Options
    57  
    58  	Clusters() []Cluster
    59  	SetClusters(clusters []Cluster) Options
    60  	ClusterForZone(z string) (Cluster, bool)
    61  
    62  	InstrumentOptions() instrument.Options
    63  	SetInstrumentOptions(iopts instrument.Options) Options
    64  
    65  	RetryOptions() retry.Options
    66  	SetRetryOptions(retryOpts retry.Options) Options
    67  
    68  	// WatchChanCheckInterval will be used to periodically check if a watch chan
    69  	// is no longer being subscribed and should be closed
    70  	WatchChanCheckInterval() time.Duration
    71  	// SetWatchChanCheckInterval sets the WatchChanCheckInterval
    72  	SetWatchChanCheckInterval(t time.Duration) Options
    73  
    74  	// WatchChanResetInterval is the delay before resetting the etcd watch chan
    75  	WatchChanResetInterval() time.Duration
    76  	// SetWatchChanResetInterval sets the WatchChanResetInterval
    77  	SetWatchChanResetInterval(t time.Duration) Options
    78  
    79  	// WatchChanInitTimeout is the timeout for a watchChan initialization
    80  	WatchChanInitTimeout() time.Duration
    81  	// SetWatchChanInitTimeout sets the WatchChanInitTimeout
    82  	SetWatchChanInitTimeout(t time.Duration) Options
    83  
    84  	WatchWithRevision() int64
    85  	SetWatchWithRevision(rev int64) Options
    86  
    87  	// EnableFastGets returns whether to use clientv3.WithSerializable() option to speed up gets.
    88  	EnableFastGets() bool
    89  	// SetEnableFastGets sets clientv3.WithSerializable() to speed up gets, but can fetch stale data.
    90  	SetEnableFastGets(enabled bool) Options
    91  
    92  	SetNewDirectoryMode(fm os.FileMode) Options
    93  	NewDirectoryMode() os.FileMode
    94  
    95  	Validate() error
    96  }
    97  
    98  // KeepAliveOptions provide a set of client-side keepAlive options.
    99  type KeepAliveOptions interface {
   100  	// KeepAliveEnabled determines whether keepAlives are enabled.
   101  	KeepAliveEnabled() bool
   102  
   103  	// SetKeepAliveEnabled sets whether keepAlives are enabled.
   104  	SetKeepAliveEnabled(value bool) KeepAliveOptions
   105  
   106  	// KeepAlivePeriod is the duration of time after which if the client doesn't see
   107  	// any activity the client pings the server to see if transport is alive.
   108  	KeepAlivePeriod() time.Duration
   109  
   110  	// SetKeepAlivePeriod sets the duration of time after which if the client doesn't see
   111  	// any activity the client pings the server to see if transport is alive.
   112  	SetKeepAlivePeriod(value time.Duration) KeepAliveOptions
   113  
   114  	// KeepAlivePeriodMaxJitter is used to add some jittering to keep alive period
   115  	// to avoid a large number of clients all sending keepalive probes at the
   116  	// same time.
   117  	KeepAlivePeriodMaxJitter() time.Duration
   118  
   119  	// SetKeepAlivePeriodMaxJitter sets the maximum jittering to keep alive period
   120  	// to avoid a large number of clients all sending keepalive probes at the
   121  	// same time.
   122  	SetKeepAlivePeriodMaxJitter(value time.Duration) KeepAliveOptions
   123  
   124  	// KeepAliveTimeout is the time that the client waits for a response for the
   125  	// keep-alive probe. If the response is not received in this time, the connection is closed.
   126  	KeepAliveTimeout() time.Duration
   127  
   128  	// SetKeepAliveTimeout sets the time that the client waits for a response for the
   129  	// keep-alive probe. If the response is not received in this time, the connection is closed.
   130  	SetKeepAliveTimeout(value time.Duration) KeepAliveOptions
   131  }
   132  
   133  // TLSOptions defines the options for TLS.
   134  type TLSOptions interface {
   135  	CrtPath() string
   136  	SetCrtPath(string) TLSOptions
   137  
   138  	KeyPath() string
   139  	SetKeyPath(string) TLSOptions
   140  
   141  	CACrtPath() string
   142  	SetCACrtPath(string) TLSOptions
   143  
   144  	Config() (*tls.Config, error)
   145  }
   146  
   147  // Cluster defines the configuration for a etcd cluster.
   148  type Cluster interface {
   149  	Zone() string
   150  	SetZone(z string) Cluster
   151  
   152  	Endpoints() []string
   153  	SetEndpoints(endpoints []string) Cluster
   154  
   155  	KeepAliveOptions() KeepAliveOptions
   156  	SetKeepAliveOptions(value KeepAliveOptions) Cluster
   157  
   158  	TLSOptions() TLSOptions
   159  	SetTLSOptions(TLSOptions) Cluster
   160  
   161  	AutoSyncInterval() time.Duration
   162  	SetAutoSyncInterval(value time.Duration) Cluster
   163  
   164  	DialTimeout() time.Duration
   165  	SetDialTimeout(value time.Duration) Cluster
   166  
   167  	// DialOptions are used by the etcd client to connect to etcd peers. They can be used to customize
   168  	// the low level networking behavior of the client (e.g. to forward connections over a proxy).
   169  	DialOptions() []grpc.DialOption
   170  	SetDialOptions(opts []grpc.DialOption) Cluster
   171  }
   172  
   173  // Client is an etcd-backed m3cluster client.
   174  type Client interface {
   175  	client.Client
   176  
   177  	Clients() []ZoneClient
   178  }