Anshu Kumar: ansharyan015

Of all the plugins that I have to make dynamic as part of my work in GSoC ’12, logging_gearman was one. This plugin is used to log all the queries to a gearman server. After making that dynamic, here is small write-up describing how it works.

This plugins register 2 variables with the server, namely, logging_gearman_host and logging_gearman_function. Logging_gearman_host specifies hostname on which the gearman server is running and logging_gearman_function is the gearman function to which the logging information is sent. Making this plugin dynamic required to make both of these variables dynamic, so that their values can be changed at run time.

Demo of dynamic logging_gearman in action
Make sure gearman in installed and running on your system.

sudo apt-get install gearman-server
sudo apt-get install gearman-job-server

Start drizzle server with logging_gearman plugin loaded.

ansh@ubuntu:~/repos/drizzle/logging_gearman_dynamic$ drizzled/drizzled –plugin-add=logging_gearman

As we have not passed any argument for logging_gearman_host and logging_gearman_function, default arguments will be used for both of them. Default value of these are ‘localhost’ and ‘drizzlelog’ respectively.

Now add a background job to the job server for function drizzlelog

ansh@ubuntu:~$ gearman -f drizzlelog -d

-d is to run this job in background

Now go to your drizzle client and make any query with the server.

drizzle> SELECT 1;
+—+
| 1 |
+—+
| 1 |
+—+
1 row in set (0.000581 sec)

Now this should have been logged to the gearman job with the specified function running. Lets check it now.

ansh@ubuntu:~$ gearman -f drizzlelog -w
1339833870643631,1,9,”",”SELECT 1″,”Query”,237936150,88,88,1,0,0,0,1,”ubuntu”

As we can see here, the query that we made with the server is logged with the gearman job.

Now lets check what may be dynamic in this plugin. Lets say for example, we want to change the function to which we want to send our logging information. Let it be, for example ‘log’  instead of ‘drizzlelog’. For this we will start another gearman job with function ‘log’.

ansh@ubuntu:~$ gearman -f log -d

Now we will change the global variable which corresponds to gearman function in our drizzle server.

drizzle> SHOW VARIABLES LIKE “%gearman%”;
+————————–+————+
| Variable_name | Value |
+————————–+————+
| logging_gearman_function | drizzlelog |
| logging_gearman_host | localhost |
+————————–+————+
2 rows in set (0.000725 sec)drizzle> SET GLOBAL logging_gearman_function=”log”;
Query OK, 0 rows affected (0.000401 sec)

drizzle> SHOW VARIABLES LIKE “%gearman%”;
+————————–+———–+
| Variable_name | Value |
+————————–+———–+
| logging_gearman_function | log |
| logging_gearman_host | localhost |
+————————–+———–+
2 rows in set (0.000664 sec)

Now we will check if these queries are logged into the gearman job with function ‘log’ running.

ansh@ubuntu:~$ gearman -f log -w
1339834035673149,1,6,”",”SET GLOBAL logging_gearman_function=\”log\”",”Query”,40936194,103,103,0,0,0,0,1,”ubuntu”1339834037806111,1,7,”",”SHOW VARIABLES LIKE \”%gearman%\”",”Query”,43069156,347,205,2,2,0,0,1,”ubuntu”

As we can see here, these queries are logged into the new gearman job.

Similar is the case with logging_gearman_host. We can change the host to some other hostname on which the required gearman job is running. Showing this in demo is not possible, though.

To check the code making this plugin dynamic, please refer to http://bazaar.launchpad.net/~ansharyan015/drizzle/logging_gearman_dynamic/revision/2567


URL: http://anshsays.wordpress.com/2012/06/16/dynamic-logging_gearman-plugin-in-action/

_______________________________________________
Mailing list: https://launchpad.net/~drizzle-discuss
Post to     : drizzle-discuss@lists.launchpad.net
Unsubscribe : https://launchpad.net/~drizzle-discuss
More help   : https://help.launchpad.net/ListHelp

Reply via email to