Skip to content

Commit 2f7c343

Browse files
authored
AAP-9761: Changes to add Created Date, Last Modified Date, last Modified by Audit details (#323)
1 parent d41389b commit 2f7c343

File tree

19 files changed

+996
-74
lines changed

19 files changed

+996
-74
lines changed

config-object-store/src/main/java/org/hypertrace/config/objectstore/ConfigObject.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,13 @@ public interface ConfigObject<T> {
77

88
Instant getCreationTimestamp();
99

10+
String getCreatedByEmail();
11+
12+
Instant getLastUserUpdateTimestamp();
13+
14+
String getLastUserUpdateEmail();
15+
1016
Instant getLastUpdatedTimestamp();
17+
18+
String getLastUpdateEmail();
1119
}

config-object-store/src/main/java/org/hypertrace/config/objectstore/ConfigObjectImpl.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,22 @@
1111
class ConfigObjectImpl<T> implements ConfigObject<T> {
1212
T data;
1313
Instant creationTimestamp;
14+
String createdByEmail;
15+
Instant lastUserUpdateTimestamp;
16+
String lastUserUpdateEmail;
1417
Instant lastUpdatedTimestamp;
18+
String lastUpdateEmail;
1519

1620
static <T> Optional<ConfigObject<T>> tryBuild(
1721
ContextSpecificConfig contextSpecificConfig, Function<Value, Optional<T>> dataBuilder) {
1822
return tryBuild(
1923
contextSpecificConfig.getConfig(),
2024
contextSpecificConfig.getCreationTimestamp(),
2125
contextSpecificConfig.getUpdateTimestamp(),
26+
contextSpecificConfig.getCreatedByEmail(),
27+
contextSpecificConfig.getLastUserUpdateTimestamp(),
28+
contextSpecificConfig.getLastUserUpdateEmail(),
29+
contextSpecificConfig.getLastUpdateEmail(),
2230
dataBuilder);
2331
}
2432

@@ -28,13 +36,21 @@ static <T> Optional<ConfigObject<T>> tryBuild(
2836
upsertResponse.getConfig(),
2937
upsertResponse.getCreationTimestamp(),
3038
upsertResponse.getUpdateTimestamp(),
39+
upsertResponse.getCreatedByEmail(),
40+
upsertResponse.getLastUserUpdateTimestamp(),
41+
upsertResponse.getLastUserUpdateEmail(),
42+
upsertResponse.getLastUpdateEmail(),
3143
dataBuilder);
3244
}
3345

3446
static <T> Optional<ConfigObject<T>> tryBuild(
3547
Value config,
3648
long creationTimestamp,
3749
long updateTimestamp,
50+
String createdByEmail,
51+
long lastUserUpdateTimestamp,
52+
String lastUserUpdateEmail,
53+
String lastUpdateEmail,
3854
Function<Value, Optional<T>> dataBuilder) {
3955
return dataBuilder
4056
.apply(config)
@@ -43,6 +59,10 @@ static <T> Optional<ConfigObject<T>> tryBuild(
4359
new ConfigObjectImpl<>(
4460
data,
4561
Instant.ofEpochMilli(creationTimestamp),
46-
Instant.ofEpochMilli(updateTimestamp)));
62+
createdByEmail,
63+
Instant.ofEpochMilli(lastUserUpdateTimestamp),
64+
lastUserUpdateEmail,
65+
Instant.ofEpochMilli(updateTimestamp),
66+
lastUpdateEmail));
4767
}
4868
}

config-object-store/src/main/java/org/hypertrace/config/objectstore/ContextualConfigObjectImpl.java

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ public class ContextualConfigObjectImpl<T> implements ContextualConfigObject<T>
1515
String context;
1616
T data;
1717
Instant creationTimestamp;
18+
String createdByEmail;
19+
Instant lastUserUpdateTimestamp;
20+
String lastUserUpdateEmail;
1821
Instant lastUpdatedTimestamp;
22+
String lastUpdateEmail;
1923

2024
static <T> Optional<ContextualConfigObject<T>> tryBuild(
2125
ContextSpecificConfig contextSpecificConfig, Function<Value, Optional<T>> dataBuilder) {
@@ -24,6 +28,10 @@ static <T> Optional<ContextualConfigObject<T>> tryBuild(
2428
contextSpecificConfig.getConfig(),
2529
contextSpecificConfig.getCreationTimestamp(),
2630
contextSpecificConfig.getUpdateTimestamp(),
31+
contextSpecificConfig.getCreatedByEmail(),
32+
contextSpecificConfig.getLastUserUpdateTimestamp(),
33+
contextSpecificConfig.getLastUserUpdateEmail(),
34+
contextSpecificConfig.getLastUpdateEmail(),
2735
dataBuilder);
2836
}
2937

