Search in sources :

Example 21 with Builder

use of org.hypertrace.gateway.service.v1.entity.Entity.Builder in project gateway-service by hypertrace.

the class ExecutionVisitorTest method test_visitOnlySelectionsNode_shouldSetTotalEntityKeys.

@Test
public void test_visitOnlySelectionsNode_shouldSetTotalEntityKeys() {
    List<OrderByExpression> orderByExpressions = List.of(buildOrderByExpression(API_ID_ATTR));
    int limit = 2;
    int offset = 2;
    long startTime = 0;
    long endTime = 10;
    String tenantId = "TENANT_ID";
    Map<String, String> requestHeaders = Map.of("x-tenant-id", tenantId);
    AttributeScope entityType = AttributeScope.API;
    Expression selectionExpression = buildExpression(API_NAME_ATTR);
    Expression metricExpression = buildAggregateExpression(API_DURATION_ATTR, FunctionType.AVG, "AVG_API.duration", List.of());
    TimeAggregation timeAggregation = buildTimeAggregation(30, API_NUM_CALLS_ATTR, FunctionType.SUM, "SUM_API.numCalls", List.of());
    EntitiesRequest entitiesRequest = EntitiesRequest.newBuilder().setEntityType(entityType.name()).setStartTimeMillis(startTime).setEndTimeMillis(endTime).setFilter(Filter.getDefaultInstance()).addSelection(selectionExpression).addSelection(metricExpression).addAllOrderBy(orderByExpressions).setLimit(limit).setOffset(offset).build();
    EntitiesRequestContext entitiesRequestContext = new EntitiesRequestContext(tenantId, startTime, endTime, entityType.name(), "API.startTime", requestHeaders);
    // Order matters since we will do the pagination ourselves. So we use a LinkedHashMap
    Map<EntityKey, Builder> entityKeyBuilderResponseMap1 = new LinkedHashMap<>();
    entityKeyBuilderResponseMap1.put(EntityKey.of("entity-id-0"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-0")));
    entityKeyBuilderResponseMap1.put(EntityKey.of("entity-id-1"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-1")));
    entityKeyBuilderResponseMap1.put(EntityKey.of("entity-id-2"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-2")));
    entityKeyBuilderResponseMap1.put(EntityKey.of("entity-id-3"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-3")));
    Map<EntityKey, Builder> entityKeyBuilderResponseMap2 = new LinkedHashMap<>();
    entityKeyBuilderResponseMap2.put(EntityKey.of("entity-id-2"), Entity.newBuilder().putMetric("AVG_API.duration", getAggregatedMetricValue(FunctionType.AVG, 14.0)));
    entityKeyBuilderResponseMap2.put(EntityKey.of("entity-id-3"), Entity.newBuilder().putMetric("AVG_API.duration", getAggregatedMetricValue(FunctionType.AVG, 15.0)));
    Map<EntityKey, Builder> expectedEntityKeyBuilderResponseMap = new LinkedHashMap<>();
    expectedEntityKeyBuilderResponseMap.put(EntityKey.of("entity-id-2"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-2")).putMetric("AVG_API.duration", getAggregatedMetricValue(FunctionType.AVG, 14.0)));
    expectedEntityKeyBuilderResponseMap.put(EntityKey.of("entity-id-3"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-3")).putMetric("AVG_API.duration", getAggregatedMetricValue(FunctionType.AVG, 15.0)));
    when(executionContext.getEntityIdExpressions()).thenReturn(List.of(buildExpression(API_ID_ATTR)));
    when(expressionContext.getSourceToSelectionExpressionMap()).thenReturn(Map.of("QS", List.of(selectionExpression)));
    when(expressionContext.getSourceToMetricExpressionMap()).thenReturn(Map.of("QS", List.of(metricExpression)));
    when(expressionContext.getSourceToTimeAggregationMap()).thenReturn(Map.of("QS", List.of(timeAggregation)));
    when(executionContext.getEntitiesRequest()).thenReturn(entitiesRequest);
    when(executionContext.getTenantId()).thenReturn(tenantId);
    when(executionContext.getRequestHeaders()).thenReturn(requestHeaders);
    when(executionContext.getTimestampAttributeId()).thenReturn("API.startTime");
    EntitiesRequest entitiesRequestForAttributes = EntitiesRequest.newBuilder(entitiesRequest).clearLimit().clearOffset().clearOrderBy().clearSelection().clearTimeAggregation().addSelection(selectionExpression).build();
    EntityFetcherResponse attributesResponse = new EntityFetcherResponse(entityKeyBuilderResponseMap1);
    EntitiesRequest entitiesRequestForMetricAggregation = EntitiesRequest.newBuilder(entitiesRequest).clearLimit().clearOffset().clearOrderBy().clearSelection().clearTimeAggregation().addSelection(metricExpression).clearFilter().setFilter(generateInFilter(API_ID_ATTR, List.of("entity-id-3", "entity-id-2"))).build();
    when(queryServiceEntityFetcher.getEntities(entitiesRequestContext, entitiesRequestForAttributes)).thenReturn(attributesResponse);
    when(queryServiceEntityFetcher.getEntities(entitiesRequestContext, entitiesRequestForMetricAggregation)).thenReturn(new EntityFetcherResponse(entityKeyBuilderResponseMap2));
    SelectionNode childSelectionNode = new SelectionNode.Builder(new NoOpNode()).setAttrSelectionSources(Set.of("QS")).build();
    SortAndPaginateNode sortAndPaginateNode = new SortAndPaginateNode(childSelectionNode, limit, offset, orderByExpressions);
    SelectionNode selectionNode = new SelectionNode.Builder(sortAndPaginateNode).setAggMetricSelectionSources(Set.of("QS")).build();
    // child selection node has no child data fetcher node. it should set total entity keys
    {
        compareEntityResponses(new EntityResponse(new EntityFetcherResponse(entityKeyBuilderResponseMap1), 4), executionVisitor.visit(childSelectionNode));
    }
    // selection node has child nodes. it should not set total entity keys, and fallback to the
    // total entity keys set by the child selection node
    {
        compareEntityResponses(new EntityResponse(new EntityFetcherResponse(expectedEntityKeyBuilderResponseMap), 4), executionVisitor.visit(selectionNode));
    }
}
Also used : Builder(org.hypertrace.gateway.service.v1.entity.Entity.Builder) NoOpNode(org.hypertrace.gateway.service.entity.query.NoOpNode) SortAndPaginateNode(org.hypertrace.gateway.service.entity.query.SortAndPaginateNode) LinkedHashMap(java.util.LinkedHashMap) EntityKey(org.hypertrace.gateway.service.entity.EntityKey) EntityFetcherResponse(org.hypertrace.gateway.service.common.datafetcher.EntityFetcherResponse) EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) AttributeScope(org.hypertrace.core.attribute.service.v1.AttributeScope) EntitiesRequestAndResponseUtils.buildAggregateExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildAggregateExpression) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) EntitiesRequestAndResponseUtils.buildExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildExpression) Expression(org.hypertrace.gateway.service.v1.common.Expression) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) EntityResponse(org.hypertrace.gateway.service.common.datafetcher.EntityResponse) EntitiesRequestContext(org.hypertrace.gateway.service.entity.EntitiesRequestContext) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) EntitiesRequestAndResponseUtils.buildTimeAggregation(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildTimeAggregation) TimeAggregation(org.hypertrace.gateway.service.v1.common.TimeAggregation) SelectionNode(org.hypertrace.gateway.service.entity.query.SelectionNode) Test(org.junit.jupiter.api.Test)

Example 22 with Builder

use of org.hypertrace.gateway.service.v1.entity.Entity.Builder in project gateway-service by hypertrace.

the class ExecutionVisitorTest method test_visitDataFetcherNodeEds.

@Test
public void test_visitDataFetcherNodeEds() {
    List<OrderByExpression> orderByExpressions = List.of(buildOrderByExpression(API_ID_ATTR));
    int limit = 10;
    int offset = 0;
    long startTime = 0;
    long endTime = 10;
    String tenantId = "TENANT_ID";
    Map<String, String> requestHeaders = Map.of("x-tenant-id", tenantId);
    AttributeScope entityType = AttributeScope.API;
    Expression selectionExpression = buildExpression(API_NAME_ATTR);
    EntitiesRequest entitiesRequest = EntitiesRequest.newBuilder().setEntityType(entityType.name()).setStartTimeMillis(startTime).setEndTimeMillis(endTime).addSelection(selectionExpression).setFilter(generateEQFilter(API_DISCOVERY_STATE, "DISCOVERED")).addAllOrderBy(orderByExpressions).setLimit(limit).setOffset(offset).build();
    EntitiesRequestContext entitiesRequestContext = new EntitiesRequestContext(tenantId, startTime, endTime, entityType.name(), "API.startTime", requestHeaders);
    Map<EntityKey, Builder> entityKeyBuilderResponseMap = Map.of(EntityKey.of("entity-id-0"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-0")), EntityKey.of("entity-id-1"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-1")), EntityKey.of("entity-id-2"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-2")));
    EntityFetcherResponse entityFetcherResponse = new EntityFetcherResponse(entityKeyBuilderResponseMap);
    when(expressionContext.getSourceToSelectionExpressionMap()).thenReturn(Map.of("EDS", List.of(selectionExpression)));
    when(executionContext.getEntitiesRequest()).thenReturn(entitiesRequest);
    when(executionContext.getTenantId()).thenReturn(tenantId);
    when(executionContext.getRequestHeaders()).thenReturn(requestHeaders);
    when(executionContext.getTimestampAttributeId()).thenReturn("API.startTime");
    when(entityDataServiceEntityFetcher.getEntities(eq(entitiesRequestContext), eq(entitiesRequest))).thenReturn(entityFetcherResponse);
    when(entityDataServiceEntityFetcher.getTotal(eq(entitiesRequestContext), eq(entitiesRequest))).thenReturn(100L);
    DataFetcherNode dataFetcherNode = new DataFetcherNode("EDS", entitiesRequest.getFilter(), limit, offset, orderByExpressions, true);
    compareEntityResponses(new EntityResponse(entityFetcherResponse, 100), executionVisitor.visit(dataFetcherNode));
}
Also used : Builder(org.hypertrace.gateway.service.v1.entity.Entity.Builder) EntityKey(org.hypertrace.gateway.service.entity.EntityKey) EntityFetcherResponse(org.hypertrace.gateway.service.common.datafetcher.EntityFetcherResponse) EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) AttributeScope(org.hypertrace.core.attribute.service.v1.AttributeScope) EntitiesRequestAndResponseUtils.buildAggregateExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildAggregateExpression) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) EntitiesRequestAndResponseUtils.buildExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildExpression) Expression(org.hypertrace.gateway.service.v1.common.Expression) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) EntityResponse(org.hypertrace.gateway.service.common.datafetcher.EntityResponse) DataFetcherNode(org.hypertrace.gateway.service.entity.query.DataFetcherNode) EntitiesRequestContext(org.hypertrace.gateway.service.entity.EntitiesRequestContext) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) Test(org.junit.jupiter.api.Test)

Example 23 with Builder

use of org.hypertrace.gateway.service.v1.entity.Entity.Builder in project gateway-service by hypertrace.

the class ExecutionVisitorTest method test_visitDataFetcherNodeQs.

@Test
public void test_visitDataFetcherNodeQs() {
    List<OrderByExpression> orderByExpressions = List.of(buildOrderByExpression(API_ID_ATTR));
    int limit = 10;
    int offset = 0;
    long startTime = 0;
    long endTime = 10;
    String tenantId = "TENANT_ID";
    Map<String, String> requestHeaders = Map.of("x-tenant-id", tenantId);
    AttributeScope entityType = AttributeScope.API;
    Expression selectionExpression = buildExpression(API_NAME_ATTR);
    EntitiesRequest entitiesRequest = EntitiesRequest.newBuilder().setEntityType(entityType.name()).setStartTimeMillis(startTime).setEndTimeMillis(endTime).addSelection(selectionExpression).setFilter(generateEQFilter(API_DISCOVERY_STATE, "DISCOVERED")).addAllOrderBy(orderByExpressions).setLimit(limit).setOffset(offset).build();
    EntitiesRequestContext entitiesRequestContext = new EntitiesRequestContext(tenantId, startTime, endTime, entityType.name(), "API.startTime", requestHeaders);
    Map<EntityKey, Builder> entityKeyBuilderResponseMap = Map.of(EntityKey.of("entity-id-0"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-0")), EntityKey.of("entity-id-1"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-1")), EntityKey.of("entity-id-2"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-2")));
    EntityFetcherResponse entityFetcherResponse = new EntityFetcherResponse(entityKeyBuilderResponseMap);
    when(expressionContext.getSourceToSelectionExpressionMap()).thenReturn(Map.of("QS", List.of(selectionExpression)));
    when(executionContext.getEntitiesRequest()).thenReturn(entitiesRequest);
    when(executionContext.getTenantId()).thenReturn(tenantId);
    when(executionContext.getRequestHeaders()).thenReturn(requestHeaders);
    when(executionContext.getTimestampAttributeId()).thenReturn("API.startTime");
    when(queryServiceEntityFetcher.getEntities(eq(entitiesRequestContext), eq(entitiesRequest))).thenReturn(entityFetcherResponse);
    when(queryServiceEntityFetcher.getTotal(eq(entitiesRequestContext), eq(entitiesRequest))).thenReturn(100L);
    when(queryServiceEntityFetcher.getTimeAggregatedMetrics(eq(entitiesRequestContext), eq(entitiesRequest))).thenReturn(new EntityFetcherResponse());
    DataFetcherNode dataFetcherNode = new DataFetcherNode("QS", entitiesRequest.getFilter(), limit, offset, orderByExpressions, true);
    compareEntityResponses(new EntityResponse(entityFetcherResponse, 100L), executionVisitor.visit(dataFetcherNode));
}
Also used : Builder(org.hypertrace.gateway.service.v1.entity.Entity.Builder) EntityKey(org.hypertrace.gateway.service.entity.EntityKey) EntityFetcherResponse(org.hypertrace.gateway.service.common.datafetcher.EntityFetcherResponse) EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) AttributeScope(org.hypertrace.core.attribute.service.v1.AttributeScope) EntitiesRequestAndResponseUtils.buildAggregateExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildAggregateExpression) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) EntitiesRequestAndResponseUtils.buildExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildExpression) Expression(org.hypertrace.gateway.service.v1.common.Expression) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) EntityResponse(org.hypertrace.gateway.service.common.datafetcher.EntityResponse) DataFetcherNode(org.hypertrace.gateway.service.entity.query.DataFetcherNode) EntitiesRequestContext(org.hypertrace.gateway.service.entity.EntitiesRequestContext) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) Test(org.junit.jupiter.api.Test)

