port external test fix (#10263)
This commit is contained in:
parent
f8a248ce48
commit
fc94e16805
|
@ -16,18 +16,16 @@ import (
|
|||
)
|
||||
|
||||
func TestMountTableMetrics(t *testing.T) {
|
||||
inm := metrics.NewInmemSink(time.Minute, time.Minute*10)
|
||||
clusterSink := metricsutil.NewClusterMetricSink("mycluster", inm)
|
||||
clusterSink.GaugeInterval = time.Second
|
||||
clusterName := "mycluster"
|
||||
conf := &vault.CoreConfig{
|
||||
BuiltinRegistry: vault.NewMockBuiltinRegistry(),
|
||||
MetricsHelper: metricsutil.NewMetricsHelper(inm, true),
|
||||
MetricSink: clusterSink,
|
||||
ClusterName: clusterName,
|
||||
}
|
||||
cluster := vault.NewTestCluster(t, conf, &vault.TestClusterOptions{
|
||||
KeepStandbysSealed: false,
|
||||
HandlerFunc: vaulthttp.Handler,
|
||||
NumCores: 2,
|
||||
CoreMetricSinkProvider: testMetricSinkProvider(time.Minute),
|
||||
})
|
||||
|
||||
cluster.Start()
|
||||
|
@ -129,19 +127,26 @@ func gaugeConditionCheck(comparator string, compareVal int, compareToVal int) er
|
|||
return nil
|
||||
}
|
||||
|
||||
func testMetricSinkProvider(gaugeInterval time.Duration) func(string) (*metricsutil.ClusterMetricSink, *metricsutil.MetricsHelper) {
|
||||
return func(clusterName string) (*metricsutil.ClusterMetricSink, *metricsutil.MetricsHelper) {
|
||||
inm := metrics.NewInmemSink(1000000*time.Hour, 2000000*time.Hour)
|
||||
clusterSink := metricsutil.NewClusterMetricSink(clusterName, inm)
|
||||
clusterSink.GaugeInterval = gaugeInterval
|
||||
return clusterSink, metricsutil.NewMetricsHelper(inm, false)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLeaderReElectionMetrics(t *testing.T) {
|
||||
inm := metrics.NewInmemSink(time.Minute, time.Minute*10)
|
||||
clusterSink := metricsutil.NewClusterMetricSink("mycluster", inm)
|
||||
clusterSink.GaugeInterval = time.Second
|
||||
clusterName := "mycluster"
|
||||
conf := &vault.CoreConfig{
|
||||
BuiltinRegistry: vault.NewMockBuiltinRegistry(),
|
||||
MetricsHelper: metricsutil.NewMetricsHelper(inm, true),
|
||||
MetricSink: clusterSink,
|
||||
ClusterName: clusterName,
|
||||
}
|
||||
cluster := vault.NewTestCluster(t, conf, &vault.TestClusterOptions{
|
||||
KeepStandbysSealed: false,
|
||||
HandlerFunc: vaulthttp.Handler,
|
||||
NumCores: 2,
|
||||
CoreMetricSinkProvider: testMetricSinkProvider(time.Minute),
|
||||
})
|
||||
|
||||
cluster.Start()
|
||||
|
|
|
@ -1048,6 +1048,8 @@ type TestClusterOptions struct {
|
|||
// RaftAddressProvider should only be specified if the underlying physical
|
||||
// storage is Raft.
|
||||
RaftAddressProvider raftlib.ServerAddressProvider
|
||||
|
||||
CoreMetricSinkProvider func(clusterName string) (*metricsutil.ClusterMetricSink, *metricsutil.MetricsHelper)
|
||||
}
|
||||
|
||||
var DefaultNumCores = 3
|
||||
|
@ -1412,6 +1414,7 @@ func NewTestCluster(t testing.T, base *CoreConfig, opts *TestClusterOptions) *Te
|
|||
coreConfig.MetricSink = base.MetricSink
|
||||
coreConfig.SecureRandomReader = base.SecureRandomReader
|
||||
coreConfig.DisableSentinelTrace = base.DisableSentinelTrace
|
||||
coreConfig.ClusterName = base.ClusterName
|
||||
|
||||
if base.BuiltinRegistry != nil {
|
||||
coreConfig.BuiltinRegistry = base.BuiltinRegistry
|
||||
|
@ -1467,6 +1470,9 @@ func NewTestCluster(t testing.T, base *CoreConfig, opts *TestClusterOptions) *Te
|
|||
|
||||
testApplyEntBaseConfig(coreConfig, base)
|
||||
}
|
||||
if coreConfig.ClusterName == "" {
|
||||
coreConfig.ClusterName = t.Name()
|
||||
}
|
||||
|
||||
if coreConfig.ClusterHeartbeatInterval == 0 {
|
||||
// Set this lower so that state populates quickly to standby nodes
|
||||
|
@ -1758,6 +1764,9 @@ func (testCluster *TestCluster) newCore(t testing.T, idx int, coreConfig *CoreCo
|
|||
metrics.DefaultInmemSignal(inm)
|
||||
localConfig.MetricsHelper = metricsutil.NewMetricsHelper(inm, false)
|
||||
}
|
||||
if opts != nil && opts.CoreMetricSinkProvider != nil {
|
||||
localConfig.MetricSink, localConfig.MetricsHelper = opts.CoreMetricSinkProvider(localConfig.ClusterName)
|
||||
}
|
||||
|
||||
c, err := NewCore(&localConfig)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue