NaisEndpoints.java

  1. package no.nav.data.common.nais;

  2. import io.micrometer.core.instrument.Gauge;
  3. import io.micrometer.core.instrument.MeterRegistry;
  4. import lombok.extern.slf4j.Slf4j;
  5. import no.nav.data.common.security.domain.AuthRepository;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.http.HttpStatus;
  8. import org.springframework.http.ResponseEntity;
  9. import org.springframework.web.bind.annotation.GetMapping;
  10. import org.springframework.web.bind.annotation.RequestMapping;
  11. import org.springframework.web.bind.annotation.RestController;

  12. import java.util.concurrent.atomic.AtomicInteger;

  13. @Slf4j
  14. @RestController
  15. @RequestMapping(("/internal/"))
  16. public class NaisEndpoints {

  17.     private static final AtomicInteger isReady = new AtomicInteger(1);
  18.     private final AuthRepository authRepository;

  19.     @Autowired
  20.     public NaisEndpoints(MeterRegistry meterRegistry, AuthRepository authRepository) {
  21.         this.authRepository = authRepository;
  22.         Gauge.builder("dok_app_is_ready", isReady, AtomicInteger::get).register(meterRegistry);
  23.     }

  24.     @GetMapping("isAlive")
  25.     public ResponseEntity<String> isAlive() {
  26.         try {
  27.             authRepository.count();
  28.         } catch (Exception e) {
  29.             log.warn("isAlive error", e);
  30.             return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
  31.         }
  32.         return new ResponseEntity<>(HttpStatus.OK);
  33.     }

  34.     @GetMapping(value = "isReady")
  35.     public ResponseEntity<String> isReady() {
  36.         return new ResponseEntity<>(HttpStatus.OK);
  37.     }
  38. }