DB Flags for Your Tools and Monitoring Apps

I’ve written a lot about the monitoring tool I wrote for my job… it monitors various aspects of our production environment (call quality, metrics, servers, etc), sending email alerts when a element fails X times…

However, there are times a server is pulled out of rotation… it may be down or in error for awhile.  Rather than update the codebase, I started using the Grails app to generate a form to update a table called Flag.

The Flag table is a collection of flags.  It has these columns:



The status column would be to set the “on” or “off” value.  This way we could just update a web form to turn off email alerts, specific tests or the display of specific test results from the UI.

Create the Domain

In Grails, you create a domain… in my case I named it Flag

After creating your domain class you edit it and add the following:

Date dateCreated

String name

Boolean status

Using your IDE or from the command line do a generate-all on your project.Flag This will generate a scaffold for us… now we have a controller and view, where we can add a flag with it’s ‘on / off’ state (true or false) into the database.

Example Controller

Let’s say you have a page of results… such as monitored results from various tests.  You can update that controller with a SQL query that stores the query result to a variable… then we can check the on off state based on that lookup.

Let’s say our tool had a controller called Home.  Maybe that view (views/home/index.gsp) is where the app loads as the default landing page.  So we go to the Home controller… and we add some queries into our index method.  The index method is what’s called on each load of the index page (in this case /views/home/index.gsp.)

A query lookup can use GORM syntax or standard SQL… here’s an example of doing this in SQL:

def showTestAResults = Flag.executeQuery(“select status from Flag where name=’testAViewable’ order by dateCreated desc”, [max:1)[0]

That variable assignment tells Grails to run a query that looks up a status (true or false will be returned since the field is a boolean), where the name is testAViewable. Perhaps Test A is some test we run and we want to be able to control if the results are displayed or not to the users… We order this by dateCreated desc (since we may have multiple entries… maybe some days we want to show Test A Results and some days we don’t.)  The max:1 tells Grails to only retrieve the top item in the list returned… since we are sorting by date desc. that will be the latest entry.  That way we always are getting the latest entry in the database.  Lastly, I’m using a [0], that’s because the results come back in a list… we want to get the real result and not [true].  with the [0] appended, we will get true or false returned outside a list.

at the end of our index() method, we may have some variables being returned to the view (these will be listed in square brackets. Add a lookup to this variable there… or if you don’t have a set of variables returned, you can create it like so:

[showTestAResults: showTestAResults]

The left side is the name we are passing to the view.  The right side of the colon is the variable result returned by the sql query.  We could name the left side anything we want… we could say [testA: showTestAResults]

View Example

In our view (/views/home/index.gsp) we could now do something like this:

<g:if test=”${showTestAResults == true”>

… some code would go here on your presentation of Test A results….


Seeding Data

One we’ve done all this we can run our app and go to our app in a browser and do /flag.  This should bring up a view with a web form.  We can now add a new flag value:

name: showTestAResults

and check the checkbox… (which assigns true to the db.)

If we refresh our home/index.gsp it will now check the controller, which does a lookup for that flag.  If the flag is true it will return true.  In the GSP whatever is in the g:if closure will render to the user.  If the latest value in the database is not true for that item… then it won’t render…

To test that, you can make a new flag entry…

name: showTestAResults

leave the checkbox blank and save.  This will create a new timestamp with the same flag, but with the value false.  Refresh the page… it should no longer display the item.


This is one solution to updating functionality without a deploy.  It’s a pain to deploy code just to stop a test from running, a result from showing, etc.  This way we can turn off email alerts, specific tests or UI elements with simple flag updates.

DB Flags for Your Tools and Monitoring Apps
User Rating: 0 (0 votes)