Skip to content
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

feat: Add message for when API Mediation Layer starts #3523

Merged
merged 8 commits into from
Apr 30, 2024
Merged
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
7 changes: 7 additions & 0 deletions apiml-utility/src/main/resources/utility-log-messages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ messages:
reason: "The service started."
action: "No action required."

- key: org.zowe.apiml.common.mediationLayerStarted
number: ZWEAM001
type: INFO
text: "started"
reason: "All API ML services started."
action: "No action required."

# General messages
# 100-199

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import org.springframework.security.authentication.AuthenticationServiceException;
import org.springframework.stereotype.Component;
import org.zowe.apiml.gateway.security.login.Providers;
import org.zowe.apiml.message.log.ApimlLogger;
import org.zowe.apiml.message.yaml.YamlMessageServiceInstance;
import org.zowe.apiml.product.constants.CoreService;

import static org.springframework.boot.actuate.health.Status.DOWN;
Expand All @@ -31,6 +33,10 @@ public class GatewayHealthIndicator extends AbstractHealthIndicator {
private final DiscoveryClient discoveryClient;
private final Providers loginProviders;
private String apiCatalogServiceId;

private final ApimlLogger apimlLog = ApimlLogger.of(GatewayHealthIndicator.class,
YamlMessageServiceInstance.getInstance());
boolean startedInformationPublished = false;

public GatewayHealthIndicator(DiscoveryClient discoveryClient,
Providers providers,
Expand Down Expand Up @@ -69,6 +75,11 @@ protected void doHealthCheck(Health.Builder builder) {
if (anyCatalogIsAvailable) {
builder.withDetail(CoreService.API_CATALOG.getServiceId(), toStatus(apiCatalogUp).getCode());
}

if (!startedInformationPublished && discoveryUp && apiCatalogUp && authUp) {
apimlLog.log("org.zowe.apiml.common.mediationLayerStarted");
startedInformationPublished = true;
}
}

private Status toStatus(boolean up) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,22 @@ void givenCustomCatalogProvider_whenHealthIsRequested_thenStatusIsUp() {
String code = (String) builder.build().getDetails().get(CoreService.API_CATALOG.getServiceId());
assertThat(code, is("UP"));
}

@Test
void givenEverythingIsHealthy_whenHealthRequested_onceLogMessageAboutStartup() {
when(providers.isZosfmUsed()).thenReturn(true);
when(providers.isZosmfAvailableAndOnline()).thenReturn(true);

DiscoveryClient discoveryClient = mock(DiscoveryClient.class);
when(discoveryClient.getInstances(CoreService.API_CATALOG.getServiceId())).thenReturn(
Collections.singletonList(getDefaultServiceInstance(CoreService.API_CATALOG.getServiceId(), "host", 10014)));
when(discoveryClient.getInstances(CoreService.DISCOVERY.getServiceId())).thenReturn(
Collections.singletonList(getDefaultServiceInstance(CoreService.DISCOVERY.getServiceId(), "host", 10011)));

GatewayHealthIndicator gatewayHealthIndicator = new GatewayHealthIndicator(discoveryClient, providers, CoreService.API_CATALOG.getServiceId());
Health.Builder builder = new Health.Builder();
gatewayHealthIndicator.doHealthCheck(builder);

assertThat(gatewayHealthIndicator.startedInformationPublished, is(true));
}
}
Loading