change InnerMethodName

This commit is contained in:
lucio 2024-02-21 20:22:49 +01:00
parent 6454f71672
commit 64fb289c40
4 changed files with 21 additions and 23 deletions

View File

@ -5,7 +5,7 @@
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.2.0</version>
<version>1.1.0</version>
<relativePath />
</parent>
<groupId>org.gcube.core</groupId>

View File

@ -34,21 +34,21 @@ public class RequestAccounting extends RequestHandler {
String context = getContext(appContext);
if (InnerMethodName.instance.get() == null) {
if (InnerMethodName.get() == null) {
String calledMethod = e.request().getRequestURI().substring(e.request().getContextPath().length());
if (calledMethod.isEmpty())
calledMethod = "/";
calledMethod = e.request().getMethod() + " " + calledMethod;
InnerMethodName.instance.set(calledMethod);
InnerMethodName.set(calledMethod);
}
String caller = SecretManagerProvider.instance.get() != null
? SecretManagerProvider.instance.get().getOwner().getId()
String caller = SecretManagerProvider.get() != null
? SecretManagerProvider.get().getOwner().getId()
: UNKNOWN;
startCallThreadLocal.set(System.currentTimeMillis());
log.info("REQUEST START ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} ", appContext.configuration().name(),
appContext.configuration().group(), InnerMethodName.instance.get(), caller,
appContext.configuration().group(), InnerMethodName.get(), caller,
e.request().getRemoteHost(), context);
}
@ -61,8 +61,8 @@ public class RequestAccounting extends RequestHandler {
String context = getContext(appContext);
String caller = SecretManagerProvider.instance.get() != null
? SecretManagerProvider.instance.get().getOwner().getId()
String caller = SecretManagerProvider.get() != null
? SecretManagerProvider.get().getOwner().getId()
: UNKNOWN;
String callerQualifier = UNKNOWN;
// retieves caller Ip when there is a proxy
@ -91,7 +91,7 @@ public class RequestAccounting extends RequestHandler {
log.info("REQUEST SERVED ON {}:{}({}) CALLED FROM {}@{} IN SCOPE {} {}(CODE {}) IN {} millis",
appContext.configuration().name(), appContext.configuration().group(),
InnerMethodName.instance.get(), caller, callerIp, context, success ? "SUCCEDED" : "FAILED",
InnerMethodName.get(), caller, callerIp, context, success ? "SUCCEDED" : "FAILED",
e.response().getStatus(), durationInMillis);
} catch (Exception e1) {
@ -99,7 +99,7 @@ public class RequestAccounting extends RequestHandler {
throw e1;
} finally {
startCallThreadLocal.remove();
InnerMethodName.instance.reset();
InnerMethodName.reset();
}
}
@ -120,7 +120,7 @@ public class RequestAccounting extends RequestHandler {
serviceUsageRecord.setHost(appContext.container().configuration().hostname() + ":"
+ appContext.container().configuration().port());
serviceUsageRecord.setCalledMethod(InnerMethodName.instance.get());
serviceUsageRecord.setCalledMethod(InnerMethodName.get());
serviceUsageRecord.setCallerHost(remoteHost);
serviceUsageRecord.setOperationResult(success ? OperationResult.SUCCESS : OperationResult.FAILED);
serviceUsageRecord.setDuration(System.currentTimeMillis() - startCallThreadLocal.get());
@ -134,8 +134,8 @@ public class RequestAccounting extends RequestHandler {
private String getContext(ApplicationContext appContext) {
String infrastructure = appContext.container().configuration().infrastructure();
String context = "/" + infrastructure;
if (SecretManagerProvider.instance.get() != null)
context = SecretManagerProvider.instance.get().getContext();
if (SecretManagerProvider.get() != null)
context = SecretManagerProvider.get().getContext();
return context;
}

View File

@ -47,7 +47,7 @@ public class RequestValidator extends RequestHandler {
appContext = call.context();
SecretManagerProvider.instance.set(getSecret(call));
SecretManagerProvider.set(getSecret(call));
validateAgainstLifecycle(call);
@ -63,7 +63,7 @@ public class RequestValidator extends RequestHandler {
@Override
public void handleResponse(ResponseEvent e) {
log.debug("resetting all the Thread local for this call.");
SecretManagerProvider.instance.reset();
SecretManagerProvider.reset();
}
@ -85,7 +85,7 @@ public class RequestValidator extends RequestHandler {
private void validateScopeCall() {
String context = SecretManagerProvider.instance.get().getContext();
String context = SecretManagerProvider.get().getContext();
if (context == null) {
log.warn("rejecting unscoped call to {}",appContext.name());
@ -106,7 +106,7 @@ public class RequestValidator extends RequestHandler {
private void rejectUnauthorizedCalls(RequestEvent call){
Secret secret = SecretManagerProvider.instance.get();
Secret secret = SecretManagerProvider.get();
if (secret == null){
log.warn("rejecting call to {}, authorization required",appContext.name());

View File

@ -5,8 +5,6 @@ import org.slf4j.LoggerFactory;
public class InnerMethodName {
public static InnerMethodName instance = new InnerMethodName();
private static Logger logger = LoggerFactory.getLogger(InnerMethodName.class);
// Thread local variable containing each thread's ID
@ -14,26 +12,26 @@ public class InnerMethodName {
new InheritableThreadLocal<String>() {
@Override protected String initialValue() {
return "UNKNOWN";
return null;
}
};
private InnerMethodName(){}
public String get(){
public static String get(){
String calledMethod = threadMethod.get();
logger.trace("getting InnerMethodName as "+calledMethod+" in thread "+Thread.currentThread().getId() );
return calledMethod;
}
public void set(String calledMethod){
public static void set(String calledMethod){
if (calledMethod==null) return;
threadMethod.set(calledMethod);
logger.trace("setting InnerMethodName as "+calledMethod+" in thread "+Thread.currentThread().getId() );
}
public void reset(){
public static void reset(){
threadMethod.remove();
}
}