From 8c17394e2ccddf15aa806144f8628ef44830b3d9 Mon Sep 17 00:00:00 2001 From: siddhant2001 Date: Mon, 22 Jul 2024 13:59:43 +0530 Subject: [PATCH] Add new field "description" in attribute_metadata.proto (#233) * add new field "description" in attribute_metadata.proto and make changes to accommodate in AttributeMetadataModelTest * add new field "description" in attribute_metadata.proto and make changes to accommodate in AttributeMetadataModelTest * Fix spotless check failing * Add separate backwards comptibility tests for description * minor changes to description implementation * reverted integration tests --- .../service/v1/attribute_metadata.proto | 1 + .../service/model/AttributeMetadataModel.java | 23 +++++- .../model/AttributeMetadataModelTest.java | 75 ++++++++++++++++++- 3 files changed, 95 insertions(+), 4 deletions(-) diff --git a/attribute-service-api/src/main/proto/org/hypertrace/core/attribute/service/v1/attribute_metadata.proto b/attribute-service-api/src/main/proto/org/hypertrace/core/attribute/service/v1/attribute_metadata.proto index 4d43b837..8bbbff76 100644 --- a/attribute-service-api/src/main/proto/org/hypertrace/core/attribute/service/v1/attribute_metadata.proto +++ b/attribute-service-api/src/main/proto/org/hypertrace/core/attribute/service/v1/attribute_metadata.proto @@ -103,6 +103,7 @@ message AttributeMetadata { string scope_string = 17; bool internal = 18; bool custom = 19; + string description = 20; } message AttributeSourceMetadata { diff --git a/attribute-service-impl/src/main/java/org/hypertrace/core/attribute/service/model/AttributeMetadataModel.java b/attribute-service-impl/src/main/java/org/hypertrace/core/attribute/service/model/AttributeMetadataModel.java index 6d6ce075..d4d54780 100644 --- a/attribute-service-impl/src/main/java/org/hypertrace/core/attribute/service/model/AttributeMetadataModel.java +++ b/attribute-service-impl/src/main/java/org/hypertrace/core/attribute/service/model/AttributeMetadataModel.java @@ -77,6 +77,9 @@ public class AttributeMetadataModel implements Document { private boolean internal; + @JsonProperty(value = "description") + private String description; + protected AttributeMetadataModel() {} public static AttributeMetadataModel fromDTO(AttributeMetadata attributeMetadata) { @@ -97,6 +100,7 @@ public static AttributeMetadataModel fromDTO(AttributeMetadata attributeMetadata attributeMetadataModel.setSources(attributeMetadata.getSourcesList()); attributeMetadataModel.setGroupable(attributeMetadata.getGroupable()); attributeMetadataModel.setDefinition(attributeMetadata.getDefinition()); + attributeMetadataModel.setDescription(attributeMetadata.getDescription()); attributeMetadataModel.setMetadata( attributeMetadata.getMetadataMap().entrySet().stream() .collect( @@ -148,6 +152,14 @@ public void setDisplayName(String displayName) { this.displayName = displayName; } + public void setDescription(String description) { + this.description = description; + } + + public String getDescription() { + return description; + } + public String getScopeString() { return this.scopeString; } @@ -294,6 +306,9 @@ public AttributeMetadata.Builder toDTOBuilder() { if (!definition.equals(AttributeDefinition.getDefaultInstance())) { builder.setDefinition(definition); } + if (description != null) { + builder.setDescription(description); + } return builder; } @@ -349,6 +364,8 @@ public String toString() { + metadata + ", internal=" + internal + + ", description=" + + description + '}'; } @@ -377,7 +394,8 @@ public boolean equals(Object o) { && Objects.equals(metadata, that.metadata) && Objects.equals(definition, that.definition) && Objects.equals(scopeString, that.scopeString) - && Objects.equals(internal, that.internal); + && Objects.equals(internal, that.internal) + && Objects.equals(description, that.description); } @Override @@ -399,7 +417,8 @@ public int hashCode() { metadata, definition, scopeString, - internal); + internal, + description); } private static class ProtobufMessageSerializer extends JsonSerializer { diff --git a/attribute-service-impl/src/test/java/org/hypertrace/core/attribute/service/model/AttributeMetadataModelTest.java b/attribute-service-impl/src/test/java/org/hypertrace/core/attribute/service/model/AttributeMetadataModelTest.java index 6cd7f118..1b079463 100644 --- a/attribute-service-impl/src/test/java/org/hypertrace/core/attribute/service/model/AttributeMetadataModelTest.java +++ b/attribute-service-impl/src/test/java/org/hypertrace/core/attribute/service/model/AttributeMetadataModelTest.java @@ -40,6 +40,7 @@ public void testAttributeMetadataModelJsonSerDes() throws IOException { .setProjection(Projection.newBuilder().setAttributeId("test")) .build()); attributeMetadataModel.setInternal(true); + attributeMetadataModel.setDescription("description"); String json = attributeMetadataModel.toJson(); String expectedJson = @@ -60,7 +61,8 @@ public void testAttributeMetadataModelJsonSerDes() throws IOException { + "\"value_kind\":\"TYPE_STRING\"," + "\"display_name\":\"Some Name\"," + "\"scope_string\":\"EVENT\"," - + "\"tenant_id\":\"tenantId\"" + + "\"tenant_id\":\"tenantId\"," + + "\"description\":\"description\"" + "}"; Assertions.assertEquals(expectedJson, json); AttributeMetadataModel deserializedModel = AttributeMetadataModel.fromJson(json); @@ -82,6 +84,7 @@ public void testAttributeMetaModelToFromDto() { .setType(AttributeType.ATTRIBUTE) .setUnit("ms") .setValueKind(AttributeKind.TYPE_STRING) + .setDescription("description") .putAllMetadata( Collections.singletonMap( AttributeSource.EDS.name(), @@ -236,6 +239,7 @@ public void testAttributeDefinitionBackwardsCompatibility() throws IOException { .setType(AttributeType.ATTRIBUTE) .setUnit("ms") .setValueKind(AttributeKind.TYPE_STRING) + .setDescription("Description") .build()); String expectedJson = @@ -256,11 +260,78 @@ public void testAttributeDefinitionBackwardsCompatibility() throws IOException { + "\"value_kind\":\"TYPE_STRING\"," + "\"display_name\":\"Display\"," + "\"scope_string\":\"EVENT\"," - + "\"tenant_id\":null" + + "\"tenant_id\":null," + + "\"description\":\"Description\"" + "}"; Assertions.assertEquals(expectedJson, modelFromMetadataWithoutDefinition.toJson()); } + @Test + public void testAttributeDescriptionBackwardsCompatibility() throws IOException { + String json = + "{" + + "\"fqn\":\"fqn\"," + + "\"key\":\"key\"," + + "\"scope\":\"EVENT\"," + + "\"materialized\":true," + + "\"unit\":\"ms\"," + + "\"type\":\"ATTRIBUTE\"," + + "\"labels\":[\"item1\"]," + + "\"groupable\":true," + + "\"supportedAggregations\":[]," + + "\"onlyAggregationsAllowed\":false," + + "\"sources\":[]," + + "\"definition\":{}," + + "\"id\":\"EVENT.key\"," + + "\"value_kind\":\"TYPE_BOOL\"," + + "\"display_name\":\"Some Name\"," + + "\"tenant_id\":\"tenantId\"" + + "}"; + + AttributeMetadataModel deserializedModel = AttributeMetadataModel.fromJson(json); + Assertions.assertNull(deserializedModel.getDescription()); + AttributeMetadata metadata = deserializedModel.toDTO(); + Assertions.assertEquals("", metadata.getDescription()); + + AttributeMetadataModel modelFromMetadataWithoutDescription = + AttributeMetadataModel.fromDTO( + AttributeMetadata.newBuilder() + .setFqn("fqn") + .setId("id") + .setKey("key") + .setDisplayName("Display") + .setMaterialized(true) + .setScope(AttributeScope.EVENT) + .setDescription(AttributeDefinition.getDefaultInstance().toString()) + .setType(AttributeType.ATTRIBUTE) + .setUnit("ms") + .setValueKind(AttributeKind.TYPE_STRING) + .build()); + + String expectedJson = + "{" + + "\"fqn\":\"fqn\"," + + "\"key\":\"key\"," + + "\"materialized\":true," + + "\"unit\":\"ms\"," + + "\"type\":\"ATTRIBUTE\"," + + "\"labels\":[]," + + "\"groupable\":false," + + "\"supportedAggregations\":[]," + + "\"onlyAggregationsAllowed\":false," + + "\"sources\":[]," + + "\"definition\":{}," + + "\"internal\":false," + + "\"id\":\"EVENT.key\"," + + "\"value_kind\":\"TYPE_STRING\"," + + "\"display_name\":\"Display\"," + + "\"scope_string\":\"EVENT\"," + + "\"tenant_id\":null," + + "\"description\":\"\"" + + "}"; + Assertions.assertEquals(expectedJson, modelFromMetadataWithoutDescription.toJson()); + } + @Test void testScopeStringCompatibility() throws IOException { final AttributeMetadata template =