Developing filters for MaxScale: quick and effective

“In just a short amount of time, I added the functionality I needed and enabled a whole new way of interacting with MaxScale.” – MaxScale team’s Intern Markus Mäkelä shares his thoughts on developing for MaxScale.

Introduction

I’m writing about working with and developing MaxScale filters from the viewpoint of someone who is not yet deeply experienced in the inner workings of MaxScale. First I’ll give you a short introduction on the filter interface and how it is used with MaxScale, after which I’ll show you my own modifications on an existing filter.

Filters and the interface

In short, the filters in MaxScale are a versatile way of analyzing, modifying and controlling the contents that a router receives. The filter interface provides access into the client-router traffic without the need to understand the inner workings of MaxScale and gives an easy way to customize how MaxScale works. Without going too deep into specifics, the most essential part of the filter interface is the ‘routeQuery’ function, which passes the query down the chain of filters and finally to the router at the end. This function is where all the magic happens and you can do whatever you want with the query, change the contents, block it completely or just analyze it and pass it on.

My experiences with the filter interface

My own filter is a simple modification of the QueryLogAll filter, which timestamps and logs the queries into a file. Instead of a local file, I wanted to redirect the QLA filter logs to a remote RabbitMQ server. The time it took for me to understand and modify the QLA filter was only a minor part of the effort and most of the time went into battling with the RabbitMQ library. I’m in no way a MaxScale expert and the only parts I needed to understand about its inner workings to make my modifications were the way the queries are stored and the filter interface. In just a short amount of time, I added the functionality I needed and enabled a whole new way of interacting with MaxScale.

Summary

To sum up, filters are just what they sound like they are; things that control the flow and content of MaxScale’s traffic. Personally, I found filters and the filter interface easy to use and I saw the wanted results quickly.

Links

The source code for the aptly name MQFilter is located on GitHub: https://github.com/Markus456/