Skip to content

Add logging when (de)activating backend clusters #672

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 9 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.List;
import java.util.Optional;

import static java.lang.String.format;
import static java.util.Objects.requireNonNull;

public class HaGatewayManager
Expand Down Expand Up @@ -82,13 +83,39 @@ public Optional<ProxyBackendConfiguration> getBackendByName(String name)
@Override
public void deactivateBackend(String backendName)
{
dao.deactivate(backendName);
updateClusterActivationStatus(backendName, false, () -> dao.deactivate(backendName));
}

@Override
public void activateBackend(String backendName)
{
dao.activate(backendName);
updateClusterActivationStatus(backendName, true, () -> dao.activate(backendName));
}

private void updateClusterActivationStatus(String clusterName, boolean newStatus, Runnable action)
{
GatewayBackend model = dao.findFirstByName(clusterName);
if (model == null) {
throw new IllegalStateException(format("No cluster found with name: %s, could not (de)activate", clusterName));
}

boolean prevStatus = model.active();
try {
action.run();
logActivationStatusChange(clusterName, newStatus, prevStatus);
}
catch (Exception e) {
log.error("Failed to update activation status for cluster %s: %s", clusterName, e.getMessage());
Copy link
Member

Choose a reason for hiding this comment

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

GatewayResource also logs the error message. I don't think we should log the similar message twice.

throw e;
}
}

private void logActivationStatusChange(String clusterName, boolean newStatus, boolean prevStatus)
{
if (prevStatus != newStatus) {
log.info("Backend cluster %s activation status set to active=%s (previous status: active=%s).",
clusterName, newStatus, prevStatus);
}
}

@Override
Expand All @@ -111,6 +138,7 @@ public ProxyBackendConfiguration updateBackend(ProxyBackendConfiguration backend
}
else {
dao.update(backend.getName(), backend.getRoutingGroup(), backendProxyTo, backendExternalUrl, backend.isActive());
logActivationStatusChange(backend.getName(), backend.isActive(), model.active());
}
return backend;
}
Expand Down