Skip to content

ApiListener#RelayMessageOne(): log🪵 to which Endpoint messages are relayed #10393

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion lib/remote/apilistener.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,20 @@ void ApiListener::SyncSendMessage(const Endpoint::Ptr& endpoint, const Dictionar
}
}

/**
* Log the endpoint currently used to relay messages to our parent zone if it (the endpoint) has changed.
*
* @param zone The parent zone
* @param endpoint The new endpoint
*/
void ApiListener::LogCurrentParentEndpoint(const Zone::Ptr& zone, const Endpoint::Ptr& endpoint)
{
if (m_CurrentParentEndpoint.exchange(endpoint.get()) != endpoint.get()) {
Log(LogInformation, "ApiListener") << "Relaying messages for parent Zone '"
<< zone->GetName() << "' to Endpoint '" << endpoint->GetName() << "'";
}
}

/**
* Relay a message to a directly connected zone or to a global zone.
* If some other zone is passed as the target zone, it is not relayed.
Expand All @@ -1219,11 +1233,12 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig
ASSERT(targetZone);

Zone::Ptr localZone = Zone::GetLocalZone();
auto parentZone (localZone->GetParent());

/* only relay the message to a) the same local zone, b) the parent zone and c) direct child zones. Exception is a global zone. */
if (!targetZone->GetGlobal() &&
targetZone != localZone &&
targetZone != localZone->GetParent() &&
targetZone != parentZone &&
targetZone->GetParent() != localZone) {
return true;
}
Expand Down Expand Up @@ -1302,12 +1317,20 @@ bool ApiListener::RelayMessageOne(const Zone::Ptr& targetZone, const MessageOrig
bool isMaster = (currentZoneMaster == localEndpoint);

if (!isMaster && targetEndpoint != currentZoneMaster) {
if (currentTargetZone == parentZone) {
LogCurrentParentEndpoint(parentZone, currentZoneMaster);
}

Copy link
Member

@yhabteab yhabteab Apr 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If that if condition is triggered, the endpoint is going to be skipped, so why log here something that says otherwise?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the parent endpoint targetEndpoint is skipped. But the node is still "Relaying messages for parent Zone" via currentZoneMaster which I clearly say here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

via currentZoneMaster which I clearly say here.

It's far from clear, there's not even a single comment that explains it. We've spent literally hours discussing this in person, so I don't know what else you want me to say. So, since this PR is based on @lippserd's request from #10389 (review), I'll describe 1 what it does for you and see if that's what you asked for, but to me it clearly doesn't reflect what the actual code does.

Footnotes

  1. Suppose you have two endpoints (S1 and S2) in a satellite HA zone, and a master zone with endpoints (M1 and M2) as parents. In such a HA setup, only one of the endpoints from either zone is allowed to communicate with the respective parent/child zone at a time. Now let's say that M1 and S1 are responsible for message exchange between these zones, i.e. only S1 is responsible for forwarding the messages to the parent (master) zone and M1 is responsible for accepting them and sending back other messages from/to the satellite zone. So each time S2 wants to send messages to M1 and M2 endpoints (it's target zone being set to the master zone) it will trigger this if condition and with this PR it would also log something like ...Relaying messages for parent zone 'master' to endpoint 'S1' even though it's skipping the endpoints (M1 and M2). Well, hopefully messages intended for the parent zone will be sent to the partner endpoint (S1) at some point, but whether and when they will be sent as this log claims is not known at all, because this log is based on the assumption that when this condition is triggered, the message might even have been sent already or will possibly be sent to S1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's not even a single comment that explains it.

Technically, yes.

It's far from clear,

But, to my defense, there's the log message itself using names from clearly named distinct variables.

it clearly doesn't reflect what the actual code does.

It absolutely reflects it! Please see my test in OP and/or, at your option, run own tests with M1/M2/S1/S2. Shut down any combination of nodes and I forecast you: the actual log message will be correct.

I'm aware it's not 100% perfect. But I need you to understand there's only one ApiListener#RelayMessageOne() call per message if latter is intended for the parent zone. So (if I don't wanna hope in that one function call whether another one will/has happen(ed),) I have to use the opportunity of this one call while inside. And luckily I have everything I need! I know for sure whether the message is for the parent zone and whether it's send directly (log message 2) or indirectly (log message 1). It's just fine and, as requested, I log every time the routing changes from logger PoV.

skippedEndpoints.push_back(targetEndpoint);
continue;
}

relayed = true;

if (currentTargetZone == parentZone) {
LogCurrentParentEndpoint(parentZone, targetEndpoint);
}

SyncSendMessage(targetEndpoint, message);
}

Expand Down
4 changes: 4 additions & 0 deletions lib/remote/apilistener.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "remote/httpserverconnection.hpp"
#include "remote/endpoint.hpp"
#include "remote/messageorigin.hpp"
#include "base/atomic.hpp"
#include "base/configobject.hpp"
#include "base/process.hpp"
#include "base/shared.hpp"
Expand Down Expand Up @@ -183,6 +184,7 @@ class ApiListener final : public ObjectImpl<ApiListener>
Timer::Ptr m_RenewOwnCertTimer;

Endpoint::Ptr m_LocalEndpoint;
Atomic<Endpoint*> m_CurrentParentEndpoint {nullptr};
StoppableWaitGroup::Ptr m_WaitGroup = new StoppableWaitGroup();

static ApiListener::Ptr m_Instance;
Expand Down Expand Up @@ -213,6 +215,8 @@ class ApiListener final : public ObjectImpl<ApiListener>
Stream::Ptr m_LogFile;
size_t m_LogMessageCount{0};

void LogCurrentParentEndpoint(const Zone::Ptr& zone, const Endpoint::Ptr& endpoint);

bool RelayMessageOne(const Zone::Ptr& zone, const MessageOrigin::Ptr& origin, const Dictionary::Ptr& message, const Endpoint::Ptr& currentZoneMaster);
void SyncRelayMessage(const MessageOrigin::Ptr& origin, const ConfigObject::Ptr& secobj, const Dictionary::Ptr& message, bool log);
void PersistMessage(const Dictionary::Ptr& message, const ConfigObject::Ptr& secobj);
Expand Down
Loading