Skip to content

Commit c710fe6

Browse files
committed
[remove] configurator changes
1 parent 1e17c6a commit c710fe6

File tree

10 files changed

+46
-139
lines changed

10 files changed

+46
-139
lines changed

example/config.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
general:
22
name: NameFromConfig
3-
base_path: /tmp/jam_node
4-
modules_dir: modules
53

64
metrics:
75
enabled: true

src/app/configuration.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,6 @@ namespace jam::app {
1818
return name_;
1919
}
2020

21-
std::filesystem::path Configuration::basePath() const {
22-
return base_path_;
23-
}
24-
25-
std::filesystem::path Configuration::modulesDir() const {
26-
return modules_dir_;
27-
}
28-
2921
std::optional<Configuration::Endpoint> Configuration::metricsEndpoint()
3022
const {
3123
return metrics_endpoint_;

src/app/configuration.hpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ namespace jam::app {
2323

2424
[[nodiscard]] std::string nodeVersion() const;
2525
[[nodiscard]] std::string nodeName() const;
26-
[[nodiscard]] std::filesystem::path basePath() const;
27-
[[nodiscard]] std::filesystem::path modulesDir() const;
2826

2927
[[nodiscard]] std::optional<Endpoint> metricsEndpoint() const;
3028

@@ -33,8 +31,6 @@ namespace jam::app {
3331

3432
std::string version_;
3533
std::string name_;
36-
std::filesystem::path base_path_;
37-
std::filesystem::path modules_dir_;
3834

3935
Endpoint metrics_endpoint_;
4036
std::optional<bool> metrics_enabled_;

src/app/configurator.cpp

Lines changed: 10 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ OUTCOME_CPP_DEFINE_CATEGORY(jam::app, Configurator::Error, e) {
2727
return "CLI Arguments parse failed";
2828
case E::ConfigFileParseFailed:
2929
return "Config file parse failed";
30-
case E::InvalidValue:
31-
return "Result config has invalid values";
3230
}
3331
BOOST_UNREACHABLE_RETURN("Unknown log::Error");
3432
}
@@ -86,18 +84,16 @@ namespace jam::app {
8684

8785
po::options_description general_options("General options", 120, 100);
8886
general_options.add_options()
89-
("help,h", "Show this help message")
90-
("version,v", "Show version information")
91-
("base_path", po::value<std::string>(), "Set base path. All relative paths will be resolved based on this path.")
92-
("config,c", po::value<std::string>(), "Optional. Filepath to load configuration from. Overrides default configuration values.")
93-
("name,n", po::value<std::string>(), "Set name of node")
87+
("help,h", "show this help message")
88+
("version,v", "show version information")
89+
("name,n", po::value<std::string>(), "set name of node")
90+
("config,c", po::value<std::string>(), "optional, filepath to load configuration from. Overrides default config values")
9491
("log,l", po::value<std::vector<std::string>>(),
9592
"Sets a custom logging filter.\n"
96-
"Syntax: <target>=<level>, e.g., -llibp2p=off.\n"
97-
"Log levels: trace, debug, verbose, info, warn, error, critical, off.\n"
98-
"Default: all targets log at `info`.\n"
99-
"Global log level can be set with: -l<level>.")
100-
("modules_dir", po::value<std::string>(), "Set path to modules directory.")
93+
"Syntax is `<target>=<level>`, e.g. -llibp2p=off.\n"
94+
"Log levels (most to least verbose) are trace, debug, verbose, info, warn, error, critical, off.\n"
95+
"By default, all targets log `info`.\n"
96+
"The global log level can be set with -l<level>.")
10197
;
10298

10399
po::options_description metrics_options("Metric options");
@@ -196,8 +192,7 @@ namespace jam::app {
196192
}
197193

198194
outcome::result<std::shared_ptr<Configuration>> Configurator::calculateConfig(
199-
qtils::StrictSharedPtr<soralog::Logger> logger) {
200-
logger_ = std::move(logger);
195+
std::shared_ptr<soralog::Logger> logger) {
201196
OUTCOME_TRY(initGeneralConfig());
202197
OUTCOME_TRY(initOpenMetricsConfig());
203198

@@ -220,97 +215,24 @@ namespace jam::app {
220215
file_has_error_ = true;
221216
}
222217
}
223-
auto base_path = section["base_path"];
224-
if (base_path.IsDefined()) {
225-
if (base_path.IsScalar()) {
226-
auto value = base_path.as<std::string>();
227-
config_->base_path_ = value;
228-
} else {
229-
file_errors_ << "E: Value 'general.base_path' must be scalar\n";
230-
file_has_error_ = true;
231-
}
232-
}
233-
auto modules_dir = section["modules_dir"];
234-
if (modules_dir.IsDefined()) {
235-
if (modules_dir.IsScalar()) {
236-
auto value = modules_dir.as<std::string>();
237-
config_->modules_dir_ = value;
238-
} else {
239-
file_errors_ << "E: Value 'general.modules_dir' must be scalar\n";
240-
file_has_error_ = true;
241-
}
242-
}
243218
} else {
244-
file_errors_ << "E: Section 'general' defined, but is not map\n";
219+
file_errors_ << "E: Section 'general' defined, but is not scalar\n";
245220
file_has_error_ = true;
246221
}
247222
}
248223
}
249224

