Skip to content

Commit 7f85265

Browse files
feat: add config metadata to object store results (#75)
breaking change for object store apis
1 parent 91b1b34 commit 7f85265

File tree

20 files changed

+444
-178
lines changed

20 files changed

+444
-178
lines changed

alerting-config-service-impl/src/main/java/org/hypertrace/alerting/config/service/EventConditionConfigServiceImpl.java

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import io.grpc.Status;
55
import io.grpc.stub.StreamObserver;
66
import java.util.UUID;
7+
import java.util.stream.Collectors;
78
import lombok.extern.slf4j.Slf4j;
89
import org.hypertrace.alerting.config.service.v1.CreateEventConditionRequest;
910
import org.hypertrace.alerting.config.service.v1.CreateEventConditionResponse;
@@ -17,6 +18,7 @@
1718
import org.hypertrace.alerting.config.service.v1.NewEventCondition;
1819
import org.hypertrace.alerting.config.service.v1.UpdateEventConditionRequest;
1920
import org.hypertrace.alerting.config.service.v1.UpdateEventConditionResponse;
21+
import org.hypertrace.config.objectstore.ContextualConfigObject;
2022
import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator;
2123
import org.hypertrace.core.grpcutils.context.RequestContext;
2224

@@ -50,7 +52,8 @@ public void createEventCondition(
5052
builder.setId(UUID.randomUUID().toString());
5153
responseObserver.onNext(
5254
CreateEventConditionResponse.newBuilder()
53-
.setEventCondition(eventConditionStore.upsertObject(requestContext, builder.build()))
55+
.setEventCondition(
56+
eventConditionStore.upsertObject(requestContext, builder.build()).getData())
5457
.build());
5558
responseObserver.onCompleted();
5659
} catch (Exception e) {
@@ -69,7 +72,9 @@ public void updateEventCondition(
6972
responseObserver.onNext(
7073
UpdateEventConditionResponse.newBuilder()
7174
.setEventCondition(
72-
eventConditionStore.upsertObject(requestContext, request.getEventCondition()))
75+
eventConditionStore
76+
.upsertObject(requestContext, request.getEventCondition())
77+
.getData())
7378
.build());
7479
responseObserver.onCompleted();
7580
} catch (Exception e) {
@@ -87,7 +92,10 @@ public void getAllEventConditions(
8792
requestValidator.validateGetAllEventConditionsRequest(requestContext, request);
8893
responseObserver.onNext(
8994
GetAllEventConditionsResponse.newBuilder()
90-
.addAllEventCondition(eventConditionStore.getAllObjects(requestContext))
95+
.addAllEventCondition(
96+
eventConditionStore.getAllObjects(requestContext).stream()
97+
.map(ContextualConfigObject::getData)
98+
.collect(Collectors.toUnmodifiableList()))
9199
.build());
92100
responseObserver.onCompleted();
93101
} catch (Exception e) {

alerting-config-service-impl/src/main/java/org/hypertrace/alerting/config/service/EventConditionStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public EventConditionStore(
3232
}
3333

3434
@Override
35-
protected Optional<EventCondition> buildObjectFromValue(Value value) {
35+
protected Optional<EventCondition> buildDataFromValue(Value value) {
3636
EventCondition.Builder builder = EventCondition.newBuilder();
3737
try {
3838
ConfigProtoConverter.mergeFromValue(value, builder);
@@ -45,12 +45,12 @@ protected Optional<EventCondition> buildObjectFromValue(Value value) {
4545

4646
@SneakyThrows
4747
@Override
48-
protected Value buildValueFromObject(EventCondition object) {
48+
protected Value buildValueFromData(EventCondition object) {
4949
return ConfigProtoConverter.convertToValue(object);
5050
}
5151

5252
@Override
53-
protected String getContextFromObject(EventCondition object) {
53+
protected String getContextFromData(EventCondition object) {
5454
return object.getId();
5555
}
5656
}

label-application-rule-config-service-impl/src/main/java/org/hypertrace/label/application/rule/config/service/LabelApplicationRuleConfigServiceImpl.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import io.grpc.stub.StreamObserver;
66
import java.util.List;
77
import java.util.UUID;
8+
import java.util.stream.Collectors;
9+
import org.hypertrace.config.objectstore.ConfigObject;
810
import org.hypertrace.config.objectstore.IdentifiedObjectStore;
911
import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator;
1012
import org.hypertrace.config.service.v1.ConfigServiceGrpc;
@@ -51,7 +53,9 @@ public void createLabelApplicationRule(
5153
.setData(request.getData())
5254
.build();
5355
LabelApplicationRule createdLabelApplicationRule =
54-
this.labelApplicationRuleStore.upsertObject(requestContext, labelApplicationRule);
56+
this.labelApplicationRuleStore
57+
.upsertObject(requestContext, labelApplicationRule)
58+
.getData();
5559
responseObserver.onNext(
5660
CreateLabelApplicationRuleResponse.newBuilder()
5761
.setLabelApplicationRule(createdLabelApplicationRule)
@@ -70,7 +74,9 @@ public void getLabelApplicationRules(
7074
RequestContext requestContext = RequestContext.CURRENT.get();
7175
this.requestValidator.validateOrThrow(requestContext, request);
7276
List<LabelApplicationRule> labelApplicationRules =
73-
this.labelApplicationRuleStore.getAllObjects(requestContext);
77+
this.labelApplicationRuleStore.getAllObjects(requestContext).stream()
78+
.map(ConfigObject::getData)
79+
.collect(Collectors.toUnmodifiableList());
7480
responseObserver.onNext(
7581
GetLabelApplicationRulesResponse.newBuilder()
7682
.addAllLabelApplicationRules(labelApplicationRules)
@@ -90,12 +96,14 @@ public void updateLabelApplicationRule(
9096
this.requestValidator.validateOrThrow(requestContext, request);
9197
LabelApplicationRule existingRule =
9298
this.labelApplicationRuleStore
93-
.getObject(requestContext, request.getId())
99+
.getData(requestContext, request.getId())
94100
.orElseThrow(Status.NOT_FOUND::asRuntimeException);
95101
LabelApplicationRule updateLabelApplicationRule =
96102
existingRule.toBuilder().setData(request.getData()).build();
97103
LabelApplicationRule upsertedLabelApplicationRule =
98-
this.labelApplicationRuleStore.upsertObject(requestContext, updateLabelApplicationRule);
104+
this.labelApplicationRuleStore
105+
.upsertObject(requestContext, updateLabelApplicationRule)
106+
.getData();
99107
responseObserver.onNext(
100108
UpdateLabelApplicationRuleResponse.newBuilder()
101109
.setLabelApplicationRule(upsertedLabelApplicationRule)

label-application-rule-config-service-impl/src/main/java/org/hypertrace/label/application/rule/config/service/LabelApplicationRuleStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public class LabelApplicationRuleStore extends IdentifiedObjectStore<LabelApplic
2525
}
2626

2727
@Override
28-
protected Optional<LabelApplicationRule> buildObjectFromValue(Value value) {
28+
protected Optional<LabelApplicationRule> buildDataFromValue(Value value) {
2929
try {
3030
LabelApplicationRule.Builder builder = LabelApplicationRule.newBuilder();
3131
ConfigProtoConverter.mergeFromValue(value, builder);
@@ -37,12 +37,12 @@ protected Optional<LabelApplicationRule> buildObjectFromValue(Value value) {
3737

3838
@SneakyThrows
3939
@Override
40-
protected Value buildValueFromObject(LabelApplicationRule object) {
40+
protected Value buildValueFromData(LabelApplicationRule object) {
4141
return ConfigProtoConverter.convertToValue(object);
4242
}
4343

4444
@Override
45-
protected String getContextFromObject(LabelApplicationRule object) {
45+
protected String getContextFromData(LabelApplicationRule object) {
4646
return object.getId();
4747
}
4848
}

labels-config-service-impl/src/main/java/org/hypertrace/label/config/service/LabelStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ protected LabelStore(
2424
}
2525

2626
@Override
27-
protected Optional<Label> buildObjectFromValue(Value value) {
27+
protected Optional<Label> buildDataFromValue(Value value) {
2828
try {
2929
Label.Builder builder = Label.newBuilder();
3030
ConfigProtoConverter.mergeFromValue(value, builder);
@@ -36,12 +36,12 @@ protected Optional<Label> buildObjectFromValue(Value value) {
3636

3737
@Override
3838
@SneakyThrows
39-
protected Value buildValueFromObject(Label object) {
39+
protected Value buildValueFromData(Label object) {
4040
return ConfigProtoConverter.convertToValue(object);
4141
}
4242

4343
@Override
44-
protected String getContextFromObject(Label object) {
44+
protected String getContextFromData(Label object) {
4545
return object.getId();
4646
}
4747
}

labels-config-service-impl/src/main/java/org/hypertrace/label/config/service/LabelsConfigServiceImpl.java

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.stream.Collectors;
2222
import lombok.SneakyThrows;
2323
import lombok.extern.slf4j.Slf4j;
24+
import org.hypertrace.config.objectstore.ContextualConfigObject;
2425
import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator;
2526
import org.hypertrace.config.service.v1.ConfigServiceGrpc;
2627
import org.hypertrace.core.grpcutils.client.RequestContextClientCallCredsProviderFactory;
@@ -117,7 +118,7 @@ public void createLabel(
117118
.setId(UUID.randomUUID().toString())
118119
.setKey(createLabel.getKey())
119120
.build();
120-
Label createdLabel = labelStore.upsertObject(requestContext, label);
121+
Label createdLabel = labelStore.upsertObject(requestContext, label).getData();
121122
responseObserver.onNext(CreateLabelResponse.newBuilder().setLabel(createdLabel).build());
122123
responseObserver.onCompleted();
123124
} finally {
@@ -142,7 +143,7 @@ public void getLabel(GetLabelRequest request, StreamObserver<GetLabelResponse> r
142143
} else {
143144
label =
144145
labelStore
145-
.getObject(requestContext, labelId)
146+
.getData(requestContext, labelId)
146147
.orElseThrow(Status.NOT_FOUND::asRuntimeException);
147148
}
148149
responseObserver.onNext(GetLabelResponse.newBuilder().setLabel(label).build());
@@ -158,7 +159,10 @@ public void getLabels(
158159
RequestContext requestContext = RequestContext.CURRENT.get();
159160
List<Label> allLabels = new ArrayList<>();
160161
allLabels.addAll(systemLabels);
161-
List<Label> tenantLabels = labelStore.getAllObjects(requestContext);
162+
List<Label> tenantLabels =
163+
labelStore.getAllObjects(requestContext).stream()
164+
.map(ContextualConfigObject::getData)
165+
.collect(Collectors.toUnmodifiableList());
162166
allLabels.addAll(tenantLabels);
163167
responseObserver.onNext(GetLabelsResponse.newBuilder().addAllLabels(allLabels).build());
164168
responseObserver.onCompleted();
@@ -184,9 +188,10 @@ public void updateLabel(
184188
return;
185189
}
186190
labelStore
187-
.getObject(requestContext, updatedLabelInReq.getId())
191+
.getData(requestContext, updatedLabelInReq.getId())
188192
.orElseThrow(Status.NOT_FOUND::asRuntimeException);
189-
Label updatedLabelInRes = labelStore.upsertObject(requestContext, updatedLabelInReq);
193+
Label updatedLabelInRes =
194+
labelStore.upsertObject(requestContext, updatedLabelInReq).getData();
190195
responseObserver.onNext(
191196
UpdateLabelResponse.newBuilder().setLabel(updatedLabelInRes).build());
192197
responseObserver.onCompleted();
@@ -234,7 +239,10 @@ public void deleteLabel(
234239

235240
private boolean isDuplicateKey(String key) {
236241
RequestContext requestContext = RequestContext.CURRENT.get();
237-
List<Label> labelList = labelStore.getAllObjects(requestContext);
242+
List<Label> labelList =
243+
labelStore.getAllObjects(requestContext).stream()
244+
.map(ContextualConfigObject::getData)
245+
.collect(Collectors.toUnmodifiableList());
238246
Optional<Label> match =
239247
labelList.stream().filter(label -> label.getKey().equals(key)).findAny();
240248
return match.isPresent();

notification-channel-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationChannelConfigServiceImpl.java

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import io.grpc.stub.StreamObserver;
66
import java.util.List;
77
import java.util.UUID;
8+
import java.util.stream.Collectors;
89
import lombok.extern.slf4j.Slf4j;
10+
import org.hypertrace.config.objectstore.ConfigObject;
911
import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator;
1012
import org.hypertrace.core.grpcutils.context.RequestContext;
1113
import org.hypertrace.notification.config.service.v1.CreateNotificationChannelRequest;
@@ -49,7 +51,7 @@ public void createNotificationChannel(
4951
responseObserver.onNext(
5052
CreateNotificationChannelResponse.newBuilder()
5153
.setNotificationChannel(
52-
notificationChannelStore.upsertObject(requestContext, builder.build()))
54+
notificationChannelStore.upsertObject(requestContext, builder.build()).getData())
5355
.build());
5456
responseObserver.onCompleted();
5557
} catch (Exception e) {
@@ -68,13 +70,15 @@ public void updateNotificationChannel(
6870
responseObserver.onNext(
6971
UpdateNotificationChannelResponse.newBuilder()
7072
.setNotificationChannel(
71-
notificationChannelStore.upsertObject(
72-
requestContext,
73-
NotificationChannel.newBuilder()
74-
.setId(request.getId())
75-
.setNotificationChannelMutableData(
76-
request.getNotificationChannelMutableData())
77-
.build()))
73+
notificationChannelStore
74+
.upsertObject(
75+
requestContext,
76+
NotificationChannel.newBuilder()
77+
.setId(request.getId())
78+
.setNotificationChannelMutableData(
79+
request.getNotificationChannelMutableData())
80+
.build())
81+
.getData())
7882
.build());
7983
responseObserver.onCompleted();
8084
} catch (Exception e) {
@@ -91,7 +95,9 @@ public void getAllNotificationChannels(
9195
RequestContext requestContext = RequestContext.CURRENT.get();
9296
validator.validateGetAllNotificationChannelsRequest(requestContext, request);
9397
List<NotificationChannel> notificationChannels =
94-
notificationChannelStore.getAllObjects(requestContext);
98+
notificationChannelStore.getAllObjects(requestContext).stream()
99+
.map(ConfigObject::getData)
100+
.collect(Collectors.toUnmodifiableList());
95101
GetAllNotificationChannelsResponse getAllNotificationChannelsResponse =
96102
GetAllNotificationChannelsResponse.newBuilder()
97103
.addAllNotificationChannels(notificationChannels)
@@ -131,7 +137,7 @@ public void getNotificationChannel(
131137
validator.validateGetNotificationChannelRequest(requestContext, request);
132138
NotificationChannel notificationChannel =
133139
notificationChannelStore
134-
.getObject(requestContext, request.getNotificationChannelId())
140+
.getData(requestContext, request.getNotificationChannelId())
135141
.orElseThrow(Status.NOT_FOUND::asRuntimeException);
136142
responseObserver.onNext(
137143
GetNotificationChannelResponse.newBuilder()

notification-channel-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationChannelStore.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public NotificationChannelStore(
3232
}
3333

3434
@Override
35-
protected Optional<NotificationChannel> buildObjectFromValue(Value value) {
35+
protected Optional<NotificationChannel> buildDataFromValue(Value value) {
3636
NotificationChannel.Builder builder = NotificationChannel.newBuilder();
3737
try {
3838
ConfigProtoConverter.mergeFromValue(value, builder);
@@ -45,12 +45,12 @@ protected Optional<NotificationChannel> buildObjectFromValue(Value value) {
4545

4646
@SneakyThrows
4747
@Override
48-
protected Value buildValueFromObject(NotificationChannel object) {
48+
protected Value buildValueFromData(NotificationChannel object) {
4949
return ConfigProtoConverter.convertToValue(object);
5050
}
5151

5252
@Override
53-
protected String getContextFromObject(NotificationChannel object) {
53+
protected String getContextFromData(NotificationChannel object) {
5454
return object.getId();
5555
}
5656
}

notification-rule-config-service-impl/src/main/java/org/hypertrace/notification/config/service/NotificationRuleConfigServiceImpl.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import io.grpc.Status;
55
import io.grpc.stub.StreamObserver;
66
import java.util.UUID;
7+
import java.util.stream.Collectors;
78
import lombok.extern.slf4j.Slf4j;
9+
import org.hypertrace.config.objectstore.ConfigObject;
810
import org.hypertrace.config.service.change.event.api.ConfigChangeEventGenerator;
911
import org.hypertrace.core.grpcutils.context.RequestContext;
1012
import org.hypertrace.notification.config.service.v1.CreateNotificationRuleRequest;
@@ -48,7 +50,7 @@ public void createNotificationRule(
4850
responseObserver.onNext(
4951
CreateNotificationRuleResponse.newBuilder()
5052
.setNotificationRule(
51-
notificationRuleStore.upsertObject(requestContext, builder.build()))
53+
notificationRuleStore.upsertObject(requestContext, builder.build()).getData())
5254
.build());
5355
responseObserver.onCompleted();
5456
} catch (Exception e) {
@@ -67,12 +69,15 @@ public void updateNotificationRule(
6769
responseObserver.onNext(
6870
UpdateNotificationRuleResponse.newBuilder()
6971
.setNotificationRule(
70-
notificationRuleStore.upsertObject(
71-
requestContext,
72-
NotificationRule.newBuilder()
73-
.setId(request.getId())
74-
.setNotificationRuleMutableData(request.getNotificationRuleMutableData())
75-
.build()))
72+
notificationRuleStore
73+
.upsertObject(
74+
requestContext,
75+
NotificationRule.newBuilder()
76+
.setId(request.getId())
77+
.setNotificationRuleMutableData(
78+
request.getNotificationRuleMutableData())
79+
.build())
80+
.getData())
7681
.build());
7782
responseObserver.onCompleted();
7883
} catch (Exception e) {
@@ -90,7 +95,10 @@ public void getAllNotificationRules(
9095
validator.validateGetAllNotificationRulesRequest(requestContext, request);
9196
responseObserver.onNext(
9297
GetAllNotificationRulesResponse.newBuilder()
93-
.addAllNotificationRules(notificationRuleStore.getAllObjects(requestContext))
98+
.addAllNotificationRules(
99+
notificationRuleStore.getAllObjects(requestContext).stream()
100+
.map(ConfigObject::getData)
101+
.collect(Collectors.toUnmodifiableList()))
94102
.build());
95103
responseObserver.onCompleted();
96104
} catch (Exception e) {
@@ -126,7 +134,7 @@ public void getNotificationRule(
126134
validator.validateGetNotificationRuleRequest(requestContext, request);
127135
NotificationRule notificationRule =
128136
notificationRuleStore
129-
.getObject(requestContext, request.getNotificationRuleId())
137+
.getData(requestContext, request.getNotificationRuleId())
130138
.orElseThrow(Status.NOT_FOUND::asRuntimeException);
131139
responseObserver.onNext(
132140
GetNotificationRuleResponse.newBuilder().setNotificationRule(notificationRule).build());

0 commit comments

Comments
 (0)