This repository has been archived by the owner on Feb 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 290
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Interceptors, add CallTreeExcludingInterceptor
- Loading branch information
Felix Barnsteiner
committed
Feb 7, 2016
1 parent
c55fbc3
commit 59ebe9d
Showing
12 changed files
with
323 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
.../src/main/java/org/stagemonitor/requestmonitor/reporter/CallTreeExcludingInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package org.stagemonitor.requestmonitor.reporter; | ||
|
||
import com.codahale.metrics.Timer; | ||
import org.stagemonitor.requestmonitor.RequestMonitorPlugin; | ||
|
||
class CallTreeExcludingInterceptor implements ElasticsearchRequestTraceReporterInterceptor { | ||
|
||
@Override | ||
public void interceptReport(InterceptContext context) { | ||
if (context.getRequestTrace().getCallStack() == null) { | ||
context.addProperty("containsCallTree", false); | ||
return; | ||
} else { | ||
context.addProperty("containsCallTree", true); | ||
} | ||
|
||
final double percentileLimit = context | ||
.getConfig(RequestMonitorPlugin.class) | ||
.getExcludeCallTreeFromElasticsearchReportWhenFasterThanXPercentOfRequests(); | ||
|
||
if (percentileLimit > 0) { | ||
if (percentileLimit >= 1) { | ||
exclude(context); | ||
} else { | ||
final Timer timer = context.getTimerForThisRequest(); | ||
if (timer != null) { | ||
final double percentile = timer.getSnapshot().getValue(percentileLimit); | ||
final long executionTime = context.getRequestTrace().getExecutionTime(); | ||
if (executionTime < percentile) { | ||
exclude(context); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void exclude(InterceptContext context) { | ||
context.addExcludedProperties("callStack", "callStackJson").addProperty("containsCallTree", false); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 6 additions & 13 deletions
19
...rg/stagemonitor/requestmonitor/reporter/ElasticsearchRequestTraceReporterInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,20 @@ | ||
package org.stagemonitor.requestmonitor.reporter; | ||
|
||
import java.util.Collection; | ||
|
||
import com.codahale.metrics.Meter; | ||
import org.stagemonitor.core.configuration.Configuration; | ||
import org.stagemonitor.requestmonitor.RequestTrace; | ||
|
||
/** | ||
* Allows implementers to customize or omit reporting a request trace to Elasticsearch | ||
* <p/> | ||
* To add an interceptor, call {@link ElasticsearchRequestTraceReporter#registerInterceptor(ElasticsearchRequestTraceReporterInterceptor)} | ||
* or place a file under <code>META-INF/services/org.stagemonitor.requestmonitor.reporter.ElasticsearchRequestTraceReporterInterceptor</code> | ||
* and insert the canonical class name of your implementation. | ||
*/ | ||
public interface ElasticsearchRequestTraceReporterInterceptor { | ||
|
||
void init(Configuration configuration); | ||
|
||
/** | ||
* This method is called before a request trace gets reported to Elasticsearch. | ||
* <p/> | ||
* The implementer of this method can decide whether or not to report the request trace or to exclude certain properties. | ||
* | ||
* @param requestTrace The request trace that is about to be reported | ||
* @param reportingRate The rate at which request traces got reported | ||
* @param excludedProperties Add the names of properties you want to exclude from a report | ||
* @return <code>true</code> if the request trace should be reported, <code>false</code> if reporting should be omitted | ||
* @param context contextual information about the current report that is about to happen | ||
*/ | ||
boolean interceptReport(RequestTrace requestTrace, Meter reportingRate, Collection<String> excludedProperties); | ||
void interceptReport(InterceptContext context); | ||
} |
93 changes: 93 additions & 0 deletions
93
...questmonitor/src/main/java/org/stagemonitor/requestmonitor/reporter/InterceptContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package org.stagemonitor.requestmonitor.reporter; | ||
|
||
import static org.stagemonitor.requestmonitor.RequestMonitor.getTimerMetricName; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
|
||
import com.codahale.metrics.Meter; | ||
import com.codahale.metrics.Timer; | ||
import org.stagemonitor.core.configuration.Configuration; | ||
import org.stagemonitor.core.configuration.ConfigurationOptionProvider; | ||
import org.stagemonitor.core.metrics.metrics2.Metric2Registry; | ||
import org.stagemonitor.requestmonitor.RequestTrace; | ||
|
||
public class InterceptContext { | ||
|
||
private final Configuration configuration; | ||
private final RequestTrace requestTrace; | ||
private final Meter reportingRate; | ||
private final Metric2Registry metricRegistry; | ||
private boolean mustReport = false; | ||
private boolean report = true; | ||
private final Collection<String> excludedProperties = new LinkedList<String>(); | ||
|
||
InterceptContext(Configuration configuration, RequestTrace requestTrace, Meter reportingRate, Metric2Registry metricRegistry) { | ||
this.configuration = configuration; | ||
this.requestTrace = requestTrace; | ||
this.reportingRate = reportingRate; | ||
this.metricRegistry = metricRegistry; | ||
} | ||
|
||
public InterceptContext mustReport() { | ||
mustReport = true; | ||
report = true; | ||
return this; | ||
} | ||
|
||
public InterceptContext shouldNotReport() { | ||
if (!mustReport) { | ||
report = false; | ||
} | ||
return this; | ||
} | ||
|
||
public InterceptContext addExcludedProperty(String properties) { | ||
excludedProperties.add(properties); | ||
return this; | ||
} | ||
|
||
public InterceptContext addExcludedProperties(String... properties) { | ||
excludedProperties.addAll(Arrays.asList(properties)); | ||
return this; | ||
} | ||
|
||
public InterceptContext addProperty(String key, Object value) { | ||
requestTrace.addCustomProperty(key, value); | ||
return this; | ||
} | ||
|
||
public RequestTrace getRequestTrace() { | ||
return requestTrace; | ||
} | ||
|
||
public Meter getReportingRate() { | ||
return reportingRate; | ||
} | ||
|
||
public boolean isReport() { | ||
return report; | ||
} | ||
|
||
public Collection<String> getExcludedProperties() { | ||
return excludedProperties; | ||
} | ||
|
||
public Metric2Registry getMetricRegistry() { | ||
return metricRegistry; | ||
} | ||
|
||
/** | ||
* Returns the timer for the current request. | ||
* | ||
* @return the timer for the current request (may be <code>null</code>) | ||
*/ | ||
public Timer getTimerForThisRequest() { | ||
return metricRegistry.getTimers().get(getTimerMetricName(requestTrace.getName())); | ||
} | ||
|
||
public <T extends ConfigurationOptionProvider> T getConfig(Class<T> configClass) { | ||
return configuration.getConfig(configClass); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.