250-
if (file_has_error_) {
251-
std::string path;
252-
find_argument<std::string>(
253-
cli_values_map_, "config", [&](const std::string &value) {
254-
path = value;
255-
});
256-
SL_ERROR(logger_, "Config file `{}` has some problems:", path);
257-
std::istringstream iss(file_errors_.str());
258-
std::string line;
259-
while (std::getline(iss, line)) {
260-
SL_ERROR(logger_, " {}", std::string_view(line).substr(3));
261-
}
262-
return Error::ConfigFileParseFailed;
263-
}
264-
265-
// Adjust by CLI arguments
266225
bool fail;
267226

268227
fail = false;
269228
find_argument<std::string>(
270229
cli_values_map_, "name", [&](const std::string &value) {
271230
config_->name_ = value;
272231
});
273-
find_argument<std::string>(
274-
cli_values_map_, "base_path", [&](const std::string &value) {
275-
config_->base_path_ = value;
276-
});
277-
find_argument<std::string>(
278-
cli_values_map_, "modules_dir", [&](const std::string &value) {
279-
config_->modules_dir_ = value;
280-
});
281232
if (fail) {
282233
return Error::CliArgsParseFailed;
283234
}
284235

285-
// Check values
286-
if (not config_->base_path_.is_absolute()) {
287-
SL_ERROR(logger_,
288-
"The 'base_path' must be defined as absolute: {}",
289-
config_->base_path_.c_str());
290-
return Error::InvalidValue;
291-
}
292-
if (not is_directory(config_->base_path_)) {
293-
SL_ERROR(logger_,
294-
"The 'base_path' does not exist or is not a directory: {}",
295-
config_->base_path_.c_str());
296-
return Error::InvalidValue;
297-
}
298-
current_path(config_->base_path_);
299-
300-
auto make_absolute = [&](const std::filesystem::path &path) {
301-
return weakly_canonical(config_->base_path_.is_absolute()
302-
? path
303-
: (config_->base_path_ / path));
304-
};
305-
306-
config_->modules_dir_ = make_absolute(config_->modules_dir_);
307-
if (not is_directory(config_->modules_dir_)) {
308-
SL_ERROR(logger_,
309-
"The 'modules_dir' does not exist or is not a directory: {}",
310-
config_->modules_dir_.c_str());
311-
return Error::InvalidValue;
312-
}
313-
314236
return outcome::success();
315237
}
316238

src/app/configurator.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55

66
#pragma once
77

