Search in sources :

Example 26 with StructuredTrace

use of org.hypertrace.core.datamodel.StructuredTrace in project hypertrace-ingester by hypertrace.

the class BackendEntityEnricherTest method test_EnrichEvent_test_enrichEvent_missingBackendOperationEvent.

@Test
public void test_EnrichEvent_test_enrichEvent_missingBackendOperationEvent() {
    Event e = createApiEntryEvent(EVENT_ID).build();
    StructuredTrace trace = createStructuredTrace(TENANT_ID, e);
    enricher.enrichEvent(trace, e);
    Assertions.assertNull(EnrichedSpanUtils.getBackendOperation(e));
}
Also used : StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test) AbstractAttributeEnricherTest(org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)

Example 27 with StructuredTrace

use of org.hypertrace.core.datamodel.StructuredTrace in project hypertrace-ingester by hypertrace.

the class BackendEntityEnricherTest method test_EnrichTrace_BackendResolvedForBrokenEvent.

@Test
public void test_EnrichTrace_BackendResolvedForBrokenEvent() {
    String eventName = "broken event";
    String backendName = "peer";
    String backendId = "peerId";
    String serviceName = "client";
    Map<String, String> identifyingAttributes = Map.of(BACKEND_PROTOCOL_ATTR_NAME, "UNKNOWN", BACKEND_HOST_ATTR_NAME, backendName, BACKEND_PORT_ATTR_NAME, "-1");
    Map<String, String> attributes = Map.of("FROM_EVENT", eventName, "FROM_EVENT_ID", HexUtils.getHex(ByteBuffer.wrap(EVENT_ID.getBytes())));
    Entity backendEntity = createEntity(EntityType.BACKEND, backendName, identifyingAttributes, attributes, TENANT_ID);
    when(edsClient.upsert(eq(backendEntity))).thenReturn(Entity.newBuilder(backendEntity).setEntityId(backendId).putAllAttributes(createEdsAttributes(identifyingAttributes)).build());
    // for broken event service and peer service are different
    Event e = createApiExitEvent(EVENT_ID, serviceName, backendName).setEventName(eventName).build();
    StructuredTrace trace = createStructuredTrace(TENANT_ID, e);
    enricher.enrichTrace(trace);
    // assert that backend has been created
    Assertions.assertNotNull(EnrichedSpanUtils.getBackendId(e));
    Assertions.assertNotNull(EnrichedSpanUtils.getBackendName(e));
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test) AbstractAttributeEnricherTest(org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)

Example 28 with StructuredTrace

use of org.hypertrace.core.datamodel.StructuredTrace in project hypertrace-ingester by hypertrace.

the class BackendEntityEnricherTest method test_EnrichTrace_noBackendResolved.

@Test
public void test_EnrichTrace_noBackendResolved() {
    Event e = createApiExitEvent(EVENT_ID).build();
    StructuredTrace trace = createStructuredTrace(TENANT_ID, e);
    enricher.enrichTrace(trace);
    Assertions.assertEquals(ByteBuffer.wrap(EVENT_ID.getBytes()), e.getEventId());
    Assertions.assertNull(EnrichedSpanUtils.getBackendId(e));
}
Also used : StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test) AbstractAttributeEnricherTest(org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)

Example 29 with StructuredTrace

use of org.hypertrace.core.datamodel.StructuredTrace in project hypertrace-ingester by hypertrace.

the class BackendEntityEnricherTest method test_EnrichTrace_ExternalBackendNotResolvedAsPeerServiceExists.

