Skip to content

Commit

Permalink
Add method with datastore parameter in ConfigServiceFactory and Parti…
Browse files Browse the repository at this point in the history
…tionerConfigService (#246)

* Add method with datastore variable

* restore locks

* resolve comments

* read generic config
  • Loading branch information
Vaibhav090420 authored Oct 24, 2024
1 parent 8335b93 commit 57c6958
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,23 @@ public List<GrpcPlatformService> buildServices(
GrpcServiceContainerEnvironment grpcServiceContainerEnvironment,
List<DocStoreCustomMetricReportingConfig> configurationCounterConfig) {
this.grpcServiceContainerEnvironment = grpcServiceContainerEnvironment;
return buildServices(
localChannel,
config,
configChangeEventGenerator,
grpcServiceContainerEnvironment,
initDataStore(config, configurationCounterConfig));
}

public List<GrpcPlatformService> 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(
Expand All @@ -102,13 +117,8 @@ protected ConfigChangeEventGenerator buildChangeEventGenerator(Config config) {
.createConfigChangeEventGenerator(config, Clock.systemUTC());
}

protected ConfigStore buildConfigStore(
Config config, List<DocStoreCustomMetricReportingConfig> 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;
Expand All @@ -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<DocStoreCustomMetricReportingConfig> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 57c6958

Please sign in to comment.