Example 24 with Builder

use of org.hypertrace.gateway.service.v1.entity.Entity.Builder in project gateway-service by hypertrace.

the class ExecutionVisitorTest method test_visitDataFetcherNode_cannotFetchTotal.

@Test
public void test_visitDataFetcherNode_cannotFetchTotal() {
    List<OrderByExpression> orderByExpressions = List.of(buildOrderByExpression(API_ID_ATTR));
    int limit = 10;
    int offset = 0;
    long startTime = 0;
    long endTime = 10;
    String tenantId = "TENANT_ID";
    Map<String, String> requestHeaders = Map.of("x-tenant-id", tenantId);
    AttributeScope entityType = AttributeScope.API;
    Expression selectionExpression = buildExpression(API_NAME_ATTR);
    EntitiesRequest entitiesRequest = EntitiesRequest.newBuilder().setEntityType(entityType.name()).setStartTimeMillis(startTime).setEndTimeMillis(endTime).addSelection(selectionExpression).setFilter(generateEQFilter(API_DISCOVERY_STATE, "DISCOVERED")).addAllOrderBy(orderByExpressions).setLimit(limit).setOffset(offset).build();
    EntitiesRequestContext entitiesRequestContext = new EntitiesRequestContext(tenantId, startTime, endTime, entityType.name(), "API.startTime", requestHeaders);
    Map<EntityKey, Builder> entityKeyBuilderResponseMap = Map.of(EntityKey.of("entity-id-0"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-0")), EntityKey.of("entity-id-1"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-1")), EntityKey.of("entity-id-2"), Entity.newBuilder().putAttribute("API.name", getStringValue("entity-2")));
    EntityFetcherResponse entityFetcherResponse = new EntityFetcherResponse(entityKeyBuilderResponseMap);
    when(expressionContext.getSourceToSelectionExpressionMap()).thenReturn(Map.of("QS", List.of(selectionExpression)));
    when(executionContext.getEntitiesRequest()).thenReturn(entitiesRequest);
    when(executionContext.getTenantId()).thenReturn(tenantId);
    when(executionContext.getRequestHeaders()).thenReturn(requestHeaders);
    when(executionContext.getTimestampAttributeId()).thenReturn("API.startTime");
    when(queryServiceEntityFetcher.getEntities(eq(entitiesRequestContext), eq(entitiesRequest))).thenReturn(entityFetcherResponse);
    when(queryServiceEntityFetcher.getTimeAggregatedMetrics(eq(entitiesRequestContext), eq(entitiesRequest))).thenReturn(new EntityFetcherResponse());
    DataFetcherNode dataFetcherNode = new DataFetcherNode("QS", entitiesRequest.getFilter(), limit, offset, orderByExpressions, false);
    compareEntityResponses(new EntityResponse(entityFetcherResponse, entityFetcherResponse.getEntityKeyBuilderMap().size()), executionVisitor.visit(dataFetcherNode));
}
Also used : Builder(org.hypertrace.gateway.service.v1.entity.Entity.Builder) EntityKey(org.hypertrace.gateway.service.entity.EntityKey) EntityFetcherResponse(org.hypertrace.gateway.service.common.datafetcher.EntityFetcherResponse) EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) AttributeScope(org.hypertrace.core.attribute.service.v1.AttributeScope) EntitiesRequestAndResponseUtils.buildAggregateExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildAggregateExpression) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) EntitiesRequestAndResponseUtils.buildExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildExpression) Expression(org.hypertrace.gateway.service.v1.common.Expression) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) EntityResponse(org.hypertrace.gateway.service.common.datafetcher.EntityResponse) DataFetcherNode(org.hypertrace.gateway.service.entity.query.DataFetcherNode) EntitiesRequestContext(org.hypertrace.gateway.service.entity.EntitiesRequestContext) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) Test(org.junit.jupiter.api.Test)

