Skip to content

Commit

Permalink
Ydb configure features, part 2 (#13920)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorres authored Jan 30, 2025
1 parent 0e706fd commit bb6255c
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 32 deletions.
40 changes: 32 additions & 8 deletions ydb/tools/cfg/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
import os
from concurrent.futures import ThreadPoolExecutor

from ydb.tools.cfg import types, validation, walle
from ydb.tools.cfg import types, validation, walle, utils

from ydb.core.protos import config_pb2

DEFAULT_LOG_LEVEL = types.LogLevels.NOTICE

Expand Down Expand Up @@ -288,10 +290,6 @@ def __init__(self, template, host_info_provider, validator=None, database=None,
self._host_info_provider = walle.NopHostsInformationProvider()

self.__translated_storage_pools_deprecated = None
self.__translated_hosts = None
self.__racks = {}
self.__bodies = {}
self.__dcs = {}
self.use_new_style_kikimr_cfg = self.__cluster_description.get("use_new_style_kikimr_cfg", use_new_style_cfg)
self.need_generate_app_config = self.__cluster_description.get("need_generate_app_config", False)
self.need_txt_files = self.__cluster_description.get("need_txt_files", True)
Expand All @@ -306,6 +304,7 @@ def __init__(self, template, host_info_provider, validator=None, database=None,
self.memory_controller_config = self.__cluster_description.get("memory_controller_config")
self.channel_profile_config = self.__cluster_description.get("channel_profile_config")
self.immediate_controls_config = self.__cluster_description.get("immediate_controls_config")
self.cms_config = self.__cluster_description.get("cms_config")
self.pdisk_key_config = self.__cluster_description.get("pdisk_key_config", {})
if not self.need_txt_files and not self.use_new_style_kikimr_cfg:
assert "cannot remove txt files without new style kikimr cfg!"
Expand Down Expand Up @@ -368,8 +367,8 @@ def security_settings(self):
return self.__cluster_description.get("security_settings", {})

@property
def forbid_implicit_storage_pools(self):
return self.__cluster_description.get("forbid_implicit_storage_pools", False)
def security_config(self):
return self.__cluster_description.get("security_config", {})

def _get_datacenter(self, host_description):
if host_description.get("datacenter") is not None:
Expand Down Expand Up @@ -622,6 +621,16 @@ def domains(self):
)
return domains

@property
def domains_config(self):
domains_config_dict = self.__cluster_description.get("domains_config", {})
if domains_config_dict == {}:
return None

domains_config = config_pb2.TDomainsConfig()
utils.wrap_parse_dict(domains_config_dict, domains_config)
return domains_config

@staticmethod
def _get_domain_tenants(domain_description):
tenants = domain_description.get("databases", [])
Expand Down Expand Up @@ -662,6 +671,16 @@ def use_auth(self):
# Log Stuff
@property
def log_config(self):
# `config.yaml` style
log_config_dict = self.__cluster_description.get("log_config", {})
if log_config_dict != {}:
log_config = config_pb2.TLogConfig()
if "default_level" not in log_config_dict:
log_config["default_level"] = self.default_log_level
utils.wrap_parse_dict(log_config_dict, log_config)
return log_config

# Old, `template.yaml` style
log_config = copy.deepcopy(self.__cluster_description.get("log", {}))

if "entries" in log_config:
Expand Down Expand Up @@ -689,7 +708,12 @@ def default_log_level(self):

@property
def grpc_config(self):
return merge_with_default(GRPC_DEFAULT_CONFIG, self.__cluster_description.get("grpc", {}))
grpc_config = merge_with_default(GRPC_DEFAULT_CONFIG, self.__cluster_description.get("grpc", {}))
# specifying both `port` and `ssl_port` leads to erroneous behavior in ydbd, half of the incoming
# connections use tls, half do not, so this is prohibited
if grpc_config.get("ssl_port") is not None:
del grpc_config["port"]
return grpc_config

@property
def dynamicnameservice_config(self):
Expand Down
3 changes: 0 additions & 3 deletions ydb/tools/cfg/k8s_api/k8s_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,11 @@ def get_rack(self, hostname):

labels = self._cache.get(hostname)
if labels and self._k8s_rack_label in labels:
logging.info(f"get_rack invoked on {hostname}, value {labels[self._k8s_rack_label]}")
return labels[self._k8s_rack_label]
logging.info(f"rack not found for hostname {hostname}")
return ""

def get_datacenter(self, hostname):
logging.info(f"get_datacenter invoked on {hostname}")

if self._k8s_dc_label is None:
return "defaultDC"

Expand Down
70 changes: 49 additions & 21 deletions ydb/tools/cfg/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def __init__(
"failure_injection.txt": None,
"pdisk_key.txt": None,
"immediate_controls_config.txt": None,
"cms_config.txt": None,
}
self.__optional_config_files = set(
(
Expand All @@ -126,7 +127,6 @@ def __init__(
self.__tracing = tracing
else:
self.__tracing = None
self.__write_mbus_settings_to_kikimr_cfg = False

@property
def auth_txt(self):
Expand Down Expand Up @@ -222,10 +222,6 @@ def vdisks_txt(self):
def sqs_txt(self):
return self.__proto_config("sqs.txt", config_pb2.TSqsConfig, self.__cluster_details.get_service("sqs"))

@property
def cms_txt(self):
return self.__proto_config("cms.txt", cms_pb2.TCmsConfig, self.__cluster_details.get_service("cms"))

@property
def rb_txt(self):
return self.__proto_config(
Expand Down Expand Up @@ -276,6 +272,20 @@ def immediate_controls_config_txt(self):
def immediate_controls_config_txt_enabled(self):
return self.__proto_config("immediate_controls_config.txt").ByteSize() > 0

# Old `template.yaml` CMS style
@property
def cms_txt(self):
return self.__proto_config("cms.txt", cms_pb2.TCmsConfig, self.__cluster_details.get_service("cms"))

# New `config.yaml` CMS style
@property
def cms_config_txt(self):
return self.__proto_config("cms_config.txt", cms_pb2.TCmsConfig, self.__cluster_details.cms_config)

@property
def cms_config_txt_enabled(self):
return self.__proto_config("cms_config.txt").ByteSize() > 0

@property
def mbus_enabled(self):
mbus_config = self.__cluster_details.get_service("message_bus_config")
Expand Down Expand Up @@ -555,7 +565,6 @@ def get_normalized_config(self):
if 'channel_profile_config' in normalized_config:
for profile in normalized_config['channel_profile_config']['profile']:
for channel in profile['channel']:
print(channel)
channel['pdisk_category'] = int(channel['pdisk_category'])
if 'system_tablets' in normalized_config:
for tablets in normalized_config['system_tablets'].values():
Expand Down Expand Up @@ -656,6 +665,8 @@ def get_app_config(self):
app_config.PDiskKeyConfig.CopyFrom(self.pdisk_key_txt)
if self.immediate_controls_config_txt_enabled:
app_config.ImmediateControlsConfig.CopyFrom(self.immediate_controls_config_txt)
if self.cms_config_txt_enabled:
app_config.CmsConfig.CopyFrom(self.cms_config_txt)
return app_config

def __proto_config(self, config_file, config_class=None, cluster_details_for_field=None):
Expand Down Expand Up @@ -1001,24 +1012,37 @@ def __n_to_select(self):

return min(5, n_to_select_candidate)

def __configure_security_settings(self, domains_config):
utils.apply_config_changes(
domains_config.SecurityConfig,
self.__cluster_details.security_settings,
)
def __configure_security_config(self, domains_config):
if self.__cluster_details.security_config != {}: # consistent with `config.yaml`
utils.apply_config_changes(
domains_config.SecurityConfig,
self.__cluster_details.security_config,
)
else:
utils.apply_config_changes( # backward compatibility for old templates
domains_config.SecurityConfig,
self.__cluster_details.security_settings,
)

def __generate_domains_txt(self):
domains_config = self.__cluster_details.domains_config
if domains_config is None:
self.__generate_domains_from_old_domains_key()
else:
self.__generate_domains_from_proto(domains_config)

def __generate_domains_from_proto(self, domains_config):
self.__configure_security_config(domains_config)
self.__proto_configs["domains.txt"] = domains_config

def __generate_domains_from_old_domains_key(self):
self.__proto_configs["domains.txt"] = config_pb2.TDomainsConfig()

domains_config = self.__proto_configs["domains.txt"]

if self.__cluster_details.forbid_implicit_storage_pools:
domains_config.ForbidImplicitStoragePools = True

self.__configure_security_settings(domains_config)
self.__configure_security_config(domains_config)

tablet_types = self.__tablet_types

for domain_description in self.__cluster_details.domains:
domain_id = domain_description.domain_id
domain_name = domain_description.domain_name
Expand Down Expand Up @@ -1217,11 +1241,15 @@ def _configure_default_state_storage(self, domains_config, domain_id):
state_storage_cfg.Ring.Node.extend(selected_ids)

def __generate_log_txt(self):
self.__proto_configs["log.txt"] = config_pb2.TLogConfig()
utils.apply_config_changes(
self.__proto_configs["log.txt"],
self.__cluster_details.log_config,
)
log_config = self.__cluster_details.log_config
if isinstance(log_config, config_pb2.TLogConfig):
self.__proto_configs["log.txt"] = log_config
else:
self.__proto_configs["log.txt"] = config_pb2.TLogConfig()
utils.apply_config_changes(
self.__proto_configs["log.txt"],
self.__cluster_details.log_config,
)

def __generate_names_txt(self):
self.__proto_configs["names.txt"] = config_pb2.TStaticNameserviceConfig()
Expand Down

0 comments on commit bb6255c

Please sign in to comment.