Merge lp:~ansharyan015/drizzle/logging_query_dynamic into lp:drizzle

Proposed by Daniel Nichter
Status: Merged
Approved by: Brian Aker
Approved revision: 2569
Merged at revision: 2580
Proposed branch: lp:~ansharyan015/drizzle/logging_query_dynamic
Merge into: lp:drizzle
Diff against target: 557 lines (+417/-18)
7 files modified
plugin/logging_query/logging_query.cc (+146/-18)
plugin/logging_query/tests/parse-query-log.sh (+2/-0)
plugin/logging_query/tests/r/file.result (+46/-0)
plugin/logging_query/tests/r/thresholds.result (+54/-0)
plugin/logging_query/tests/t/file.test (+81/-0)
plugin/logging_query/tests/t/master.opt (+1/-0)
plugin/logging_query/tests/t/thresholds.test (+87/-0)
To merge this branch: bzr merge lp:~ansharyan015/drizzle/logging_query_dynamic
Reviewer Review Type Date Requested Status
Daniel Nichter (community) code review Approve
Drizzle Merge Team Pending
Review via email: mp+114035@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :
Download full text (3.3 KiB)

The new tests have hard-coded paths which fail:

logging_query.file [ fail ]
--- /home/vagrant/drizzle/stage/tests/../plugin/logging_query/tests/r/file.result 2012-07-10 02:00:27.845566000 +0300
+++ /home/vagrant/drizzle/stage/tests/../plugin/logging_query/tests/r/file.reject 2012-07-10 02:14:20.671982823 +0300
@@ -1,49 +1,49 @@
 Log file exists
-1 /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query.log
+1 /home/vagrant/drizzle/stage/tests/var/logging_query.log
 SHOW VARIABLES LIKE "%logging_query%";
 Variable_name Value
 logging_query_enable OFF
-logging_query_filename /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query.log
+logging_query_filename /home/vagrant/drizzle/stage/tests/var/logging_query.log
 logging_query_pcre
 logging_query_threshold_big_examined 0
 logging_query_threshold_big_resultset 0
 logging_query_threshold_slow 0
-1 /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query.log
+1 /home/vagrant/drizzle/stage/tests/var/logging_query.log
 SET GLOBAL logging_query_enable=true;
 SELECT 1;
 1
 1
-3 /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query.log
+3 /home/vagrant/drizzle/stage/tests/var/logging_query.log
 SET GLOBAL logging_query_pcre="SHOW.+";
 SELECT @@logging_query_enable;
 @@logging_query_enable
 1
-4 /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query.log
+4 /home/vagrant/drizzle/stage/tests/var/logging_query.log
 SHOW VARIABLES LIKE "%logging_query%";
 Variable_name Value
 logging_query_enable ON
-logging_query_filename /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query.log
+logging_query_filename /home/vagrant/drizzle/stage/tests/var/logging_query.log
 logging_query_pcre SHOW.+
 logging_query_threshold_big_examined 0
 logging_query_threshold_big_resultset 0
 logging_query_threshold_slow 0
-5 /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query.log
+5 /home/vagrant/drizzle/stage/tests/var/logging_query.log
 SET GLOBAL logging_query_filename="DRIZZLETEST_VARDIR/logging_query1.log";
-1 /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query1.log
+1 /home/vagrant/drizzle/stage/tests/var/logging_query1.log
 SELECT @@logging_query_enable;
 @@logging_query_enable
 1
-5 /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query.log
-1 /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query1.log
+5 /home/vagrant/drizzle/stage/tests/var/logging_query.log
+1 /home/vagrant/drizzle/stage/tests/var/logging_query1.log
 SHOW VARIABLES LIKE "%logging_query%";
 Variable_name Value
 logging_query_enable ON
-logging_query_filename /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query1.log
+logging_query_filename /home/vagrant/drizzle/stage/tests/var/logging_query1.log
 logging_query_pcre SHOW.+
 logging_query_threshold_big_examined 0
 logging_query_threshold_big_resultset 0
 logging_query_threshold_slow 0
-5 /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query.log
-2 /home/ansh/repos/drizzle/logging_query_dynamic/tests/var/logging_query1.log
+5 /home/vagrant/drizzle/stage/tests/var/logging_...

Read more...

