Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.hypertrace.trace.reader.entities;

import static io.reactivex.rxjava3.core.Maybe.zip;
import static java.util.function.Predicate.not;

import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.Single;
Expand Down Expand Up @@ -132,10 +133,12 @@ private Maybe<Entity> buildEntity(EntityType entityType, T trace, S span) {
this.resolveAllAttributes(entityType.getAttributeScope(), trace, span).cache();

Maybe<String> id =
attributes.mapOptional(map -> this.extractString(map, entityType.getIdAttributeKey()));
attributes.mapOptional(
map -> this.extractNonEmptyString(map, entityType.getIdAttributeKey()));

Maybe<String> name =
attributes.mapOptional(map -> this.extractString(map, entityType.getNameAttributeKey()));
attributes.mapOptional(
map -> this.extractNonEmptyString(map, entityType.getNameAttributeKey()));

return zip(
id,
Expand Down Expand Up @@ -187,13 +190,14 @@ private Maybe<Entry<String, AttributeValue>> resolveAttribute(
.map(value -> Map.entry(attributeMetadata.getKey(), value));
}

private Optional<String> extractString(
private Optional<String> extractNonEmptyString(
Map<String, AttributeValue> attributeValueMap, String key) {
return Optional.ofNullable(attributeValueMap.get(key))
.filter(value -> value.getTypeCase().equals(TypeCase.VALUE))
.map(AttributeValue::getValue)
.filter(value -> value.getTypeCase().equals(Value.TypeCase.STRING))
.map(Value::getString);
.map(Value::getString)
.filter(not(String::isEmpty));
}

private GrpcRxExecutionContext spanTenantContext(S span) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ void omitsEntityBasedOnMissingAttributes() {
.getAssociatedEntityForSpan(TEST_ENTITY_TYPE_NAME, TEST_TRACE, TEST_SPAN)
.isEmpty()
.blockingGet());
verifyNoInteractions(mockDataClient);
}

@Test
void omitsEntityBasedOnEmptyId() {
mockSingleEntityType();
mockGetAllAttributes(TEST_ENTITY_ID_ATTRIBUTE, TEST_ENTITY_NAME_ATTRIBUTE);
mockTenantId();
mockAttributeRead(TEST_ENTITY_ID_ATTRIBUTE, stringLiteral(""));
mockAttributeRead(TEST_ENTITY_NAME_ATTRIBUTE, stringLiteral(TEST_ENTITY_NAME_ATTRIBUTE_VALUE));

assertTrue(
this.entityReader
.getAssociatedEntityForSpan(TEST_ENTITY_TYPE_NAME, TEST_TRACE, TEST_SPAN)
.isEmpty()
.blockingGet());
verifyNoInteractions(mockDataClient);
}

@Test
Expand Down