Search in sources :

Example 6 with KeyValue

use of com.vmware.vim25.KeyValue in project wavefront-proxy by wavefrontHQ.

the class OtlpProtobufUtilsTest method transformSpanSetsSourceFromResourceAttributesNotSpanAttributes.

@Test
public void transformSpanSetsSourceFromResourceAttributesNotSpanAttributes() {
    List<KeyValue> resourceAttrs = Collections.singletonList(otlpAttribute("source", "a-src"));
    Span otlpSpan = OtlpTestHelpers.otlpSpanGenerator().addAttributes(otlpAttribute("source", "span-level")).build();
    actualSpan = OtlpProtobufUtils.transformSpan(otlpSpan, resourceAttrs, null, null, "ignored");
    assertEquals("a-src", actualSpan.getSource());
    assertThat(actualSpan.getAnnotations(), not(hasItem(new Annotation("source", "a-src"))));
    assertThat(actualSpan.getAnnotations(), hasItem(new Annotation("_source", "span-level")));
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) Span(io.opentelemetry.proto.trace.v1.Span) Annotation(wavefront.report.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with KeyValue

use of com.vmware.vim25.KeyValue in project wavefront-proxy by wavefrontHQ.

the class OtlpProtobufUtilsTest method testAnnotationsFromArrayAttributes.

@Test
public void testAnnotationsFromArrayAttributes() {
    KeyValue intArrayAttr = KeyValue.newBuilder().setKey("int-array").setValue(AnyValue.newBuilder().setArrayValue(ArrayValue.newBuilder().addAllValues(Arrays.asList(AnyValue.newBuilder().setIntValue(-1).build(), AnyValue.newBuilder().setIntValue(0).build(), AnyValue.newBuilder().setIntValue(1).build())).build()).build()).build();
    KeyValue boolArrayAttr = KeyValue.newBuilder().setKey("bool-array").setValue(AnyValue.newBuilder().setArrayValue(ArrayValue.newBuilder().addAllValues(Arrays.asList(AnyValue.newBuilder().setBoolValue(true).build(), AnyValue.newBuilder().setBoolValue(false).build(), AnyValue.newBuilder().setBoolValue(true).build())).build()).build()).build();
    KeyValue dblArrayAttr = KeyValue.newBuilder().setKey("dbl-array").setValue(AnyValue.newBuilder().setArrayValue(ArrayValue.newBuilder().addAllValues(Arrays.asList(AnyValue.newBuilder().setDoubleValue(-3.14).build(), AnyValue.newBuilder().setDoubleValue(0.0).build(), AnyValue.newBuilder().setDoubleValue(3.14).build())).build()).build()).build();
    List<KeyValue> attributes = Arrays.asList(intArrayAttr, boolArrayAttr, dblArrayAttr);
    List<Annotation> wfAnnotations = OtlpProtobufUtils.annotationsFromAttributes(attributes);
    Map<String, String> wfAnnotationAsMap = getWfAnnotationAsMap(wfAnnotations);
    assertEquals("[-1, 0, 1]", wfAnnotationAsMap.get("int-array"));
    assertEquals("[true, false, true]", wfAnnotationAsMap.get("bool-array"));
    assertEquals("[-3.14, 0.0, 3.14]", wfAnnotationAsMap.get("dbl-array"));
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) ByteString(com.google.protobuf.ByteString) Annotation(wavefront.report.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with KeyValue

use of com.vmware.vim25.KeyValue in project wavefront-proxy by wavefrontHQ.

the class OtlpProtobufUtilsTest method testAnnotationsFromSimpleAttributes.

@Test
public void testAnnotationsFromSimpleAttributes() {
    KeyValue emptyAttr = KeyValue.newBuilder().setKey("empty").build();
    KeyValue booleanAttr = KeyValue.newBuilder().setKey("a-boolean").setValue(AnyValue.newBuilder().setBoolValue(true).build()).build();
    KeyValue stringAttr = KeyValue.newBuilder().setKey("a-string").setValue(AnyValue.newBuilder().setStringValue("a-value").build()).build();
    KeyValue intAttr = KeyValue.newBuilder().setKey("a-int").setValue(AnyValue.newBuilder().setIntValue(1234).build()).build();
    KeyValue doubleAttr = KeyValue.newBuilder().setKey("a-double").setValue(AnyValue.newBuilder().setDoubleValue(2.1138).build()).build();
    KeyValue bytesAttr = KeyValue.newBuilder().setKey("a-bytes").setValue(AnyValue.newBuilder().setBytesValue(ByteString.copyFromUtf8("any + old & data")).build()).build();
    KeyValue noValueAttr = KeyValue.newBuilder().setKey("no-value").setValue(AnyValue.newBuilder().build()).build();
    List<KeyValue> attributes = Arrays.asList(emptyAttr, booleanAttr, stringAttr, intAttr, doubleAttr, noValueAttr, bytesAttr);
    List<Annotation> wfAnnotations = OtlpProtobufUtils.annotationsFromAttributes(attributes);
    Map<String, String> wfAnnotationAsMap = getWfAnnotationAsMap(wfAnnotations);
    assertEquals(attributes.size(), wfAnnotationAsMap.size());
    assertEquals("", wfAnnotationAsMap.get("empty"));
    assertEquals("true", wfAnnotationAsMap.get("a-boolean"));
    assertEquals("a-value", wfAnnotationAsMap.get("a-string"));
    assertEquals("1234", wfAnnotationAsMap.get("a-int"));
    assertEquals("2.1138", wfAnnotationAsMap.get("a-double"));
    assertEquals("YW55ICsgb2xkICYgZGF0YQ==", wfAnnotationAsMap.get("a-bytes"));
    assertEquals("<Unknown OpenTelemetry attribute value type VALUE_NOT_SET>", wfAnnotationAsMap.get("no-value"));
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) ByteString(com.google.protobuf.ByteString) Annotation(wavefront.report.Annotation) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with KeyValue

use of com.vmware.vim25.KeyValue in project data-prepper by opensearch-project.

the class OTelProtoHelperTest method testKeyValueListAsResourceAttributes.

/**
 * Below object has a KeyValue with a key mapped to KeyValueList and is part of the resource attributes
 *
 * @throws JsonProcessingException
 */
@Test
public void testKeyValueListAsResourceAttributes() throws JsonProcessingException {
    final KeyValue childAttr1 = KeyValue.newBuilder().setKey("ec2.instances").setValue(AnyValue.newBuilder().setIntValue(20).build()).build();
    final KeyValue childAttr2 = KeyValue.newBuilder().setKey("ec2.instance.az").setValue(AnyValue.newBuilder().setStringValue("us-east-1").build()).build();
    final KeyValue spanAttribute1 = KeyValue.newBuilder().setKey("aws.details").setValue(AnyValue.newBuilder().setKvlistValue(KeyValueList.newBuilder().addAllValues(Arrays.asList(childAttr1, childAttr2)).build()).build()).build();
    final KeyValue spanAttribute2 = KeyValue.newBuilder().setKey("service.name").setValue(AnyValue.newBuilder().setStringValue("EaglesService").build()).build();
    final Map<String, Object> actual = OTelProtoHelper.getResourceAttributes(Resource.newBuilder().addAllAttributes(Arrays.asList(spanAttribute1, spanAttribute2)).build());
    assertThat(actual.get(OTelProtoHelper.RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute2.getKey())).equals(spanAttribute2.getValue().getStringValue())).isTrue();
    assertThat(actual.containsKey(OTelProtoHelper.RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute1.getKey()))).isTrue();
    final Map<String, Object> actualValue = returnMap((String) actual.get(OTelProtoHelper.RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute1.getKey())));
    assertThat((Integer) actualValue.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr1.getKey())) == childAttr1.getValue().getIntValue()).isTrue();
    assertThat(actualValue.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr2.getKey())).equals(childAttr2.getValue().getStringValue())).isTrue();
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Example 10 with KeyValue

