Skip to content
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 @@ -48,6 +48,7 @@
import org.hypertrace.core.attribute.service.v1.UpdateMetadataRequest;
import org.hypertrace.core.attribute.service.v1.UpdateMetadataResponse;
import org.hypertrace.core.attribute.service.validator.AttributeMetadataValidator;
import org.hypertrace.core.documentstore.CloseableIterator;
import org.hypertrace.core.documentstore.Collection;
import org.hypertrace.core.documentstore.Datastore;
import org.hypertrace.core.documentstore.DatastoreProvider;
Expand Down Expand Up @@ -106,22 +107,8 @@ public AttributeServiceImpl(Config config, PlatformServiceLifecycle platformServ
private Datastore initDataStore(
Config config, PlatformServiceLifecycle platformServiceLifecycle) {
final Config docStoreConfig = config.getConfig(DOC_STORE_CONFIG_KEY);
final String dataStoreType = docStoreConfig.getString(DATA_STORE_TYPE);
final DatastoreConfig datastoreConfig =
TypesafeConfigDatastoreConfigExtractor.from(docStoreConfig, DATA_STORE_TYPE)
.hostKey(dataStoreType + ".host")
.portKey(dataStoreType + ".port")
.keysForEndpoints(dataStoreType + ".endpoints", "host", "port")
.authDatabaseKey(dataStoreType + ".authDb")
.replicaSetKey(dataStoreType + ".replicaSet")
.databaseKey(dataStoreType + ".database")
.usernameKey(dataStoreType + ".user")
.passwordKey(dataStoreType + ".password")
.applicationNameKey("appName")
.poolMaxConnectionsKey("maxPoolSize")
.poolConnectionAccessTimeoutKey("connectionAccessTimeout")
.poolConnectionSurrenderTimeoutKey("connectionIdleTime")
.extract();
TypesafeConfigDatastoreConfigExtractor.from(docStoreConfig, DATA_STORE_TYPE).extract();

final Datastore datastore = DatastoreProvider.getDatastore(datastoreConfig);
new DocStoreMetricsRegistry(datastore)
Expand Down Expand Up @@ -185,10 +172,8 @@ public void updateSourceMetadata(
return;
}

try {
// Fetch attributes by FQN
Iterator<Document> documents =
collection.search(getQueryByTenantIdAndFQN(tenantId.get(), request.getFqn()));
try (final CloseableIterator<Document> documents =
collection.search(getQueryByTenantIdAndFQN(tenantId.get(), request.getFqn()))) {
// For each attribute matching the FQN update the source metadata
boolean status =
StreamSupport.stream(Spliterators.spliteratorUnknownSize(documents, 0), false)
Expand Down Expand Up @@ -243,9 +228,8 @@ public void delete(
return;
}

try {
Iterator<Document> documents =
collection.search(getQueryForFilter(tenantId.get(), modifiedRequest));
try (final CloseableIterator<Document> documents =
collection.search(getQueryForFilter(tenantId.get(), modifiedRequest))) {
boolean status =
StreamSupport.stream(Spliterators.spliteratorUnknownSize(documents, 0), false)
.map(Document::toJson)
Expand Down Expand Up @@ -299,10 +283,8 @@ public void deleteSourceMetadata(
return;
}

try {
// Fetch attributes by FQN
Iterator<Document> documents =
collection.search(getQueryByTenantIdAndFQN(tenantId.get(), request.getFqn()));
try (final CloseableIterator<Document> documents =
collection.search(getQueryByTenantIdAndFQN(tenantId.get(), request.getFqn()))) {
// For each attribute matching the FQN update the source metadata
boolean status =
StreamSupport.stream(Spliterators.spliteratorUnknownSize(documents, 0), false)
Expand Down Expand Up @@ -354,8 +336,8 @@ public void findAttributes(
return;
}

try {
Iterator<Document> documents = collection.search(getQueryForFilter(tenantId.get(), request));
try (final CloseableIterator<Document> documents =
collection.search(getQueryForFilter(tenantId.get(), request))) {
sendResult(documents, responseObserver);
} catch (Exception e) {
LOGGER.error("Error finding attributes with filter:" + request, e);
Expand All @@ -371,12 +353,11 @@ public void findAll(Empty request, StreamObserver<AttributeMetadata> responseObs
return;
}

try {
// query with filter on Tenant id
Query query = new Query();
query.setFilter(getTenantIdInFilter(TenantUtils.getTenantHierarchy(tenantId.get())));
// query with filter on Tenant id
Query query = new Query();
query.setFilter(getTenantIdInFilter(TenantUtils.getTenantHierarchy(tenantId.get())));

Iterator<Document> documents = collection.search(query);
try (final CloseableIterator<Document> documents = collection.search(query)) {
sendResult(documents, responseObserver);
} catch (Exception e) {
LOGGER.error("Error finding all attributes", e);
Expand All @@ -393,15 +374,21 @@ public void getAttributes(
return;
}

List<AttributeMetadata> attributes =
Streams.stream(collection.search(this.getQueryForFilter(tenantId, request.getFilter())))
.map(converter::convert)
.flatMap(Optional::stream)
.collect(Collectors.toUnmodifiableList());
try (final CloseableIterator<Document> iterator =
collection.search(this.getQueryForFilter(tenantId, request.getFilter()))) {
List<AttributeMetadata> attributes =
Streams.stream(iterator)
.map(converter::convert)
.flatMap(Optional::stream)
.collect(Collectors.toUnmodifiableList());

responseObserver.onNext(
GetAttributesResponse.newBuilder().addAllAttributes(attributes).build());
responseObserver.onCompleted();
responseObserver.onNext(
GetAttributesResponse.newBuilder().addAllAttributes(attributes).build());
responseObserver.onCompleted();
} catch (Exception e) {
LOGGER.error("Error getting attributes", e);
responseObserver.onError(e);
}
}

@Override
Expand Down
19 changes: 12 additions & 7 deletions helm/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,29 @@ metadata:
data:
application.conf: |-
document.store {
{{- $dst := .Values.configMap.dataStoreType }}
{{- if .Values.database }}
{{- $dst := .Values.database.type }}
dataStoreType = {{ $dst }}
appName = {{ .Values.service.name }}

{{- range $key, $value := (index .Values "database") }}
{{- if ne $key $dst }}
{{ $key }} = {{- toJson $value }}
{{- end }}
{{- end }}

{{ $dst }} {
{{- range $key, $value := (index .Values "configMap" (printf "%s" $dst)) }}
{{- range $key, $value := (index .Values "database" (printf "%s" $dst)) }}
{{- if $value }}
{{- if hasPrefix "${?" (printf "%s" $value) }}
{{ $key }} = {{ $value }}
{{- else }}
{{- if eq $key "endpoints" }}
endpoints = {{- toJson $value }}
{{- else }}
{{ $key }} = {{ $value | quote }}
{{- end }}
{{ $key }} = {{- toJson $value }}
{{- end }}
{{- end }}
{{- end }}
}
{{- end }}
}

max.custom.attributes.per.tenant: {{ .Values.configMap.maxCustomAttributesPerTenant }}
4 changes: 2 additions & 2 deletions helm/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ spec:
value: "/var/{{ .Chart.Name }}/log/log4j2.properties"
- name: JAVA_OPTS
value: {{ .Values.javaOpts | quote }}
{{- if .Values.database.mongoAuthEnabled }}
{{- with .Values.configMap.mongo.credentials }}
{{- if and .Values.database .Values.database.mongo.authEnabled }}
{{- with .Values.database.mongo.credentials }}
- name: MONGO_SERVICE_USERNAME
valueFrom:
secretKeyRef:
Expand Down
16 changes: 0 additions & 16 deletions helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,6 @@ serviceSelectorLabels:

configMap:
name: attribute-service-config
dataStoreType: "mongo"
mongo:
endpoints:
- host: mongo
port: 27017
# credentials:
# secretName: <k8s secret name>
# secretUsernameKey: <secret key for username>
# secretPasswordKey: <secret key for password>
postgres:
host: postgres
port: 5432
url: ""
maxCustomAttributesPerTenant: 5

logConfig:
Expand All @@ -106,6 +93,3 @@ hpa:
minReplicas: 1
maxReplicas: 5
targetCPUUtilizationPercentage: 80

database:
mongoAuthEnabled: true
Loading