Skip to content

Commit

Permalink
Development: Improve health services
Browse files Browse the repository at this point in the history
  • Loading branch information
krusche committed Dec 7, 2024
1 parent 8504af9 commit 0f07355
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package de.tum.cit.aet.artemis.communication.config;

import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.util.HashMap;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpStatusCode;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;

import de.tum.cit.aet.artemis.core.service.connectors.ConnectorHealth;

/**
* Service determining the health of the Hermes push notification service.
*/
@Profile(PROFILE_CORE)
@Component
public class HermesHealthIndicator implements HealthIndicator {

private final RestTemplate shortTimeoutRestTemplate;

@Value("${artemis.push-notification-relay:https://hermes-sandbox.artemis.cit.tum.de}")
private String hermesUrl;

public HermesHealthIndicator(@Qualifier("shortTimeoutHermesRestTemplate") RestTemplate shortTimeoutRestTemplate) {
this.shortTimeoutRestTemplate = shortTimeoutRestTemplate;
}

/**
* Ping Hermes and check if the service is available.
*/
@Override
public Health health() {
var additionalInfo = new HashMap<String, Object>();
additionalInfo.put("url", hermesUrl);
ConnectorHealth health;
try {
ResponseEntity<String> response = shortTimeoutRestTemplate.getForEntity(hermesUrl, String.class);
HttpStatusCode statusCode = response.getStatusCode();
health = new ConnectorHealth(statusCode.is2xxSuccessful(), additionalInfo);
}
catch (RestClientException error) {
health = new ConnectorHealth(error);
}

return health.asActuatorHealth();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.util.List;
import java.util.Optional;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -28,8 +27,8 @@ public class ApplePushNotificationService extends PushNotificationService {

private final PushNotificationDeviceConfigurationRepository repository;

@Value("${artemis.push-notification-relay:#{null}}")
private Optional<String> relayServerBaseUrl;
@Value("${artemis.push-notification-relay:https://hermes-sandbox.artemis.cit.tum.de}")
private String relayServerBaseUrl;

public ApplePushNotificationService(PushNotificationDeviceConfigurationRepository repository, RestTemplate restTemplate) {
super(restTemplate);
Expand All @@ -47,7 +46,7 @@ public PushNotificationDeviceType getDeviceType() {
}

@Override
Optional<String> getRelayBaseUrl() {
String getRelayBaseUrl() {
return relayServerBaseUrl;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static de.tum.cit.aet.artemis.core.config.Constants.PROFILE_CORE;

import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;

import org.slf4j.Logger;
Expand Down Expand Up @@ -32,8 +31,8 @@ public class FirebasePushNotificationService extends PushNotificationService {

private final PushNotificationDeviceConfigurationRepository repository;

@Value("${artemis.push-notification-relay:#{null}}")
private Optional<String> relayServerBaseUrl;
@Value("${artemis.push-notification-relay:https://hermes-sandbox.artemis.cit.tum.de}")
private String relayServerBaseUrl;

public FirebasePushNotificationService(PushNotificationDeviceConfigurationRepository pushNotificationDeviceConfigurationRepository, RestTemplate restTemplate) {
super(restTemplate);
Expand Down Expand Up @@ -61,7 +60,7 @@ public PushNotificationDeviceType getDeviceType() {
}

@Override
Optional<String> getRelayBaseUrl() {
String getRelayBaseUrl() {
return relayServerBaseUrl;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void sendNotification(Notification notification, User user, Object notifi
@Override
@Async
public void sendNotification(Notification notification, Set<User> users, Object notificationSubject) {
final Optional<String> relayServerBaseUrl = getRelayBaseUrl();
final String relayServerBaseUrl = getRelayBaseUrl();

if (relayServerBaseUrl.isEmpty()) {
return;
Expand Down Expand Up @@ -174,7 +174,7 @@ public void sendNotification(Notification notification, Set<User> users, Object
.map(s -> new RelayNotificationRequest(ivAsString, s, deviceConfiguration.getToken(), deviceConfiguration.getApiType().getDatabaseKey()));
}).toList();

sendNotificationRequestsToEndpoint(notificationRequests, relayServerBaseUrl.get());
sendNotificationRequestsToEndpoint(notificationRequests, relayServerBaseUrl);
}
catch (JsonProcessingException e) {
log.error("Error creating push notification payload!", e);
Expand All @@ -185,7 +185,7 @@ public void sendNotification(Notification notification, Set<User> users, Object

abstract PushNotificationDeviceType getDeviceType();

abstract Optional<String> getRelayBaseUrl();
abstract String getRelayBaseUrl();

abstract String getRelayPath();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public RestTemplate shortTimeoutApollonRestTemplate() {
return createShortTimeoutRestTemplate();
}

@Bean
public RestTemplate shortTimeoutHermesRestTemplate() {
return createShortTimeoutRestTemplate();
}

// Note: for certain requests, e.g. the Athena submission selection, we would like to have even shorter timeouts.
// Therefore, we need additional rest templates. It is recommended to keep the timeout settings constant per rest template.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ public String getPlanKey(Object requestBody) throws LocalCIException {

@Override
public ConnectorHealth health() {
return new ConnectorHealth(true, Map.of("buildAgents", sharedQueueManagementService.getBuildAgentInformation()));
return new ConnectorHealth(true, Map.of("buildAgents", sharedQueueManagementService.getBuildAgentInformationWithoutRecentBuildJobs()));
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/config/application-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ theia:
c:
C: "ghcr.io/ls1intum/theia/c:latest"

# Telemetry service: disabled for development
artemis:
push-notification-relay: https://hermes-sandbox.artemis.cit.tum.de
# Telemetry service: disabled for development
telemetry:
enabled: false # Disable sending any telemetry information to the telemetry service by setting this to false
sendAdminDetails: false # Include the admins email and name in the telemetry data. Set to false to disable
Expand Down
4 changes: 3 additions & 1 deletion src/main/webapp/i18n/de/health.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"websocketBroker": "Websocket Broker (Server -> Broker)",
"athena": "Athena",
"apollon": "Apollon Conversion Server",
"pyris": "Pyris"
"pyris": "Pyris",
"ssl": "SSL",
"hermes": "Hermes Push Notifications"
},
"table": {
"service": "Dienst Name",
Expand Down
4 changes: 3 additions & 1 deletion src/main/webapp/i18n/en/health.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
"websocketBroker": "Websocket Broker (Server -> Broker)",
"athena": "Athena",
"apollon": "Apollon Conversion Server",
"pyris": "Pyris"
"pyris": "Pyris",
"ssl": "SSL",
"hermes": "Hermes Push Notifications"
},
"table": {
"service": "Service name",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import java.util.Collections;
import java.util.Date;
import java.util.HexFormat;
import java.util.Optional;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -81,8 +80,8 @@ void setUp() {
applePushNotificationService = new ApplePushNotificationService(repositoryMock, appleRestTemplateMock);
firebasePushNotificationService = new FirebasePushNotificationService(repositoryMock, firebaseRestTemplateMock);

ReflectionTestUtils.setField(applePushNotificationService, "relayServerBaseUrl", Optional.of("test"));
ReflectionTestUtils.setField(firebasePushNotificationService, "relayServerBaseUrl", Optional.of("test"));
ReflectionTestUtils.setField(applePushNotificationService, "relayServerBaseUrl", "test");
ReflectionTestUtils.setField(firebasePushNotificationService, "relayServerBaseUrl", "test");
}

@AfterEach
Expand Down

0 comments on commit 0f07355

Please sign in to comment.