Search in sources :

Example 1 with SERVING

use of com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.SERVING in project titus-control-plane by Netflix.

the class DefaultHealthService method getServerStatus.

public Details getServerStatus() {
    RuntimeMXBean rb = ManagementFactory.getRuntimeMXBean();
    Duration uptime = Durations.fromMillis(rb.getUptime());
    if (!leaderActivator.isLeader()) {
        return Details.newBuilder().setStatus(NOT_SERVING).setLeader(false).setActive(false).setUptime(uptime).build();
    }
    boolean active = leaderActivator.isActivated();
    List<ServiceActivation> serviceActivations = activationLifecycle.getServiceActionTimesMs().stream().sorted(Comparator.comparing(Pair::getRight)).map(pair -> ServiceActivation.newBuilder().setName(pair.getLeft()).setActivationTime(Durations.fromMillis(pair.getRight())).build()).collect(Collectors.toList());
    Details.Builder details = Details.newBuilder().setStatus(SERVING).setCell(cellInfoResolver.getCellName()).setLeader(true).setActive(active).setUptime(uptime).setElectionTimestamp(Timestamps.fromMillis(leaderActivator.getElectionTimestamp())).setActivationTimestamp(Timestamps.fromMillis(leaderActivator.getActivationEndTimestamp())).addAllServiceActivationTimes(serviceActivations);
    if (active) {
        details.setActivationTime(Durations.fromMillis(leaderActivator.getActivationTime()));
    }
    return details.build();
}
Also used : RuntimeMXBean(java.lang.management.RuntimeMXBean) LeaderActivator(com.netflix.titus.api.supervisor.service.LeaderActivator) NOT_SERVING(com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.NOT_SERVING) ServiceActivation(com.netflix.titus.grpc.protogen.ServiceActivation) SERVING(com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.SERVING) Timestamps(com.google.protobuf.util.Timestamps) Singleton(javax.inject.Singleton) Collectors(java.util.stream.Collectors) Durations(com.google.protobuf.util.Durations) Inject(javax.inject.Inject) List(java.util.List) Duration(com.google.protobuf.Duration) Pair(com.netflix.titus.common.util.tuple.Pair) ActivationLifecycle(com.netflix.titus.common.util.guice.ActivationLifecycle) CellInfoResolver(com.netflix.titus.master.config.CellInfoResolver) Details(com.netflix.titus.grpc.protogen.HealthCheckResponse.Details) ManagementFactory(java.lang.management.ManagementFactory) Comparator(java.util.Comparator) Details(com.netflix.titus.grpc.protogen.HealthCheckResponse.Details) Duration(com.google.protobuf.Duration) RuntimeMXBean(java.lang.management.RuntimeMXBean) ServiceActivation(com.netflix.titus.grpc.protogen.ServiceActivation)

Example 2 with SERVING

use of com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.SERVING in project titus-control-plane by Netflix.

the class AggregatingHealthServiceTest method allCellsOK.

@Test
public void allCellsOK() {
    cellOne.getServiceRegistry().addService(new CellWithHealthStatus(ok("one")));
    cellTwo.getServiceRegistry().addService(new CellWithHealthStatus(ok("two")));
    AssertableSubscriber<HealthCheckResponse> subscriber = service.check(HealthCheckRequest.newBuilder().build()).test();
    subscriber.awaitTerminalEvent(10, TimeUnit.SECONDS);
    subscriber.assertNoErrors();
    subscriber.assertValueCount(1);
    HealthCheckResponse response = subscriber.getOnNextEvents().get(0);
    assertThat(response.getStatus()).isEqualTo(SERVING);
    assertThat(response.getDetailsCount()).isEqualTo(2);
    assertThat(response.getDetails(0).hasDetails()).isTrue();
    assertThat(response.getDetails(1).hasDetails()).isTrue();
    Set<String> cellsSeen = response.getDetailsList().stream().map(s -> s.getDetails().getCell()).collect(Collectors.toSet());
    assertThat(cellsSeen).contains("one", "two");
}
Also used : ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) AnonymousCallMetadataResolver(com.netflix.titus.runtime.endpoint.metadata.AnonymousCallMetadataResolver) ManagedChannel(io.grpc.ManagedChannel) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) HealthCheckRequest(com.netflix.titus.grpc.protogen.HealthCheckRequest) Durations(com.google.protobuf.util.Durations) AssertableSubscriber(rx.observers.AssertableSubscriber) StreamObserver(io.grpc.stub.StreamObserver) HealthGrpc(com.netflix.titus.grpc.protogen.HealthGrpc) GrpcConfiguration(com.netflix.titus.federation.startup.GrpcConfiguration) Map(java.util.Map) Details(com.netflix.titus.grpc.protogen.HealthCheckResponse.Details) Status(io.grpc.Status) Before(org.junit.Before) Clocks(com.netflix.titus.common.util.time.Clocks) HealthCheckResponse(com.netflix.titus.grpc.protogen.HealthCheckResponse) NOT_SERVING(com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.NOT_SERVING) Cell(com.netflix.titus.api.federation.model.Cell) SERVING(com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.SERVING) Set(java.util.Set) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Collectors(java.util.stream.Collectors) ServerStatus(com.netflix.titus.grpc.protogen.HealthCheckResponse.ServerStatus) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) DEADLINE_EXCEEDED(io.grpc.Status.Code.DEADLINE_EXCEEDED) Rule(org.junit.Rule) Optional(java.util.Optional) GrpcServerRule(io.grpc.testing.GrpcServerRule) TestClock(com.netflix.titus.common.util.time.TestClock) Collections(java.util.Collections) Mockito.reset(org.mockito.Mockito.reset) Mockito.mock(org.mockito.Mockito.mock) HealthCheckResponse(com.netflix.titus.grpc.protogen.HealthCheckResponse) Test(org.junit.Test)

Aggregations

Durations (com.google.protobuf.util.Durations)2 Details (com.netflix.titus.grpc.protogen.HealthCheckResponse.Details)2 NOT_SERVING (com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.NOT_SERVING)2 SERVING (com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.SERVING)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Duration (com.google.protobuf.Duration)1 Timestamps (com.google.protobuf.util.Timestamps)1 Cell (com.netflix.titus.api.federation.model.Cell)1 LeaderActivator (com.netflix.titus.api.supervisor.service.LeaderActivator)1 ActivationLifecycle (com.netflix.titus.common.util.guice.ActivationLifecycle)1 Clocks (com.netflix.titus.common.util.time.Clocks)1 TestClock (com.netflix.titus.common.util.time.TestClock)1 Pair (com.netflix.titus.common.util.tuple.Pair)1 GrpcConfiguration (com.netflix.titus.federation.startup.GrpcConfiguration)1 HealthCheckRequest (com.netflix.titus.grpc.protogen.HealthCheckRequest)1 HealthCheckResponse (com.netflix.titus.grpc.protogen.HealthCheckResponse)1 ServerStatus (com.netflix.titus.grpc.protogen.HealthCheckResponse.ServerStatus)1 HealthGrpc (com.netflix.titus.grpc.protogen.HealthGrpc)1 ServiceActivation (com.netflix.titus.grpc.protogen.ServiceActivation)1