Search in sources :

Example 1 with NOT_SERVING

use of com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.NOT_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 NOT_SERVING

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

the class AggregatingHealthServiceTest method allCellsFailing.

@Test
public void allCellsFailing() {
    cellOne.getServiceRegistry().addService(new CellWithHealthStatus(failing("one")));
    cellTwo.getServiceRegistry().addService(new CellWithHealthStatus(failing("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(NOT_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)

Example 3 with NOT_SERVING

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

the class AggregatingHealthServiceTest method oneCellFailing.

@Test
public void oneCellFailing() {
    cellOne.getServiceRegistry().addService(new CellWithHealthStatus(ok("one")));
    cellTwo.getServiceRegistry().addService(new CellWithHealthStatus(failing("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(NOT_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)3 Details (com.netflix.titus.grpc.protogen.HealthCheckResponse.Details)3 NOT_SERVING (com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.NOT_SERVING)3 SERVING (com.netflix.titus.grpc.protogen.HealthCheckResponse.ServingStatus.SERVING)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 Cell (com.netflix.titus.api.federation.model.Cell)2 Clocks (com.netflix.titus.common.util.time.Clocks)2 TestClock (com.netflix.titus.common.util.time.TestClock)2 GrpcConfiguration (com.netflix.titus.federation.startup.GrpcConfiguration)2 HealthCheckRequest (com.netflix.titus.grpc.protogen.HealthCheckRequest)2 HealthCheckResponse (com.netflix.titus.grpc.protogen.HealthCheckResponse)2 ServerStatus (com.netflix.titus.grpc.protogen.HealthCheckResponse.ServerStatus)2 HealthGrpc (com.netflix.titus.grpc.protogen.HealthGrpc)2 AnonymousCallMetadataResolver (com.netflix.titus.runtime.endpoint.metadata.AnonymousCallMetadataResolver)2 ManagedChannel (io.grpc.ManagedChannel)2 Status (io.grpc.Status)2 DEADLINE_EXCEEDED (io.grpc.Status.Code.DEADLINE_EXCEEDED)2 StreamObserver (io.grpc.stub.StreamObserver)2 GrpcServerRule (io.grpc.testing.GrpcServerRule)2