port external test fix (#10263)

This commit is contained in:
Hridoy Roy 2020-10-29 10:55:26 -07:00 committed by GitHub
parent f8a248ce48
commit fc94e16805
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 16 deletions

View file

@ -16,18 +16,16 @@ import (
) )
func TestMountTableMetrics(t *testing.T) { func TestMountTableMetrics(t *testing.T) {
inm := metrics.NewInmemSink(time.Minute, time.Minute*10) clusterName := "mycluster"
clusterSink := metricsutil.NewClusterMetricSink("mycluster", inm)
clusterSink.GaugeInterval = time.Second
conf := &vault.CoreConfig{ conf := &vault.CoreConfig{
BuiltinRegistry: vault.NewMockBuiltinRegistry(), BuiltinRegistry: vault.NewMockBuiltinRegistry(),
MetricsHelper: metricsutil.NewMetricsHelper(inm, true), ClusterName: clusterName,
MetricSink: clusterSink,
} }
cluster := vault.NewTestCluster(t, conf, &vault.TestClusterOptions{ cluster := vault.NewTestCluster(t, conf, &vault.TestClusterOptions{
KeepStandbysSealed: false, KeepStandbysSealed: false,
HandlerFunc: vaulthttp.Handler, HandlerFunc: vaulthttp.Handler,
NumCores: 2, NumCores: 2,
CoreMetricSinkProvider: testMetricSinkProvider(time.Minute),
}) })
cluster.Start() cluster.Start()
@ -129,19 +127,26 @@ func gaugeConditionCheck(comparator string, compareVal int, compareToVal int) er
return nil 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) { func TestLeaderReElectionMetrics(t *testing.T) {
inm := metrics.NewInmemSink(time.Minute, time.Minute*10) clusterName := "mycluster"
clusterSink := metricsutil.NewClusterMetricSink("mycluster", inm)
clusterSink.GaugeInterval = time.Second
conf := &vault.CoreConfig{ conf := &vault.CoreConfig{
BuiltinRegistry: vault.NewMockBuiltinRegistry(), BuiltinRegistry: vault.NewMockBuiltinRegistry(),
MetricsHelper: metricsutil.NewMetricsHelper(inm, true), ClusterName: clusterName,
MetricSink: clusterSink,
} }
cluster := vault.NewTestCluster(t, conf, &vault.TestClusterOptions{ cluster := vault.NewTestCluster(t, conf, &vault.TestClusterOptions{
KeepStandbysSealed: false, KeepStandbysSealed: false,
HandlerFunc: vaulthttp.Handler, HandlerFunc: vaulthttp.Handler,
NumCores: 2, NumCores: 2,
CoreMetricSinkProvider: testMetricSinkProvider(time.Minute),
}) })
cluster.Start() cluster.Start()

View file

@ -1048,6 +1048,8 @@ type TestClusterOptions struct {
// RaftAddressProvider should only be specified if the underlying physical // RaftAddressProvider should only be specified if the underlying physical
// storage is Raft. // storage is Raft.
RaftAddressProvider raftlib.ServerAddressProvider RaftAddressProvider raftlib.ServerAddressProvider
CoreMetricSinkProvider func(clusterName string) (*metricsutil.ClusterMetricSink, *metricsutil.MetricsHelper)
} }
var DefaultNumCores = 3 var DefaultNumCores = 3
@ -1412,6 +1414,7 @@ func NewTestCluster(t testing.T, base *CoreConfig, opts *TestClusterOptions) *Te
coreConfig.MetricSink = base.MetricSink coreConfig.MetricSink = base.MetricSink
coreConfig.SecureRandomReader = base.SecureRandomReader coreConfig.SecureRandomReader = base.SecureRandomReader
coreConfig.DisableSentinelTrace = base.DisableSentinelTrace coreConfig.DisableSentinelTrace = base.DisableSentinelTrace
coreConfig.ClusterName = base.ClusterName
if base.BuiltinRegistry != nil { if base.BuiltinRegistry != nil {
coreConfig.BuiltinRegistry = base.BuiltinRegistry coreConfig.BuiltinRegistry = base.BuiltinRegistry
@ -1467,6 +1470,9 @@ func NewTestCluster(t testing.T, base *CoreConfig, opts *TestClusterOptions) *Te
testApplyEntBaseConfig(coreConfig, base) testApplyEntBaseConfig(coreConfig, base)
} }
if coreConfig.ClusterName == "" {
coreConfig.ClusterName = t.Name()
}
if coreConfig.ClusterHeartbeatInterval == 0 { if coreConfig.ClusterHeartbeatInterval == 0 {
// Set this lower so that state populates quickly to standby nodes // 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) metrics.DefaultInmemSignal(inm)
localConfig.MetricsHelper = metricsutil.NewMetricsHelper(inm, false) localConfig.MetricsHelper = metricsutil.NewMetricsHelper(inm, false)
} }
if opts != nil && opts.CoreMetricSinkProvider != nil {
localConfig.MetricSink, localConfig.MetricsHelper = opts.CoreMetricSinkProvider(localConfig.ClusterName)
}
c, err := NewCore(&localConfig) c, err := NewCore(&localConfig)
if err != nil { if err != nil {