Skip to content

Commit 127c5f5

Browse files
Enhancements to the metadata schema (#118)
1 parent 1f00fb9 commit 127c5f5

File tree

5 files changed

+77
-49
lines changed

5 files changed

+77
-49
lines changed

hypertrace-core-graphql-attribute-store/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ dependencies {
1414
implementation("com.google.guava:guava")
1515

1616
implementation("org.hypertrace.core.attribute.service:caching-attribute-service-client")
17+
implementation("org.hypertrace.core.attribute.service:attribute-service-api")
1718
implementation("org.hypertrace.core.grpcutils:grpc-client-rx-utils")
1819
implementation(project(":hypertrace-core-graphql-grpc-utils"))
1920
implementation(project(":hypertrace-core-graphql-rx-utils"))

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

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

3+
import static org.hypertrace.core.attribute.service.v1.AttributeKind.TYPE_BOOL;
4+
import static org.hypertrace.core.attribute.service.v1.AttributeKind.TYPE_DOUBLE;
5+
import static org.hypertrace.core.attribute.service.v1.AttributeKind.TYPE_INT64;
6+
import static org.hypertrace.core.attribute.service.v1.AttributeKind.TYPE_STRING;
7+
import static org.hypertrace.core.attribute.service.v1.AttributeKind.TYPE_STRING_ARRAY;
8+
import static org.hypertrace.core.attribute.service.v1.AttributeKind.TYPE_STRING_MAP;
9+
import static org.hypertrace.core.attribute.service.v1.AttributeKind.TYPE_TIMESTAMP;
10+
11+
import com.google.common.collect.ImmutableBiMap;
312
import java.util.List;
413
import java.util.Optional;
514
import java.util.UnknownFormatConversionException;
@@ -11,8 +20,18 @@
1120
import org.slf4j.Logger;
1221
import org.slf4j.LoggerFactory;
1322

14-
class AttributeModelTranslator {
23+
public class AttributeModelTranslator {
1524
private static final Logger LOGGER = LoggerFactory.getLogger(AttributeModelTranslator.class);
25+
private static final ImmutableBiMap<AttributeKind, AttributeModelType> TYPE_MAPPING =
26+
ImmutableBiMap.<AttributeKind, AttributeModelType>builder()
27+
.put(TYPE_STRING, AttributeModelType.STRING)
28+
.put(TYPE_BOOL, AttributeModelType.BOOLEAN)
29+
.put(TYPE_INT64, AttributeModelType.LONG)
30+
.put(TYPE_DOUBLE, AttributeModelType.DOUBLE)
31+
.put(TYPE_TIMESTAMP, AttributeModelType.TIMESTAMP)
32+
.put(TYPE_STRING_MAP, AttributeModelType.STRING_MAP)
33+
.put(TYPE_STRING_ARRAY, AttributeModelType.STRING_ARRAY)
34+
.build();
1635

1736
public Optional<AttributeModel> translate(AttributeMetadata attributeMetadata) {
1837
try {
@@ -34,6 +53,14 @@ public Optional<AttributeModel> translate(AttributeMetadata attributeMetadata) {
3453
}
3554
}
3655

56+
public AttributeKind convertType(AttributeModelType type) {
57+
return Optional.ofNullable(TYPE_MAPPING.inverse().get(type))
58+
.orElseThrow(
59+
() ->
60+
new UnknownFormatConversionException(
61+
String.format("Unrecognized attribute type %s", type.name())));
62+
}
63+
3764
private List<AttributeModelMetricAggregationType> convertMetricAggregationTypes(
3865
List<AggregateFunction> aggregationTypes) {
3966
return aggregationTypes.stream()
@@ -71,30 +98,10 @@ private AttributeModelMetricAggregationType convertMetricAggregationType(
7198
}
7299

73100
private AttributeModelType convertType(AttributeKind kind) {
74-
switch (kind) {
75-
case TYPE_STRING:
76-
return AttributeModelType.STRING;
77-
case TYPE_BOOL:
78-
return AttributeModelType.BOOLEAN;
79-
case TYPE_INT64:
80-
return AttributeModelType.LONG;
81-
case TYPE_DOUBLE:
82-
return AttributeModelType.DOUBLE;
83-
case TYPE_TIMESTAMP:
84-
return AttributeModelType.TIMESTAMP;
85-
case TYPE_STRING_MAP:
86-
return AttributeModelType.STRING_MAP;
87-
case TYPE_STRING_ARRAY:
88-
return AttributeModelType.STRING_ARRAY;
89-
case KIND_UNDEFINED:
90-
case UNRECOGNIZED:
91-
case TYPE_BYTES:
92-
case TYPE_INT64_ARRAY:
93-
case TYPE_DOUBLE_ARRAY:
94-
case TYPE_BOOL_ARRAY:
95-
default:
96-
throw new UnknownFormatConversionException(
97-
String.format("Unrecognized attribute kind %s", kind.name()));
98-
}
101+
return Optional.ofNullable(TYPE_MAPPING.get(kind))
102+
.orElseThrow(
103+
() ->
104+
new UnknownFormatConversionException(
105+
String.format("Unrecognized attribute kind %s", kind.name())));
99106
}
100107
}
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
11
package org.hypertrace.core.graphql.common.utils.attributes;
22

3+
import static org.hypertrace.core.graphql.attributes.AttributeModelType.BOOLEAN;
4+
import static org.hypertrace.core.graphql.attributes.AttributeModelType.DOUBLE;
5+
import static org.hypertrace.core.graphql.attributes.AttributeModelType.LONG;
6+
import static org.hypertrace.core.graphql.attributes.AttributeModelType.STRING;
7+
import static org.hypertrace.core.graphql.attributes.AttributeModelType.STRING_ARRAY;
8+
import static org.hypertrace.core.graphql.attributes.AttributeModelType.STRING_MAP;
9+
import static org.hypertrace.core.graphql.attributes.AttributeModelType.TIMESTAMP;
10+
11+
import com.google.common.collect.ImmutableBiMap;
312
import io.reactivex.rxjava3.core.Single;
13+
import java.util.Optional;
414
import java.util.UnknownFormatConversionException;
515
import org.hypertrace.core.graphql.attributes.AttributeModelType;
616
import org.hypertrace.core.graphql.common.schema.attributes.AttributeType;
717
import org.hypertrace.core.graphql.common.utils.Converter;
818

9-
class AttributeTypeConverter implements Converter<AttributeModelType, AttributeType> {
19+
public class AttributeTypeConverter implements Converter<AttributeModelType, AttributeType> {
20+
private static final ImmutableBiMap<AttributeModelType, AttributeType> TYPE_MAPPING =
21+
ImmutableBiMap.<AttributeModelType, AttributeType>builder()
22+
.put(STRING, AttributeType.STRING)
23+
.put(BOOLEAN, AttributeType.BOOLEAN)
24+
.put(LONG, AttributeType.LONG)
25+
.put(DOUBLE, AttributeType.DOUBLE)
26+
.put(TIMESTAMP, AttributeType.TIMESTAMP)
27+
.put(STRING_MAP, AttributeType.STRING_MAP)
28+
.put(STRING_ARRAY, AttributeType.STRING_ARRAY)
29+
.build();
1030

1131
@Override
1232
public Single<AttributeType> convert(AttributeModelType type) {
13-
switch (type) {
14-
case STRING:
15-
return Single.just(AttributeType.STRING);
16-
case BOOLEAN:
17-
return Single.just(AttributeType.BOOLEAN);
18-
case LONG:
19-
return Single.just(AttributeType.LONG);
20-
case DOUBLE:
21-
return Single.just(AttributeType.DOUBLE);
22-
case TIMESTAMP:
23-
return Single.just(AttributeType.TIMESTAMP);
24-
case STRING_MAP:
25-
return Single.just(AttributeType.STRING_MAP);
26-
case STRING_ARRAY:
27-
return Single.just(AttributeType.STRING_ARRAY);
28-
default:
29-
return Single.error(
30-
new UnknownFormatConversionException(
31-
String.format("Unrecognized attribute type %s", type.name())));
32-
}
33+
return Optional.ofNullable(TYPE_MAPPING.get(type))
34+
.map(Single::just)
35+
.orElseGet(
36+
() ->
37+
Single.error(
38+
new UnknownFormatConversionException(
39+
String.format("Unrecognized attribute type %s", type.name()))));
40+
}
41+
42+
public Single<AttributeModelType> convert(final AttributeType type) {
43+
return Optional.ofNullable(TYPE_MAPPING.inverse().get(type))
44+
.map(Single::just)
45+
.orElseGet(
46+
() ->
47+
Single.error(
48+
new UnknownFormatConversionException(
49+
String.format("Unrecognized attribute type %s", type.name()))));
3350
}
3451
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public Single<List<AttributeMetadata>> build(List<AttributeModel> modelList) {
4141
.collect(Collectors.toUnmodifiableList());
4242
}
4343

44-
private Maybe<AttributeMetadata> build(AttributeModel model) {
44+
public Maybe<AttributeMetadata> build(AttributeModel model) {
4545
return zip(
4646
this.convertMetricAggregationTypes(model.supportedMetricAggregationTypes()),
4747
this.typeConverter.convert(model.type()),

hypertrace-core-graphql-platform/build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ javaPlatform {
66
allowDependencies()
77
}
88

9+
val attributeServiceVersion: String = "0.14.11"
10+
911
dependencies {
1012
api(platform("io.grpc:grpc-bom:1.47.0"))
1113
constraints {
@@ -15,7 +17,8 @@ dependencies {
1517
api("org.hypertrace.core.grpcutils:grpc-client-rx-utils:0.8.2")
1618
api("org.hypertrace.core.grpcutils:grpc-client-rx-utils:0.8.2")
1719
api("org.hypertrace.gateway.service:gateway-service-api:0.2.15")
18-
api("org.hypertrace.core.attribute.service:caching-attribute-service-client:0.14.8")
20+
api("org.hypertrace.core.attribute.service:caching-attribute-service-client:${attributeServiceVersion}")
21+
api("org.hypertrace.core.attribute.service:attribute-service-api:${attributeServiceVersion}")
1922

2023
api("com.google.inject:guice:5.1.0")
2124
api("com.graphql-java:graphql-java:19.2")

0 commit comments

Comments
 (0)