Merge lp:~daniel-nichter/drizzle/query-log-ts into lp:~drizzle-trunk/drizzle/development

Proposed by Daniel Nichter
Status: Merged
Approved by: Mark Atwood
Approved revision: 2421
Merged at revision: 2422
Proposed branch: lp:~daniel-nichter/drizzle/query-log-ts
Merge into: lp:~drizzle-trunk/drizzle/development
Diff against target: 385 lines (+64/-42)
8 files modified
plugin/query_log/docs/index.rst (+42/-18)
plugin/query_log/file.cc (+2/-1)
plugin/query_log/tests/check-query-log-attribute.pl (+1/-4)
plugin/query_log/tests/r/check_query_log_attribute.result (+1/-1)
plugin/query_log/tests/r/file.result (+14/-14)
plugin/query_log/tests/r/thresholds.result (+2/-2)
plugin/query_log/tests/samples/sample-event.log (+1/-1)
plugin/query_log/tests/t/file.test (+1/-1)
To merge this branch: bzr merge lp:~daniel-nichter/drizzle/query-log-ts
Reviewer Review Type Date Requested Status
Drizzle Merge Team Pending
Review via email: mp+75924@code.launchpad.net

Description of the change

Just changes to query_log plugin, primarily: make first line of events "start_ts=VALUE" instead of a special bare "VALUE". This makes it possible to match/parse all attributes with one pattern because they are now all of the form ATTRIBUTE=VALUE. Documented meta-format of query log file.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'plugin/query_log/docs/index.rst'
2--- plugin/query_log/docs/index.rst 2011-09-03 22:25:16 +0000
3+++ plugin/query_log/docs/index.rst 2011-09-18 20:15:24 +0000
4@@ -116,7 +116,7 @@
5 * ``query_log_enabled``
6
7 :Scope: Global
8- :Dynamic: No
9+ :Dynamic: Yes
10 :Option:
11
12 If query logging is globally enabled or not.
13@@ -126,7 +126,7 @@
14 * ``query_log_file``
15
16 :Scope: Global
17- :Dynamic: No
18+ :Dynamic: Yes
19 :Option: :option:`--query-log.file`
20
21 Query log file.
22@@ -136,7 +136,7 @@
23 * ``query_log_file_enabled``
24
25 :Scope: Global
26- :Dynamic: No
27+ :Dynamic: Yes
28 :Option: :option:`--query-log.file-enabled`
29
30 If query logging to a file is enabled.
31@@ -146,7 +146,7 @@
32 * ``query_log_threshold_execution_time``
33
34 :Scope: Global
35- :Dynamic: No
36+ :Dynamic: Yes
37 :Option: :option:`--query-log.threshold-execution-time`
38
39 Threshold for logging slow queries.
40@@ -156,7 +156,7 @@
41 * ``query_log_threshold_lock_time``
42
43 :Scope: Global
44- :Dynamic: No
45+ :Dynamic: Yes
46 :Option: :option:`--query-log.threshold-lock-time`
47
48 Threshold for logging long locking queries.
49@@ -166,7 +166,7 @@
50 * ``query_log_threshold_rows_examined``
51
52 :Scope: Global
53- :Dynamic: No
54+ :Dynamic: Yes
55 :Option: :option:`--query-log.threshold-rows-examined`
56
57 Threshold for logging queries that examine too many rows.
58@@ -176,7 +176,7 @@
59 * ``query_log_threshold_rows_sent``
60
61 :Scope: Global
62- :Dynamic: No
63+ :Dynamic: Yes
64 :Option: :option:`--query-log.threshold-rows-sent`
65
66 Threshold for logging queries that return too many rows.
67@@ -186,7 +186,7 @@
68 * ``query_log_threshold_session_time``
69
70 :Scope: Global
71- :Dynamic: No
72+ :Dynamic: Yes
73 :Option: :option:`--query-log.threshold-session-time`
74
75 Threshold for logging queries that are active too long.
76@@ -196,7 +196,7 @@
77 * ``query_log_threshold_tmp_tables``
78
79 :Scope: Global
80- :Dynamic: No
81+ :Dynamic: Yes
82 :Option: :option:`--query-log.threshold-tmp-tables`
83
84 Threshold for logging queries that use too many temporary tables.
85@@ -206,7 +206,7 @@
86 * ``query_log_threshold_warnings``
87
88 :Scope: Global
89- :Dynamic: No
90+ :Dynamic: Yes
91 :Option: :option:`--query-log.threshold-warnings`
92
93 Threshold for logging queries that cause too many warnings.
94@@ -214,7 +214,7 @@
95 Examples
96 --------
97
98-Start Drizzle with the query plugin and log queries that take longer than 1 second to execute to the default log file:
99+Start Drizzle with the query plugin and log queries that take longer than 1 second to execute to the default query log file:
100
101 .. code-block:: none
102
103@@ -257,20 +257,20 @@
104 Log File
105 ^^^^^^^^
106
107-The log file destination is enabled when both ``query_log_enabled`` and ``query_log_file_enabled`` are true (``SHOW VARIABLES`` lists ``ON`` and ``OFF`` instead of ``TRUE`` and ``FASLE``). When ``query_log_file_enabled`` is true, the ``query_log_file`` is open. When ``query_log_file_enabled`` is set false, the log file is closed. This is helpful if you want to rotate the log file.
108+The query log file destination is enabled when both ``query_log_enabled`` and ``query_log_file_enabled`` are true (``SHOW VARIABLES`` lists ``ON`` and ``OFF`` instead of ``TRUE`` and ``FASLE``). When ``query_log_file_enabled`` is true, the ``query_log_file`` is open. When ``query_log_file_enabled`` is set false, the query log file is closed. This is helpful if you want to rotate the query log file.
109
110-The log file is a plain text, structured file that is readable by humans and easily parsable by tools. It looks like:
111+The query log file is a plain text, structured file that is readable by humans and easily parsable by tools. It looks like:
112
113 .. code-block:: none
114
115- # 2011-05-15T01:48:17.814985
116+ # start_ts=2011-05-15T01:48:17.814985
117 # session_id=1 query_id=6 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=1
118 # execution_time=0.000315 lock_time=0.000315 session_time=16.723020
119 # error=true
120 # schema=""
121 set query_log_file_enabled=true;
122 #
123- # 2011-05-15T01:48:21.526746
124+ # start_ts=2011-05-15T01:48:21.526746
125 # session_id=1 query_id=7 rows_examined=10 rows_sent=10 tmp_tables=0 warnings=0
126 # execution_time=0.000979 lock_time=0.000562 session_time=20.435445
127 # error=false
128@@ -280,7 +280,31 @@
129
130 Events are separated by a single ``#`` character. This record separator can be used by programs like :program:`awk` and :program:`perl` to easily separate events in a log.
131
132-The first line line of each event is a UTC/GMT timestamp with microsecond precision; the timezone cannot be changed. The second line has attributes with integer values. The third line has attributes with high-precision time values, always with six decimals places of precision. The fourth line has attributes with boolean values, either ``true`` or ``false``. The fifth line has attributes with string values, always double-quoted. Remaining lines are the query which can contain multiple lines, blank lines, et. The record separator marks the event of the event.
133+The first line of each event has UTC/GMT timestamps with microsecond precision; the timezone cannot be changed. The second line has attributes with integer values. The third line has attributes with high-precision time values, always with six decimals places of precision. The fourth line has attributes with boolean values, either ``true`` or ``false``. The fifth line has attributes with string values, always double-quoted. Remaining lines are the query which can contain multiple lines, blank lines, et. The record separator marks the event of the event.
134+
135+As the example above demonstrates, the meta-format for each event in the query log is::
136+
137+ # attribute=value
138+ query
139+ #
140+
141+Parsing a query log file should be easy since the format is static, consistent, and follows
142+these rules:
143+
144+ * Attribute-value pairs are on comment lines that begin with one ``#`` character followed
145+ by a space.
146+ * Comment lines have one or more attribute-value pairs.
147+ * Attribute-value pairs are separated by one space.
148+ * Attribute names are lowercase with only characters ``a`` to ``z`` and ``_`` (underscore).
149+ * Attribute names with suffix ``_ts`` have microsecond UTC/GMT timestamp values.
150+ * Attribute names with suffix ``_time`` have values with an amount of time in seconds with
151+ microsecond precision.
152+ * One or more comment line precedes the query.
153+ * A query is always printed; there are no "admin commands" or special queries.
154+ * Every query is terminated by one ``#`` character followed by a newline (``\n``),
155+ even the last query in the log file.
156+ * There are no blank lines between events.
157+ * Only events with this format are printed; there are no special or "fluff" lines.
158
159 Bugs and Limitations
160 --------------------
161@@ -316,7 +340,7 @@
162 Version
163 -------
164
165-This documentation applies to **query_log 0.1**.
166+This documentation applies to **query_log 1.0**.
167
168 To see which version of the plugin a Drizzle server is running, execute:
169
170@@ -327,6 +351,6 @@
171 Changelog
172 ---------
173
174-v0.1
175+v1.0
176 ^^^^
177 * First release.
178
179=== modified file 'plugin/query_log/file.cc'
180--- plugin/query_log/file.cc 2011-07-30 21:28:21 +0000
181+++ plugin/query_log/file.cc 2011-09-18 20:15:24 +0000
182@@ -37,7 +37,8 @@
183 {
184 if (_fh.is_open())
185 {
186- _fh << "# " << event->ts << "\n"
187+ _fh << "# start_ts=" << event->ts
188+ << "\n"
189 << "# session_id=" << event->session_id
190 << " query_id=" << event->query_id
191 << " rows_examined=" << event->rows_examined
192
193=== modified file 'plugin/query_log/tests/check-query-log-attribute.pl'
194--- plugin/query_log/tests/check-query-log-attribute.pl 2011-05-15 17:58:28 +0000
195+++ plugin/query_log/tests/check-query-log-attribute.pl 2011-09-18 20:15:24 +0000
196@@ -103,10 +103,7 @@
197 my $lineno = 1;
198 foreach my $line ( @event_lines ) {
199 next if $line =~ m/^$/;
200- if ( $lineno == 1 ) { # timestamp
201- push @props, 'ts', $line =~ m/^# (\S+)/;
202- }
203- elsif ( $lineno >= 2 && $lineno <= 4 ) { # ints, floats and bools
204+ if ( $lineno <= 4 ) { # ts, ints, floats and bools
205 push @props, $line =~ m/([a-z_]+)=(\S+)/g;
206 }
207 elsif ( $lineno == 5 ) { # strings
208
209=== modified file 'plugin/query_log/tests/r/check_query_log_attribute.result'
210--- plugin/query_log/tests/r/check_query_log_attribute.result 2011-05-15 17:58:28 +0000
211+++ plugin/query_log/tests/r/check_query_log_attribute.result 2011-09-18 20:15:24 +0000
212@@ -9,6 +9,6 @@
213 schema=test
214 session_id=1
215 session_time=1.234567
216+start_ts=1234-56-78T90:12:34.567890
217 tmp_tables=5
218-ts=1234-56-78T90:12:34.567890
219 warnings=6
220
221=== modified file 'plugin/query_log/tests/r/file.result'
222--- plugin/query_log/tests/r/file.result 2011-08-03 16:10:06 +0000
223+++ plugin/query_log/tests/r/file.result 2011-09-18 20:15:24 +0000
224@@ -21,14 +21,14 @@
225 SELECT @@query_log_enabled, @@query_log_file_enabled;
226 @@query_log_enabled @@query_log_file_enabled
227 1 1
228-# 0000-00-00T00:00:00.000000
229+# start_ts=0-00-00T00:00:00.000000
230 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
231 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
232 # error=false
233 # schema="test"
234 SET GLOBAL query_log_file_enabled=TRUE;
235 #
236-# 0000-00-00T00:00:00.000000
237+# start_ts=0-00-00T00:00:00.000000
238 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
239 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
240 # error=false
241@@ -42,14 +42,14 @@
242 SELECT 2;
243 2
244 2
245-# 0000-00-00T00:00:00.000000
246+# start_ts=0-00-00T00:00:00.000000
247 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
248 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
249 # error=false
250 # schema="test"
251 SET GLOBAL query_log_file_enabled=TRUE;
252 #
253-# 0000-00-00T00:00:00.000000
254+# start_ts=0-00-00T00:00:00.000000
255 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
256 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
257 # error=false
258@@ -71,14 +71,14 @@
259 this is the second log file
260 this is the second log file
261 Log file exists
262-# 0000-00-00T00:00:00.000000
263+# start_ts=0-00-00T00:00:00.000000
264 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
265 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
266 # error=false
267 # schema="test"
268 SET GLOBAL query_log_file_enabled=TRUE;
269 #
270-# 0000-00-00T00:00:00.000000
271+# start_ts=0-00-00T00:00:00.000000
272 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
273 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
274 # error=false
275@@ -93,49 +93,49 @@
276 SELECT 'this is the third log file';
277 this is the third log file
278 this is the third log file
279-# 0000-00-00T00:00:00.000000
280+# start_ts=0-00-00T00:00:00.000000
281 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
282 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
283 # error=false
284 # schema="third-log-file"
285 SET GLOBAL query_log_file="third-log-file";
286 #
287-# 0000-00-00T00:00:00.000000
288+# start_ts=0-00-00T00:00:00.000000
289 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
290 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
291 # error=false
292 # schema="third-log-file"
293 SELECT @@query_log_enabled, @@query_log_file_enabled, @@query_log_file;
294 #
295-# 0000-00-00T00:00:00.000000
296+# start_ts=0-00-00T00:00:00.000000
297 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
298 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
299 # error=false
300 # schema="third-log-file"
301 SELECT 'this is the third log file';
302 #
303-# 0000-00-00T00:00:00.000000
304+# start_ts=0-00-00T00:00:00.000000
305 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
306 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
307 # error=false
308 # schema="test"
309 SET GLOBAL query_log_file_enabled=TRUE;
310 #
311-# 0000-00-00T00:00:00.000000
312+# start_ts=0-00-00T00:00:00.000000
313 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
314 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
315 # error=false
316 # schema="test"
317 SELECT @@query_log_enabled, @@query_log_file_enabled;
318 #
319-# 0000-00-00T00:00:00.000000
320+# start_ts=0-00-00T00:00:00.000000
321 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
322 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
323 # error=false
324 # schema="test"
325 SET GLOBAL query_log_file_enabled=TRUE;
326 #
327-# 0000-00-00T00:00:00.000000
328+# start_ts=0-00-00T00:00:00.000000
329 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
330 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
331 # error=false
332@@ -144,7 +144,7 @@
333 #
334 SET GLOBAL query_log_file="DRIZZLETEST_VARDIR/query.log";
335 Checking attributes and values of query SELECT DATE(NOW());
336-ts value matches OK
337+start_ts value matches OK
338 Checking attributes and values of query SELECT DATE(NOW());
339 execution_time value matches OK
340 lock_time value matches OK
341
342=== modified file 'plugin/query_log/tests/r/thresholds.result'
343--- plugin/query_log/tests/r/thresholds.result 2011-08-03 16:10:06 +0000
344+++ plugin/query_log/tests/r/thresholds.result 2011-09-18 20:15:24 +0000
345@@ -26,7 +26,7 @@
346 Checking attributes and values of query SELECT SLEEP(0.5);
347 arg value equals SELECT SLEEP(0.5); OK
348
349-# 0000-00-00T00:00:00.000000
350+# start_ts=0-00-00T00:00:00.000000
351 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
352 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
353 # error=false
354@@ -45,7 +45,7 @@
355 Checking attributes and values of query SELECT 'one';
356 arg value equals SELECT 'one'; OK
357
358-# 0000-00-00T00:00:00.000000
359+# start_ts=0-00-00T00:00:00.000000
360 # session_id=0 query_id=0 rows_examined=0 rows_sent=0 tmp_tables=0 warnings=0
361 # execution_time=0.000000 lock_time=0.000000 session_time=0.000000
362 # error=false
363
364=== modified file 'plugin/query_log/tests/samples/sample-event.log'
365--- plugin/query_log/tests/samples/sample-event.log 2011-05-15 17:58:28 +0000
366+++ plugin/query_log/tests/samples/sample-event.log 2011-09-18 20:15:24 +0000
367@@ -1,4 +1,4 @@
368-# 1234-56-78T90:12:34.567890
369+# start_ts=1234-56-78T90:12:34.567890
370 # session_id=1 query_id=2 rows_examined=3 rows_sent=4 tmp_tables=5 warnings=6
371 # execution_time=7.890123 lock_time=4.567890 session_time=1.234567
372 # error=false
373
374=== modified file 'plugin/query_log/tests/t/file.test'
375--- plugin/query_log/tests/t/file.test 2011-08-03 16:10:06 +0000
376+++ plugin/query_log/tests/t/file.test 2011-09-18 20:15:24 +0000
377@@ -100,7 +100,7 @@
378 # YYYY-MM-DDTHH:MM:SS.uuuuuu. We just check that the start of the ts
379 # matches today's date.
380 let $today= `SELECT DATE(NOW())`;
381---exec $TOP_SRCDIR/plugin/query_log/tests/check-query-log-attribute.pl $DRIZZLETEST_VARDIR/query.log ts matches "^$today"
382+--exec $TOP_SRCDIR/plugin/query_log/tests/check-query-log-attribute.pl $DRIZZLETEST_VARDIR/query.log start_ts matches "^$today"
383
384 # The 3rd line of an event should be microsecond times like 1.123456
385 --exec $TOP_SRCDIR/plugin/query_log/tests/check-query-log-attribute.pl $DRIZZLETEST_VARDIR/query.log execution_time,lock_time,session_time matches '\d\.\d{6}','\d\.\d{6}','\d\.\d{6}'