-
Notifications
You must be signed in to change notification settings - Fork 7
Attribute expressions #128
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
Changes from 6 commits
7ea4b70
5335c63
09b7fd9
614b9a5
19c026a
e4574e3
f0bfa9d
08d7619
7fea23a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import static java.util.concurrent.TimeUnit.MILLISECONDS; | ||
|
|
||
| import com.google.protobuf.util.JsonFormat; | ||
| import io.grpc.CallCredentials; | ||
| import io.reactivex.rxjava3.core.Scheduler; | ||
| import io.reactivex.rxjava3.core.Single; | ||
|
|
@@ -11,6 +12,7 @@ | |
| import javax.inject.Inject; | ||
| import javax.inject.Singleton; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.hypertrace.core.graphql.common.request.AttributeRequest; | ||
| import org.hypertrace.core.graphql.context.GraphQlRequestContext; | ||
| import org.hypertrace.core.graphql.rx.BoundedIoScheduler; | ||
| import org.hypertrace.core.graphql.spi.config.GraphQlServiceConfig; | ||
|
|
@@ -23,6 +25,7 @@ | |
| import org.hypertrace.gateway.service.v1.entity.EntitiesResponse; | ||
| import org.hypertrace.gateway.service.v1.entity.Entity; | ||
| import org.hypertrace.graphql.entity.health.BaselineDao; | ||
| import org.hypertrace.graphql.entity.request.EntityLabelRequest; | ||
| import org.hypertrace.graphql.entity.request.EntityRequest; | ||
| import org.hypertrace.graphql.entity.schema.EntityResultSet; | ||
| import org.hypertrace.graphql.label.joiner.LabelJoiner; | ||
|
|
@@ -73,13 +76,15 @@ public Single<EntityResultSet> getEntities(EntityRequest request) { | |
| GraphQlRequestContext context = request.resultSetRequest().context(); | ||
| return this.requestBuilder | ||
| .buildRequest(request) | ||
| .doOnSuccess(built -> log.warn(JsonFormat.printer().print(built))) | ||
| .subscribeOn(this.boundedIoScheduler) | ||
| .flatMap(serverRequest -> this.fetchAndMapEntities(context, request, serverRequest)); | ||
| } | ||
|
|
||
| private Single<EntityResultSet> fetchAndMapEntities( | ||
| GraphQlRequestContext context, EntityRequest request, EntitiesRequest serverRequest) { | ||
| return this.makeEntityRequest(context, serverRequest) | ||
| .doOnSuccess(built -> log.warn(JsonFormat.printer().print(built))) | ||
|
||
| .flatMap(serverResponse -> this.getEntityResultSet(request, serverRequest, serverResponse)); | ||
| } | ||
|
|
||
|
|
@@ -117,21 +122,22 @@ private Single<Map<Entity, LabelResultSet>> buildLabelResultSetMap( | |
| .flatMap( | ||
| joiner -> | ||
| joiner.joinLabels( | ||
| entitiesResponse.getEntityList(), getEntityLabelsGetter(request))); | ||
| } | ||
|
|
||
| private LabelJoiner.LabelIdGetter<Entity> getEntityLabelsGetter(EntityRequest request) { | ||
| return entity -> Single.just(getLabelAttributeValue(request, entity)); | ||
| entitiesResponse.getEntityList(), | ||
| entity -> Single.just(getLabelAttributeValue(request, entity)))); | ||
| } | ||
|
|
||
| private List<String> getLabelAttributeValue(EntityRequest request, Entity entity) { | ||
| Value labelAttributeValue = | ||
| entity.getAttributeOrDefault( | ||
| request.labelRequest().get().labelIdArrayAttributeRequest().attribute().id(), null); | ||
| if (labelAttributeValue == null) { | ||
| log.warn("Unable to fetch labels attribute for entity with id {}", entity.getId()); | ||
| return Collections.emptyList(); | ||
| } | ||
| return labelAttributeValue.getStringArrayList(); | ||
| return request | ||
| .labelRequest() | ||
| .map(EntityLabelRequest::labelIdArrayAttributeRequest) | ||
| .map(AttributeRequest::asMapKey) | ||
| .filter(entity::containsAttribute) | ||
| .map(entity::getAttributeOrThrow) | ||
| .<List<String>>map(Value::getStringArrayList) | ||
| .orElseGet( | ||
| () -> { | ||
| log.warn("Unable to fetch labels attribute for entity with id {}", entity.getId()); | ||
| return Collections.emptyList(); | ||
| }); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we go with
debug- log.debug?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks - will strip this, it was only for debugging. Thought I had removed it, but I forgot to check in the removal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done