Skip to content

Commit

Permalink
added logging a type hint to AbstractEnforcement successful enforcement
Browse files Browse the repository at this point in the history
* fixed toString() in Contextual

Signed-off-by: Thomas Jaeckle <thomas.jaeckle@bosch.io>
  • Loading branch information
thjaeckle committed May 17, 2021
1 parent 2e3a4fb commit ef64c1b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Expand Up @@ -14,6 +14,7 @@

import java.time.Duration;
import java.util.Objects;
import java.util.Optional;
import java.util.concurrent.CompletionStage;
import java.util.function.BiFunction;
import java.util.function.Function;
Expand All @@ -24,16 +25,17 @@
import org.eclipse.ditto.base.model.exceptions.DittoRuntimeException;
import org.eclipse.ditto.base.model.headers.DittoHeaders;
import org.eclipse.ditto.base.model.headers.WithDittoHeaders;
import org.eclipse.ditto.policies.model.enforcers.EffectedSubjects;
import org.eclipse.ditto.policies.model.enforcers.Enforcer;
import org.eclipse.ditto.policies.model.ResourceKey;
import org.eclipse.ditto.things.model.ThingConstants;
import org.eclipse.ditto.policies.api.Permission;
import org.eclipse.ditto.base.model.signals.Signal;
import org.eclipse.ditto.base.model.signals.WithType;
import org.eclipse.ditto.base.model.signals.commands.exceptions.GatewayInternalErrorException;
import org.eclipse.ditto.internal.utils.akka.logging.ThreadSafeDittoLoggingAdapter;
import org.eclipse.ditto.internal.utils.cache.CacheKey;
import org.eclipse.ditto.internal.utils.metrics.instruments.timer.StartedTimer;
import org.eclipse.ditto.base.model.signals.Signal;
import org.eclipse.ditto.base.model.signals.commands.exceptions.GatewayInternalErrorException;
import org.eclipse.ditto.policies.api.Permission;
import org.eclipse.ditto.policies.model.ResourceKey;
import org.eclipse.ditto.policies.model.enforcers.EffectedSubjects;
import org.eclipse.ditto.policies.model.enforcers.Enforcer;
import org.eclipse.ditto.things.model.ThingConstants;

import akka.actor.ActorRef;
import akka.pattern.AskTimeoutException;
Expand Down Expand Up @@ -88,8 +90,12 @@ private BiFunction<Contextual<WithDittoHeaders>, Throwable, Contextual<WithDitto
.map(startedTimer -> startedTimer.tag("outcome", throwable != null ? "fail" : "success"))
.ifPresent(StartedTimer::stop);
if (null != result) {
final Optional<String> typeHint = result.getMessageOptional()
.filter(WithType.class::isInstance)
.map(msg -> ((WithType) msg).getType());
result.getLog().withCorrelationId(result)
.info("Completed enforcement with outcome 'success' and headers: <{}>", result.getDittoHeaders());
.info("Completed enforcement of contextual message type <{}> with outcome 'success' " +
"and headers: <{}>", typeHint.orElse("?"), result.getDittoHeaders());
} else {
log().info("Completed enforcement with outcome 'failed' and headers: <{}>", dittoHeaders());
}
Expand Down
Expand Up @@ -216,7 +216,7 @@ <S extends WithDittoHeaders> Optional<Contextual<S>> tryToMapMessage(final Funct
<S extends WithDittoHeaders> Contextual<S> withReceivedMessage(@Nullable final S message,
@Nullable final ActorRef sender) {
return new Contextual<>(message, self, sender, pubSubMediator, conciergeForwarder, askTimeout,
log, entityIdFor(message), startedTimer, receiver, receiverWrapperFunction, responseReceivers,
log, cacheKeyFor(message), startedTimer, receiver, receiverWrapperFunction, responseReceivers,
askFuture);
}

Expand All @@ -239,7 +239,7 @@ Contextual<T> withReceiverWrapperFunction(final Function<Object, Object> receive
}

@Nullable
private static CacheKey entityIdFor(@Nullable final WithDittoHeaders signal) {
private static CacheKey cacheKeyFor(@Nullable final WithDittoHeaders signal) {

if (signal == null) {
return null;
Expand All @@ -259,7 +259,7 @@ public String toString() {
"message=" + message +
", self=" + self +
", sender=" + sender +
", entityId=" + cacheKey +
", cacheKey=" + cacheKey +
", receiver=" + receiver +
", receiverWrapperFunction=" + receiverWrapperFunction +
", responseReceivers=" + responseReceivers +
Expand Down

0 comments on commit ef64c1b

Please sign in to comment.