OptionalauthEtcd password auth, if using. You can also specify call options for the authentication token exchange call.
OptionalcallOptions?: CallOptionsFactoryCall options to use for the password-to-token exchange.
OptionalcredentialsOptional client certificate credentials for talking to etcd. See the etcd security guide. They are passed to createSsl.
For example:
const etcd = new Etcd3({
credentials: {
rootCertificate: fs.readFileSync('ca.crt'),
},
});
OptionaldefaultDefault call options used for all requests. This can be an object, or a function which will be called for each etcd method call. As a function, it will be called with a context object, which looks like:
{
service: 'KV', // etcd service name
method: 'range', // etcd method name
isStream: false, // whether the call creates a stream
params: { ... }, // arguments given to the call
}
For example, this will set a 10 second timeout on all calls which are not streams:
const etcd3 = new Etcd3({
defaultCallOptions: context => context.isStream ? {} : { deadline: Date.now() + 10000 },
});
The default options are shallow merged with any call-specific options.
For example this will always result in a 5 second timeout, regardless of
what the defaultCallOptions contains:
etcd3.get('foo').options({ deadline: Date.now() + 5000 })
OptionaldialDuration in milliseconds to wait while connecting before timing out. Defaults to 30 seconds.
OptionalfaultDefines the fault-handling policies for the client via Cockatiel. There are two policies: per-host, and global. Calls will call through the global policy, and then to a host policy. Each time the global policy retries, it will pick a new host to run the call on.
The recommended setup for this is to put a retry policy on the global
slot, and a circuit-breaker policy guarding each host. Additionally,
you can configure a backoff that the watch manager will use for
reconnecting watch streams.
By default, global is set to a three-retry policy and host is a
circuit breaker that will open (stop sending requests) for five seconds
after three consecutive failures. The watch backoff defaults to
Cockatiel's default exponential options (a max 30 second delay on
a decorrelated jitter).
For example, this is how you would manually specify the default options:
import { Etcd3, isRecoverableError } from 'etcd3';
import {
circuitBreaker,
ConsecutiveBreaker,
ExponentialBackoff,
handleWhen,
retry,
} from 'cockatiel';
const etcd = new Etcd3({
faultHandling: {
host: () =>
circuitBreaker(handleWhen(isRecoverableError), {
halfOpenAfter: 5_000,
breaker: new ConsecutiveBreaker(3),
}),
global: retry(handleWhen(isRecoverableError), { maxAttempts: 3 }),
watchBackoff: new ExponentialBackoff(),
},
});
Here's how you can disable all fault-handling logic:
import { Etcd3 } from 'etcd3';
import { NoopPolicy } from 'cockatiel';
const etcd = new Etcd3({
faultHandling: {
host: () => new NoopPolicy(),
global: new NoopPolicy(),
},
});
OptionalgrpcOptions to configure the gRPC client. These are channel options as enumerated in their C++ documentation. For example:
const etcd = new Etcd3({
// ...
grpcOptions: {
'grpc.http2.max_ping_strikes': 3,
},
})
A list of hosts to connect to. Hosts should include the https?:// prefix.
IOptions are passed into the client constructor to configure how the client connects to etcd. It supports defining multiple servers and configuring how load is balanced between those servers.