Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method with datastore parameter in ConfigServiceFactory and PartitionerConfigService #246

Merged
merged 4 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(
aaron-steinfeld marked this conversation as resolved.
Show resolved Hide resolved
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);
}
}
Loading