Skip to content

Commit e0b0148

Browse files
Introduce the isCustom field and map it from the gRPC response (#120)
1 parent e3ea1d2 commit e0b0148

File tree

13 files changed

+64
-22
lines changed

13 files changed

+64
-22
lines changed

hypertrace-core-graphql-attribute-store/src/main/java/org/hypertrace/core/graphql/attributes/AttributeModel.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ public interface AttributeModel {
2323
List<AttributeModelMetricAggregationType> supportedMetricAggregationTypes();
2424

2525
boolean groupable();
26+
27+
boolean isCustom();
2628
}

hypertrace-core-graphql-attribute-store/src/main/java/org/hypertrace/core/graphql/attributes/AttributeModelTranslator.java

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,23 +36,28 @@ public class AttributeModelTranslator {
3636
public Optional<AttributeModel> translate(AttributeMetadata attributeMetadata) {
3737
try {
3838
return Optional.of(
39-
new DefaultAttributeModel(
40-
attributeMetadata.getId(),
41-
attributeMetadata.getScopeString(),
42-
attributeMetadata.getKey(),
43-
attributeMetadata.getDisplayName(),
44-
this.convertType(attributeMetadata.getValueKind()),
45-
attributeMetadata.getUnit(),
46-
attributeMetadata.getOnlyAggregationsAllowed(),
47-
attributeMetadata.getType().equals(AttributeType.METRIC),
48-
this.convertMetricAggregationTypes(attributeMetadata.getSupportedAggregationsList()),
49-
attributeMetadata.getGroupable()));
39+
DefaultAttributeModel.builder()
40+
.id(attributeMetadata.getId())
41+
.scope(attributeMetadata.getScopeString())
42+
.key(attributeMetadata.getKey())
43+
.displayName(attributeMetadata.getDisplayName())
44+
.type(this.convertType(attributeMetadata.getValueKind()))
45+
.units(attributeMetadata.getUnit())
46+
.onlySupportsGrouping(attributeMetadata.getOnlyAggregationsAllowed())
47+
.onlySupportsAggregation(attributeMetadata.getType().equals(AttributeType.METRIC))
48+
.supportedMetricAggregationTypes(
49+
this.convertMetricAggregationTypes(
50+
attributeMetadata.getSupportedAggregationsList()))
51+
.groupable(attributeMetadata.getGroupable())
52+
.isCustom(attributeMetadata.getCustom())
53+
.build());
5054
} catch (Exception e) {
5155
LOGGER.warn("Dropping attribute {} : {}", attributeMetadata.getId(), e.getMessage());
5256
return Optional.empty();
5357
}
5458
}
5559

60+
@SuppressWarnings("unused")
5661
public AttributeKind convertType(AttributeModelType type) {
5762
return Optional.ofNullable(TYPE_MAPPING.inverse().get(type))
5863
.orElseThrow(

hypertrace-core-graphql-attribute-store/src/main/java/org/hypertrace/core/graphql/attributes/DefaultAttributeModel.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
package org.hypertrace.core.graphql.attributes;
22

3+
import static lombok.AccessLevel.PRIVATE;
4+
35
import java.util.List;
6+
import lombok.AllArgsConstructor;
47
import lombok.Builder;
58
import lombok.Value;
69
import lombok.experimental.Accessors;
710

811
@Value
912
@Builder(toBuilder = true)
1013
@Accessors(fluent = true)
14+
@AllArgsConstructor(access = PRIVATE)
1115
class DefaultAttributeModel implements AttributeModel {
1216
String id;
1317
String scope;
@@ -19,4 +23,5 @@ class DefaultAttributeModel implements AttributeModel {
1923
boolean onlySupportsAggregation;
2024
List<AttributeModelMetricAggregationType> supportedMetricAggregationTypes;
2125
boolean groupable;
26+
boolean isCustom;
2227
}

hypertrace-core-graphql-attribute-store/src/test/java/org/hypertrace/core/graphql/attributes/AttributeModelTranslatorTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ void beforeEach() {
3232
.setOnlyAggregationsAllowed(true)
3333
.addAllSupportedAggregations(List.of(AggregateFunction.SUM, AggregateFunction.AVG))
3434
.setGroupable(true)
35+
.setCustom(true)
3536
.build();
3637

3738
this.expectedModel =
@@ -49,6 +50,7 @@ void beforeEach() {
4950
AttributeModelMetricAggregationType.SUM,
5051
AttributeModelMetricAggregationType.AVG))
5152
.groupable(true)
53+
.isCustom(true)
5254
.build();
5355
}
5456

@@ -90,6 +92,7 @@ void testStringArrayAttributeKindTranslation() {
9092
.addAllSupportedAggregations(
9193
List.of(AggregateFunction.DISTINCT_COUNT, AggregateFunction.AVGRATE))
9294
.setGroupable(false)
95+
.setCustom(false)
9396
.build();
9497

9598
this.expectedModel =
@@ -106,6 +109,7 @@ void testStringArrayAttributeKindTranslation() {
106109
AttributeModelMetricAggregationType.DISTINCT_COUNT,
107110
AttributeModelMetricAggregationType.AVGRATE))
108111
.groupable(false)
112+
.isCustom(false)
109113
.build();
110114

111115
assertEquals(Optional.of(this.expectedModel), this.translator.translate(this.metadata));

hypertrace-core-graphql-log-event-schema/src/test/java/org/hypertrace/core/graphql/log/event/dao/BaseDaoTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ static class DefaultAttributeModel implements AttributeModel {
5353
boolean onlySupportsAggregation;
5454
List<AttributeModelMetricAggregationType> supportedMetricAggregationTypes;
5555
boolean groupable;
56+
boolean isCustom;
5657
}
5758

5859
@Value

hypertrace-core-graphql-log-event-schema/src/test/java/org/hypertrace/core/graphql/log/event/dao/GatewayServiceLogEventsRequestBuilderTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ void testBuildRequest() {
8989
false,
9090
false,
9191
Collections.emptyList(),
92+
false,
9293
false),
9394
AttributeExpression.forAttributeKey("traceId"))),
9495
new DefaultAttributeRequest(
@@ -103,6 +104,7 @@ void testBuildRequest() {
103104
false,
104105
false,
105106
Collections.emptyList(),
107+
false,
106108
false),
107109
AttributeExpression.forAttributeKey("timestamp"))));
108110
DefaultLogEventRequest defaultLogEventRequest =