use of com.vmware.vim25.KeyValue in project data-prepper by opensearch-project.

the class OTelProtoHelperTest method testArrayOfValueAsResourceAttributes.

/**
 * Below object has a KeyValue with a key mapped to KeyValueList and is part of the span attributes
 *
 * @throws JsonProcessingException
 */
@Test
public void testArrayOfValueAsResourceAttributes() throws JsonProcessingException {
    final KeyValue childAttr1 = KeyValue.newBuilder().setKey("ec2.instances").setValue(AnyValue.newBuilder().setIntValue(20).build()).build();
    final KeyValue childAttr2 = KeyValue.newBuilder().setKey("ec2.instance.az").setValue(AnyValue.newBuilder().setStringValue("us-east-1").build()).build();
    final AnyValue anyValue1 = AnyValue.newBuilder().setStringValue(UUID.randomUUID().toString()).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 spanAttribute1 = KeyValue.newBuilder().setKey("aws.details").setValue(AnyValue.newBuilder().setArrayValue(arrayValue)).build();
    final Map<String, Object> actual = OTelProtoHelper.getResourceAttributes(Resource.newBuilder().addAllAttributes(Collections.singletonList(spanAttribute1)).build());
    assertThat(actual.containsKey(OTelProtoHelper.RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute1.getKey()))).isTrue();
    final List<Object> actualValue = returnList((String) actual.get(OTelProtoHelper.RESOURCE_ATTRIBUTES_REPLACE_DOT_WITH_AT.apply(spanAttribute1.getKey())));
    assertThat((actualValue.get(0)).equals(anyValue1.getStringValue())).isTrue();
    assertThat(((Double) actualValue.get(1)) == (anyValue2.getDoubleValue())).isTrue();
    final Map<String, Object> map = returnMap((String) actualValue.get(2));
    assertThat((Integer) map.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr1.getKey())) == childAttr1.getValue().getIntValue()).isTrue();
    assertThat(map.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr2.getKey())).equals(childAttr2.getValue().getStringValue())).isTrue();
    assertThat((Integer) map.get(OTelProtoHelper.REPLACE_DOT_WITH_AT.apply(childAttr1.getKey())) == (childAttr1.getValue().getIntValue())).isTrue();
}
Also used : KeyValue(io.opentelemetry.proto.common.v1.KeyValue) AnyValue(io.opentelemetry.proto.common.v1.AnyValue) ByteString(com.google.protobuf.ByteString) ArrayValue(io.opentelemetry.proto.common.v1.ArrayValue) Test(org.junit.Test)

