Skip to content

Commit 5004dc4

Browse files
authored
fix: Fix logging in SubscriptionSource (#1617)
For #1616. Later should be ported to develop as well.
1 parent 665fab1 commit 5004dc4

File tree

3 files changed

+16
-9
lines changed

3 files changed

+16
-9
lines changed

src/etl/LoadBalancer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ LoadBalancer::getETLState() noexcept
314314
void
315315
LoadBalancer::chooseForwardingSource()
316316
{
317+
LOG(log_.info()) << "Choosing a new source to forward subscriptions";
317318
hasForwardingSource_ = false;
318319
for (auto& source : sources_) {
319320
if (not hasForwardingSource_ and source->isConnected()) {

src/etl/impl/GrpcSource.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
namespace etl::impl {
4747

4848
GrpcSource::GrpcSource(std::string const& ip, std::string const& grpcPort, std::shared_ptr<BackendInterface> backend)
49-
: log_(fmt::format("ETL_Grpc[{}:{}]", ip, grpcPort)), backend_(std::move(backend))
49+
: log_(fmt::format("GrpcSource[{}:{}]", ip, grpcPort)), backend_(std::move(backend))
5050
{
5151
try {
5252
boost::asio::ip::tcp::endpoint const endpoint{boost::asio::ip::make_address(ip), std::stoi(grpcPort)};

src/etl/impl/SubscriptionSource.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ SubscriptionSource::SubscriptionSource(
6969
std::chrono::steady_clock::duration const connectionTimeout,
7070
std::chrono::steady_clock::duration const retryDelay
7171
)
72-
: log_(fmt::format("GrpcSource[{}:{}]", ip, wsPort))
72+
: log_(fmt::format("SubscriptionSource[{}:{}]", ip, wsPort))
7373
, wsConnectionBuilder_(ip, wsPort)
7474
, validatedLedgers_(std::move(validatedLedgers))
7575
, subscriptions_(std::move(subscriptions))
@@ -133,6 +133,7 @@ void
133133
SubscriptionSource::setForwarding(bool isForwarding)
134134
{
135135
isForwarding_ = isForwarding;
136+
LOG(log_.info()) << "Forwarding set to " << isForwarding_;
136137
}
137138

138139
std::chrono::steady_clock::time_point
@@ -168,6 +169,7 @@ SubscriptionSource::subscribe()
168169
wsConnection_ = std::move(connection).value();
169170
isConnected_ = true;
170171
onConnect_();
172+
LOG(log_.info()) << "Connected";
171173

172174
auto const& subscribeCommand = getSubscribeCommandJson();
173175
auto const writeErrorOpt = wsConnection_->write(subscribeCommand, yield);
@@ -224,10 +226,11 @@ SubscriptionSource::handleMessage(std::string const& message)
224226
auto validatedLedgers = boost::json::value_to<std::string>(result.at(JS(validated_ledgers)));
225227
setValidatedRange(std::move(validatedLedgers));
226228
}
227-
LOG(log_.info()) << "Received a message on ledger subscription stream. Message : " << object;
229+
LOG(log_.debug()) << "Received a message on ledger subscription stream. Message: " << object;
228230

229231
} else if (object.contains(JS(type)) && object.at(JS(type)) == JS_LedgerClosed) {
230-
LOG(log_.info()) << "Received a message on ledger subscription stream. Message : " << object;
232+
LOG(log_.debug()) << "Received a message of type 'ledgerClosed' on ledger subscription stream. Message: "
233+
<< object;
231234
if (object.contains(JS(ledger_index))) {
232235
ledgerIndex = object.at(JS(ledger_index)).as_int64();
233236
}
@@ -245,11 +248,16 @@ SubscriptionSource::handleMessage(std::string const& message)
245248
// 2 - Validated transaction
246249
// Only forward proposed transaction, validated transactions are sent by Clio itself
247250
if (object.contains(JS(transaction)) and !object.contains(JS(meta))) {
251+
LOG(log_.debug()) << "Forwarding proposed transaction: " << object;
248252
subscriptions_->forwardProposedTransaction(object);
249253
} else if (object.contains(JS(type)) && object.at(JS(type)) == JS_ValidationReceived) {
254+
LOG(log_.debug()) << "Forwarding validation: " << object;
250255
subscriptions_->forwardValidation(object);
251256
} else if (object.contains(JS(type)) && object.at(JS(type)) == JS_ManifestReceived) {
257+
LOG(log_.debug()) << "Forwarding manifest: " << object;
252258
subscriptions_->forwardManifest(object);
259+
} else {
260+
LOG(log_.error()) << "Unknown message: " << object;
253261
}
254262
}
255263
}
@@ -261,7 +269,7 @@ SubscriptionSource::handleMessage(std::string const& message)
261269

262270
return std::nullopt;
263271
} catch (std::exception const& e) {
264-
LOG(log_.error()) << "Exception in handleMessage : " << e.what();
272+
LOG(log_.error()) << "Exception in handleMessage: " << e.what();
265273
return util::requests::RequestError{fmt::format("Error handling message: {}", e.what())};
266274
}
267275
}
@@ -273,13 +281,11 @@ SubscriptionSource::handleError(util::requests::RequestError const& error, boost
273281
isForwarding_ = false;
274282
if (not stop_) {
275283
onDisconnect_();
284+
LOG(log_.info()) << "Disconnected";
276285
}
277286

278287
if (wsConnection_ != nullptr) {
279-
auto const err = wsConnection_->close(yield);
280-
if (err) {
281-
LOG(log_.error()) << "Error closing websocket connection: " << err->message();
282-
}
288+
wsConnection_->close(yield);
283289
wsConnection_.reset();
284290
}
285291

0 commit comments

Comments
 (0)