Skip to content

Commit

Permalink
feat: support nameservice_config
Browse files Browse the repository at this point in the history
  • Loading branch information
Jorres committed Jan 23, 2025
1 parent fbbae90 commit dffe95a
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 15 deletions.
4 changes: 4 additions & 0 deletions ydb/tools/cfg/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,10 @@ def grpc_config(self):
def dynamicnameservice_config(self):
return merge_with_default(DYNAMIC_NAME_SERVICE, self.__cluster_description.get("dynamicnameservice", {}))

@property
def nameservice_config(self):
return self.__cluster_description.get("nameservice_config")

@property
def grpc_port(self):
return self.grpc_config.get("port")
Expand Down
40 changes: 40 additions & 0 deletions ydb/tools/cfg/data.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@



## `drives`

host_configs in template and host_configs in config.yaml have different structure

`host_configs` in `config.yaml` has a very defined structure and can be written to config.yaml type-safely
because it's specified by proto

`host_configs` in `template` seems to be untyped and somehow parsed without validation by ydb_configure

why not move to parsing the host_configs with proto? because this merge will never succeed with the right team



## we need to know the set of options that gets dumped into `config.yaml` direcly



## Experiments


---

# Data

## We only run ydb_configure after we receive nodes from ik8s marked with labels

- it means we only prepare `config_cluster_template.yaml`, not the `config.yaml`, when we deploy a new region
- effectively it slows us down because we postpone steps that we COULD do earlier (such as copying `immediate_control_board` into config.yaml)

## `host-configs` is the only known option that is not required in runtime


## Do we allow copying of arbitrary fields (such as immediate_control_board)?

No. Copying is bad because typos can render config:
- either unusable (kikimr does not boot)
- or even more inconvenient, ignored by ydbd entirely
32 changes: 32 additions & 0 deletions ydb/tools/cfg/questions2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@





## we need to know the set of options that gets dumped into `config.yaml` direcly





## Experiments

- run my build and expect `host_configs` to be generated

---

# Data

## We only run ydb_configure after we receive nodes from ik8s marked with labels

- it means we only prepare `config_cluster_template.yaml`, not the `config.yaml`, when we deploy a new region
- effectively it slows us down because we postpone steps that we COULD do earlier (such as copying `immediate_control_board` into config.yaml)

## `host-configs` is the only known option that is not required in runtime


## Do we allow copying of arbitrary fields (such as immediate_control_board)?

No. Copying is bad because typos can render config:
- either unusable (kikimr does not boot)
- or even more inconvenient, ignored by ydbd entirely
24 changes: 9 additions & 15 deletions ydb/tools/cfg/static.py
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,6 @@ def mbus_enabled(self):
@property
def host_configs(self):
return self.__cluster_details.get_service("host_configs")

@property
def table_service_config(self):
return self.__cluster_details.get_service("table_service_config")
Expand Down Expand Up @@ -1225,6 +1224,7 @@ def __generate_log_txt(self):

def __generate_names_txt(self):
self.__proto_configs["names.txt"] = config_pb2.TStaticNameserviceConfig()
json_format.ParseDict(utils.convert_keys(self.__cluster_details.nameservice_config), self.names_txt)

for host in self.__cluster_details.hosts:
node = self.names_txt.Node.add(
Expand All @@ -1250,7 +1250,13 @@ def __generate_names_txt(self):

if self.__cluster_details.use_cluster_uuid:
accepted_uuids = self.__cluster_details.accepted_cluster_uuids
cluster_uuid = self.__cluster_details.cluster_uuid

# cluster_uuid can be initialized from `nameservice_config` proto, same as `config.yaml`,
# OR in the old manner, through `cluster_uuid: ...` key in `template.yaml`
cluster_uuid = self.names_txt.ClusterUUID # already read from proto
if cluster_uuid is None:
cluster_uuid = self.__cluster_details.cluster_uuid # fall back to `cluster_uuid: ...`

cluster_uuid = "ydb:{}".format(utils.uuid()) if cluster_uuid is None else cluster_uuid
self.names_txt.ClusterUUID = cluster_uuid
self.names_txt.AcceptUUID.append(cluster_uuid)
Expand Down Expand Up @@ -1280,22 +1286,10 @@ def __generate_sys_txt(self):
self.__generate_sys_txt_advanced()

def __generate_tracing_txt(self):
def get_camel_case_string(snake_str):
components = snake_str.split('_')
return ''.join(x.capitalize() for x in components)

def convert_keys(data):
if isinstance(data, dict):
return {get_camel_case_string(k): convert_keys(v) for k, v in data.items()}
elif isinstance(data, list):
return [convert_keys(item) for item in data]
else:
return data

pb = config_pb2.TAppConfig()
if self.__tracing:
tracing_pb = pb.TracingConfig
json_format.ParseDict(convert_keys(self.__tracing), tracing_pb)
json_format.ParseDict(utils.convert_keys(self.__tracing), tracing_pb)
self.__proto_configs["tracing.txt"] = pb

def __generate_sys_txt_advanced(self):
Expand Down
17 changes: 17 additions & 0 deletions ydb/tools/cfg/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,3 +153,20 @@ def apply_config_changes(target, changes, fix_names=None):
def random_int(low, high, *seed):
random.seed(''.join(map(str, seed)))
return random.randint(low, high)


def get_camel_case_string(snake_str):
abbreviations = {
'uuid': 'UUID',
}
components = snake_str.split('_')
return ''.join(abbreviations.get(x.lower(), x.capitalize()) for x in components)


def convert_keys(data):
if isinstance(data, dict):
return {get_camel_case_string(k): convert_keys(v) for k, v in data.items()}
elif isinstance(data, list):
return [convert_keys(item) for item in data]
else:
return data

0 comments on commit dffe95a

Please sign in to comment.