Search in sources :

Example 1 with HostStoreLags

use of io.confluent.ksql.rest.entity.HostStoreLags in project ksql by confluentinc.

the class LagReportingAgentTest method shouldReceiveLags_listAllCurrentPositions.

@Test
public void shouldReceiveLags_listAllCurrentPositions() {
    // When:
    lagReportingAgent.receiveHostLag(hostLag(HOST_ENTITY1, LAG_MAP1, 100));
    lagReportingAgent.receiveHostLag(hostLag(HOST_ENTITY2, LAG_MAP2, 200));
    lagReportingAgent.onHostStatusUpdated(HOSTS_ALIVE);
    // Then:
    ImmutableMap<KsqlHostInfoEntity, HostStoreLags> allLags = lagReportingAgent.getAllLags();
    LagInfoEntity lag = allLags.get(HOST_ENTITY1).getStateStoreLags(QUERY_STORE_A).flatMap(s -> s.getLagByPartition(1)).get();
    assertEquals(M1_A1_CUR, lag.getCurrentOffsetPosition());
    assertEquals(M1_A1_END, lag.getEndOffsetPosition());
    assertEquals(M1_A1_LAG, lag.getOffsetLag());
    lag = allLags.get(HOST_ENTITY1).getStateStoreLags(QUERY_STORE_A).flatMap(s -> s.getLagByPartition(3)).get();
    assertEquals(M1_A3_CUR, lag.getCurrentOffsetPosition());
    assertEquals(M1_A3_END, lag.getEndOffsetPosition());
    assertEquals(M1_A3_LAG, lag.getOffsetLag());
    lag = allLags.get(HOST_ENTITY1).getStateStoreLags(QUERY_STORE_B).flatMap(s -> s.getLagByPartition(4)).get();
    assertEquals(M1_B4_CUR, lag.getCurrentOffsetPosition());
    assertEquals(M1_B4_END, lag.getEndOffsetPosition());
    assertEquals(M1_B4_LAG, lag.getOffsetLag());
    lag = allLags.get(HOST_ENTITY2).getStateStoreLags(QUERY_STORE_A).flatMap(s -> s.getLagByPartition(1)).get();
    assertEquals(M2_A1_CUR, lag.getCurrentOffsetPosition());
    assertEquals(M2_A1_END, lag.getEndOffsetPosition());
    assertEquals(M2_A1_LAG, lag.getOffsetLag());
    lag = allLags.get(HOST_ENTITY2).getStateStoreLags(QUERY_STORE_B).flatMap(s -> s.getLagByPartition(4)).get();
    assertEquals(M2_B4_CUR, lag.getCurrentOffsetPosition());
    assertEquals(M2_B4_END, lag.getEndOffsetPosition());
    assertEquals(M2_B4_LAG, lag.getOffsetLag());
}
Also used : StateStoreLags(io.confluent.ksql.rest.entity.StateStoreLags) Mock(org.mockito.Mock) HostStoreLags(io.confluent.ksql.rest.entity.HostStoreLags) ServiceContext(io.confluent.ksql.services.ServiceContext) RunWith(org.junit.runner.RunWith) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) LagReportingMessage(io.confluent.ksql.rest.entity.LagReportingMessage) URI(java.net.URI) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) Before(org.junit.Before) ImmutableMap(com.google.common.collect.ImmutableMap) KsqlEngine(io.confluent.ksql.engine.KsqlEngine) Builder(io.confluent.ksql.rest.server.LagReportingAgent.Builder) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) SimpleKsqlClient(io.confluent.ksql.services.SimpleKsqlClient) Mockito.verify(org.mockito.Mockito.verify) SendLagService(io.confluent.ksql.rest.server.LagReportingAgent.SendLagService) LagInfo(org.apache.kafka.streams.LagInfo) Assert.assertFalse(org.junit.Assert.assertFalse) HostStatus(io.confluent.ksql.util.HostStatus) Clock(java.time.Clock) Optional(java.util.Optional) QueryStateStoreId(io.confluent.ksql.rest.entity.QueryStateStoreId) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.eq(org.mockito.Mockito.eq) HostStoreLags(io.confluent.ksql.rest.entity.HostStoreLags) LagInfoEntity(io.confluent.ksql.rest.entity.LagInfoEntity) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity) Test(org.junit.Test)

