FilterManager { public FilterProcessor getFilterProcessor(String endpoint) { FilterProcessor ret = (onlyNamedTransactions ? null : unnamedBTxn); synchronized (filterMap) { for (int i = 0; i < globalExclusionFilters.size(); i++) { if (globalExclusionFilters.get(i).isExcluded(endpoint)) { if (log.isLoggable(Level.FINEST)) { log.finest("Excluding endpoint=" + endpoint); } return null; } } for (int i = 0; i < btxnFilters.size(); i++) { if (btxnFilters.get(i).isIncluded(endpoint)) { if (log.isLoggable(Level.FINEST)) { log.finest("Endpoint has passed inclusion filter: endpoint=" + endpoint); } if (btxnFilters.get(i).isExcluded(endpoint)) { if (log.isLoggable(Level.FINEST)) { log.finest("Endpoint has failed exclusion filter: endpoint=" + endpoint); } return null; } ret = btxnFilters.get(i); if (log.isLoggable(Level.FINEST)) { log.finest("Endpoint belongs to transaction '" + ret + ": endpoint=" + endpoint); } break; } } } return ret; } FilterManager(CollectorConfiguration config); void init(String txn, TransactionConfig btc); void remove(String txn); FilterProcessor getFilterProcessor(String endpoint);  }
@Test public void testGlobalExclusion() { CollectorConfiguration config = new CollectorConfiguration(); TransactionConfig btc1 = new TransactionConfig(); config.getTransactions().put("btc1", btc1); TransactionConfig btc2 = new TransactionConfig(); config.getTransactions().put("btc2", btc2); Filter f1 = new Filter(); btc1.setFilter(f1); f1.getExclusions().add("clude"); Filter f2 = new Filter(); btc2.setFilter(f2); f2.getInclusions().add("include"); FilterManager fm = new FilterManager(config); assertNull(fm.getFilterProcessor("include")); }
@Test public void testTransactionInclusion() { CollectorConfiguration config = new CollectorConfiguration(); TransactionConfig btc2 = new TransactionConfig(); config.getTransactions().put("btc2", btc2); Filter f2 = new Filter(); btc2.setFilter(f2); f2.getInclusions().add("include"); FilterManager fm = new FilterManager(config); FilterProcessor fp = fm.getFilterProcessor("include and exclude"); assertNotNull(fp); assertEquals("btc2", fp.getTransaction()); }
@Test public void testTransactionIncludeExclude() { CollectorConfiguration config = new CollectorConfiguration(); TransactionConfig btc2 = new TransactionConfig(); config.getTransactions().put("btc2", btc2); Filter f2 = new Filter(); btc2.setFilter(f2); f2.getInclusions().add("include"); f2.getExclusions().add("exclude"); FilterManager fm = new FilterManager(config); assertNull(fm.getFilterProcessor("include and exclude")); }
@Test public void testExcludeDefaults() { CollectorConfiguration config = new CollectorConfiguration(); TransactionConfig btc2 = new TransactionConfig(); config.getTransactions().put("btc2", btc2); Filter f2 = new Filter(); btc2.setFilter(f2); f2.getExclusions().add("^https?: f2.getExclusions().add("^https?: FilterManager fm = new FilterManager(config); assertNull(fm.getFilterProcessor("http: assertNull(fm.getFilterProcessor( "http: }
@Test public void testTransactionIncludedByDefault() { CollectorConfiguration config = new CollectorConfiguration(); TransactionConfig btc2 = new TransactionConfig(); config.getTransactions().put("btc2", btc2); Filter f2 = new Filter(); btc2.setFilter(f2); f2.getInclusions().add("include"); FilterManager fm = new FilterManager(config); FilterProcessor fp = fm.getFilterProcessor("notrecognised"); assertNotNull(fp); assertNull(fp.getTransaction()); }
@Test public void testTransactionExcludedByDefault() { CollectorConfiguration config = new CollectorConfiguration(); config.getProperties().put("HAWKULAR_APM_COLLECTOR_ONLYNAMED", "true"); TransactionConfig btc2 = new TransactionConfig(); config.getTransactions().put("btc2", btc2); Filter f2 = new Filter(); btc2.setFilter(f2); f2.getInclusions().add("include"); FilterManager fm = new FilterManager(config); assertNull(fm.getFilterProcessor("notrecognised")); }