@Test
public void test_EnrichTrace_ExternalBackendNotResolvedAsPeerServiceExists() {
    String eventName = "service exists";
    String backendName = "external-backend";
    String serviceId = "serviceId";
    String peerService = "peerService";
    // return false for backend service name identified by http backend resolver
    AttributeValue fqnAttribute = AttributeValue.newBuilder().setValue(Value.newBuilder().setString(backendName)).build();
    ByTypeAndIdentifyingAttributes request = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType(EntityType.SERVICE.name()).putIdentifyingAttributes(EntityConstants.getValue(org.hypertrace.entity.constants.v1.CommonAttribute.COMMON_ATTRIBUTE_FQN), fqnAttribute).build();
    // check for if service exists for peer service
    when(edsClient.getByTypeAndIdentifyingAttributes(eq(TENANT_ID), eq(request))).thenReturn(null);
    AttributeValue fqnAttributePeerService = AttributeValue.newBuilder().setValue(Value.newBuilder().setString(peerService)).build();
    ByTypeAndIdentifyingAttributes requestPeerService = ByTypeAndIdentifyingAttributes.newBuilder().setEntityType(EntityType.SERVICE.name()).putIdentifyingAttributes(EntityConstants.getValue(org.hypertrace.entity.constants.v1.CommonAttribute.COMMON_ATTRIBUTE_FQN), fqnAttributePeerService).build();
    when(edsClient.getByTypeAndIdentifyingAttributes(eq(TENANT_ID), eq(requestPeerService))).thenReturn(Entity.newBuilder().setEntityId(serviceId).build());
    // for broken event service and peer service are different
    Event.Builder eventBuilder = createApiExitEvent(EVENT_ID, backendName, peerService).setEventName(eventName).setEnrichedAttributes(createNewAvroAttributes(Map.of("PROTOCOL", "HTTPS")));
    eventBuilder.getHttpBuilder().getRequestBuilder().setHost(backendName).setScheme("https").setPath("/abc/v1/book");
    Event e = eventBuilder.build();
    StructuredTrace trace = createStructuredTrace(TENANT_ID, e);
    enricher.enrichTrace(trace);
    // assert that backend has been created
    Assertions.assertNull(EnrichedSpanUtils.getBackendId(e));
    Assertions.assertNull(EnrichedSpanUtils.getBackendName(e));
}
Also used : AttributeValue(org.hypertrace.entity.data.service.v1.AttributeValue) ByTypeAndIdentifyingAttributes(org.hypertrace.entity.data.service.v1.ByTypeAndIdentifyingAttributes) StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Event(org.hypertrace.core.datamodel.Event) Test(org.junit.jupiter.api.Test) AbstractAttributeEnricherTest(org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)

Example 30 with StructuredTrace

use of org.hypertrace.core.datamodel.StructuredTrace in project hypertrace-ingester by hypertrace.

the class ApiBoundaryTypeAttributeEnricherTest method test_enrichEvent_noAttributes_noNPE.

@Test
public void test_enrichEvent_noAttributes_noNPE() {
    StructuredTrace noAttributesTrace = mock(StructuredTrace.class, RETURNS_DEEP_STUBS);
    when(noAttributesTrace.getAttributes()).thenReturn(null);
}
Also used : StructuredTrace(org.hypertrace.core.datamodel.StructuredTrace) Test(org.junit.jupiter.api.Test)

Aggregations

StructuredTrace (org.hypertrace.core.datamodel.StructuredTrace)79 Test (org.junit.jupiter.api.Test)66 Event (org.hypertrace.core.datamodel.Event)47 HashMap (java.util.HashMap)15 AbstractAttributeEnricherTest (org.hypertrace.traceenricher.enrichment.enrichers.AbstractAttributeEnricherTest)15 Config (com.typesafe.config.Config)7 ByteBuffer (java.nio.ByteBuffer)7 Map (java.util.Map)7 Edge (org.hypertrace.core.datamodel.Edge)7 File (java.io.File)6 List (java.util.List)6 Entity (org.hypertrace.entity.data.service.v1.Entity)6 URL (java.net.URL)5 ArrayList (java.util.ArrayList)5 SpecificDatumReader (org.apache.avro.specific.SpecificDatumReader)5 RawSpan (org.hypertrace.core.datamodel.RawSpan)5 HexUtils (org.hypertrace.core.datamodel.shared.HexUtils)5 Counter (io.micrometer.core.instrument.Counter)4 Duration (java.time.Duration)4 Instant (java.time.Instant)4