Example 2 with HostStoreLags

use of io.confluent.ksql.rest.entity.HostStoreLags in project ksql by confluentinc.

the class LagReportingAgentFunctionalTest method allLagsReported.

private static boolean allLagsReported(ClusterStatusResponse response) {
    if (response.getClusterStatus().size() == 2) {
        HostStoreLags store0 = response.getClusterStatus().get(HOST0).getHostStoreLags();
        HostStoreLags store1 = response.getClusterStatus().get(HOST1).getHostStoreLags();
        if (arePartitionsCurrent(store0) && arePartitionsCurrent(store1)) {
            LOG.info("Found expected lags: {}", response.getClusterStatus().toString());
            return true;
        }
    }
    LOG.info("Didn't yet find expected lags: {}", response.getClusterStatus().toString());
    return false;
}
Also used : HostStoreLags(io.confluent.ksql.rest.entity.HostStoreLags)

Example 3 with HostStoreLags

use of io.confluent.ksql.rest.entity.HostStoreLags in project ksql by confluentinc.

the class LagReportingAgent method receiveHostLag.

/**
 * Stores the host lag received from a remote Ksql server.
 * @param lagReportingMessage The host lag information sent directly from the other node.
 */
public void receiveHostLag(final LagReportingMessage lagReportingMessage) {
    final HostStoreLags hostStoreLags = lagReportingMessage.getHostStoreLags();
    final long updateTimeMs = hostStoreLags.getUpdateTimeMs();
    final KsqlHostInfoEntity KsqlHostInfoEntity = lagReportingMessage.getKsqlHost();
    final KsqlHostInfo KsqlHostInfo = KsqlHostInfoEntity.toKsqlHost();
    LOG.debug("Receive lag at: {} from host: {} lag: {} ", updateTimeMs, KsqlHostInfoEntity, hostStoreLags.getStateStoreLags());
    receivedLagInfo.compute(KsqlHostInfo, (hi, previousHostLagInfo) -> previousHostLagInfo != null && previousHostLagInfo.getUpdateTimeMs() > updateTimeMs ? previousHostLagInfo : hostStoreLags);
}
Also used : HostStoreLags(io.confluent.ksql.rest.entity.HostStoreLags) KsqlHostInfo(io.confluent.ksql.util.KsqlHostInfo) KsqlHostInfoEntity(io.confluent.ksql.rest.entity.KsqlHostInfoEntity)

Aggregations

HostStoreLags (io.confluent.ksql.rest.entity.HostStoreLags)3 KsqlHostInfoEntity (io.confluent.ksql.rest.entity.KsqlHostInfoEntity)2 KsqlHostInfo (io.confluent.ksql.util.KsqlHostInfo)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 KsqlEngine (io.confluent.ksql.engine.KsqlEngine)1 LagInfoEntity (io.confluent.ksql.rest.entity.LagInfoEntity)1 LagReportingMessage (io.confluent.ksql.rest.entity.LagReportingMessage)1 QueryStateStoreId (io.confluent.ksql.rest.entity.QueryStateStoreId)1 StateStoreLags (io.confluent.ksql.rest.entity.StateStoreLags)1 Builder (io.confluent.ksql.rest.server.LagReportingAgent.Builder)1 SendLagService (io.confluent.ksql.rest.server.LagReportingAgent.SendLagService)1 ServiceContext (io.confluent.ksql.services.ServiceContext)1 SimpleKsqlClient (io.confluent.ksql.services.SimpleKsqlClient)1 HostStatus (io.confluent.ksql.util.HostStatus)1 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)1 URI (java.net.URI)1 Clock (java.time.Clock)1 Map (java.util.Map)1 Optional (java.util.Optional)1