Search code examples
javagroovycassandraservlet-filtersnetflix-zuul

Netflix Zuul filters pulled from Cassandra not working


I have been using Zuul in combination with other Netflix OSS softs like Eureka, Hystrix, etc. At first, I was able to create my own filter and make it work from the FileSystem. Then, I wanted to use ZuulFilterDAOCassandra API to be able to pull filters from a Cassandra database. The problem is that I'm not able to make it work.

I have translated the Java filter I used from the FileSystem to a Groovy filter, and added it to Cassandra using the ZuulFilterDAO.addFilter() method, and activate it using ZuulFilterDAO.setFilterActive().After that, I started the ZuulFilterPoller to start pulling the filters from the database, if it already had any. For the database table model, I assumed it by looking at the FilterInfo object and its attributes, and from the ZuulFilterDAOCassandra.addFilter()method.

Here's a more complete section of code :

ZuulFilterDAO dao = new ZuulFilterDAOCassandra(keyspace);
try {
    FilterInfo fi = dao.addFilter(code, "pre", "testFilter", "false", "1");
    dao.setFilterActive(fi.getFilterName(), 1); // 1 is the filter revision
    ZuulFilterPoller.start(dao);
} catch (Exception e) {
    // Logging
}

// Show every active filter
List<FilterInfo> allActiveFilters = dao.getAllActiveFilters();
for (FilterInfo fi : allActiveFilters) {
    LOG.info("FilterName: " + fi.getFilterName()); // outputs : FilterName: testFilter
}

In the Zuul console, I also get the following :

adding filter to diskFilterInfo{filter_id='zuul-server:testFilter:pre', 
filter_name='testFilter', filter_type='pre', revision=1, creationDate=/*date*/,
isActive=true, isCanary=false, application_name=zuul-server}

filter written testFilter.groovy

I can then edit the testFilter.groovy at the root of my project, which contains the code I have mentioned in the dao.addFilter() method. I know the code is working, since it worked when pulling filters from the FS. And, when adding a filter, there's a verification of the code done by FilterVerifier.

And when I send my http requests to my application, Zuul doesn't filter them anymore. Am I missing something ?


Solution

  • Try using the FilterFileManager. It's my understanding that ZuulFilterPoller saves the filters from Cassandra to disk, and the FilterFileManager puts them to work.