backport of commit 0ff9059967aa3fc0f2be0fd46926f9a7f1de5573 (#21124)

Co-authored-by: Josh Black <raskchanky@gmail.com>
This commit is contained in:
hc-github-team-secure-vault-core 2023-06-09 18:04:11 -04:00 committed by GitHub
parent 354d49e4eb
commit 6c26b96b31
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 22 additions and 7 deletions

View File

@ -6,6 +6,7 @@ package teststorage
import (
"fmt"
"io/ioutil"
"math/rand"
"os"
"time"
@ -36,6 +37,17 @@ func MakeInmemBackend(t testing.T, logger hclog.Logger) *vault.PhysicalBackendBu
}
}
func MakeLatentInmemBackend(t testing.T, logger hclog.Logger) *vault.PhysicalBackendBundle {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
jitter := r.Intn(20)
latency := time.Duration(r.Intn(15)) * time.Millisecond
pbb := MakeInmemBackend(t, logger)
latencyInjector := physical.NewTransactionalLatencyInjector(pbb.Backend, latency, jitter, logger)
pbb.Backend = latencyInjector
return pbb
}
func MakeInmemNonTransactionalBackend(t testing.T, logger hclog.Logger) *vault.PhysicalBackendBundle {
inm, err := inmem.NewInmem(nil, logger)
if err != nil {
@ -185,6 +197,10 @@ func InmemBackendSetup(conf *vault.CoreConfig, opts *vault.TestClusterOptions) {
opts.PhysicalFactory = SharedPhysicalFactory(MakeInmemBackend)
}
func InmemLatentBackendSetup(conf *vault.CoreConfig, opts *vault.TestClusterOptions) {
opts.PhysicalFactory = SharedPhysicalFactory(MakeLatentInmemBackend)
}
func InmemNonTransactionalBackendSetup(conf *vault.CoreConfig, opts *vault.TestClusterOptions) {
opts.PhysicalFactory = SharedPhysicalFactory(MakeInmemNonTransactionalBackend)
}

View File

@ -59,6 +59,9 @@ func NewLatencyInjector(b Backend, latency time.Duration, jitter int, logger log
}
// NewTransactionalLatencyInjector creates a new transactional LatencyInjector
// jitter is the random percent that latency will vary between.
// For example, if you specify latency = 50ms and jitter = 20, then for any
// given operation, the latency will be 50ms +- 10ms (20% of 50), or between 40 and 60ms.
func NewTransactionalLatencyInjector(b Backend, latency time.Duration, jitter int, logger log.Logger) *TransactionalLatencyInjector {
return &TransactionalLatencyInjector{
LatencyInjector: NewLatencyInjector(b, latency, jitter, logger),

View File

@ -1217,6 +1217,9 @@ type TestClusterOptions struct {
// if populated, the callback is called for every request
RequestResponseCallback func(logical.Backend, *logical.Request, *logical.Response)
// ABCDLoggerNames names the loggers according to our ABCD convention when generating 4 clusters
ABCDLoggerNames bool
}
type TestPluginConfig struct {

View File

@ -471,13 +471,6 @@ docs](#generate-disaster-recovery-operation-token) for more information.
PEM-format files that the secondary can use when unwrapping the token from the
primary. If this and ca_file are not given, defaults to system CA roots.
- `update_primary_addrs` `array: []`  List of cluster addresses for potential
primary clusters. These addresses will be pinged in sequence, and if any of them
respond successfully, these will be recorded as the new primary addresses. This is
a lighter weight version of specifying a token and should result in less disruption
of replication. Note that it's invalid to specify this and `token` in the same API call.
They are mutually exclusive.
### Sample Payload
```json