Skip to content

Improve logging for backend cluster (de)activation #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 2 commits into
base: main
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
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public Response activateBackend(@PathParam("name") String name)
this.gatewayBackendManager.activateBackend(name);
}
catch (Exception e) {
log.error(e);
log.error(e, e.getMessage());
return throwError(e);
}
return Response.ok().build();
Expand Down
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 com.google.common.base.Preconditions.checkState;
import static java.util.Objects.requireNonNull;

public class HaGatewayManager
Expand Down Expand Up @@ -82,13 +83,30 @@ 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 changeActiveStatus)
{
GatewayBackend model = dao.findFirstByName(clusterName);
checkState(model != null, "No cluster found with name: %s, could not (de)activate", clusterName);

boolean previousStatus = model.active();
changeActiveStatus.run();
logActivationStatusChange(clusterName, newStatus, previousStatus);
}

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

@Override
Expand All @@ -111,6 +129,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