Search in sources :

Example 6 with ArrayValue

use of com.google.datastore.v1.ArrayValue in project data-prepper by opensearch-project.

the class MetricsPluginSumTest method test.

@Test
public void test() throws JsonProcessingException {
    final KeyValue childAttr1 = KeyValue.newBuilder().setKey("statement").setValue(AnyValue.newBuilder().setIntValue(1_000).build()).build();
    final KeyValue childAttr2 = KeyValue.newBuilder().setKey("statement.params").setValue(AnyValue.newBuilder().setStringValue("us-east-1").build()).build();
    final KeyValue attribute1 = KeyValue.newBuilder().setKey("db.details").setValue(AnyValue.newBuilder().setKvlistValue(KeyValueList.newBuilder().addAllValues(Arrays.asList(childAttr1, childAttr2)).build()).build()).build();
    final KeyValue attribute2 = KeyValue.newBuilder().setKey("http.status").setValue(AnyValue.newBuilder().setStringValue("4xx").build()).build();
    final AnyValue anyValue1 = AnyValue.newBuilder().setStringValue("asdf").build();
    final AnyValue anyValue2 = AnyValue.newBuilder().setDoubleValue(2000.123).build();
    final AnyValue anyValue3 = AnyValue.newBuilder().setKvlistValue(KeyValueList.newBuilder().addAllValues(Arrays.asList(childAttr1, childAttr2))).build();
    final ArrayValue arrayValue = ArrayValue.newBuilder().addAllValues(Arrays.asList(anyValue1, anyValue2, anyValue3)).build();
    final KeyValue attribute3 = KeyValue.newBuilder().setKey("aws.details").setValue(AnyValue.newBuilder().setArrayValue(arrayValue)).build();
    NumberDataPoint dataPoint = NumberDataPoint.newBuilder().setAsInt(3).addAllAttributes(Arrays.asList(attribute1, attribute2, attribute3)).build();
    Sum sum = Sum.newBuilder().addAllDataPoints(Collections.singletonList(dataPoint)).build();
    Metric metric = Metric.newBuilder().setSum(sum).setUnit("seconds").setName("name").setDescription("description").build();
    InstrumentationLibraryMetrics instLib = InstrumentationLibraryMetrics.newBuilder().setInstrumentationLibrary(InstrumentationLibrary.newBuilder().setVersion("v1").setName("name").build()).addMetrics(metric).build();
    Resource resource = Resource.newBuilder().addAttributes(KeyValue.newBuilder().setKey("service.name").setValue(AnyValue.newBuilder().setStringValue("service").build())).build();
    ResourceMetrics resourceMetrics = ResourceMetrics.newBuilder().setResource(resource).addInstrumentationLibraryMetrics(instLib).build();
    ExportMetricsServiceRequest exportMetricRequest = ExportMetricsServiceRequest.newBuilder().addResourceMetrics(resourceMetrics).build();
    Record record = new Record<>(exportMetricRequest);
    List<Record<Event>> rec = (List<Record<Event>>) rawProcessor.doExecute(Arrays.asList(record));
    Record<Event> firstRecord = rec.get(0);
    ObjectMapper objectMapper = new ObjectMapper();
    Map map = objectMapper.readValue(firstRecord.getData().toJsonString(), Map.class);
    assertSumProcessing(map);
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) Resource(io.opentelemetry.proto.resource.v1.Resource) Sum(io.opentelemetry.proto.metrics.v1.Sum) InstrumentationLibraryMetrics(io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics) ResourceMetrics(io.opentelemetry.proto.metrics.v1.ResourceMetrics) AnyValue(io.opentelemetry.proto.common.v1.AnyValue) NumberDataPoint(io.opentelemetry.proto.metrics.v1.NumberDataPoint) Event(com.amazon.dataprepper.model.event.Event) Metric(io.opentelemetry.proto.metrics.v1.Metric) Record(com.amazon.dataprepper.model.record.Record) KeyValueList(io.opentelemetry.proto.common.v1.KeyValueList) List(java.util.List) ArrayValue(io.opentelemetry.proto.common.v1.ArrayValue) Map(java.util.Map) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ExportMetricsServiceRequest(io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest) Test(org.junit.Test)

Aggregations

ArrayValue (com.google.firestore.v1.ArrayValue)3 AnyValue (io.opentelemetry.proto.common.v1.AnyValue)3 ArrayValue (io.opentelemetry.proto.common.v1.ArrayValue)3 KeyValue (io.opentelemetry.proto.common.v1.KeyValue)3 Test (org.junit.Test)3 Value (com.google.firestore.v1.Value)2 Event (com.amazon.dataprepper.model.event.Event)1 Record (com.amazon.dataprepper.model.record.Record)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 FieldFilter (com.google.firebase.firestore.core.FieldFilter)1 Operator (com.google.firebase.firestore.core.FieldFilter.Operator)1 ObjectValue (com.google.firebase.firestore.model.ObjectValue)1 MapValue (com.google.firestore.v1.MapValue)1 ByteString (com.google.protobuf.ByteString)1 NullValue (com.google.protobuf.NullValue)1 AttributesBuilder (io.opentelemetry.api.common.AttributesBuilder)1 ExportMetricsServiceRequest (io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest)1 KeyValueList (io.opentelemetry.proto.common.v1.KeyValueList)1 InstrumentationLibraryMetrics (io.opentelemetry.proto.metrics.v1.InstrumentationLibraryMetrics)1 Metric (io.opentelemetry.proto.metrics.v1.Metric)1