Search in sources :

Example 16 with BackendInfo

use of org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo in project hypertrace-ingester by hypertrace.

the class ElasticsearchBackendProviderTest method testBackendResolution.

@Test
public void testBackendResolution() {
    BackendInfo backendInfo = backendEntityEnricher.resolve(getElasticsearchEvent(), structuredTrace, structuredTraceGraph).get();
    Entity entity = backendInfo.getEntity();
    Assertions.assertEquals("test-index", entity.getEntityName());
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("GET"), "BACKEND_DESTINATION", AttributeValueCreator.create("test-index")), attributes);
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Example 17 with BackendInfo

use of org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo in project hypertrace-ingester by hypertrace.

the class HttpBackendProviderTest method checkBackendEntityGeneratedFromHttpEventType1.

@Test
public void checkBackendEntityGeneratedFromHttpEventType1() {
    Event e = Event.newBuilder().setCustomerId("__default").setEventId(ByteBuffer.wrap("bdf03dfabf5c70f8".getBytes())).setEntityIdList(Arrays.asList("4bfca8f7-4974-36a4-9385-dd76bf5c8824")).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(Map.of("SPAN_TYPE", AttributeValue.newBuilder().setValue("EXIT").build(), "PROTOCOL", AttributeValue.newBuilder().setValue("HTTP").build())).build()).setAttributes(Attributes.newBuilder().setAttributeMap(Map.of("http.status_code", AttributeValue.newBuilder().setValue("200").build(), "http.user_agent", AttributeValue.newBuilder().setValue("").build(), "http.path", AttributeValue.newBuilder().setValue("/product/5d644175551847d7408760b1").build(), "FLAGS", AttributeValue.newBuilder().setValue("OK").build(), "status.message", AttributeValue.newBuilder().setValue("200").build(), Constants.getRawSpanConstant(Http.HTTP_METHOD), AttributeValue.newBuilder().setValue("GET").build(), "http.host", AttributeValue.newBuilder().setValue("dataservice:9394").build(), "http.target", AttributeValue.newBuilder().setValue("/path/12314/?q=ddds#123").build(), "status.code", AttributeValue.newBuilder().setValue("0").build())).build()).setEventName("Sent./product/5d644175551847d7408760b1").setStartTimeMillis(1566869077746L).setEndTimeMillis(1566869077750L).setMetrics(Metrics.newBuilder().setMetricMap(Map.of("Duration", MetricValue.newBuilder().setValue(4.0).build())).build()).setEventRefList(Arrays.asList(EventRef.newBuilder().setTraceId(ByteBuffer.wrap("random_trace_id".getBytes())).setEventId(ByteBuffer.wrap("random_event_id".getBytes())).setRefType(EventRefType.CHILD_OF).build())).setHttp(org.hypertrace.core.datamodel.eventfields.http.Http.newBuilder().setRequest(Request.newBuilder().setHost("dataservice:9394").setPath("/product/5d644175551847d7408760b1").setMethod("GET").build()).build()).build();
    final BackendInfo backendInfo = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get();
    final Entity backendEntity = backendInfo.getEntity();
    assertEquals(backendEntity.getEntityName(), "dataservice:9394");
    assertEquals(3, backendEntity.getIdentifyingAttributesCount());
    assertEquals(BackendType.HTTP.name(), backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL)).getValue().getString());
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_HOST)).getValue().getString(), "dataservice");
    assertEquals(backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PORT)).getValue().getString(), "9394");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT)).getValue().getString(), "Sent./product/5d644175551847d7408760b1");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT_ID)).getValue().getString(), "62646630336466616266356337306638");
    assertEquals(backendEntity.getAttributesMap().get(Constants.getRawSpanConstant(Http.HTTP_METHOD)).getValue().getString(), "GET");
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_DESTINATION", AttributeValueCreator.create("/product/5d644175551847d7408760b1"), "BACKEND_OPERATION", AttributeValueCreator.create("GET")), attributes);
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Example 18 with BackendInfo

