Skip to content

Commit e4f6856

Browse files
Document store config overhaul (#254)
1 parent e0b8d08 commit e4f6856

File tree

8 files changed

+78
-48
lines changed

8 files changed

+78
-48
lines changed
Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,21 @@
11
package org.hypertrace.entity.service;
22

33
import com.typesafe.config.Config;
4-
import org.hypertrace.core.documentstore.DocumentStoreConfig;
5-
import org.slf4j.Logger;
6-
import org.slf4j.LoggerFactory;
4+
import org.hypertrace.core.documentstore.model.config.DatastoreConfig;
5+
import org.hypertrace.core.documentstore.model.config.TypesafeConfigDatastoreConfigExtractor;
76

87
public class EntityServiceDataStoreConfig {
98

10-
private static final Logger LOG = LoggerFactory.getLogger(EntityServiceDataStoreConfig.class);
9+
private static final String DATASTORE_TYPE_CONFIG = "dataStoreType";
1110

12-
private final String dataStoreType;
13-
14-
private final Config entityServiceConfig;
11+
private final Config documentStoreConfig;
1512

1613
public EntityServiceDataStoreConfig(Config config) {
17-
entityServiceConfig = config.getConfig("entity.service.config.entity-service");
18-
dataStoreType = entityServiceConfig.getString(DocumentStoreConfig.DATASTORE_TYPE_CONFIG_KEY);
19-
}
20-
21-
public String getDataStoreType() {
22-
return dataStoreType;
14+
documentStoreConfig = config.getConfig("entity.service.config.document.store");
2315
}
2416

25-
public Config getDataStoreConfig() {
26-
entityServiceConfig.entrySet().forEach(e -> LOG.info("Config key {}", e.getKey()));
27-
return entityServiceConfig.getConfig(getDataStoreType());
17+
public DatastoreConfig getDataStoreConfig() {
18+
return TypesafeConfigDatastoreConfigExtractor.from(documentStoreConfig, DATASTORE_TYPE_CONFIG)
19+
.extract();
2820
}
2921
}

entity-service-factory/src/main/java/org/hypertrace/entity/service/EntityServiceFactory.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,11 @@ public List<GrpcPlatformService> buildServices(
3535
GrpcServiceContainerEnvironment grpcServiceContainerEnvironment) {
3636
this.grpcServiceContainerEnvironment = grpcServiceContainerEnvironment;
3737
Config config = grpcServiceContainerEnvironment.getConfig(SERVICE_NAME);
38-
EntityServiceDataStoreConfig dataStoreConfig = new EntityServiceDataStoreConfig(config);
39-
this.datastore =
40-
DatastoreProvider.getDatastore(
41-
dataStoreConfig.getDataStoreType(), dataStoreConfig.getDataStoreConfig());
38+
EntityServiceDataStoreConfig entityServiceDatastoreConfig =
39+
new EntityServiceDataStoreConfig(config);
40+
datastore = DatastoreProvider.getDatastore(entityServiceDatastoreConfig.getDataStoreConfig());
41+
grpcServiceContainerEnvironment.getLifecycle().shutdownComplete().thenRun(datastore::close);
42+
4243
EntityAttributeMapping entityAttributeMapping =
4344
new EntityAttributeMapping(config, grpcServiceContainerEnvironment.getChannelRegistry());
4445
EntityChangeEventGenerator entityChangeEventGenerator =

entity-service/src/integrationTest/java/org/hypertrace/entity/service/service/EntityQueryServiceTest.java

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,9 +146,6 @@ public class EntityQueryServiceTest {
146146
private static final String ATTRIBUTE_SERVICE_HOST_KEY = "attribute.service.config.host";
147147
private static final String ATTRIBUTE_SERVICE_PORT_KEY = "attribute.service.config.port";
148148

149-
private static final String MONGO_HOST_KEY = "entity.service.config.entity-service.mongo.host";
150-
private static final String MONGO_PORT_KEY = "entity.service.config.entity-service.mongo.port";
151-
152149
private static final Config config = getServiceConfig();
153150

154151
@BeforeAll
@@ -2943,13 +2940,7 @@ private Expression createExpression(String columnName) {
29432940

29442941
private static Datastore getDatastore() {
29452942
EntityServiceDataStoreConfig entityServiceConfig = new EntityServiceDataStoreConfig(config);
2946-
2947-
Map<String, String> mongoConfig = new HashMap<>();
2948-
mongoConfig.putIfAbsent("host", config.getString(MONGO_HOST_KEY));
2949-
mongoConfig.putIfAbsent("port", config.getString(MONGO_PORT_KEY));
2950-
Config dataStoreConfig = ConfigFactory.parseMap(mongoConfig);
2951-
String dataStoreType = entityServiceConfig.getDataStoreType();
2952-
return DatastoreProvider.getDatastore(dataStoreType, dataStoreConfig);
2943+
return DatastoreProvider.getDatastore(entityServiceConfig.getDataStoreConfig());
29532944
}
29542945

29552946
private static Map<String, Map<String, String>> getAttributesMap() {

entity-service/src/integrationTest/resources/configs/entity-service/application.conf

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,23 @@ service.name = entity-service
33
service.port = 50061
44
service.admin.port = 50062
55
entity.service.config = {
6-
entity-service {
6+
document.store {
77
dataStoreType = mongo
8+
appName = entity-service-integration-test
9+
maxPoolSize = 10
810
mongo {
9-
host = localhost
10-
host = ${?MONGO_HOST}
11-
port = 37017
12-
port = ${?MONGO_PORT}
11+
database = default_db
12+
endpoints = [
13+
{
14+
host = localhost
15+
host = ${?MONGO_HOST}
16+
port = 37017
17+
port = ${?MONGO_PORT}
18+
}
19+
]
1320
}
1421
}
22+
1523
publish.change.events = false
1624
}
1725

entity-service/src/main/resources/configs/common/application.conf

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,22 @@ service.name = entity-service
33
service.port = 50061
44
service.admin.port = 50062
55
entity.service.config = {
6-
entity-service {
6+
document.store {
77
dataStoreType = mongo
8+
appName = entity-service-local
9+
maxPoolSize = 10
810
mongo {
9-
host = localhost
10-
host = ${?MONGO_HOST}
11-
port = 27017
11+
database = default_db
12+
user = ${?MONGO_SERVICE_USERNAME}
13+
password = ${?MONGO_SERVICE_USER_PASSWORD}
14+
endpoints = [
15+
{
16+
host = localhost
17+
host = ${?MONGO_HOST} # provides a way to override the mongo_host via an environment variable
18+
port = 27017
19+
port = ${?MONGO_PORT}
20+
}
21+
]
1222
}
1323
}
1424
publish.change.events = false

helm/templates/deployment.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,20 @@ spec:
8383
value: "/var/{{ .Chart.Name }}/log/log4j2.properties"
8484
- name: JAVA_OPTS
8585
value: {{ .Values.javaOpts | quote }}
86+
{{- if and .Values.database .Values.database.mongo.authEnabled }}
87+
{{- with .Values.database.mongo.credentials }}
88+
- name: MONGO_SERVICE_USERNAME
89+
valueFrom:
90+
secretKeyRef:
91+
name: {{ .secretName }}
92+
key: {{ .secretUsernameKey }}
93+
- name: MONGO_SERVICE_USER_PASSWORD
94+
valueFrom:
95+
secretKeyRef:
96+
name: {{ .secretName }}
97+
key: {{ .secretPasswordKey }}
98+
{{- end }}
99+
{{- end }}
86100
volumeMounts:
87101
- name: service-config
88102
mountPath: /app/resources/configs/{{ .Chart.Name }}/application.conf

helm/templates/entity-service-config.yaml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,24 @@ metadata:
77
data:
88
application.conf: |-
99
entity.service.config = {
10-
entity-service {
11-
{{- $dst := .Values.entityServiceConfig.dataStoreType }}
10+
document.store {
11+
{{- if .Values.database }}
12+
{{- $dst := .Values.database.type }}
1213
dataStoreType = {{ $dst }}
14+
appName = {{ .Values.service.name }}
15+
1316
{{ $dst }} {
14-
{{- range $key, $value := (index .Values "entityServiceConfig" (printf "%s" $dst)) }}
17+
{{- range $key, $value := (index .Values "database" (printf "%s" $dst)) }}
1518
{{- if $value }}
16-
{{- if eq $key "password" }}
19+
{{- if hasPrefix "${?" (printf "%s" $value) }}
1720
{{ $key }} = {{ $value }}
1821
{{- else }}
19-
{{ $key }} = {{ $value | quote }}
22+
{{ $key }} = {{- toJson $value }}
2023
{{- end }}
2124
{{- end }}
2225
{{- end }}
2326
}
27+
{{- end }}
2428
}
2529
publish.change.events = {{ .Values.entityServiceConfig.publishChangeEvents }}
2630
}

helm/values.yaml

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,6 @@ serviceSelectorLabels:
9292
entityServiceConfig:
9393
name: entity-service-config
9494
publishChangeEvents: false
95-
dataStoreType: "mongo"
96-
mongo:
97-
host: mongo
98-
url: ""
9995
postgres:
10096
host: postgres
10197
port: 5432
@@ -106,6 +102,20 @@ entityServiceConfig:
106102
host: attribute-service
107103
port: 9012
108104

105+
database:
106+
type: mongo
107+
mongo:
108+
authEnabled: true
109+
endpoints:
110+
- host: mongo
111+
port: 27017
112+
replicaSet: rs0
113+
authDb: admin
114+
credentials:
115+
secretName: mongodb-credentials
116+
secretUsernameKey: mongodb-service-username
117+
secretPasswordKey: mongodb-service-password
118+
109119
attributes: []
110120
idAttributes:
111121
- scope: API

0 commit comments

Comments
 (0)