Skip to content

Commit ac5f04b

Browse files
committed
Access configuration variables from configuration directly
NetworkStatusNotifier keeps a reference to our configuration object, but also makes copies of several trivial variables. Accessing them directly from the configuration reference should be preferred for consistency and it would make it easier in the future if we want to implement some sort of hot reloading for configuration.
1 parent 97bfc3c commit ac5f04b

File tree

2 files changed

+8
-18
lines changed

2 files changed

+8
-18
lines changed

collector/lib/NetworkStatusNotifier.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,15 @@ void NetworkStatusNotifier::ReportConnectionStats() {
196196
}
197197

198198
bool NetworkStatusNotifier::UpdateAllConnsAndEndpoints() {
199-
if (turn_off_scraping_) {
199+
if (config_.TurnOffScrape()) {
200200
return true;
201201
}
202202

203203
int64_t ts = NowMicros();
204204
std::vector<Connection> all_conns;
205205
std::vector<ContainerEndpoint> all_listen_endpoints;
206206
WITH_TIMER(CollectorStats::net_scrape_read) {
207-
bool success = conn_scraper_->Scrape(&all_conns, scrape_listen_endpoints_ ? &all_listen_endpoints : nullptr);
207+
bool success = conn_scraper_->Scrape(&all_conns, config_.ScrapeListenEndpoints() ? &all_listen_endpoints : nullptr);
208208
if (!success) {
209209
CLOG(ERROR) << "Failed to scrape connections and no pending connections to send";
210210
return false;
@@ -227,7 +227,7 @@ void NetworkStatusNotifier::RunSingle(IDuplexClientWriter<sensor::NetworkConnect
227227

228228
while (writer->Sleep(next_scrape)) {
229229
CLOG(DEBUG) << "Starting network status notification";
230-
next_scrape = std::chrono::system_clock::now() + std::chrono::seconds(scrape_interval_);
230+
next_scrape = std::chrono::system_clock::now() + std::chrono::seconds(config_.ScrapeInterval());
231231

232232
if (!UpdateAllConnsAndEndpoints()) {
233233
CLOG(DEBUG) << "No connection or endpoint to report";
@@ -244,8 +244,8 @@ void NetworkStatusNotifier::RunSingle(IDuplexClientWriter<sensor::NetworkConnect
244244
conn_tracker_->EnableExternalIPs(config_.EnableExternalIPs());
245245

246246
new_conn_state = conn_tracker_->FetchConnState(true, true);
247-
if (enable_afterglow_) {
248-
ConnectionTracker::ComputeDeltaAfterglow(new_conn_state, old_conn_state, delta_conn, time_micros, time_at_last_scrape, afterglow_period_micros_);
247+
if (config_.EnableAfterglow()) {
248+
ConnectionTracker::ComputeDeltaAfterglow(new_conn_state, old_conn_state, delta_conn, time_micros, time_at_last_scrape, config_.AfterglowPeriod());
249249
} else {
250250
ConnectionTracker::ComputeDelta(new_conn_state, &old_conn_state);
251251
}
@@ -255,9 +255,9 @@ void NetworkStatusNotifier::RunSingle(IDuplexClientWriter<sensor::NetworkConnect
255255
}
256256

257257
WITH_TIMER(CollectorStats::net_create_message) {
258-
if (enable_afterglow_) {
258+
if (config_.EnableAfterglow()) {
259259
msg = CreateInfoMessage(delta_conn, old_cep_state);
260-
ConnectionTracker::UpdateOldState(&old_conn_state, new_conn_state, time_micros, afterglow_period_micros_);
260+
ConnectionTracker::UpdateOldState(&old_conn_state, new_conn_state, time_micros, config_.AfterglowPeriod());
261261
} else {
262262
msg = CreateInfoMessage(old_conn_state, old_cep_state);
263263
old_conn_state = std::move(new_conn_state);

collector/lib/NetworkStatusNotifier.h

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@ class NetworkStatusNotifier : protected ProtoAllocator<sensor::NetworkConnection
2323
system_inspector::Service* inspector,
2424
prometheus::Registry* registry)
2525
: conn_scraper_(std::make_unique<ConnScraper>(config, inspector)),
26-
scrape_interval_(config.ScrapeInterval()),
27-
turn_off_scraping_(config.TurnOffScrape()),
28-
scrape_listen_endpoints_(config.ScrapeListenEndpoints()),
2926
conn_tracker_(std::move(conn_tracker)),
30-
afterglow_period_micros_(config.AfterglowPeriod()),
31-
enable_afterglow_(config.EnableAfterglow()),
3227
config_(config),
3328
comm_(std::make_unique<NetworkConnectionInfoServiceComm>(config.grpc_channel)) {
34-
if (config.EnableConnectionStats()) {
29+
if (config_.EnableConnectionStats()) {
3530
connections_total_reporter_ = {{registry,
3631
"rox_connections_total",
3732
"Amount of stored connections over time",
@@ -99,13 +94,8 @@ class NetworkStatusNotifier : protected ProtoAllocator<sensor::NetworkConnection
9994
StoppableThread thread_;
10095

10196
std::unique_ptr<IConnScraper> conn_scraper_;
102-
int scrape_interval_;
103-
bool turn_off_scraping_;
104-
bool scrape_listen_endpoints_;
10597
std::shared_ptr<ConnectionTracker> conn_tracker_;
10698

107-
int64_t afterglow_period_micros_;
108-
bool enable_afterglow_;
10999
const CollectorConfig& config_;
110100
std::unique_ptr<INetworkConnectionInfoServiceComm> comm_;
111101

0 commit comments

Comments
 (0)