Skip to content

Commit

Permalink
update pigeoncall requestsize
Browse files Browse the repository at this point in the history
  • Loading branch information
andyyin committed Jan 18, 2017
1 parent a42d606 commit 6ca1148
Showing 1 changed file with 118 additions and 114 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,125 +28,129 @@

public class RemoteCallMonitorInvokeFilter extends InvocationInvokeFilter {

private static final Logger logger = LoggerLoader.getLogger(RemoteCallMonitorInvokeFilter.class);
private static final Logger logger = LoggerLoader.getLogger(RemoteCallMonitorInvokeFilter.class);

private final Monitor monitor = MonitorLoader.getMonitor();
private final Monitor monitor = MonitorLoader.getMonitor();

public RemoteCallMonitorInvokeFilter() {
}
public RemoteCallMonitorInvokeFilter() {
}

@Override
public InvocationResponse invoke(ServiceInvocationHandler handler, InvokerContext invocationContext)
throws Throwable {
invocationContext.getTimeline().add(new TimePoint(TimePhase.O));
MonitorTransaction transaction = null;
InvocationRequest request = invocationContext.getRequest();
String targetApp = null;
String callInterface = null;
InvokerConfig<?> invokerConfig = invocationContext.getInvokerConfig();
if (monitor != null) {
try {
callInterface = InvocationUtils.getRemoteCallFullName(invokerConfig.getUrl(),
invocationContext.getMethodName(), invocationContext.getParameterTypes());
transaction = monitor.createTransaction("PigeonCall", callInterface, invocationContext);
if (transaction != null) {
monitor.setCurrentCallTransaction(transaction);
transaction.setStatusOk();
transaction.logEvent("PigeonCall.callType",
invokerConfig.getCallType(invocationContext.getMethodName()), "");
transaction.logEvent("PigeonCall.serialize", invokerConfig.getSerialize() + "", "");
transaction.logEvent("PigeonCall.timeout",
invokerConfig.getTimeout(invocationContext.getMethodName()) + "", "");
transaction.logEvent("PigeonCall.QPS", "S" + Calendar.getInstance().get(Calendar.SECOND), "");
}
} catch (Throwable e) {
monitor.logMonitorError(e);
}
}
boolean error = false;
try {
InvocationResponse response = handler.handle(invocationContext);
if (transaction != null) {
if (invocationContext.isDegraded()) {
transaction.logEvent("PigeonCall.degrade", callInterface, "");
}
Client client = invocationContext.getClient();
if (client != null) {
targetApp = RegistryManager.getInstance().getReferencedAppFromCache(client.getAddress());
transaction.logEvent("PigeonCall.app", targetApp, "");
String parameters = "";
if (Constants.LOG_PARAMETERS) {
parameters = InvocationUtils.toJsonString(request.getParameters(), 1000, 50);
}
transaction.logEvent("PigeonCall.server", client.getAddress(), parameters);
}

request = invocationContext.getRequest();

@Override
public InvocationResponse invoke(ServiceInvocationHandler handler, InvokerContext invocationContext)
throws Throwable {
invocationContext.getTimeline().add(new TimePoint(TimePhase.O));
MonitorTransaction transaction = null;
InvocationRequest request = invocationContext.getRequest();
String targetApp = null;
String callInterface = null;
InvokerConfig<?> invokerConfig = invocationContext.getInvokerConfig();
if (monitor != null) {
try {
callInterface = InvocationUtils.getRemoteCallFullName(invokerConfig.getUrl(),
invocationContext.getMethodName(), invocationContext.getParameterTypes());
transaction = monitor.createTransaction("PigeonCall", callInterface, invocationContext);
if (transaction != null) {
monitor.setCurrentCallTransaction(transaction);
transaction.setStatusOk();
transaction.logEvent("PigeonCall.callType",
invokerConfig.getCallType(invocationContext.getMethodName()), "");
transaction.logEvent("PigeonCall.serialize", invokerConfig.getSerialize() + "", "");
transaction.logEvent("PigeonCall.timeout",
invokerConfig.getTimeout(invocationContext.getMethodName()) + "", "");
transaction.logEvent("PigeonCall.QPS", "S" + Calendar.getInstance().get(Calendar.SECOND), "");
}
} catch (Throwable e) {
monitor.logMonitorError(e);
}
}
boolean error = false;
try {
InvocationResponse response = handler.handle(invocationContext);
if (transaction != null) {
if (invocationContext.isDegraded()) {
transaction.logEvent("PigeonCall.degrade", callInterface, "");
}
Client client = invocationContext.getClient();
if (client != null) {
targetApp = RegistryManager.getInstance().getReferencedAppFromCache(client.getAddress());
transaction.logEvent("PigeonCall.app", targetApp, "");
String parameters = "";
if (Constants.LOG_PARAMETERS) {
parameters = InvocationUtils.toJsonString(request.getParameters(), 1000, 50);
}
transaction.logEvent("PigeonCall.server", client.getAddress(), parameters);
}
if (request != null) {
String reqSize = SizeMonitor.getInstance().getLogSize(request.getSize());
if (reqSize != null) {
monitor.logEvent("PigeonCall.requestSize", reqSize, "" + request.getSize());
}
}
if (response != null && response.getSize() > 0) {
String respSize = SizeMonitor.getInstance().getLogSize(response.getSize());
if (respSize != null) {
monitor.logEvent("PigeonCall.responseSize", respSize, "" + response.getSize());
}
invocationContext.getTimeline().add(new TimePoint(TimePhase.R, response.getCreateMillisTime()));
invocationContext.getTimeline().add(new TimePoint(TimePhase.R));
}
}
return response;
} catch (Throwable e) {
if (transaction != null) {
if (invocationContext.isDegraded()) {
transaction.logEvent("PigeonCall.degrade", callInterface, "");
}
Client client = invocationContext.getClient();
String remoteAddress = null;
if (client != null) {
remoteAddress = client.getAddress();
targetApp = RegistryManager.getInstance().getReferencedAppFromCache(remoteAddress);
transaction.logEvent("PigeonCall.app", targetApp, "");
String parameters = "";
if (request != null && Constants.LOG_PARAMETERS) {
parameters = InvocationUtils.toJsonString(request.getParameters(), 1000, 50);
}
transaction.logEvent("PigeonCall.server", client.getAddress(), parameters);
}
if (request != null) {
String reqSize = SizeMonitor.getInstance().getLogSize(request.getSize());
if (reqSize != null) {
monitor.logEvent("PigeonCall.requestSize", reqSize, "" + request.getSize());
}
}
if (request != null) {
String reqSize = SizeMonitor.getInstance().getLogSize(request.getSize());
if (reqSize != null) {
monitor.logEvent("PigeonCall.requestSize", reqSize, "" + request.getSize());
}
}
if (response != null && response.getSize() > 0) {
String respSize = SizeMonitor.getInstance().getLogSize(response.getSize());
if (respSize != null) {
monitor.logEvent("PigeonCall.responseSize", respSize, "" + response.getSize());
}
invocationContext.getTimeline().add(new TimePoint(TimePhase.R, response.getCreateMillisTime()));
invocationContext.getTimeline().add(new TimePoint(TimePhase.R));
}
}
return response;
} catch (Throwable e) {
if (transaction != null) {
if (invocationContext.isDegraded()) {
transaction.logEvent("PigeonCall.degrade", callInterface, "");
}
Client client = invocationContext.getClient();
String remoteAddress = null;
if (client != null) {
remoteAddress = client.getAddress();
targetApp = RegistryManager.getInstance().getReferencedAppFromCache(remoteAddress);
transaction.logEvent("PigeonCall.app", targetApp, "");
String parameters = "";
if (request != null && Constants.LOG_PARAMETERS) {
parameters = InvocationUtils.toJsonString(request.getParameters(), 1000, 50);
}
transaction.logEvent("PigeonCall.server", client.getAddress(), parameters);
}
request = invocationContext.getRequest();
if (request != null) {
String reqSize = SizeMonitor.getInstance().getLogSize(request.getSize());
if (reqSize != null) {
monitor.logEvent("PigeonCall.requestSize", reqSize, "" + request.getSize());
}
}

ExceptionManager.INSTANCE.logRpcException(remoteAddress, invokerConfig.getUrl(),
invocationContext.getMethodName(), "", e, request, null, transaction);
}
throw e;
} finally {
ExceptionManager.INSTANCE.logRpcException(remoteAddress, invokerConfig.getUrl(),
invocationContext.getMethodName(), "", e, request, null, transaction);
}
throw e;
} finally {

if (transaction != null) {
try {
if (invocationContext.getRequest() != null) {
InvocationRequest _request = invocationContext.getRequest();
InvokerConfig config = invocationContext.getInvokerConfig();
if (_request.getSerialize() != config.getSerialize()) {
transaction.addData("CurrentSerialize", _request.getSerialize());
}
monitorProtocal(invocationContext, _request, targetApp);
}
invocationContext.getTimeline().add(new TimePoint(TimePhase.E, System.currentTimeMillis()));
transaction.complete();
} catch (Throwable e) {
monitor.logMonitorError(e);
}
if (monitor != null) {
monitor.clearCallTransaction();
}
}
}
}
if (transaction != null) {
try {
if (invocationContext.getRequest() != null) {
InvocationRequest _request = invocationContext.getRequest();
InvokerConfig config = invocationContext.getInvokerConfig();
if (_request.getSerialize() != config.getSerialize()) {
transaction.addData("CurrentSerialize", _request.getSerialize());
}
monitorProtocal(invocationContext, _request, targetApp);
}
invocationContext.getTimeline().add(new TimePoint(TimePhase.E, System.currentTimeMillis()));
transaction.complete();
} catch (Throwable e) {
monitor.logMonitorError(e);
}
if (monitor != null) {
monitor.clearCallTransaction();
}
}
}
}


private void monitorProtocal(InvokerContext invokerContext, InvocationRequest request, String targetApp) {
Expand Down

0 comments on commit 6ca1148

Please sign in to comment.