Example 25 with Builder

use of org.hypertrace.gateway.service.v1.entity.Entity.Builder in project gateway-service by hypertrace.

the class QueryServiceEntityFetcherTests method testGetTimeAggregatedMetricsForAvgRateInIsoFormat.

@Test
public void testGetTimeAggregatedMetricsForAvgRateInIsoFormat() {
    List<OrderByExpression> orderByExpressions = List.of(buildOrderByExpression(API_ID_ATTR));
    long startTime = 1L;
    long endTime = 10L;
    int limit = 10;
    int offset = 5;
    String tenantId = "TENANT_ID";
    Map<String, String> requestHeaders = Map.of("x-tenant-id", tenantId);
    AttributeScope entityType = AttributeScope.API;
    TimeAggregation timeAggregation = buildTimeAggregation(30, API_NUM_CALLS_ATTR, FunctionType.AVGRATE, "AVGRATE_API.numCalls", List.of(Expression.newBuilder().setLiteral(LiteralConstant.newBuilder().setValue(Value.newBuilder().setString("PT1M").setValueType(ValueType.STRING))).build()));
    EntitiesRequest entitiesRequest = EntitiesRequest.newBuilder().setEntityType(entityType.name()).setStartTimeMillis(startTime).setEndTimeMillis(endTime).addTimeAggregation(timeAggregation).setFilter(Filter.newBuilder().setOperator(AND).addChildFilter(EntitiesRequestAndResponseUtils.getTimeRangeFilter("API.startTime", startTime, endTime)).addChildFilter(generateEQFilter(API_DISCOVERY_STATE_ATTR, "DISCOVERED"))).addAllOrderBy(orderByExpressions).setLimit(limit).setOffset(offset).build();
    EntitiesRequestContext entitiesRequestContext = new EntitiesRequestContext(tenantId, startTime, endTime, entityType.name(), "API.startTime", requestHeaders);
    QueryRequest expectedQueryRequest = QueryRequest.newBuilder().addSelection(QueryAndGatewayDtoConverter.convertToQueryExpression(timeAggregation.getAggregation())).setFilter(createQsRequestFilter(API_START_TIME_ATTR, API_ID_ATTR, startTime, endTime, createStringFilter(API_DISCOVERY_STATE_ATTR, Operator.EQ, "DISCOVERED"))).addAllGroupBy(List.of(API_ID_ATTR).stream().map(QueryRequestUtil::createAttributeExpression).collect(Collectors.toList())).addGroupBy(createTimeColumnGroupByExpression(API_START_TIME_ATTR, 30)).setOffset(0).setLimit(10000).build();
    List<ResultSetChunk> resultSetChunks = List.of(getResultSetChunk(List.of("API.apiId", "timeColumn", "AVGRATE_API.numCalls"), new String[][] { { "apiId1", "10000", "34" }, { "apiId2", "20000", "34" } }));
    when(queryServiceClient.executeQuery(eq(expectedQueryRequest), eq(requestHeaders), eq(500))).thenReturn(resultSetChunks.iterator());
    EntityFetcherResponse response = queryServiceEntityFetcher.getTimeAggregatedMetrics(entitiesRequestContext, entitiesRequest);
    assertEquals(2, response.size());
    Map<String, MetricSeries> metricSeriesMap1 = new LinkedHashMap<>();
    metricSeriesMap1.put("AVGRATE_API.numCalls", MetricSeries.newBuilder().addValue(Interval.newBuilder().setStartTimeMillis(10000).setEndTimeMillis(40000).setValue(Value.newBuilder().setValueType(ValueType.DOUBLE).setDouble(34.0))).setAggregation("AVGRATE").setPeriod(Period.newBuilder().setUnit("SECONDS").setValue(30).build()).build());
    Map<String, MetricSeries> metricSeriesMap2 = new LinkedHashMap<>();
    metricSeriesMap2.put("AVGRATE_API.numCalls", MetricSeries.newBuilder().addValue(Interval.newBuilder().setStartTimeMillis(20000).setEndTimeMillis(50000).setValue(Value.newBuilder().setValueType(ValueType.DOUBLE).setDouble(34.0))).setAggregation("AVGRATE").setPeriod(Period.newBuilder().setUnit("SECONDS").setValue(30).build()).build());
    Map<EntityKey, Builder> expectedEntityKeyBuilderResponseMap = new LinkedHashMap<>();
    expectedEntityKeyBuilderResponseMap.put(EntityKey.of("apiId1"), Entity.newBuilder().setId("apiId1").setEntityType("API").putAllMetricSeries(metricSeriesMap1).putAttribute("API.id", getStringValue("apiId1")));
    expectedEntityKeyBuilderResponseMap.put(EntityKey.of("apiId2"), Entity.newBuilder().setId("apiId2").setEntityType("API").putAllMetricSeries(metricSeriesMap2).putAttribute("API.id", getStringValue("apiId2")));
    compareEntityFetcherResponses(new EntityFetcherResponse(expectedEntityKeyBuilderResponseMap), response);
}
Also used : QueryRequest(org.hypertrace.core.query.service.api.QueryRequest) Builder(org.hypertrace.gateway.service.v1.entity.Entity.Builder) LinkedHashMap(java.util.LinkedHashMap) EntityKey(org.hypertrace.gateway.service.entity.EntityKey) MetricSeries(org.hypertrace.gateway.service.v1.common.MetricSeries) EntitiesRequest(org.hypertrace.gateway.service.v1.entity.EntitiesRequest) AttributeScope(org.hypertrace.core.attribute.service.v1.AttributeScope) EntitiesRequestContext(org.hypertrace.gateway.service.entity.EntitiesRequestContext) EntitiesRequestAndResponseUtils.buildOrderByExpression(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression) OrderByExpression(org.hypertrace.gateway.service.v1.common.OrderByExpression) EntitiesRequestAndResponseUtils.buildTimeAggregation(org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildTimeAggregation) TimeAggregation(org.hypertrace.gateway.service.v1.common.TimeAggregation) QueryRequestUtil(org.hypertrace.gateway.service.common.converters.QueryRequestUtil) QueryServiceRequestAndResponseUtils.getResultSetChunk(org.hypertrace.gateway.service.common.QueryServiceRequestAndResponseUtils.getResultSetChunk) ResultSetChunk(org.hypertrace.core.query.service.api.ResultSetChunk) Test(org.junit.jupiter.api.Test)