use of org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo in project hypertrace-ingester by hypertrace.

the class JdbcBackendProviderTest method testBackendOperationWithDbStatement.

@Test
public void testBackendOperationWithDbStatement() {
    Event e = Event.newBuilder().setCustomerId("__default").setEventId(ByteBuffer.wrap("bdf03dfabf5c70f8".getBytes())).setEntityIdList(Arrays.asList("4bfca8f7-4974-36a4-9385-dd76bf5c8824")).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(Map.of("SPAN_TYPE", AttributeValue.newBuilder().setValue("EXIT").build())).build()).setAttributes(Attributes.newBuilder().setAttributeMap(Map.of("sql.url", AttributeValue.newBuilder().setValue("jdbc:hsqldb:hsql://dbhost:9001/webgoat").build(), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "db.statement", AttributeValue.newBuilder().setValue("insert into audit_message (message, id) values (?, ?)").build())).build()).setEventName("jdbc.connection.prepare").setEventRefList(Arrays.asList(EventRef.newBuilder().setTraceId(ByteBuffer.wrap("random_trace_id".getBytes())).setEventId(ByteBuffer.wrap("random_event_id".getBytes())).setRefType(EventRefType.CHILD_OF).build())).build();
    BackendInfo backendInfo = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get();
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("insert")), attributes);
}
Also used : TestUtil.buildAttributeValue(org.hypertrace.traceenricher.TestUtil.buildAttributeValue) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Example 19 with BackendInfo

use of org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo in project hypertrace-ingester by hypertrace.

the class JdbcBackendProviderTest method checkBackendEntityGeneratedFromJdbcEvent.

@Test
public void checkBackendEntityGeneratedFromJdbcEvent() {
    Event e = Event.newBuilder().setCustomerId("__default").setEventId(ByteBuffer.wrap("bdf03dfabf5c70f8".getBytes())).setEntityIdList(Arrays.asList("4bfca8f7-4974-36a4-9385-dd76bf5c8824")).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(Map.of("SPAN_TYPE", AttributeValue.newBuilder().setValue("EXIT").build())).build()).setAttributes(Attributes.newBuilder().setAttributeMap(Map.of("sql.url", AttributeValue.newBuilder().setValue("jdbc:mysql://mysql:3306/shop").build(), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "sql.query", AttributeValue.newBuilder().setValue("insert into audit_message (message, id) values (?, ?)").build(), "k8s.pod_id", AttributeValue.newBuilder().setValue("55636196-c840-11e9-a417-42010a8a0064").build(), "db.operation", AttributeValue.newBuilder().setValue("select").build(), "docker.container_id", AttributeValue.newBuilder().setValue("ee85cf2cfc3b24613a3da411fdbd2f3eabbe729a5c86c5262971c8d8c29dad0f").build(), "FLAGS", AttributeValue.newBuilder().setValue("0").build())).build()).setEventName("jdbc.connection.prepare").setStartTimeMillis(1566869077746L).setEndTimeMillis(1566869077750L).setMetrics(Metrics.newBuilder().setMetricMap(Map.of("Duration", MetricValue.newBuilder().setValue(4.0).build())).build()).setEventRefList(Arrays.asList(EventRef.newBuilder().setTraceId(ByteBuffer.wrap("random_trace_id".getBytes())).setEventId(ByteBuffer.wrap("random_event_id".getBytes())).setRefType(EventRefType.CHILD_OF).build())).build();
    BackendInfo backendInfo = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get();
    final Entity backendEntity = backendInfo.getEntity();
    assertEquals("mysql:3306", backendEntity.getEntityName());
    assertEquals(3, backendEntity.getIdentifyingAttributesCount());
    Assertions.assertEquals(BackendType.JDBC.name(), backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PROTOCOL)).getValue().getString());
    assertEquals("mysql", backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_HOST)).getValue().getString());
    assertEquals("3306", backendEntity.getIdentifyingAttributesMap().get(Constants.getEntityConstant(BackendAttribute.BACKEND_ATTRIBUTE_PORT)).getValue().getString());
    assertEquals("mysql", backendEntity.getAttributesMap().get(Constants.getRawSpanConstant(Sql.SQL_DB_TYPE)).getValue().getString());
    assertEquals("jdbc.connection.prepare", backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT)).getValue().getString());
    assertEquals("62646630336466616266356337306638", backendEntity.getAttributesMap().get(Constants.getEnrichedSpanConstant(Backend.BACKEND_FROM_EVENT_ID)).getValue().getString());
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("select")), attributes);
}
Also used : Entity(org.hypertrace.entity.data.service.v1.Entity) TestUtil.buildAttributeValue(org.hypertrace.traceenricher.TestUtil.buildAttributeValue) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Example 20 with BackendInfo