Aggregations

KeyValue (io.opentelemetry.proto.common.v1.KeyValue)15 Test (org.junit.Test)11 ByteString (com.google.protobuf.ByteString)9 Annotation (wavefront.report.Annotation)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 Span (io.opentelemetry.proto.trace.v1.Span)5 KeyValue (com.vmware.vim25.KeyValue)3 ArrayList (java.util.ArrayList)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ManagedObjectReference (com.vmware.vim25.ManagedObjectReference)2 OvfCreateImportSpecParams (com.vmware.vim25.OvfCreateImportSpecParams)2 OvfCreateImportSpecResult (com.vmware.vim25.OvfCreateImportSpecResult)2 AnyValue (io.opentelemetry.proto.common.v1.AnyValue)2 ArrayValue (io.opentelemetry.proto.common.v1.ArrayValue)2 GetMoRef (com.vmware.photon.controller.model.adapters.vsphere.util.connection.GetMoRef)1 FinderException (com.vmware.photon.controller.model.adapters.vsphere.util.finders.FinderException)1 HttpNfcLeaseDeviceUrl (com.vmware.vim25.HttpNfcLeaseDeviceUrl)1 HttpNfcLeaseInfo (com.vmware.vim25.HttpNfcLeaseInfo)1 KeyAnyValue (com.vmware.vim25.KeyAnyValue)1 OvfFileItem (com.vmware.vim25.OvfFileItem)1