Skip to content

Commit

Permalink
feat: fix discovery flags configuration keys
Browse files Browse the repository at this point in the history
Signed-off-by: Manan Gupta <[email protected]>
  • Loading branch information
GuptaManan100 committed Dec 28, 2024
1 parent dce8d00 commit afa0322
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 6 deletions.
6 changes: 5 additions & 1 deletion go/test/endtoend/cluster/vtgate_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,11 @@ type VtgateProcess struct {
}

type VTGateConfiguration struct {
TransactionMode string `json:"transaction_mode,omitempty"`
TransactionMode string `json:"transaction_mode,omitempty"`
DiscoveryLowReplicationLag string `json:"discovery_low_replication_lag,omitempty"`
DiscoveryHighReplicationLag string `json:"discovery_high_replication_lag,omitempty"`
DiscoveryMinServingVttablets string `json:"discovery_min_number_serving_vttablets,omitempty"`
DiscoveryLegacyReplicationLagAlgo string `json:"discovery_legacy_replication_lag_algorithm"`
}

// ToJSONString will marshal this configuration as JSON
Expand Down
75 changes: 75 additions & 0 deletions go/test/endtoend/vtgate/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,6 +814,81 @@ func TestDDLTargeted(t *testing.T) {
utils.AssertMatches(t, conn, `select id from ddl_targeted`, `[[INT64(1)]]`)
}

// TestDynamicConfig tests the dynamic configurations.
func TestDynamicConfig(t *testing.T) {
t.Run("DiscoveryLowReplicationLag", func(t *testing.T) {
// Test initial config value
err := clusterInstance.VtgateProcess.WaitForConfig(`"discovery_low_replication_lag":30000000000`)
require.NoError(t, err)
defer func() {
// Restore default back.
clusterInstance.VtgateProcess.Config.DiscoveryLowReplicationLag = "30s"
err = clusterInstance.VtgateProcess.RewriteConfiguration()
require.NoError(t, err)
}()
clusterInstance.VtgateProcess.Config.DiscoveryLowReplicationLag = "15s"
err = clusterInstance.VtgateProcess.RewriteConfiguration()
require.NoError(t, err)
// Test final config value.
err = clusterInstance.VtgateProcess.WaitForConfig(`"discovery_low_replication_lag":"15s"`)
require.NoError(t, err)
})

t.Run("DiscoveryHighReplicationLag", func(t *testing.T) {
// Test initial config value
err := clusterInstance.VtgateProcess.WaitForConfig(`"discovery_high_replication_lag":7200000000000`)
require.NoError(t, err)
defer func() {
// Restore default back.
clusterInstance.VtgateProcess.Config.DiscoveryHighReplicationLag = "2h"
err = clusterInstance.VtgateProcess.RewriteConfiguration()
require.NoError(t, err)
}()
clusterInstance.VtgateProcess.Config.DiscoveryHighReplicationLag = "1h"
err = clusterInstance.VtgateProcess.RewriteConfiguration()
require.NoError(t, err)
// Test final config value.
err = clusterInstance.VtgateProcess.WaitForConfig(`"discovery_high_replication_lag":"1h"`)
require.NoError(t, err)
})

t.Run("DiscoveryMinServingVttablets", func(t *testing.T) {
// Test initial config value
err := clusterInstance.VtgateProcess.WaitForConfig(`"discovery_min_number_serving_vttablets":2`)
require.NoError(t, err)
defer func() {
// Restore default back.
clusterInstance.VtgateProcess.Config.DiscoveryMinServingVttablets = "2"
err = clusterInstance.VtgateProcess.RewriteConfiguration()
require.NoError(t, err)
}()
clusterInstance.VtgateProcess.Config.DiscoveryMinServingVttablets = "1"
err = clusterInstance.VtgateProcess.RewriteConfiguration()
require.NoError(t, err)
// Test final config value.
err = clusterInstance.VtgateProcess.WaitForConfig(`"discovery_min_number_serving_vttablets":"1"`)
require.NoError(t, err)
})

t.Run("DiscoveryLegacyReplicationLagAlgo", func(t *testing.T) {
// Test initial config value
err := clusterInstance.VtgateProcess.WaitForConfig(`"discovery_legacy_replication_lag_algorithm":""`)
require.NoError(t, err)
defer func() {
// Restore default back.
clusterInstance.VtgateProcess.Config.DiscoveryLegacyReplicationLagAlgo = "true"
err = clusterInstance.VtgateProcess.RewriteConfiguration()
require.NoError(t, err)
}()
clusterInstance.VtgateProcess.Config.DiscoveryLegacyReplicationLagAlgo = "false"
err = clusterInstance.VtgateProcess.RewriteConfiguration()
require.NoError(t, err)
// Test final config value.
err = clusterInstance.VtgateProcess.WaitForConfig(`"discovery_legacy_replication_lag_algorithm":"false"`)
require.NoError(t, err)
})
}

func TestLookupErrorMetric(t *testing.T) {
conn, closer := start(t)
defer closer()
Expand Down
9 changes: 4 additions & 5 deletions go/vt/discovery/replicationlag.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,34 +28,33 @@ import (
)

var (
configKey = viperutil.KeyPrefixFunc("discovery")
// lowReplicationLag defines the duration that replication lag is low enough that the VTTablet is considered healthy.
lowReplicationLag = viperutil.Configure(
configKey("low_replication_lag"),
"discovery_low_replication_lag",
viperutil.Options[time.Duration]{
FlagName: "discovery_low_replication_lag",
Default: 30 * time.Second,
Dynamic: true,
},
)
highReplicationLagMinServing = viperutil.Configure(
configKey("high_replication_lag"),
"discovery_high_replication_lag",
viperutil.Options[time.Duration]{
FlagName: "discovery_high_replication_lag_minimum_serving",
Default: 2 * time.Hour,
Dynamic: true,
},
)
minNumTablets = viperutil.Configure(
configKey("min_number_serving_vttablets"),
"discovery_min_number_serving_vttablets",
viperutil.Options[int]{
FlagName: "min_number_serving_vttablets",
Default: 2,
Dynamic: true,
},
)
legacyReplicationLagAlgorithm = viperutil.Configure(
configKey("legacy_replication_lag_algorithm"),
"discovery_legacy_replication_lag_algorithm",
viperutil.Options[bool]{
FlagName: "legacy_replication_lag_algorithm",
Default: true,
Expand Down

0 comments on commit afa0322

Please sign in to comment.