diff --git a/config-service-factory/src/main/java/org/hypertrace/config/service/ConfigServiceFactory.java b/config-service-factory/src/main/java/org/hypertrace/config/service/ConfigServiceFactory.java index 585a6695..6a7ca265 100644 --- a/config-service-factory/src/main/java/org/hypertrace/config/service/ConfigServiceFactory.java +++ b/config-service-factory/src/main/java/org/hypertrace/config/service/ConfigServiceFactory.java @@ -75,8 +75,23 @@ public List buildServices( GrpcServiceContainerEnvironment grpcServiceContainerEnvironment, List configurationCounterConfig) { this.grpcServiceContainerEnvironment = grpcServiceContainerEnvironment; + return buildServices( + localChannel, + config, + configChangeEventGenerator, + grpcServiceContainerEnvironment, + initDataStore(config, configurationCounterConfig)); + } + + public List buildServices( + Channel localChannel, + Config config, + ConfigChangeEventGenerator configChangeEventGenerator, + GrpcServiceContainerEnvironment grpcServiceContainerEnvironment, + Datastore datastore) { + this.grpcServiceContainerEnvironment = grpcServiceContainerEnvironment; return Stream.of( - new ConfigServiceGrpcImpl(this.buildConfigStore(config, configurationCounterConfig)), + new ConfigServiceGrpcImpl(this.buildConfigStore(datastore)), new SpacesConfigServiceImpl(localChannel), new LabelsConfigServiceImpl(localChannel, config, configChangeEventGenerator), new LabelApplicationRuleConfigServiceImpl( @@ -102,13 +117,8 @@ protected ConfigChangeEventGenerator buildChangeEventGenerator(Config config) { .createConfigChangeEventGenerator(config, Clock.systemUTC()); } - protected ConfigStore buildConfigStore( - Config config, List configurationCounterConfig) { + protected ConfigStore buildConfigStore(Datastore datastore) { try { - Datastore datastore = initDataStore(config.getConfig(GENERIC_CONFIG_SERVICE_CONFIG)); - new ConfigMetricsReporter( - datastore, grpcServiceContainerEnvironment.getLifecycle(), configurationCounterConfig) - .monitor(); ConfigStore configStore = new DocumentConfigStore(Clock.systemUTC(), datastore); this.store = configStore; return configStore; @@ -117,9 +127,16 @@ protected ConfigStore buildConfigStore( } } - private Datastore initDataStore(Config config) { - Config docStoreConfig = config.getConfig(DOC_STORE_CONFIG_KEY); - return DatastoreProvider.getDatastore( - TypesafeConfigDatastoreConfigExtractor.from(docStoreConfig, DATA_STORE_TYPE).extract()); + private Datastore initDataStore( + Config config, List configurationCounterConfig) { + Config genericConfig = config.getConfig(GENERIC_CONFIG_SERVICE_CONFIG); + Config docStoreConfig = genericConfig.getConfig(DOC_STORE_CONFIG_KEY); + Datastore datastore = + DatastoreProvider.getDatastore( + TypesafeConfigDatastoreConfigExtractor.from(docStoreConfig, DATA_STORE_TYPE).extract()); + new ConfigMetricsReporter( + datastore, grpcServiceContainerEnvironment.getLifecycle(), configurationCounterConfig) + .monitor(); + return datastore; } } diff --git a/partitioner-config-service-impl/src/main/java/org/hypertrace/partitioner/config/service/PartitionerConfigServiceFactory.java b/partitioner-config-service-impl/src/main/java/org/hypertrace/partitioner/config/service/PartitionerConfigServiceFactory.java index a696dd5e..8da9fd0d 100644 --- a/partitioner-config-service-impl/src/main/java/org/hypertrace/partitioner/config/service/PartitionerConfigServiceFactory.java +++ b/partitioner-config-service-impl/src/main/java/org/hypertrace/partitioner/config/service/PartitionerConfigServiceFactory.java @@ -4,7 +4,7 @@ import com.google.inject.Injector; import com.typesafe.config.Config; import io.grpc.BindableService; -import org.hypertrace.core.serviceframework.spi.PlatformServiceLifecycle; +import org.hypertrace.core.documentstore.Datastore; public class PartitionerConfigServiceFactory { @@ -14,8 +14,8 @@ public static BindableService build(Config config) { return injector.getInstance(BindableService.class); } - public static BindableService build(Config config, PlatformServiceLifecycle lifecycle) { - Injector injector = Guice.createInjector(new PartitionerConfigServiceModule(config, lifecycle)); + public static BindableService build(Config config, Datastore datastore) { + Injector injector = Guice.createInjector(new PartitionerConfigServiceModule(config, datastore)); return injector.getInstance(BindableService.class); } } diff --git a/partitioner-config-service-impl/src/main/java/org/hypertrace/partitioner/config/service/PartitionerConfigServiceModule.java b/partitioner-config-service-impl/src/main/java/org/hypertrace/partitioner/config/service/PartitionerConfigServiceModule.java index 56897bfe..caa947c9 100644 --- a/partitioner-config-service-impl/src/main/java/org/hypertrace/partitioner/config/service/PartitionerConfigServiceModule.java +++ b/partitioner-config-service-impl/src/main/java/org/hypertrace/partitioner/config/service/PartitionerConfigServiceModule.java @@ -4,48 +4,34 @@ import com.typesafe.config.Config; import io.grpc.BindableService; import org.hypertrace.core.documentstore.Datastore; -import org.hypertrace.core.documentstore.DatastoreProvider; -import org.hypertrace.core.documentstore.model.config.TypesafeConfigDatastoreConfigExtractor; -import org.hypertrace.core.serviceframework.spi.PlatformServiceLifecycle; import org.hypertrace.partitioner.config.service.store.PartitionerProfilesDocumentStore; import org.hypertrace.partitioner.config.service.store.PartitionerProfilesStore; public class PartitionerConfigServiceModule extends AbstractModule { - public static final String GENERIC_CONFIG_SERVICE = "generic.config.service"; - public static final String DOC_STORE_CONFIG_KEY = "document.store"; - public static final String DATA_STORE_TYPE = "dataStoreType"; public static final String PARTITIONER_CONFIG_SERVICE = "partitioner.config.service"; private final Config config; - private PlatformServiceLifecycle lifecycle; + private Datastore datastore; @Deprecated public PartitionerConfigServiceModule(Config config) { this.config = config; } - public PartitionerConfigServiceModule(Config config, PlatformServiceLifecycle lifecycle) { + public PartitionerConfigServiceModule(Config config, Datastore datastore) { this.config = config; - this.lifecycle = lifecycle; + this.datastore = datastore; } @Override protected void configure() { bind(BindableService.class).to(PartitionerConfigServiceImpl.class); - bind(PartitionerProfilesStore.class).toInstance(getDocumentStore(config, lifecycle)); + bind(PartitionerProfilesStore.class).toInstance(getDocumentStore(config, datastore)); } - private PartitionerProfilesDocumentStore getDocumentStore( - Config config, PlatformServiceLifecycle lifecycle) { - Config genericConfig = config.getConfig(GENERIC_CONFIG_SERVICE); - Config docStoreConfig = genericConfig.getConfig(DOC_STORE_CONFIG_KEY); + private PartitionerProfilesDocumentStore getDocumentStore(Config config, Datastore datastore) { Config partitionerConfig = config.getConfig(PARTITIONER_CONFIG_SERVICE); - Datastore datastore = - DatastoreProvider.getDatastore( - TypesafeConfigDatastoreConfigExtractor.from(docStoreConfig, DATA_STORE_TYPE).extract()); - new DBMetricsReporter(datastore, lifecycle).monitor(); - lifecycle.shutdownComplete().thenRun(datastore::close); return new PartitionerProfilesDocumentStore(datastore, partitionerConfig); } }