From 8c03d73c8fa6cd81449749e013a25eaf5e3e93ee Mon Sep 17 00:00:00 2001 From: Pavan Kumar Kolamuri Date: Tue, 6 May 2025 17:56:03 +0530 Subject: [PATCH 1/3] Added condition to handle old records which doesn't have latest in the id --- .../test/MockGenericConfigService.java | 40 +++++++++++++++++++ .../service/store/DocumentConfigStore.java | 7 ++++ 2 files changed, 47 insertions(+) diff --git a/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java b/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java index 73e9adeb..26fc4349 100644 --- a/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java +++ b/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java @@ -28,6 +28,7 @@ import java.util.List; import java.util.Objects; import java.util.Optional; +import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; import org.hypertrace.config.service.v1.ConfigServiceGrpc.ConfigServiceImplBase; @@ -178,6 +179,45 @@ public MockGenericConfigService mockGetAll() { return this; } + public MockGenericConfigService mockGetAllWithFilter( + Predicate filterPredicate) { + Mockito.doAnswer( + invocation -> { + StreamObserver responseObserver = + invocation.getArgument(1, StreamObserver.class); + GetAllConfigsRequest request = invocation.getArgument(0, GetAllConfigsRequest.class); + + List matchingConfigs = + currentValues + .row( + ResourceType.of( + request.getResourceNamespace(), request.getResourceName())) + .values() + .stream() + .filter( + config -> { + if (request.hasFilter()) { + return filterPredicate.test(config); + } + return true; + }) + .collect(Collectors.toList()); + + GetAllConfigsResponse response = + GetAllConfigsResponse.newBuilder() + .addAllContextSpecificConfigs(matchingConfigs) + .build(); + + responseObserver.onNext(response); + responseObserver.onCompleted(); + return null; + }) + .when(this.mockConfigService) + .getAllConfigs(ArgumentMatchers.any(), ArgumentMatchers.any()); + + return this; + } + @SuppressWarnings("unchecked") public MockGenericConfigService mockDelete() { Mockito.doAnswer( diff --git a/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java b/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java index 29f187a4..7d6406f4 100644 --- a/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java +++ b/config-service-impl/src/main/java/org/hypertrace/config/service/store/DocumentConfigStore.java @@ -105,6 +105,13 @@ public UpsertedConfig writeConfig( .withDescription("Update failed because upsert condition did not match given record") .asRuntimeException(); } + } else if (optionalPreviousConfig.isPresent() + && optionalPreviousConfig.get().getCreationTimestamp() < 1648630400000L) { + // Delete documents older than 2022-04-01, and recreate them with their IDs ending in "latest" + // Since documents before this date don't have "latest" in their _id, they are causing + // duplicate entries. + collection.delete(buildConfigResourceContextsFilter(List.of(configResourceContext))); + collection.upsert(latestDocKey, latestConfigDocument); } else { collection.upsert(latestDocKey, latestConfigDocument); } From bebc6ccf51db9f325ba0607bc09189f8ff38884b Mon Sep 17 00:00:00 2001 From: Pavan Kumar Kolamuri Date: Tue, 6 May 2025 18:01:32 +0530 Subject: [PATCH 2/3] Removed generic mock config change --- .../test/MockGenericConfigService.java | 39 ------------------- 1 file changed, 39 deletions(-) diff --git a/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java b/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java index 26fc4349..4ef6cc14 100644 --- a/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java +++ b/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java @@ -179,45 +179,6 @@ public MockGenericConfigService mockGetAll() { return this; } - public MockGenericConfigService mockGetAllWithFilter( - Predicate filterPredicate) { - Mockito.doAnswer( - invocation -> { - StreamObserver responseObserver = - invocation.getArgument(1, StreamObserver.class); - GetAllConfigsRequest request = invocation.getArgument(0, GetAllConfigsRequest.class); - - List matchingConfigs = - currentValues - .row( - ResourceType.of( - request.getResourceNamespace(), request.getResourceName())) - .values() - .stream() - .filter( - config -> { - if (request.hasFilter()) { - return filterPredicate.test(config); - } - return true; - }) - .collect(Collectors.toList()); - - GetAllConfigsResponse response = - GetAllConfigsResponse.newBuilder() - .addAllContextSpecificConfigs(matchingConfigs) - .build(); - - responseObserver.onNext(response); - responseObserver.onCompleted(); - return null; - }) - .when(this.mockConfigService) - .getAllConfigs(ArgumentMatchers.any(), ArgumentMatchers.any()); - - return this; - } - @SuppressWarnings("unchecked") public MockGenericConfigService mockDelete() { Mockito.doAnswer( From 50c866e01b8ed51447b862a774f33cc5a2903f29 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Kolamuri Date: Tue, 6 May 2025 18:02:19 +0530 Subject: [PATCH 3/3] Removed generic mock config change --- .../hypertrace/config/service/test/MockGenericConfigService.java | 1 - 1 file changed, 1 deletion(-) diff --git a/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java b/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java index 4ef6cc14..73e9adeb 100644 --- a/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java +++ b/config-service-api/src/testFixtures/java/org/hypertrace/config/service/test/MockGenericConfigService.java @@ -28,7 +28,6 @@ import java.util.List; import java.util.Objects; import java.util.Optional; -import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; import org.hypertrace.config.service.v1.ConfigServiceGrpc.ConfigServiceImplBase;