@@ -34,6 +42,10 @@ static <T> Optional<ContextualConfigObject<T>> tryBuild(
3442
upsertedConfig.getConfig(),
3543
upsertedConfig.getCreationTimestamp(),
3644
upsertedConfig.getUpdateTimestamp(),
45+
upsertedConfig.getCreatedByEmail(),
46+
upsertedConfig.getLastUserUpdateTimestamp(),
47+
upsertedConfig.getLastUserUpdateEmail(),
48+
upsertedConfig.getLastUpdateEmail(),
3749
dataBuilder);
3850
}
3951

@@ -49,14 +61,22 @@ static <T> Optional<ContextualConfigObject<T>> tryBuild(
4961
contextBuilder.apply(data),
5062
data,
5163
Instant.ofEpochMilli(upsertResponse.getCreationTimestamp()),
52-
Instant.ofEpochMilli(upsertResponse.getUpdateTimestamp())));
64+
upsertResponse.getCreatedByEmail(),
65+
Instant.ofEpochMilli(upsertResponse.getLastUserUpdateTimestamp()),
66+
upsertResponse.getLastUserUpdateEmail(),
67+
Instant.ofEpochMilli(upsertResponse.getUpdateTimestamp()),
68+
upsertResponse.getLastUpdateEmail()));
5369
}
5470

5571
private static <T> Optional<ContextualConfigObject<T>> tryBuild(
5672
String context,
5773
Value config,
5874
long creationTimestamp,
5975
long updateTimestamp,
76+
String createdByEmail,
77+
long lastUserUpdateTimestamp,
78+
String lastUserUpdateEmail,
79+
String lastUpdateEmail,
6080
Function<Value, Optional<T>> dataBuilder) {
6181
return dataBuilder
6282
.apply(config)
@@ -66,6 +86,10 @@ private static <T> Optional<ContextualConfigObject<T>> tryBuild(
6686
context,
6787
data,
6888
Instant.ofEpochMilli(creationTimestamp),
69-
Instant.ofEpochMilli(updateTimestamp)));
89+
createdByEmail,
90+
Instant.ofEpochMilli(lastUserUpdateTimestamp),
91+
lastUserUpdateEmail,
92+
Instant.ofEpochMilli(updateTimestamp),
93+
lastUpdateEmail));
7094
}
7195
}

