Skip to content

Commit

Permalink
[#10918] Backport: Increase the coverage of the apiId cache
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Apr 17, 2024
1 parent 546a049 commit bcab2f6
Show file tree
Hide file tree
Showing 89 changed files with 1,166 additions and 736 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Copyright 2024 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.bootstrap.context;

public class MethodDescriptorHelper {

public static MethodDescriptor apiId(final int apiId) {
return new MethodDescriptor() {
@Override
public String getMethodName() {
return "";
}

@Override
public String getClassName() {
return "";
}

@Override
public String[] getParameterTypes() {
return new String[0];
}

@Override
public String[] getParameterVariableName() {
return new String[0];
}

@Override
public String getParameterDescriptor() {
return "";
}

@Override
public int getLineNumber() {
return 0;
}

@Override
public String getFullName() {
return "";
}

@Override
public void setApiId(int apiId) {
}

@Override
public int getApiId() {
return apiId;
}

@Override
public String getApiDescriptor() {
return "";
}

@Override
public int getType() {
return 0;
}

@Override
public String toString() {
return "{" +
"apiId=" + apiId +
'}';
}
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2019 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.bootstrap.interceptor;

import com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessorUtils;
import com.navercorp.pinpoint.bootstrap.context.AsyncContext;
import com.navercorp.pinpoint.bootstrap.context.AsyncContextUtils;
import com.navercorp.pinpoint.bootstrap.context.Trace;
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;

import java.util.Objects;

/**
* @author jaehong.kim
*/
public abstract class AbstractAsyncContextSpanEventEndPointInterceptor {
protected final PLogger logger = PLoggerFactory.getLogger(getClass());
protected final boolean isDebug = logger.isDebugEnabled();

protected final TraceContext traceContext;

public AbstractAsyncContextSpanEventEndPointInterceptor(TraceContext traceContext) {
this.traceContext = Objects.requireNonNull(traceContext, "traceContext");
}

protected AsyncContext getAsyncContext(Object target, Object[] args) {
return AsyncContextAccessorUtils.getAsyncContext(target);
}

protected AsyncContext getAsyncContext(Object target, Object[] args, Object result, Throwable throwable) {
return AsyncContextAccessorUtils.getAsyncContext(target);
}

protected Trace getAsyncTrace(AsyncContext asyncContext) {
final Trace trace = asyncContext.continueAsyncTraceObject();
if (trace == null) {
return null;
}

return trace;
}

protected void deleteAsyncTrace(final Trace trace) {
traceContext.removeTraceObject();
trace.close();
}


protected void finishAsyncState(final AsyncContext asyncContext) {
if (AsyncContextUtils.asyncStateFinish(asyncContext)) {
if (isDebug) {
logger.debug("finished asyncState. asyncTraceId={}", asyncContext);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* Copyright 2017 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.navercorp.pinpoint.bootstrap.interceptor;

import com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessorUtils;
import com.navercorp.pinpoint.bootstrap.context.AsyncContext;
import com.navercorp.pinpoint.bootstrap.context.Trace;
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;

import java.util.Objects;

public abstract class AbstractAsyncContextSpanEventInterceptor {
protected final PLogger logger = PLoggerFactory.getLogger(getClass());
protected final boolean isDebug = logger.isDebugEnabled();
protected final boolean isTrace = logger.isTraceEnabled();

public AbstractAsyncContextSpanEventInterceptor(TraceContext traceContext) {
Objects.requireNonNull(traceContext, "traceContext");
}

protected AsyncContext getAsyncContext(Object target, Object[] args) {
return AsyncContextAccessorUtils.getAsyncContext(target);
}

protected AsyncContext getAsyncContext(Object target, Object[] args, Object result, Throwable throwable) {
return AsyncContextAccessorUtils.getAsyncContext(target);
}

protected Trace getAsyncTrace(AsyncContext asyncContext) {
final Trace trace = asyncContext.continueAsyncTraceObject();
if (trace == null) {
if (isDebug) {
logger.debug("Failed to continue async trace. 'result is null'");
}
return null;
}
if (isDebug) {
logger.debug("getAsyncTrace() trace {}, asyncContext={}", trace, asyncContext);
}

return trace;
}

protected void deleteAsyncContext(final Trace trace, AsyncContext asyncContext) {
if (isDebug) {
logger.debug("Delete async trace {}.", trace);
}

trace.close();
asyncContext.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2014 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.bootstrap.interceptor;

import com.navercorp.pinpoint.bootstrap.context.Trace;
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
import com.navercorp.pinpoint.bootstrap.logging.PLogger;
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;

import java.util.Objects;

/**
* @author emeroad
* @author jaehong.kim
*/
public abstract class AbstractSpanEventInterceptorForPlugin {
protected final PLogger logger = PLoggerFactory.getLogger(getClass());
protected final boolean isDebug = logger.isDebugEnabled();

protected final TraceContext traceContext;

protected AbstractSpanEventInterceptorForPlugin(TraceContext traceContext) {
this.traceContext = Objects.requireNonNull(traceContext, "traceContext");
}

protected Trace currentTrace() {
return traceContext.currentTraceObject();
}

protected void logBeforeInterceptor(Object target, Object[] args) {
logger.beforeInterceptor(target, args);
}

protected void logAfterInterceptor(Object target, Object[] args, Object result, Throwable throwable) {
logger.afterInterceptor(target, args, result, throwable);
}

protected TraceContext getTraceContext() {
return traceContext;
}
}
Loading

0 comments on commit bcab2f6

Please sign in to comment.