review: Needs Fixing (code review)
Revision history for this message
Daniel Nichter (daniel-nichter) :
review: Approve (code review)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugin/logging_query/logging_query.cc'
2--- plugin/logging_query/logging_query.cc 2012-01-16 02:37:54 +0000
3+++ plugin/logging_query/logging_query.cc 2012-07-10 18:31:49 +0000
4@@ -18,6 +18,7 @@
5 */
6
7 #include <config.h>
8+#include <drizzled/item.h>
9 #include <drizzled/plugin.h>
10 #include <drizzled/plugin/logging.h>
11 #include <drizzled/gettext.h>
12@@ -44,8 +45,9 @@
13 #define ESCAPE_CHAR '\\'
14 #define SEPARATOR_CHAR ','
15
16-namespace drizzle_plugin
17-{
18+namespace drizzle_plugin {
19+namespace logging_query {
20+
21
22 static bool sysvar_logging_query_enable= false;
23 /* TODO fix these to not be unsigned long once we have sensible sys_var system */
24@@ -53,6 +55,10 @@
25 static uint32_constraint sysvar_logging_query_threshold_big_resultset;
26 static uint32_constraint sysvar_logging_query_threshold_big_examined;
27
28+bool updateFileName(Session *, set_var*);
29+bool updatePCRE(Session *, set_var*);
30+
31+
32 /* quote a string to be safe to include in a CSV line
33 that means backslash quoting all commas, doublequotes, backslashes,
34 and all the ASCII unprintable characters
35@@ -146,8 +152,8 @@
36
37 class Logging_query: public drizzled::plugin::Logging
38 {
39- const std::string _filename;
40- const std::string _query_pcre;
41+ std::string sysvar_filename;
42+ std::string sysvar_pcre;
43 int fd;
44 pcre *re;
45 pcre_extra *pe;
46@@ -160,37 +166,116 @@
47 Logging_query(const std::string &filename,
48 const std::string &query_pcre) :
49 drizzled::plugin::Logging("csv_query_log"),
50- _filename(filename),
51- _query_pcre(query_pcre),
52+ sysvar_filename(filename),
53+ sysvar_pcre(query_pcre),
54 fd(-1), re(NULL), pe(NULL),
55 formatter("%1%,%2%,%3%,\"%4%\",\"%5%\",\"%6%\",%7%,%8%,"
56 "%9%,%10%,%11%,%12%,%13%,%14%,\"%15%\"\n")
57 {
58
59 /* if there is no destination filename, dont bother doing anything */
60- if (_filename.empty())
61+ if (sysvar_filename.empty())
62 return;
63
64- fd= open(_filename.c_str(),
65+ fd= open(sysvar_filename.c_str(),
66 O_WRONLY | O_APPEND | O_CREAT,
67 S_IRUSR|S_IWUSR);
68
69 if (fd < 0)
70 {
71- sql_perror( _("fail open()"), _filename);
72+ sql_perror( _("fail open()"), sysvar_filename);
73 return;
74 }
75
76- if (not _query_pcre.empty())
77+ if (not sysvar_pcre.empty())
78 {
79 const char *this_pcre_error;
80 int this_pcre_erroffset;
81- re= pcre_compile(_query_pcre.c_str(), 0, &this_pcre_error,
82+ re= pcre_compile(sysvar_pcre.c_str(), 0, &this_pcre_error,
83 &this_pcre_erroffset, NULL);
84 pe= pcre_study(re, 0, &this_pcre_error);
85 /* TODO emit error messages if there is a problem */
86 }
87 }
88+
89+
90+ /**
91+ * This function changes the current query log file to the parameter passed to the function.
92+ *
93+ * @return True on success, False on error.
94+ */
95+ bool setFileName(std::string new_filename)
96+ {
97+ if (new_filename.empty())
98+ return false;
99+
100+ int tmp_fd= open(new_filename.c_str(),
101+ O_WRONLY | O_APPEND | O_CREAT,
102+ S_IRUSR|S_IWUSR);
103+
104+ if (tmp_fd < 0)
105+ {
106+ sql_perror( _("fail open()"), new_filename);
107+ return false;
108+ }
109+ if(fd >= 0)
110+ {
111+ close(fd);
112+ }
113+ fd= tmp_fd;
114+ sysvar_filename= new_filename;
115+ return true;
116+ }
117+
118+ /**
119+ * This function updates the current regex expression with the new regex expression passed as parameter.
120+ *
121+ * @return True on success, False on error.
122+ */
123+ bool setPCRE(std::string new_pcre)
124+ {
125+ if (not new_pcre.empty())
126+ {
127+ if (pe != NULL)
128+ {
129+ pcre_free(pe);
130+ }
131+
132+ if (re != NULL)
133+ {
134+ pcre_free(re);
135+ }
136+
137+ const char *tmp_this_pcre_error;
138+ int tmp_this_pcre_erroffset;
139+ re= pcre_compile(new_pcre.c_str(), 0, &tmp_this_pcre_error,
140+ &tmp_this_pcre_erroffset, NULL);
141+ pe= pcre_study(re, 0, &tmp_this_pcre_error);
142+ /* TODO emit error messages if there is a problem */
143+ }
144+ sysvar_pcre= new_pcre;
145+ return true;
146+ }
147+
148+ /**
149+ * Getter for query log filename
150+ *
151+ * @return sysvar_filename
152+ */
153+ std::string& getFileName()
154+ {
155+ return sysvar_filename;
156+ }
157+
158+ /**
159+ * Getter for pcre
160+ *
161+ * @return sysvar_pcre
162+ */
163+ std::string& getPCRE()
164+ {
165+ return sysvar_pcre;
166+ }
167
168 ~Logging_query()
169 {
170@@ -295,17 +380,58 @@
171 }
172 };
173
174-static int logging_query_plugin_init(drizzled::module::Context &context)
175+static Logging_query *handler= NULL;
176+
177+/**
178+ * This function is called when the value of logging_query_filename is updated dynamically.
179+ *
180+ * @return False on success, True on error.
181+ */
182+bool updateFileName(Session *, set_var* var)
183+{
184+ if (not var->value->str_value.empty())
185+ {
186+ std::string new_filename(var->value->str_value.data());
187+ if (handler->setFileName(new_filename))
188+ return false; //success
189+ else
190+ return true; // error
191+ }
192+ errmsg_printf(error::ERROR, _("logging_query_filename cannot be NULL"));
193+ return true; // error
194+}
195+
196+/**
197+ * This function is called when the value of logging_query_pcre is updated dynamically.
198+ *
199+ * @return False on success, True on error.
200+ */
201+bool updatePCRE(Session *, set_var* var)
202+{
203+ if (not var->value->str_value.empty())
204+ {
205+ std::string new_pcre(var->value->str_value.data());
206+ if (handler->setPCRE(new_pcre))
207+ return false; //success
208+ else
209+ return true; // error
210+ }
211+ return false; // success
212+}
213+
214+static int init(drizzled::module::Context &context)
215 {
216 const module::option_map &vm= context.getOptions();
217
218 if (vm.count("filename"))
219 {
220- context.add(new Logging_query(vm["filename"].as<string>(),
221- vm["pcre"].as<string>()));
222+ handler= new Logging_query(vm["filename"].as<string>(),
223+ vm["pcre"].as<string>());
224+
225+ context.add(handler);
226 context.registerVariable(new sys_var_bool_ptr("enable", &sysvar_logging_query_enable));
227- context.registerVariable(new sys_var_const_string_val("filename", vm["filename"].as<string>()));
228- context.registerVariable(new sys_var_const_string_val("pcre", vm["pcre"].as<string>()));
229+ context.registerVariable(new sys_var_std_string("filename", handler->getFileName(), NULL, &updateFileName));
230+ context.registerVariable(new sys_var_std_string("pcre", handler->getPCRE(), NULL, &updatePCRE));
231 context.registerVariable(new sys_var_constrained_value<uint32_t>("threshold_slow", sysvar_logging_query_threshold_slow));
232 context.registerVariable(new sys_var_constrained_value<uint32_t>("threshold_big_resultset", sysvar_logging_query_threshold_big_resultset));
233 context.registerVariable(new sys_var_constrained_value<uint32_t>("threshold_big_examined", sysvar_logging_query_threshold_big_examined));
234@@ -336,6 +462,8 @@
235 _("Threshold for logging big queries, for rows examined"));
236 }
237
238+} /* namespace logging_query */
239+
240 } /* namespace drizzle_plugin */
241
242 DRIZZLE_DECLARE_PLUGIN
243@@ -346,8 +474,8 @@
244 "Mark Atwood",
245 N_("Logs queries to a CSV file"),
246 PLUGIN_LICENSE_GPL,
247- drizzle_plugin::logging_query_plugin_init,
248+ drizzle_plugin::logging_query::init,
249 NULL,
250- drizzle_plugin::init_options
251+ drizzle_plugin::logging_query::init_options
252 }
253 DRIZZLE_DECLARE_PLUGIN_END;
254
255=== added directory 'plugin/logging_query/tests'
256=== added file 'plugin/logging_query/tests/parse-query-log.sh'
257--- plugin/logging_query/tests/parse-query-log.sh 1970-01-01 00:00:00 +0000
258+++ plugin/logging_query/tests/parse-query-log.sh 2012-07-10 18:31:49 +0000
259@@ -0,0 +1,2 @@
260+#!/bin/sh
261+wc -l "$1"|awk '{print($1)}'
262
263=== added directory 'plugin/logging_query/tests/r'
264=== added file 'plugin/logging_query/tests/r/file.result'
265--- plugin/logging_query/tests/r/file.result 1970-01-01 00:00:00 +0000
266+++ plugin/logging_query/tests/r/file.result 2012-07-10 18:31:49 +0000
267@@ -0,0 +1,46 @@
268+Log file exists
269+1
270+SHOW VARIABLES WHERE Variable_Name NOT LIKE "%logging_query_filename%" AND Variable_Name LIKE "%logging_query%";
271+Variable_name Value
272+logging_query_enable OFF
273+logging_query_pcre
274+logging_query_threshold_big_examined 0
275+logging_query_threshold_big_resultset 0
276+logging_query_threshold_slow 0
277+1
278+SET GLOBAL logging_query_enable=true;
279+SELECT 1;
280+1
281+1
282+3
283+SET GLOBAL logging_query_pcre="SHOW.+";
284+SELECT @@logging_query_enable;
285+@@logging_query_enable
286+1
287+4
288+SHOW VARIABLES WHERE Variable_Name NOT LIKE "%logging_query_filename%" AND Variable_Name LIKE "%logging_query%";
289+Variable_name Value
290+logging_query_enable ON
291+logging_query_pcre SHOW.+
292+logging_query_threshold_big_examined 0
293+logging_query_threshold_big_resultset 0
294+logging_query_threshold_slow 0
295+5
296+SET GLOBAL logging_query_filename="DRIZZLETEST_VARDIR/logging_query1.log";
297+1
298+SELECT @@logging_query_enable;
299+@@logging_query_enable
300+1
301+5
302+1
303+SHOW VARIABLES WHERE Variable_Name NOT LIKE "%logging_query_filename%" AND Variable_Name LIKE "%logging_query%";
304+Variable_name Value
305+logging_query_enable ON
306+logging_query_pcre SHOW.+
307+logging_query_threshold_big_examined 0
308+logging_query_threshold_big_resultset 0
309+logging_query_threshold_slow 0
310+5
311+2
312+SET GLOBAL logging_query_filename="";
313+ERROR HY000: Incorrect arguments to SET
314
315=== added file 'plugin/logging_query/tests/r/thresholds.result'
316--- plugin/logging_query/tests/r/thresholds.result 1970-01-01 00:00:00 +0000
317+++ plugin/logging_query/tests/r/thresholds.result 2012-07-10 18:31:49 +0000
318@@ -0,0 +1,54 @@
319+SET GLOBAL logging_query_filename="DRIZZLETEST_VARDIR/logging_query.log";
320+SET GLOBAL logging_query_pcre=".+";
321+SET GLOBAL logging_query_enable=true;
322+SHOW VARIABLES LIKE 'logging_query_threshold%';
323+Variable_name Value
324+logging_query_threshold_big_examined 0
325+logging_query_threshold_big_resultset 0
326+logging_query_threshold_slow 0
327+SET GLOBAL logging_query_threshold_slow=500000;
328+SELECT @@logging_query_threshold_slow;
329+@@logging_query_threshold_slow
330+500000
331+
332+SELECT SLEEP(0.4);
333+SLEEP(0.4)
334+0
335+1
336+SELECT SLEEP(0.5);
337+SLEEP(0.5)
338+0
339+2
340+SET GLOBAL logging_query_threshold_slow=0;
341+SELECT SLEEP(1);
342+SLEEP(1)
343+0
344+4
345+
346+SHOW VARIABLES WHERE Variable_Name NOT LIKE "%logging_query_filename%" AND Variable_Name LIKE "%logging_query%";
347+Variable_name Value
348+logging_query_enable ON
349+logging_query_pcre .+
350+logging_query_threshold_big_examined 0
351+logging_query_threshold_big_resultset 0
352+logging_query_threshold_slow 0
353+2
354+SET GLOBAL logging_query_threshold_big_resultset=2;
355+SELECT "This should not be logged";
356+This should not be logged
357+This should not be logged
358+2
359+
360+SHOW VARIABLES WHERE Variable_Name NOT LIKE "%logging_query_filename%" AND Variable_Name LIKE "%logging_query%";
361+Variable_name Value
362+logging_query_enable ON
363+logging_query_pcre .+
364+logging_query_threshold_big_examined 0
365+logging_query_threshold_big_resultset 2
366+logging_query_threshold_slow 0
367+2
368+SET GLOBAL logging_query_threshold_big_examined=2;
369+SELECT "This should not be logged";
370+This should not be logged
371+This should not be logged
372+2
373
374=== added directory 'plugin/logging_query/tests/t'
375=== added file 'plugin/logging_query/tests/t/file.test'
376--- plugin/logging_query/tests/t/file.test 1970-01-01 00:00:00 +0000
377+++ plugin/logging_query/tests/t/file.test 2012-07-10 18:31:49 +0000
378@@ -0,0 +1,81 @@
379+
380+# ###########################################################################
381+# This tests the dynamic behaviour of logging_query plugin
382+# ###########################################################################
383+
384+# Logging_query plugin is loaded into the system. This checks if the file which we passed through the command line is opened or not.
385+--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
386+--exec if [ -f $DRIZZLETEST_VARDIR/logging_query.log ]; then echo "Log file exists"; else echo "Log file does not exist"; fi
387+# Clear log file.
388+--exec echo "" > $DRIZZLETEST_VARDIR/logging_query.log
389+# Double-check that log file is clear.
390+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
391+
392+# Since logging_query_enable is OFF by default, this should not be logged into the log file.
393+SHOW VARIABLES WHERE Variable_Name NOT LIKE "%logging_query_filename%" AND Variable_Name LIKE "%logging_query%";
394+
395+#This should not print anything
396+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
397+
398+#Enabling logging_query plugin
399+SET GLOBAL logging_query_enable=true;
400+
401+#Now as logging_query_enable is set to true, this should be logged.
402+SELECT 1;
403+
404+#This should print the content of log file as SET GLOBAL query and SELECT query
405+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
406+
407+#Setting logging_query_pcre as "SHOW.+". Only queries starting with 'SHOW' will be logged from now.
408+SET GLOBAL logging_query_pcre="SHOW.+";
409+
410+#This should not be logged
411+SELECT @@logging_query_enable;
412+
413+#This should print the content of log file updated with
414+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
415+
416+#This should be logged
417+SHOW VARIABLES WHERE Variable_Name NOT LIKE "%logging_query_filename%" AND Variable_Name LIKE "%logging_query%";
418+
419+#This should print the content of log file updated with SHOW query as it matched the regex.
420+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
421+
422+#Now changing the query log filename
423+--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
424+eval SET GLOBAL logging_query_filename="$DRIZZLETEST_VARDIR/logging_query1.log";
425+--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
426+#--exec if [ -f $DRIZZLETEST_VARDIR/logging_query1.log ]; then echo "New log file exists"; else echo "New log file does not exist"; fi
427+
428+# Clear log file.
429+--exec echo "" > $DRIZZLETEST_VARDIR/logging_query1.log
430+
431+# Double-check that log file is clear.
432+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query1.log
433+
434+#This should not be logged. Neither into new log file. Nor into new log file.
435+SELECT @@logging_query_enable;
436+
437+#Checking the content of both the files.
438+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
439+
440+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query1.log
441+
442+#This should be logged into new log file
443+SHOW VARIABLES WHERE Variable_Name NOT LIKE "%logging_query_filename%" AND Variable_Name LIKE "%logging_query%";
444+
445+#Checking the contents of boh the log files.
446+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
447+
448+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query1.log
449+
450+#Changing log file to null string. This should throw error.
451+--error ER_WRONG_ARGUMENTS
452+eval SET GLOBAL logging_query_filename="";
453+
454+--exec rm $DRIZZLETEST_VARDIR/logging_query*.log
455+
456+# ###########################################################################
457+# Done.
458+# ###########################################################################
459+
460
461=== added file 'plugin/logging_query/tests/t/master.opt'
462--- plugin/logging_query/tests/t/master.opt 1970-01-01 00:00:00 +0000
463+++ plugin/logging_query/tests/t/master.opt 2012-07-10 18:31:49 +0000
464@@ -0,0 +1,1 @@
465+--plugin-add=logging_query --logging-query.filename=$DRIZZLETEST_VARDIR/logging_query.log
466
467=== added file 'plugin/logging_query/tests/t/thresholds.test'
468--- plugin/logging_query/tests/t/thresholds.test 1970-01-01 00:00:00 +0000
469+++ plugin/logging_query/tests/t/thresholds.test 2012-07-10 18:31:49 +0000
470@@ -0,0 +1,87 @@
471+
472+# ###########################################################################
473+# This tests the various logging_query_threshold_ variables.
474+# ###########################################################################
475+
476+# First make sure the logging_query plugin is enabled.
477+--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
478+eval SET GLOBAL logging_query_filename="$DRIZZLETEST_VARDIR/logging_query.log";
479+eval SET GLOBAL logging_query_pcre=".+";
480+--replace_result $DRIZZLETEST_VARDIR DRIZZLETEST_VARDIR
481+SET GLOBAL logging_query_enable=true;
482+
483+# Make sure we have all our threshold variables and that they're all
484+# off (zero) by default.
485+SHOW VARIABLES LIKE 'logging_query_threshold%';
486+
487+# ###########################################################################
488+# logging_query_threshold_slow
489+# ###########################################################################
490+
491+# Set a 0.5s execution time threshold.
492+SET GLOBAL logging_query_threshold_slow=500000;
493+SELECT @@logging_query_threshold_slow;
494+
495+# Clear log file.
496+--exec echo "" > $DRIZZLETEST_VARDIR/logging_query.log
497+# Double-check that log file is clear.
498+--cat_file $DRIZZLETEST_VARDIR/logging_query.log
499+
500+# This query should *not* log since it's below the threshold.
501+SELECT SLEEP(0.4);
502+# This should not print anything.
503+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
504+
505+# This query should log since it's just a few microseconds past the threshold.
506+SELECT SLEEP(0.5);
507+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
508+
509+# Set query_log_threshold_execution_time back to zero.
510+SET GLOBAL logging_query_threshold_slow=0;
511+#This should be logged
512+SELECT SLEEP(1);
513+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
514+
515+# Clear log file.
516+--exec echo "" > $DRIZZLETEST_VARDIR/logging_query.log
517+# Double-check that log file is clear.
518+--cat_file $DRIZZLETEST_VARDIR/logging_query.log
519+
520+# ###########################################################################
521+# logging_query_threshold_big_resultset
522+# ###########################################################################
523+# This should be logged
524+SHOW VARIABLES WHERE Variable_Name NOT LIKE "%logging_query_filename%" AND Variable_Name LIKE "%logging_query%";
525+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
526+SET GLOBAL logging_query_threshold_big_resultset=2;
527+
528+#This should not be logged
529+SELECT "This should not be logged";
530+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
531+
532+# Clear log file.
533+--exec echo "" > $DRIZZLETEST_VARDIR/logging_query.log
534+# Double-check that log file is clear.
535+--cat_file $DRIZZLETEST_VARDIR/logging_query.log
536+
537+# ###########################################################################
538+# logging_query_threshold_big_examined
539+# ###########################################################################
540+# This should be logged
541+SHOW VARIABLES WHERE Variable_Name NOT LIKE "%logging_query_filename%" AND Variable_Name LIKE "%logging_query%";
542+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
543+
544+#Changing threshold_big_examined to 2, so that queries which examine less that 2 rows will not be logged
545+SET GLOBAL logging_query_threshold_big_examined=2;
546+#This should not be logged
547+SELECT "This should not be logged";
548+--exec $TOP_SRCDIR/plugin/logging_query/tests/parse-query-log.sh $DRIZZLETEST_VARDIR/logging_query.log
549+
550+# ############################################################################
551+# Clean up.
552+# ############################################################################
553+--exec rm $DRIZZLETEST_VARDIR/logging_query*.log
554+
555+# ###########################################################################
556+# Done.
557+# ###########################################################################

Subscribers

People subscribed via source and target branches

to all changes: