Skip to content

Commit

Permalink
Nais preStop hook gir større margin for slengere fra lastbalanserer +…
Browse files Browse the repository at this point in the history
… graceful shutdown (#2655)
  • Loading branch information
dijjal authored Feb 14, 2024
1 parent 709cad2 commit a616dbd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .deploy/naiserator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ spec:
readiness:
path: /internal/actuator/health/readiness
initialDelay: 15
preStopHook:
http:
path: /internal/preStop
prometheus:
enabled: true
path: /internal/actuator/prometheus
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package no.nav.foreldrepenger.selvbetjening.http;

import no.nav.security.token.support.core.api.Unprotected;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.Duration;

@RestController
public class PreStopHookController {
private static final Logger LOG = LoggerFactory.getLogger(PreStopHookController.class);

@Unprotected
@GetMapping("/internal/preStop")
public ResponseEntity<String> preStop() throws InterruptedException {
LOG.info("Mottok kall på /internal/preStop, sover 6 sekunder");
Thread.sleep(Duration.ofSeconds(6));
return ResponseEntity.ok().build();
}
}
1 change: 1 addition & 0 deletions domene/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ server:
servlet:
context-path: /
forward-headers-strategy: native
shutdown: graceful
spring:
cloud.discovery.enabled: false
cache:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

class RestApiSikredeEndepunktTest extends RestApiTestUtil {

private static final List<Class<?>> UNNTATT_RESTCONTROLLER = List.of(UttakController.class);
private static final String ENDEPUNKT_SOM_KAN_VÆRE_UNPROTECTED = "ping";
private static final List<Class<?>> UNNTATT_RESTCONTROLLER = List.of(UttakController.class, PreStopHookController.class);
private static final List<String> ENDEPUNKT_SOM_KAN_VÆRE_UNPROTECTED = List.of("ping", "preStop");

@Test
void sjekkAtProtectedRestControllerIkkeHarUbeskyttetAnnotering() {
Expand Down Expand Up @@ -59,7 +59,7 @@ private boolean erRestControllerUbeskyttet(Class<?> klasse) {
}

private boolean erEndepunktUnprotected(Method metode) {
if (metode.isAnnotationPresent(ConditionalOnNotProd.class) || metode.getName().equalsIgnoreCase(ENDEPUNKT_SOM_KAN_VÆRE_UNPROTECTED)) {
if (metode.isAnnotationPresent(ConditionalOnNotProd.class) || ENDEPUNKT_SOM_KAN_VÆRE_UNPROTECTED.stream().anyMatch(ep -> ep.equalsIgnoreCase(metode.getName()))) {
return false;
}
return metode.isAnnotationPresent(Unprotected.class);
Expand Down

0 comments on commit a616dbd

Please sign in to comment.