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