Skip to content

Commit

Permalink
Revert "Use DNS names for MySQL host and avoid envoy discovery"
Browse files Browse the repository at this point in the history
This reverts commit bef6f61.
  • Loading branch information
VinaySagarGonabavi committed Aug 9, 2024
1 parent e5cb6ce commit 1076dc7
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 23 deletions.
4 changes: 4 additions & 0 deletions paasta_tools/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2043,6 +2043,7 @@ class SystemPaastaConfigDict(TypedDict, total=False):
service_auth_token_settings: ProjectedSAVolume
service_auth_vault_role: str
always_authenticating_services: List[str]
mysql_port_mappings: Dict
vitess_images: Dict
superregion_to_region_mapping: Dict
vitess_tablet_types: List[str]
Expand Down Expand Up @@ -2762,6 +2763,9 @@ def get_service_auth_vault_role(self) -> str:
def get_always_authenticating_services(self) -> List[str]:
return self.config_dict.get("always_authenticating_services", [])

def get_mysql_port_mappings(self) -> Dict:
return self.config_dict.get("mysql_port_mappings", {})

def get_vitess_images(self) -> Dict:
return self.config_dict.get(
"vitess_images",
Expand Down
20 changes: 14 additions & 6 deletions paasta_tools/vitesscluster_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def get_tablet_pool_config(
cell: str,
db_name: str,
keyspace: str,
host: str,
port: str,
zk_address: str,
throttle_query_table: str,
throttle_metrics_threshold: str,
Expand Down Expand Up @@ -478,8 +478,8 @@ def get_tablet_pool_config(
},
externalDatastore={
"database": db_name,
"host": host,
"port": 3306,
"host": SOURCE_DB_HOST,
"port": port,
"user": "vt_app",
"credentialsSecret": {
"key": "/etc/credentials.yaml",
Expand Down Expand Up @@ -519,11 +519,19 @@ def get_keyspaces_config(

tablet_pools = []

mysql_port_mappings = load_system_paasta_config().get_mysql_port_mappings()

# get vttablets
tablet_types = load_system_paasta_config().get_vitess_tablet_types()
for tablet_type in tablet_types:
ecosystem = region.split("-")[-1]
host = f"mysql-{cluster}-{tablet_type}.dre-{ecosystem}"
# We don't have migration or reporting tablets in all clusters
if cluster not in mysql_port_mappings:
log.error(
f"MySQL Cluster {cluster} not found in system paasta config mysql_port_mappings"
)
if tablet_type not in mysql_port_mappings[cluster]:
continue
port = mysql_port_mappings[cluster][tablet_type]

# We use migration_replication delay for migration tablets and read_replication_delay for everything else
# Also throttling threshold for refresh and sanitized primaries is set at 30 seconds and everything else at 3 seconds
Expand Down Expand Up @@ -553,7 +561,7 @@ def get_keyspaces_config(
cell,
db_name,
keyspace,
host,
port,
zk_address,
throttle_query_table,
throttle_metrics_threshold,
Expand Down
76 changes: 59 additions & 17 deletions tests/test_vitesscluster_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
MOCK_SYSTEM_PAASTA_CONFIG = SystemPaastaConfig(
config={
"superregion_to_region_mapping": {"fake_superregion": "fake_region"},
"mysql_port_mappings": {
"fake_cluster": {
"primary": 1234,
"migration": 1234,
"read": 1234,
"reporting": 1234,
},
},
"vitess_tablet_pool_type_mapping": {
"primary": "externalmaster",
"migration": "externalreplica",
Expand Down Expand Up @@ -84,11 +92,11 @@
"extraEnv": [
{
"name": "VAULT_ADDR",
"value": "https://vault-dre.mock_region-devc.yelpcorp.com:8200",
"value": "https://vault-dre.mock_region.yelpcorp.com:8200",
},
{
"name": "VAULT_CACERT",
"value": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt",
"value": "/etc/vault/all_cas/acm-privateca-mock_region.crt",
},
{
"name": "VAULT_ROLEID",
Expand All @@ -111,9 +119,9 @@
],
"extraFlags": {
"mysql_auth_server_impl": "vault",
"mysql_auth_vault_addr": "https://vault-dre.mock_region-devc.yelpcorp.com:8200",
"mysql_auth_vault_addr": "https://vault-dre.mock_region.yelpcorp.com:8200",
"mysql_auth_vault_path": "secrets/vitess/vt-gate/vttablet_credentials.json",
"mysql_auth_vault_tls_ca": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt",
"mysql_auth_vault_tls_ca": "/etc/vault/all_cas/acm-privateca-mock_region.crt",
"mysql_auth_vault_ttl": "60s",
},
"extraLabels": {"tablet_type": "fake_keyspaces_migration"},
Expand Down Expand Up @@ -189,18 +197,18 @@
"volumeName": "vttablet-fake-credentials",
},
"database": "fake_keyspaces",
"host": "mysql-fake_cluster-primary.dre-devc",
"port": 3306,
"host": "169.254.255.254",
"port": 1234,
"user": "vt_app",
},
"extraEnv": [
{
"name": "VAULT_ADDR",
"value": "https://vault-dre.mock_region-devc.yelpcorp.com:8200",
"value": "https://vault-dre.mock_region.yelpcorp.com:8200",
},
{
"name": "VAULT_CACERT",
"value": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt",
"value": "/etc/vault/all_cas/acm-privateca-mock_region.crt",
},
{
"name": "TOPOLOGY_FLAGS",
Expand Down Expand Up @@ -303,9 +311,9 @@
"vttablet": {
"extraFlags": {
"db-credentials-server": "vault",
"db-credentials-vault-addr": "https://vault-dre.mock_region-devc.yelpcorp.com:8200",
"db-credentials-vault-addr": "https://vault-dre.mock_region.yelpcorp.com:8200",
"db-credentials-vault-path": "secrets/vitess/vt-tablet/vttablet_credentials.json",
"db-credentials-vault-tls-ca": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt",
"db-credentials-vault-tls-ca": "/etc/vault/all_cas/acm-privateca-mock_region.crt",
"db-credentials-vault-ttl": "60s",
"db_charset": "utf8mb4",
"dba_pool_size": "4",
Expand Down Expand Up @@ -377,18 +385,18 @@
"volumeName": "vttablet-fake-credentials",
},
"database": "fake_keyspaces",
"host": "mysql-fake_cluster-migration.dre-devc",
"port": 3306,
"host": "169.254.255.254",
"port": 1234,
"user": "vt_app",
},
"extraEnv": [
{
"name": "VAULT_ADDR",
"value": "https://vault-dre.mock_region-devc.yelpcorp.com:8200",
"value": "https://vault-dre.mock_region.yelpcorp.com:8200",
},
{
"name": "VAULT_CACERT",
"value": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt",
"value": "/etc/vault/all_cas/acm-privateca-mock_region.crt",
},
{
"name": "TOPOLOGY_FLAGS",
Expand Down Expand Up @@ -491,9 +499,9 @@
"vttablet": {
"extraFlags": {
"db-credentials-server": "vault",
"db-credentials-vault-addr": "https://vault-dre.mock_region-devc.yelpcorp.com:8200",
"db-credentials-vault-addr": "https://vault-dre.mock_region.yelpcorp.com:8200",
"db-credentials-vault-path": "secrets/vitess/vt-tablet/vttablet_credentials.json",
"db-credentials-vault-tls-ca": "/etc/vault/all_cas/acm-privateca-mock_region-devc.crt",
"db-credentials-vault-tls-ca": "/etc/vault/all_cas/acm-privateca-mock_region.crt",
"db-credentials-vault-ttl": "60s",
"db_charset": "utf8mb4",
"dba_pool_size": "4",
Expand Down Expand Up @@ -628,7 +636,7 @@
@pytest.fixture
def mock_vitess_deployment_config():
with mock.patch.object(
VitessDeploymentConfig, "get_region", return_value="mock_region-devc"
VitessDeploymentConfig, "get_region", return_value="mock_region"
), mock.patch.object(
VitessDeploymentConfig, "get_container_env", return_value=[]
), mock.patch.object(
Expand Down Expand Up @@ -674,6 +682,40 @@ def test_load_vitess_service_instance_configs(
assert vitess_service_instance_configs == VITESS_CONFIG


@mock.patch(
"paasta_tools.vitesscluster_tools.load_vitess_instance_config",
autospec=True,
)
@mock.patch(
"paasta_tools.vitesscluster_tools.load_system_paasta_config",
autospec=True,
)
def test_load_vitess_service_instance_configs_missing_mysql_cluster_mapping_entry(
mock_load_system_paasta_config,
mock_load_vitess_instance_config,
mock_vitess_deployment_config,
):
mock_load_vitess_instance_config.return_value = VitessDeploymentConfig(
service="fake_service",
instance="fake_instance",
cluster="fake_cluster",
config_dict=CONFIG_DICT,
branch_dict={},
soa_dir="fake_soa_dir",
)
mock_load_system_paasta_config.return_value = SystemPaastaConfig(
config={},
directory="/fake/config/directory",
)
with pytest.raises(KeyError):
load_vitess_service_instance_configs(
service="fake_service",
soa_dir="fake_soa_dir",
cluster="fake_cluster",
instance="fake_instance",
)


@mock.patch("paasta_tools.vitesscluster_tools.load_v2_deployments_json", autospec=True)
@mock.patch(
"paasta_tools.vitesscluster_tools.load_service_instance_config",
Expand Down

0 comments on commit 1076dc7

Please sign in to comment.