Aggregations

EntityKey (org.hypertrace.gateway.service.entity.EntityKey)15 EntitiesRequest (org.hypertrace.gateway.service.v1.entity.EntitiesRequest)15 EntitiesRequestContext (org.hypertrace.gateway.service.entity.EntitiesRequestContext)14 Builder (org.hypertrace.gateway.service.v1.entity.Entity.Builder)14 OrderByExpression (org.hypertrace.gateway.service.v1.common.OrderByExpression)12 Test (org.junit.jupiter.api.Test)11 AttributeScope (org.hypertrace.core.attribute.service.v1.AttributeScope)10 Expression (org.hypertrace.gateway.service.v1.common.Expression)10 LinkedHashMap (java.util.LinkedHashMap)9 EntitiesRequestAndResponseUtils.buildOrderByExpression (org.hypertrace.gateway.service.common.EntitiesRequestAndResponseUtils.buildOrderByExpression)9 EntityFetcherResponse (org.hypertrace.gateway.service.common.datafetcher.EntityFetcherResponse)9 QueryRequest (org.hypertrace.core.query.service.api.QueryRequest)8 ResultSetChunk (org.hypertrace.core.query.service.api.ResultSetChunk)8 EntityResponse (org.hypertrace.gateway.service.common.datafetcher.EntityResponse)8 TimeAggregation (org.hypertrace.gateway.service.v1.common.TimeAggregation)8 AttributeMetadata (org.hypertrace.core.attribute.service.v1.AttributeMetadata)7 ArrayList (java.util.ArrayList)5 List (java.util.List)5 Map (java.util.Map)5 Collectors (java.util.stream.Collectors)5