use of com.newrelic.agent.database.SqlObfuscator in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method multipleTransactions.
@Test
public void multipleTransactions() throws Exception {
Map<String, Object> configMap = createStagingMap();
createServiceManager(configMap);
// run a transaction
Tracer requestDispatcherTracer = startDispatcherTracer();
long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1, TimeUnit.MILLISECONDS);
startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dude where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dudette where somevalue = 'cool'", duration).finish(Opcodes.RETURN, null);
requestDispatcherTracer.finish(Opcodes.RETURN, null);
// run another transaction
requestDispatcherTracer = startDispatcherTracer();
long duration2 = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1, TimeUnit.MILLISECONDS);
startSqlTracer("select * from dude where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dude where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
startSqlTracer("select * from dudette where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
startSqlTracer("select * from duderino where somevalue = 'cool'", duration2).finish(Opcodes.RETURN, null);
requestDispatcherTracer.finish(Opcodes.RETURN, null);
// run a harvest
MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMService();
List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
// verify results
Assert.assertEquals(3, sqlTraces.size());
long expectedDuration = TimeUnit.MILLISECONDS.convert(duration, TimeUnit.NANOSECONDS);
long expectedDuration2 = TimeUnit.MILLISECONDS.convert(duration2, TimeUnit.NANOSECONDS);
String expectedSql = "select * from dude where somevalue = ?";
SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
long expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
SqlTrace sqlTrace = getSqlTrace(expectedId, sqlTraces);
Assert.assertNotNull(sqlTrace);
Assert.assertEquals(expectedId, sqlTrace.getId());
Assert.assertEquals(expectedSql, sqlTrace.getQuery());
Assert.assertEquals(4, sqlTrace.getCallCount());
Assert.assertEquals((expectedDuration * 2) + (expectedDuration2 * 2), sqlTrace.getTotal());
Assert.assertEquals(expectedDuration, sqlTrace.getMin());
Assert.assertEquals(expectedDuration2, sqlTrace.getMax());
expectedSql = "select * from dudette where somevalue = ?";
expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
sqlTrace = getSqlTrace(expectedId, sqlTraces);
Assert.assertNotNull(sqlTrace);
Assert.assertEquals(expectedId, sqlTrace.getId());
Assert.assertEquals(expectedSql, sqlTrace.getQuery());
Assert.assertEquals(2, sqlTrace.getCallCount());
Assert.assertEquals(expectedDuration + expectedDuration2, sqlTrace.getTotal());
Assert.assertEquals(expectedDuration, sqlTrace.getMin());
Assert.assertEquals(expectedDuration2, sqlTrace.getMax());
expectedSql = "select * from duderino where somevalue = ?";
expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
sqlTrace = getSqlTrace(expectedId, sqlTraces);
Assert.assertNotNull(sqlTrace);
Assert.assertEquals(expectedId, sqlTrace.getId());
Assert.assertEquals(expectedSql, sqlTrace.getQuery());
Assert.assertEquals(1, sqlTrace.getCallCount());
Assert.assertEquals(expectedDuration2, sqlTrace.getTotal());
Assert.assertEquals(expectedDuration2, sqlTrace.getMin());
Assert.assertEquals(expectedDuration2, sqlTrace.getMax());
}
use of com.newrelic.agent.database.SqlObfuscator in project newrelic-java-agent by newrelic.
the class SqlTraceServiceTest method overSqlLimit.
@Test
public void overSqlLimit() throws Exception {
Map<String, Object> configMap = createStagingMap();
createServiceManager(configMap);
int sqlLimit = SlowQueryAggregatorImpl.SLOW_QUERY_LIMIT_PER_REPORTING_PERIOD;
// run a transaction
Tracer requestDispatcherTracer = startDispatcherTracer();
for (int i = 0; i < sqlLimit * 2; i++) {
String sql = "select * from dude where column" + i + " = 'cool'";
long duration = TimeUnit.NANOSECONDS.convert(getExplainThresholdInMillis() + 1 + i, TimeUnit.MILLISECONDS);
startSqlTracer(sql, duration).finish(Opcodes.RETURN, null);
}
requestDispatcherTracer.finish(Opcodes.RETURN, null);
// run a harvest
MockHarvestService mockharvestService = (MockHarvestService) ServiceFactory.getHarvestService();
mockharvestService.runHarvest(ServiceFactory.getConfigService().getDefaultAgentConfig().getApplicationName(), new StatsEngineImpl());
MockRPMService mockRPMService = (MockRPMService) ServiceFactory.getRPMService();
List<SqlTrace> sqlTraces = mockRPMService.getSqlTraces();
// verify results
Assert.assertEquals(sqlLimit, sqlTraces.size());
SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
for (int i = sqlLimit; i < sqlLimit * 2; i++) {
String expectedSql = "select * from dude where column" + i + " = ?";
long expectedId = sqlObfuscator.obfuscateSql(expectedSql).hashCode();
SqlTrace sqlTrace = getSqlTrace(expectedId, sqlTraces);
Assert.assertNotNull(sqlTrace);
long expectedDuration = getExplainThresholdInMillis() + 1 + i;
Assert.assertEquals(expectedId, sqlTrace.getId());
Assert.assertEquals(expectedSql, sqlTrace.getQuery());
Assert.assertEquals(1, sqlTrace.getCallCount());
Assert.assertEquals(expectedDuration, sqlTrace.getTotal());
Assert.assertEquals(expectedDuration, sqlTrace.getMin());
Assert.assertEquals(expectedDuration, sqlTrace.getMax());
}
}
use of com.newrelic.agent.database.SqlObfuscator in project newrelic-java-agent by newrelic.
the class ExternalTracerTest method testExternalTracerExcludeUri.
@Test
public void testExternalTracerExcludeUri() throws Exception {
before("/com/newrelic/agent/config/exclude_request_uri.yml");
DefaultTracer tracer = prepareTracer();
TransactionTracerConfig ttConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getTransactionTracerConfig();
SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
TransactionSegment segment = tracer.getTransactionSegment(ttConfig, sqlObfuscator, 0, null);
TransactionStats stats = tracer.getTransactionActivity().getTransactionStats();
String uri = "http://myhost:1234/Parameters";
String queryParams = "?data=confidential";
tracer.reportAsExternal(GenericParameters.library("MyLibrary").uri(URI.create(uri + queryParams)).procedure("other").build());
tracer.recordMetrics(stats);
String segmentUri = segment.getUri();
tracer.finish(Opcodes.RETURN, null);
Assert.assertEquals(null, segmentUri);
}
use of com.newrelic.agent.database.SqlObfuscator in project newrelic-java-agent by newrelic.
the class ExternalTracerTest method testExternalTracerIncludeUri.
@Test
public void testExternalTracerIncludeUri() throws Exception {
before("/com/newrelic/agent/config/span_events.yml");
DefaultTracer tracer = prepareTracer();
TransactionTracerConfig ttConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getTransactionTracerConfig();
SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
TransactionSegment segment = tracer.getTransactionSegment(ttConfig, sqlObfuscator, 0, null);
TransactionStats stats = tracer.getTransactionActivity().getTransactionStats();
String uri = "http://myhost:1234/Parameters";
String queryParams = "?data=confidential";
tracer.reportAsExternal(GenericParameters.library("MyLibrary").uri(URI.create(uri + queryParams)).procedure("other").build());
tracer.recordMetrics(stats);
String segmentUri = segment.getUri();
tracer.finish(Opcodes.RETURN, null);
Assert.assertNotNull(segmentUri);
}
use of com.newrelic.agent.database.SqlObfuscator in project newrelic-java-agent by newrelic.
the class DefaultTracerTest method stackTrace.
@Test
public void stackTrace() throws Exception {
Transaction transaction = Transaction.getTransaction();
ClassMethodSignature sig = new ClassMethodSignature("java.lang.String", "valueof", "(J)Ljava/lang/String;");
DefaultTracer tracer = new DefaultTracer(transaction, sig, "12345");
tracer.storeStackTrace();
SqlObfuscator sqlObfuscator = ServiceFactory.getDatabaseService().getDefaultSqlObfuscator();
TransactionTracerConfig ttConfig = ServiceFactory.getConfigService().getDefaultAgentConfig().getTransactionTracerConfig();
TransactionSegment segment = new TransactionSegment(ttConfig, sqlObfuscator, 0, tracer);
JSONArray json = (JSONArray) AgentHelper.serializeJSON(segment);
Map params = (Map) json.get(3);
List backtrace = (List) params.get(DefaultSqlTracer.BACKTRACE_PARAMETER_NAME);
Assert.assertTrue(backtrace.size() > 2);
}
Aggregations