hypertrace-core-graphql-log-event-schema/src/test/java/org/hypertrace/core/graphql/log/event/dao/GatewayServiceLogEventsResponseConverterTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ void testConvert() {
9595
false,
9696
false,
9797
Collections.emptyList(),
98+
false,
9899
false),
99100
AttributeExpression.forAttributeKey("traceId"))),
100101
new DefaultAttributeRequest(
@@ -109,6 +110,7 @@ void testConvert() {
109110
false,
110111
false,
111112
Collections.emptyList(),
113+
false,
112114
false),
113115
AttributeExpression.forAttributeKey("timestamp"))));
114116
DefaultLogEventRequest defaultLogEventRequest =

hypertrace-core-graphql-metadata-schema/src/main/java/org/hypertrace/core/graphql/metadata/response/DefaultAttributeMetadata.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package org.hypertrace.core.graphql.metadata.response;
22

3+
import static lombok.AccessLevel.PRIVATE;
4+
35
import java.util.List;
6+
import lombok.AllArgsConstructor;
47
import lombok.Builder;
58
import lombok.Value;
69
import lombok.experimental.Accessors;
@@ -11,6 +14,7 @@
1114
@Value
1215
@Builder
1316
@Accessors(fluent = true)
17+
@AllArgsConstructor(access = PRIVATE)
1418
class DefaultAttributeMetadata implements AttributeMetadata {
1519
String scope;
1620
String name;
@@ -21,4 +25,5 @@ class DefaultAttributeMetadata implements AttributeMetadata {
2125
boolean onlySupportsAggregation;
2226
List<MetricAggregationType> supportedAggregations;
2327
boolean groupable;
28+
boolean isCustom;
2429
}

hypertrace-core-graphql-metadata-schema/src/main/java/org/hypertrace/core/graphql/metadata/response/MetadataResponseBuilder.java

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,16 +46,18 @@ public Maybe<AttributeMetadata> build(AttributeModel model) {
4646
this.convertMetricAggregationTypes(model.supportedMetricAggregationTypes()),
4747
this.typeConverter.convert(model.type()),
4848
(aggregations, type) ->
49-
new DefaultAttributeMetadata(
50-
this.scopeStringTranslator.toExternal(model.scope()),
51-
model.key(),
52-
model.displayName(),
53-
type,
54-
model.units(),
55-
model.onlySupportsGrouping(),
56-
model.onlySupportsAggregation(),
57-
aggregations,
58-
model.groupable()))
49+
DefaultAttributeMetadata.builder()
50+
.scope(this.scopeStringTranslator.toExternal(model.scope()))
51+
.name(model.key())
52+
.displayName(model.displayName())
53+
.type(type)
54+
.units(model.units())
55+
.onlySupportsGrouping(model.onlySupportsGrouping())
56+
.onlySupportsAggregation(model.onlySupportsAggregation())
57+
.supportedAggregations(aggregations)
58+
.groupable(model.groupable())
59+
.isCustom(model.isCustom())
60+
.build())
5961
.cast(AttributeMetadata.class)
6062
.onErrorComplete();
6163
}

hypertrace-core-graphql-metadata-schema/src/main/java/org/hypertrace/core/graphql/metadata/schema/AttributeMetadata.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public interface AttributeMetadata {
2020
String ATTRIBUTE_METADATA_ONLY_SUPPORTS_GROUPING_NAME = "onlySupportsGrouping";
2121
String ATTRIBUTE_METADATA_SUPPORTED_AGGREGATIONS_NAME = "supportedAggregations";
2222
String ATTRIBUTE_METADATA_GROUPABLE_NAME = "groupable";
23+
String ATTRIBUTE_METADATA_IS_CUSTOM = "isCustom";
2324

2425
@GraphQLField
2526
@GraphQLNonNull
@@ -67,4 +68,9 @@ public interface AttributeMetadata {
6768
@GraphQLNonNull
6869
@GraphQLName(ATTRIBUTE_METADATA_GROUPABLE_NAME)
6970
boolean groupable();
71+
72+
@GraphQLField
73+
@GraphQLNonNull
74+
@GraphQLName(ATTRIBUTE_METADATA_IS_CUSTOM)
75+
boolean isCustom();
7076
}

0 commit comments

Comments
 (0)