Search in sources :

Example 6 with SqlObfuscator

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());
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) MockHarvestService(com.newrelic.agent.MockHarvestService) SqlObfuscator(com.newrelic.agent.database.SqlObfuscator) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 7 with SqlObfuscator

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());
    }
}
Also used : StatsEngineImpl(com.newrelic.agent.stats.StatsEngineImpl) SqlTracer(com.newrelic.agent.tracers.SqlTracer) OtherRootSqlTracer(com.newrelic.agent.tracers.OtherRootSqlTracer) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) Tracer(com.newrelic.agent.tracers.Tracer) MockHarvestService(com.newrelic.agent.MockHarvestService) SqlObfuscator(com.newrelic.agent.database.SqlObfuscator) MockRPMService(com.newrelic.agent.MockRPMService) Test(org.junit.Test)

Example 8 with SqlObfuscator

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);
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) TransactionStats(com.newrelic.agent.stats.TransactionStats) SqlObfuscator(com.newrelic.agent.database.SqlObfuscator) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig) Test(org.junit.Test)

Example 9 with SqlObfuscator

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);
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) TransactionStats(com.newrelic.agent.stats.TransactionStats) SqlObfuscator(com.newrelic.agent.database.SqlObfuscator) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig) Test(org.junit.Test)

Example 10 with SqlObfuscator

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);
}
Also used : TransactionSegment(com.newrelic.agent.trace.TransactionSegment) Transaction(com.newrelic.agent.Transaction) JSONArray(org.json.simple.JSONArray) SqlObfuscator(com.newrelic.agent.database.SqlObfuscator) List(java.util.List) TransactionTracerConfig(com.newrelic.agent.config.TransactionTracerConfig) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Aggregations

SqlObfuscator (com.newrelic.agent.database.SqlObfuscator)15 Test (org.junit.Test)14 TransactionTracerConfig (com.newrelic.agent.config.TransactionTracerConfig)9 TransactionSegment (com.newrelic.agent.trace.TransactionSegment)8 Tracer (com.newrelic.agent.tracers.Tracer)6 JSONArray (org.json.simple.JSONArray)6 MockHarvestService (com.newrelic.agent.MockHarvestService)5 MockRPMService (com.newrelic.agent.MockRPMService)5 StatsEngineImpl (com.newrelic.agent.stats.StatsEngineImpl)5 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)5 SqlTracer (com.newrelic.agent.tracers.SqlTracer)5 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)5 JSONObject (org.json.simple.JSONObject)3 AgentConfig (com.newrelic.agent.config.AgentConfig)2 TransactionStats (com.newrelic.agent.stats.TransactionStats)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 Transaction (com.newrelic.agent.Transaction)1 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)1 List (java.util.List)1 Map (java.util.Map)1