8+
#include <optional>
9+
810
#include <boost/program_options.hpp>
9-
#include <log/logger.hpp>
1011
#include <qtils/enum_error_code.hpp>
1112
#include <qtils/outcome.hpp>
12-
#include <qtils/strict_sptr.hpp>
1313
#include <yaml-cpp/yaml.h>
1414

1515
#include "injector/dont_inject.hpp"
@@ -29,7 +29,6 @@ namespace jam::app {
2929
enum class Error : uint8_t {
3030
CliArgsParseFailed,
3131
ConfigFileParseFailed,
32-
InvalidValue,
3332
};
3433

3534
DONT_INJECT(Configurator);
@@ -52,7 +51,7 @@ namespace jam::app {
5251
outcome::result<YAML::Node> getLoggingConfig();
5352

5453
outcome::result<std::shared_ptr<Configuration>> calculateConfig(
55-
qtils::StrictSharedPtr<soralog::Logger> logger);
54+
std::shared_ptr<soralog::Logger> logger);
5655

5756
private:
5857
outcome::result<void> initGeneralConfig();
@@ -63,7 +62,6 @@ namespace jam::app {
6362
const char **env_;
6463

6564
std::shared_ptr<Configuration> config_;
66-
std::shared_ptr<soralog::Logger> logger_;
6765

6866
std::optional<YAML::Node> config_file_;
6967
bool file_has_warn_ = false;

src/app/impl/application_impl.cpp

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@
2020
namespace jam::app {
2121

2222
ApplicationImpl::ApplicationImpl(
23-
qtils::StrictSharedPtr<log::LoggingSystem> logsys,
24-
qtils::StrictSharedPtr<Configuration> config,
25-
qtils::StrictSharedPtr<StateManager> state_manager,
26-
qtils::StrictSharedPtr<Watchdog> watchdog,
27-
qtils::StrictSharedPtr<metrics::Exposer> metrics_exposer,
28-
qtils::StrictSharedPtr<clock::SystemClock> system_clock)
23+
std::shared_ptr<log::LoggingSystem> logsys,
24+
std::shared_ptr<Configuration> config,
25+
std::shared_ptr<StateManager> state_manager,
26+
std::shared_ptr<Watchdog> watchdog,
27+
std::shared_ptr<metrics::Exposer> metrics_exposer,
28+
std::shared_ptr<clock::SystemClock> system_clock)
2929
: logger_(logsys->getLogger("Application", "application")),
3030
app_config_(std::move(config)),
3131
state_manager_(std::move(state_manager)),
@@ -34,13 +34,15 @@ namespace jam::app {
3434
system_clock_(std::move(system_clock)),
3535
metrics_registry_(metrics::createRegistry()) {
3636
// Metric for exposing name and version of node
37-
metrics::GaugeHelper(
38-
"jam_build_info",
39-
"A metric with a constant '1' value labeled by name, version",
40-
std::map<std::string, std::string>{
41-
{"name", app_config_->nodeName()},
42-
{"version", app_config_->nodeVersion()}})
43-
->set(1);
37+
constexpr auto buildInfoMetricName = "jam_build_info";
38+
metrics_registry_->registerGaugeFamily(
39+
buildInfoMetricName,
40+
"A metric with a constant '1' value labeled by name, version");
41+
auto metric_build_info = metrics_registry_->registerGaugeMetric(
42+
buildInfoMetricName,
43+
{{"name", app_config_->nodeName()},
44+
{"version", app_config_->nodeVersion()}});
45+
metric_build_info->set(1);
4446
}
4547

4648
void ApplicationImpl::run() {

src/app/impl/application_impl.hpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,22 +44,22 @@ namespace jam::app {
4444

4545
class ApplicationImpl final : public Application {
4646
public:
47-
ApplicationImpl(qtils::StrictSharedPtr<log::LoggingSystem> logsys,
48-
qtils::StrictSharedPtr<Configuration> config,
49-
qtils::StrictSharedPtr<StateManager> state_manager,
50-
qtils::StrictSharedPtr<Watchdog> watchdog,
51-
qtils::StrictSharedPtr<metrics::Exposer> metrics_exposer,
52-
qtils::StrictSharedPtr<clock::SystemClock> system_clock);
47+
ApplicationImpl(std::shared_ptr<log::LoggingSystem> logsys,
48+
std::shared_ptr<Configuration> config,
49+
std::shared_ptr<StateManager> state_manager,
50+
std::shared_ptr<Watchdog> watchdog,
51+
std::shared_ptr<metrics::Exposer> metrics_exposer,
52+
std::shared_ptr<clock::SystemClock> system_clock);
5353

5454
void run() override;
5555

5656
private:
57-
qtils::StrictSharedPtr<soralog::Logger> logger_;
58-
qtils::StrictSharedPtr<Configuration> app_config_;
59-
qtils::StrictSharedPtr<StateManager> state_manager_;
60-
qtils::StrictSharedPtr<Watchdog> watchdog_;
61-
qtils::StrictSharedPtr<metrics::Exposer> metrics_exposer_;
62-
qtils::StrictSharedPtr<clock::SystemClock> system_clock_;
57+
std::shared_ptr<soralog::Logger> logger_;
58+
std::shared_ptr<Configuration> app_config_;
59+
std::shared_ptr<StateManager> state_manager_;
60+
std::shared_ptr<Watchdog> watchdog_;
61+
std::shared_ptr<metrics::Exposer> metrics_exposer_;
62+
std::shared_ptr<clock::SystemClock> system_clock_;
6363

6464
// Metrics
6565
std::unique_ptr<metrics::Registry> metrics_registry_;

src/app/impl/state_manager_impl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ namespace jam::app {
9292
}
9393

9494
StateManagerImpl::StateManagerImpl(
95-
qtils::StrictSharedPtr<log::LoggingSystem> logging_system)
95+
std::shared_ptr<log::LoggingSystem> logging_system)
9696
: logger_(logging_system->getLogger("StateManager", "application")),
9797
logging_system_(std::move(logging_system)) {
9898
shuttingDownSignalsEnable();

src/app/impl/state_manager_impl.hpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,10 @@
77
#pragma once
88

99
#include <condition_variable>
10+
#include <csignal>
1011
#include <mutex>
1112
#include <queue>
1213

13-
#include <qtils/strict_sptr.hpp>
14-
1514
#include "app/state_manager.hpp"
1615
#include "utils/ctor_limiters.hpp"
1716

@@ -29,7 +28,7 @@ namespace jam::app {
2928
public StateManager,
3029
public std::enable_shared_from_this<StateManagerImpl> {
3130
public:
32-
StateManagerImpl(qtils::StrictSharedPtr<log::LoggingSystem> logging_system);
31+
StateManagerImpl(std::shared_ptr<log::LoggingSystem> logging_system);
3332

3433
~StateManagerImpl() override;
3534

@@ -66,8 +65,8 @@ namespace jam::app {
6665

6766
void shutdownRequestWaiting();
6867

69-
qtils::StrictSharedPtr<soralog::Logger> logger_;
70-
qtils::StrictSharedPtr<log::LoggingSystem> logging_system_;
68+
std::shared_ptr<soralog::Logger> logger_;
69+
std::shared_ptr<log::LoggingSystem> logging_system_;
7170

7271
std::atomic<State> state_ = State::Init;
7372

src/executable/jam_node.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace {
4848
// Load modules
4949
{
5050
auto logger = logsys->getLogger("Modules", "jam");
51-
const std::string path(appcfg->modulesDir());
51+
const std::string path("modules");
5252

5353
jam::modules::ModuleLoader module_loader(path);
5454
auto modules = module_loader.get_modules();

0 commit comments

Comments
 (0)