use of org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo in project hypertrace-ingester by hypertrace.

the class JdbcBackendProviderTest method testBackendOperationWithSqlQuery.

@Test
public void testBackendOperationWithSqlQuery() {
    Event e = Event.newBuilder().setCustomerId("__default").setEventId(ByteBuffer.wrap("bdf03dfabf5c70f8".getBytes())).setEntityIdList(Arrays.asList("4bfca8f7-4974-36a4-9385-dd76bf5c8824")).setEnrichedAttributes(Attributes.newBuilder().setAttributeMap(Map.of("SPAN_TYPE", AttributeValue.newBuilder().setValue("EXIT").build())).build()).setAttributes(Attributes.newBuilder().setAttributeMap(Map.of("sql.url", AttributeValue.newBuilder().setValue("jdbc:hsqldb:hsql://dbhost:9001/webgoat").build(), "span.kind", AttributeValue.newBuilder().setValue("client").build(), "sql.query", AttributeValue.newBuilder().setValue("insert into audit_message (message, id) values (?, ?)").build())).build()).setEventName("jdbc.connection.prepare").setEventRefList(Arrays.asList(EventRef.newBuilder().setTraceId(ByteBuffer.wrap("random_trace_id".getBytes())).setEventId(ByteBuffer.wrap("random_event_id".getBytes())).setRefType(EventRefType.CHILD_OF).build())).build();
    BackendInfo backendInfo = backendEntityEnricher.resolve(e, structuredTrace, structuredTraceGraph).get();
    Map<String, AttributeValue> attributes = backendInfo.getAttributes();
    assertEquals(Map.of("BACKEND_OPERATION", AttributeValueCreator.create("insert")), attributes);
}
Also used : TestUtil.buildAttributeValue(org.hypertrace.traceenricher.TestUtil.buildAttributeValue) AttributeValue(org.hypertrace.core.datamodel.AttributeValue) Event(org.hypertrace.core.datamodel.Event) BackendInfo(org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo) Test(org.junit.jupiter.api.Test)

Aggregations

BackendInfo (org.hypertrace.traceenricher.enrichment.enrichers.resolver.backend.BackendInfo)26 Test (org.junit.jupiter.api.Test)25 AttributeValue (org.hypertrace.core.datamodel.AttributeValue)24 Entity (org.hypertrace.entity.data.service.v1.Entity)20 Event (org.hypertrace.core.datamodel.Event)12 TestUtil.buildAttributeValue (org.hypertrace.traceenricher.TestUtil.buildAttributeValue)10 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 AttributeValue (org.hypertrace.entity.data.service.v1.AttributeValue)1 Builder (org.hypertrace.entity.data.service.v1.Entity.Builder)1 BackendType (org.hypertrace.traceenricher.enrichment.enrichers.BackendType)1 BackendProvider (org.hypertrace.traceenricher.enrichment.enrichers.backend.provider.BackendProvider)1