config-object-store/src/main/java/org/hypertrace/config/objectstore/DefaultObjectStore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,10 @@ public Optional<ConfigObject<T>> getObject(RequestContext context) {
9292
getConfigResponse.getConfig(),
9393
getConfigResponse.getCreationTimestamp(),
9494
getConfigResponse.getUpdateTimestamp(),
95+
getConfigResponse.getCreatedByEmail(),
96+
getConfigResponse.getLastUserUpdateTimestamp(),
97+
getConfigResponse.getLastUserUpdateEmail(),
98+
getConfigResponse.getLastUpdateEmail(),
9599
this::buildDataFromValue);
96100
} catch (Exception exception) {
97101
if (Status.fromThrowable(exception).equals(Status.NOT_FOUND)) {

config-object-store/src/main/java/org/hypertrace/config/objectstore/IdentifiedObjectStore.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ public Optional<ContextualConfigObject<T>> getObject(RequestContext context, Str
140140
.setConfig(getConfigResponse.getConfig())
141141
.setCreationTimestamp(getConfigResponse.getCreationTimestamp())
142142
.setUpdateTimestamp(getConfigResponse.getUpdateTimestamp())
143+
.setCreatedByEmail(getConfigResponse.getCreatedByEmail())
144+
.setLastUserUpdateEmail(getConfigResponse.getLastUserUpdateEmail())
145+
.setLastUserUpdateTimestamp(getConfigResponse.getLastUserUpdateTimestamp())
146+
.setLastUpdateEmail(getConfigResponse.getLastUpdateEmail())
143147
.build();
144148
return ContextualConfigObjectImpl.tryBuild(contextSpecificConfig, this::buildDataFromValue);
145149
} catch (Exception exception) {

config-object-store/src/test/java/org/hypertrace/config/objectstore/ContextuallyIdentifiedObjectStoreTest.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ class ContextuallyIdentifiedObjectStoreTest {
3333
private static final String TEST_RESOURCE_NAME = "test-resource";
3434
private static final Instant TEST_CREATE_TIMESTAMP = Instant.ofEpochMilli(20);
3535
private static final Instant TEST_UPDATE_TIMESTAMP = Instant.ofEpochMilli(40);
36+
private static final String TEST_CREATED_BY_EMAIL = "test-created-by";
37+
private static final String TEST_LAST_UPDATED_BY_EMAIL = "test-last-modified-by";
3638

3739
@Mock(answer = Answers.RETURNS_SELF)
3840
ConfigServiceBlockingStub mockStub;
@@ -82,11 +84,22 @@ void generatesConfigReadRequestForGetObject() {
8284
.setConfig(Values.of("test"))
8385
.setCreationTimestamp(TEST_CREATE_TIMESTAMP.toEpochMilli())
8486
.setUpdateTimestamp(TEST_UPDATE_TIMESTAMP.toEpochMilli())
87+
.setCreatedByEmail(TEST_CREATED_BY_EMAIL)
88+
.setLastUserUpdateEmail(TEST_LAST_UPDATED_BY_EMAIL)
89+
.setLastUserUpdateTimestamp(TEST_UPDATE_TIMESTAMP.toEpochMilli())
90+
.setLastUpdateEmail(TEST_LAST_UPDATED_BY_EMAIL)
8591
.build());
8692
assertEquals(
8793
Optional.of(
8894
new ContextualConfigObjectImpl<>(
89-
"my-tenant", new TestObject("test"), TEST_CREATE_TIMESTAMP, TEST_UPDATE_TIMESTAMP)),
95+
"my-tenant",
96+
new TestObject("test"),
97+
TEST_CREATE_TIMESTAMP,
98+
TEST_CREATED_BY_EMAIL,
99+
TEST_UPDATE_TIMESTAMP,
100+
TEST_LAST_UPDATED_BY_EMAIL,
101+
TEST_UPDATE_TIMESTAMP,
102+
TEST_LAST_UPDATED_BY_EMAIL)),
90103
this.store.getObject(RequestContext.forTenantId("my-tenant")));
91104

92105
verify(this.mockStub, times(1))
@@ -154,13 +167,21 @@ void generatesConfigUpsertRequest() {
154167
.setConfig(Values.of("updated"))
155168
.setCreationTimestamp(TEST_CREATE_TIMESTAMP.toEpochMilli())
156169
.setUpdateTimestamp(TEST_UPDATE_TIMESTAMP.toEpochMilli())
170+
.setCreatedByEmail(TEST_CREATED_BY_EMAIL)
171+
.setLastUserUpdateEmail(TEST_LAST_UPDATED_BY_EMAIL)
172+
.setLastUserUpdateTimestamp(TEST_UPDATE_TIMESTAMP.toEpochMilli())
173+
.setLastUpdateEmail(TEST_LAST_UPDATED_BY_EMAIL)
157174
.build());
158175
assertEquals(
159176
new ContextualConfigObjectImpl<>(
160177
"upsert-tenant",
161178
new TestObject("updated"),
162179
TEST_CREATE_TIMESTAMP,
163-
TEST_UPDATE_TIMESTAMP),
180+
TEST_CREATED_BY_EMAIL,
181+
TEST_UPDATE_TIMESTAMP,
182+
TEST_LAST_UPDATED_BY_EMAIL,
183+
TEST_UPDATE_TIMESTAMP,
184+
TEST_LAST_UPDATED_BY_EMAIL),
164185
this.store.upsertObject(
165186
RequestContext.forTenantId("upsert-tenant"), new TestObject("updated")));
166187
verify(this.mockStub, times(1))

config-object-store/src/test/java/org/hypertrace/config/objectstore/DefaultObjectStoreTest.java

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class DefaultObjectStoreTest {
3636
private static final String TEST_RESOURCE_NAME = "test-resource";
3737
private static final Instant TEST_CREATE_TIMESTAMP = Instant.ofEpochMilli(20);
3838
private static final Instant TEST_UPDATE_TIMESTAMP = Instant.ofEpochMilli(40);
39+
private static final String TEST_CREATED_BY_EMAIL = "test-created-by";
40+
private static final String TEST_LAST_UPDATED_BY_EMAIL = "test-last-modified-by";
3941

4042
@Mock(answer = Answers.RETURNS_SELF)
4143
ConfigServiceBlockingStub mockStub;
@@ -60,12 +62,22 @@ void generatesConfigReadRequestForGetObject() {
6062
.setConfig(Values.of("test"))
6163
.setCreationTimestamp(TEST_CREATE_TIMESTAMP.toEpochMilli())
6264
.setUpdateTimestamp(TEST_UPDATE_TIMESTAMP.toEpochMilli())
65+
.setCreatedByEmail(TEST_CREATED_BY_EMAIL)
66+
.setLastUserUpdateEmail(TEST_LAST_UPDATED_BY_EMAIL)
67+
.setLastUserUpdateTimestamp(TEST_UPDATE_TIMESTAMP.toEpochMilli())
68+
.setLastUpdateEmail(TEST_LAST_UPDATED_BY_EMAIL)
6369
.build());
6470

6571
assertEquals(
6672
Optional.of(
6773
new ConfigObjectImpl<>(
68-
new TestInternalObject("test"), TEST_CREATE_TIMESTAMP, TEST_UPDATE_TIMESTAMP)),
74+
new TestInternalObject("test"),
75+
TEST_CREATE_TIMESTAMP,
76+
TEST_CREATED_BY_EMAIL,
77+
TEST_UPDATE_TIMESTAMP,
78+
TEST_LAST_UPDATED_BY_EMAIL,
79+
TEST_UPDATE_TIMESTAMP,
80+
TEST_LAST_UPDATED_BY_EMAIL)),
6981
this.store.getObject(this.mockRequestContext));
7082

