From 54af0626f6dbbe3ae234368c8b3cfa6e74aeda36 Mon Sep 17 00:00:00 2001
From: Vartan Babayan <vardbabayan.work@gmail.com>
Date: Tue, 16 Jul 2024 18:14:24 +0300
Subject: [PATCH] feat: add instance configuration params at startup

---
 src/cli/run.rs               |  1 +
 src/config.rs                | 16 +++++++++--
 test/conftest.py             | 10 +++----
 test/int/test_config_file.py | 54 ++++++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+), 7 deletions(-)

diff --git a/src/cli/run.rs b/src/cli/run.rs
index 258c8d6c65..eff78f69bd 100644
--- a/src/cli/run.rs
+++ b/src/cli/run.rs
@@ -24,6 +24,7 @@ pub fn main(args: args::Run) -> ! {
     // Set the log level as soon as possible to not miss any messages during
     // initialization.
     tlog::set_log_level(config.instance.log_level());
+    config.log_config_params();
 
     if let Some(filename) = &config.instance.service_password_file {
         if let Err(e) = crate::pico_service::read_pico_service_password_from_file(filename) {
diff --git a/src/config.rs b/src/config.rs
index db407f0098..b0db59a20d 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -589,7 +589,7 @@ Using configuration file '{args_path}'.");
         for path in &leaf_field_paths::<PicodataConfig>() {
             let value = donor
                 .get_field_as_rmpv(path)
-                .expect("this should be tested thouroughly");
+                .expect("this should be tested thoroughly");
 
             if !value_is_specified(path, &value) {
                 continue;
@@ -658,6 +658,18 @@ Using configuration file '{args_path}'.");
         // accept a `&self` parameter, but for now it's not necessary.
         1048576
     }
+
+    pub fn log_config_params(&self) {
+        for path in &leaf_field_paths::<PicodataConfig>() {
+            let value = self
+                .get_field_as_rmpv(path)
+                .expect("this should be tested thoroughly");
+
+            if value_is_specified(path, &value) {
+                tlog!(Info, "'{}': {}", path, value);
+            }
+        }
+    }
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -685,7 +697,7 @@ fn mark_non_none_field_sources(
     for path in leaf_field_paths::<PicodataConfig>() {
         let value = config
             .get_field_as_rmpv(&path)
-            .expect("this should be tested thouroughly");
+            .expect("this should be tested thoroughly");
 
         if !value_is_specified(&path, &value) {
             continue;
diff --git a/test/conftest.py b/test/conftest.py
index e85a5bfd7e..438c9fe0b2 100644
--- a/test/conftest.py
+++ b/test/conftest.py
@@ -650,7 +650,7 @@ class Instance:
             )
         except Exception as e:
             self.check_process_alive()
-            # if process is dead, the above call will raise an expection
+            # if process is dead, the above call will raise an exception
             # otherwise we raise the original exception
             raise e from e
 
@@ -894,7 +894,7 @@ class Instance:
             #
             # For `os.killpg()` to work properly (killing this
             # particular instance and not others) we want each instance
-            # to form it's own process group. The easiest way to
+            # to form its own process group. The easiest way to
             # accomplish it is to start a new session. With this flag
             # pytest implicitly calls `setsid()`.
             start_new_session=True,
@@ -1125,9 +1125,9 @@ class Instance:
     ) -> int:
         """
         Proposes a space creation ddl prepare operation. Returns the index of
-        the corresponding finilazing ddl commit or ddl abort entry.
+        the corresponding finalizing ddl commit or ddl abort entry.
 
-        If `wait_index` is `True` will wait for the finilazing entry
+        If `wait_index` is `True` will wait for the finalizing entry
         to be applied for `timeout` seconds.
         """
         op = dict(
@@ -1163,7 +1163,7 @@ class Instance:
             # Note: The process may have crashed due to the RPC, but there may
             # be a race between when the python connector receives the
             # connection reset error and when the OS will finish cleaning up
-            # the process (especially considerring we have a supervisor
+            # the process (especially considering we have a supervisor
             # process). So we introduce a tiny timeout here (which may still not
             # be enough in every case).
             exit_code = self.process.wait(timeout=0.1)  # type: ignore
diff --git a/test/int/test_config_file.py b/test/int/test_config_file.py
index 55875704c4..3c1ccfaeca 100644
--- a/test/int/test_config_file.py
+++ b/test/int/test_config_file.py
@@ -422,3 +422,57 @@ cluster:
         sudo=True,
     )
     assert dql == []
+
+
+def test_output_config_parameters(cluster: Cluster):
+    cluster.set_config_file(
+        yaml="""
+    cluster:
+        tier:
+            default:
+    instance:
+        cluster_id: test
+        instance_id: from-config
+        replicaset_id: with-love
+        memtx:
+            memory: 42069
+    """
+    )
+
+    output_params = """'cluster.cluster_id':
+        'cluster.tier':
+        'cluster.default_replication_factor':
+        'instance.data_dir':
+        'instance.config_file':
+        'instance.cluster_id':
+        'instance.instance_id': "i1"
+        'instance.replicaset_id': "with-love"
+        'instance.tier': "default"
+        'instance.failure_domain': {}
+        'instance.peer':
+        'instance.listen':
+        'instance.advertise_address':
+        'instance.admin_socket':
+        'instance.plugin_dir':
+        'instance.audit':
+        'instance.shredding': false
+        'instance.log.level': "verbose"
+        'instance.log.format': "plain"
+        'instance.memtx.memory': 42069"""
+
+    params_list = [line.strip().encode("ASCII") for line in output_params.splitlines()]
+    found_params = set()
+
+    def check_output(line: bytes):
+        nonlocal params_list
+        nonlocal found_params
+
+        for param in params_list:
+            if line.find(param) != -1:
+                found_params.add(param)
+
+    i1 = cluster.add_instance(wait_online=False)
+    i1.on_output_line(check_output)
+    i1.start()
+    i1.wait_online()
+    assert len(found_params) == len(params_list)
-- 
GitLab