7183
verify(this.mockStub, times(1))
@@ -123,12 +135,22 @@ void generatesConfigDeleteRequest() {
123135
ContextSpecificConfig.newBuilder()
124136
.setConfig(Values.of("test"))
125137
.setCreationTimestamp(TEST_CREATE_TIMESTAMP.toEpochMilli())
126-
.setUpdateTimestamp(TEST_UPDATE_TIMESTAMP.toEpochMilli()))
138+
.setUpdateTimestamp(TEST_UPDATE_TIMESTAMP.toEpochMilli())
139+
.setCreatedByEmail(TEST_CREATED_BY_EMAIL)
140+
.setLastUserUpdateEmail(TEST_LAST_UPDATED_BY_EMAIL)
141+
.setLastUserUpdateTimestamp(TEST_UPDATE_TIMESTAMP.toEpochMilli())
142+
.setLastUpdateEmail(TEST_LAST_UPDATED_BY_EMAIL))
127143
.build());
128144
assertEquals(
129145
Optional.of(
130146
new ConfigObjectImpl<>(
131-
new TestInternalObject("test"), TEST_CREATE_TIMESTAMP, TEST_UPDATE_TIMESTAMP)),
147+
new TestInternalObject("test"),
148+
TEST_CREATE_TIMESTAMP,
149+
TEST_CREATED_BY_EMAIL,
150+
TEST_UPDATE_TIMESTAMP,
151+
TEST_LAST_UPDATED_BY_EMAIL,
152+
TEST_UPDATE_TIMESTAMP,
153+
TEST_LAST_UPDATED_BY_EMAIL)),
132154
this.store.deleteObject(mockRequestContext));
133155

134156
verify(this.mockStub)
@@ -159,11 +181,21 @@ void generatesConfigUpsertRequest() {
159181
UpsertConfigResponse.newBuilder()
160182
.setCreationTimestamp(TEST_CREATE_TIMESTAMP.toEpochMilli())
161183
.setUpdateTimestamp(TEST_UPDATE_TIMESTAMP.toEpochMilli())
184+
.setCreatedByEmail(TEST_CREATED_BY_EMAIL)
185+
.setLastUserUpdateEmail(TEST_LAST_UPDATED_BY_EMAIL)
186+
.setLastUserUpdateTimestamp(TEST_UPDATE_TIMESTAMP.toEpochMilli())
187+
.setLastUpdateEmail(TEST_LAST_UPDATED_BY_EMAIL)
162188
.setConfig(Values.of("updated"))
163189
.build());
164190
ConfigObject configObject =
165191
new ConfigObjectImpl<>(
166-
new TestInternalObject("updated"), TEST_CREATE_TIMESTAMP, TEST_UPDATE_TIMESTAMP);
192+
new TestInternalObject("updated"),
193+
TEST_CREATE_TIMESTAMP,
194+
TEST_CREATED_BY_EMAIL,
195+
TEST_UPDATE_TIMESTAMP,
196+
TEST_LAST_UPDATED_BY_EMAIL,
197+
TEST_UPDATE_TIMESTAMP,
198+
TEST_LAST_UPDATED_BY_EMAIL);
167199
assertEquals(
168200
configObject,
169201
this.store.upsertObject(this.mockRequestContext, new TestInternalObject("updated")));

0 commit comments

Comments
 (0)