fluent-plugin-groonga-query-log 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 74fcfe61f76412fb02a18b924ecf9538f6792d920caa88fda7b22f7bd1d7216c
4
- data.tar.gz: b81d0f452cb132cd280b79ec67b9bbea86a5531a5b47cb584dda49423ca3cdc7
2
+ SHA1:
3
+ metadata.gz: 9e58ddf4db5a50f79ccd3a3eab2019fddfcc8f05
4
+ data.tar.gz: 4a42331b5306b1c2f716f294cf26bf2255fe3658
5
5
  SHA512:
6
- metadata.gz: 5ecc7257af50cd3868ab7f3327bf9e9ad838357aa6bef2c1d3d13c7fbbe3cededa54dde3d55fdb181a5a11473b3b0adde010ac643ae73700913fc26a53c5abf1
7
- data.tar.gz: d5054e6b5967f2f113f2bdb582c3759cfc5a099d9ff00adef9ce9bd8b3174ed6bc1c91262a409c7b079e5a8832441389cb1703acfb7068595caa7d98d35ba8b2
6
+ metadata.gz: 854b11444303e84033d6c92bb20efd6c37966166d5229ef46f000a63ae077af19d9292ee20adfa66cd728485db540e56a65d36cbe7caaa32b78ffb0520ea8a00
7
+ data.tar.gz: fd1da24e2e1ca1678f9ca9a8e755a3a687634c62e5f7894f0d9b5b5e2397547d5200158b3cfd242da0ab13c8dbd5a2bc1671789344bf165734692da0783cbec0
@@ -1,5 +1,13 @@
1
1
  # News
2
2
 
3
+ ## 1.0.2: 2019-02-08
4
+
5
+ ### Improvements
6
+
7
+ * Added a new parameter `timezone`.
8
+
9
+ * Added a new parameter `time_format`.
10
+
3
11
  ## 1.0.1: 2019-01-09
4
12
 
5
13
  ### Improvements
@@ -17,7 +17,7 @@
17
17
 
18
18
  Gem::Specification.new do |spec|
19
19
  spec.name = "fluent-plugin-groonga-query-log"
20
- spec.version = "1.0.1"
20
+ spec.version = "1.0.2"
21
21
  spec.authors = ["Kouhei Sutou"]
22
22
  spec.email = ["kou@clear-code.com"]
23
23
  spec.summary = "Fluentd plugin to parse Groonga's query log."
@@ -26,6 +26,10 @@ module Fluent
26
26
  config_param :slow_response_threshold, :float, :default => 0.2
27
27
  config_param :flatten, :bool, :default => false
28
28
  config_param :flatten_separator, :string, :default => nil
29
+ config_param :timezone, :enum,
30
+ :list => [:utc, :localtime],
31
+ :default => :utc
32
+ config_param :time_format, :string, :default => "iso8601"
29
33
 
30
34
  def configure(conf)
31
35
  super
@@ -33,6 +37,8 @@ module Fluent
33
37
  options = {
34
38
  :slow_operation_threshold => @slow_operation_threshold,
35
39
  :slow_response_threshold => @slow_response_threshold,
40
+ :timezone => @timezone,
41
+ :time_format => @time_format,
36
42
  }
37
43
  @parser = GroongaQueryLog::Parser.new(options)
38
44
  end
@@ -62,7 +68,24 @@ module Fluent
62
68
  end
63
69
 
64
70
  def format_time(time)
65
- time.utc.iso8601(6)
71
+ time.utc if @timezone == :utc
72
+ time.strftime(resolve_time_format)
73
+ end
74
+
75
+ def resolve_time_format
76
+ case @time_format
77
+ when "iso8601"
78
+ format = "%Y-%m-%dT%H:%M:%S.%6N"
79
+ if @timezone == :utc
80
+ format << "Z"
81
+ else
82
+ format << "%:z"
83
+ end
84
+ when "sql"
85
+ format = "%Y-%m-%d %H:%M:%S.%6N"
86
+ else
87
+ @time_format
88
+ end
66
89
  end
67
90
 
68
91
  def flatten_record!(record)
@@ -40,6 +40,8 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
40
40
  :slow_response_threshold => 0.2,
41
41
  :flatten => false,
42
42
  :flatten_separator => nil,
43
+ :timezone => :utc,
44
+ :time_format => "iso8601",
43
45
  },
44
46
  {
45
47
  :raw_data_column_name => filter.raw_data_column_name,
@@ -47,6 +49,8 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
47
49
  :slow_response_threshold => filter.slow_response_threshold,
48
50
  :flatten => filter.flatten,
49
51
  :flatten_separator => filter.flatten_separator,
52
+ :timezone => filter.timezone,
53
+ :time_format => filter.time_format,
50
54
  })
51
55
  end
52
56
 
@@ -79,6 +83,18 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
79
83
  filter = driver.instance
80
84
  assert_equal("_", filter.flatten_separator)
81
85
  end
86
+
87
+ test "timezone" do
88
+ driver = create_driver("timezone localtime")
89
+ filter = driver.instance
90
+ assert_equal(:localtime, filter.timezone)
91
+ end
92
+
93
+ test "time_format" do
94
+ driver = create_driver("time_format %Y-%m-%d %H:%M:%S.%6N")
95
+ filter = driver.instance
96
+ assert_equal("%Y-%m-%d %H:%M:%S.%6N", filter.time_format)
97
+ end
82
98
  end
83
99
 
84
100
  sub_test_case "filter_stream" do
@@ -323,5 +339,255 @@ class GroongaQueryLogFilterTest < Test::Unit::TestCase
323
339
  event_stream = emit("slow_response_threshold 0.01", messages)
324
340
  assert_equal([[@now, statistics]], event_stream.to_a)
325
341
  end
342
+
343
+ sub_test_case "timezone" do
344
+ test "localtime" do
345
+ messages = [
346
+ "2015-08-12 15:50:40.130990|0x7fb07d113da0|>/d/select?table=Entries&match_columns=name&query=xml",
347
+ "2015-08-12 15:50:40.296165|0x7fb07d113da0|:000000165177838 filter(10)",
348
+ "2015-08-12 15:50:40.296172|0x7fb07d113da0|:000000165184723 select(10)",
349
+ "2015-08-12 15:50:41.228129|0x7fb07d113da0|:000001097153433 output(10)",
350
+ "2015-08-12 15:50:41.228317|0x7fb07d113da0|<000001097334986 rc=0",
351
+ ]
352
+ statistic = {
353
+ "start_time" => "2015-08-12T15:50:40.130990+09:00",
354
+ "last_time" => "2015-08-12T15:50:41.228324+09:00",
355
+ "elapsed" => 1.0973349860000001,
356
+ "return_code" => 0,
357
+ "slow" => true,
358
+ "command" => {
359
+ "raw" => "/d/select?table=Entries&match_columns=name&query=xml",
360
+ "name" => "select",
361
+ "parameters" => [
362
+ {"key" => :table, "value" => "Entries"},
363
+ {"key" => :match_columns, "value" => "name"},
364
+ {"key" => :query, "value" => "xml"},
365
+ ],
366
+ },
367
+ "operations" => [
368
+ {
369
+ "context" => "query: xml",
370
+ "name" => "filter",
371
+ "relative_elapsed" => 0.165177838,
372
+ "slow" => true,
373
+ },
374
+ {
375
+ "context" => nil,
376
+ "name" => "select",
377
+ "relative_elapsed" => 6.884999999999999e-06,
378
+ "slow" => false,
379
+ },
380
+ {
381
+ "context" => nil,
382
+ "name" => "output",
383
+ "relative_elapsed" => 0.93196871,
384
+ "slow" => true,
385
+ },
386
+ ],
387
+ }
388
+ event_stream = emit("timezone localtime", messages)
389
+ assert_equal([[@now, statistic]], event_stream.to_a)
390
+ end
391
+ end
392
+
393
+ sub_test_case "time_format" do
394
+ test "sql" do
395
+ messages = [
396
+ "2015-08-12 15:50:40.130990|0x7fb07d113da0|>/d/select?table=Entries&match_columns=name&query=xml",
397
+ "2015-08-12 15:50:40.296165|0x7fb07d113da0|:000000165177838 filter(10)",
398
+ "2015-08-12 15:50:40.296172|0x7fb07d113da0|:000000165184723 select(10)",
399
+ "2015-08-12 15:50:41.228129|0x7fb07d113da0|:000001097153433 output(10)",
400
+ "2015-08-12 15:50:41.228317|0x7fb07d113da0|<000001097334986 rc=0",
401
+ ]
402
+ statistic = {
403
+ "start_time" => "2015-08-12 06:50:40.130990",
404
+ "last_time" => "2015-08-12 06:50:41.228324",
405
+ "elapsed" => 1.0973349860000001,
406
+ "return_code" => 0,
407
+ "slow" => true,
408
+ "command" => {
409
+ "raw" => "/d/select?table=Entries&match_columns=name&query=xml",
410
+ "name" => "select",
411
+ "parameters" => [
412
+ {"key" => :table, "value" => "Entries"},
413
+ {"key" => :match_columns, "value" => "name"},
414
+ {"key" => :query, "value" => "xml"},
415
+ ],
416
+ },
417
+ "operations" => [
418
+ {
419
+ "context" => "query: xml",
420
+ "name" => "filter",
421
+ "relative_elapsed" => 0.165177838,
422
+ "slow" => true,
423
+ },
424
+ {
425
+ "context" => nil,
426
+ "name" => "select",
427
+ "relative_elapsed" => 6.884999999999999e-06,
428
+ "slow" => false,
429
+ },
430
+ {
431
+ "context" => nil,
432
+ "name" => "output",
433
+ "relative_elapsed" => 0.93196871,
434
+ "slow" => true,
435
+ },
436
+ ],
437
+ }
438
+ event_stream = emit("time_format sql", messages)
439
+ assert_equal([[@now, statistic]], event_stream.to_a)
440
+ end
441
+
442
+ test "string" do
443
+ messages = [
444
+ "2015-08-12 15:50:40.130990|0x7fb07d113da0|>/d/select?table=Entries&match_columns=name&query=xml",
445
+ "2015-08-12 15:50:40.296165|0x7fb07d113da0|:000000165177838 filter(10)",
446
+ "2015-08-12 15:50:40.296172|0x7fb07d113da0|:000000165184723 select(10)",
447
+ "2015-08-12 15:50:41.228129|0x7fb07d113da0|:000001097153433 output(10)",
448
+ "2015-08-12 15:50:41.228317|0x7fb07d113da0|<000001097334986 rc=0",
449
+ ]
450
+ statistic = {
451
+ "start_time" => "2015-08-12 06:50:40.130990",
452
+ "last_time" => "2015-08-12 06:50:41.228324",
453
+ "elapsed" => 1.0973349860000001,
454
+ "return_code" => 0,
455
+ "slow" => true,
456
+ "command" => {
457
+ "raw" => "/d/select?table=Entries&match_columns=name&query=xml",
458
+ "name" => "select",
459
+ "parameters" => [
460
+ {"key" => :table, "value" => "Entries"},
461
+ {"key" => :match_columns, "value" => "name"},
462
+ {"key" => :query, "value" => "xml"},
463
+ ],
464
+ },
465
+ "operations" => [
466
+ {
467
+ "context" => "query: xml",
468
+ "name" => "filter",
469
+ "relative_elapsed" => 0.165177838,
470
+ "slow" => true,
471
+ },
472
+ {
473
+ "context" => nil,
474
+ "name" => "select",
475
+ "relative_elapsed" => 6.884999999999999e-06,
476
+ "slow" => false,
477
+ },
478
+ {
479
+ "context" => nil,
480
+ "name" => "output",
481
+ "relative_elapsed" => 0.93196871,
482
+ "slow" => true,
483
+ },
484
+ ],
485
+ }
486
+ event_stream = emit("time_format %Y-%m-%d %H:%M:%S.%6N", messages)
487
+ assert_equal([[@now, statistic]], event_stream.to_a)
488
+ end
489
+
490
+ test "sql and localtime" do
491
+ messages = [
492
+ "2015-08-12 15:50:40.130990|0x7fb07d113da0|>/d/select?table=Entries&match_columns=name&query=xml",
493
+ "2015-08-12 15:50:40.296165|0x7fb07d113da0|:000000165177838 filter(10)",
494
+ "2015-08-12 15:50:40.296172|0x7fb07d113da0|:000000165184723 select(10)",
495
+ "2015-08-12 15:50:41.228129|0x7fb07d113da0|:000001097153433 output(10)",
496
+ "2015-08-12 15:50:41.228317|0x7fb07d113da0|<000001097334986 rc=0",
497
+ ]
498
+ statistic = {
499
+ "start_time" => "2015-08-12 15:50:40.130990",
500
+ "last_time" => "2015-08-12 15:50:41.228324",
501
+ "elapsed" => 1.0973349860000001,
502
+ "return_code" => 0,
503
+ "slow" => true,
504
+ "command" => {
505
+ "raw" => "/d/select?table=Entries&match_columns=name&query=xml",
506
+ "name" => "select",
507
+ "parameters" => [
508
+ {"key" => :table, "value" => "Entries"},
509
+ {"key" => :match_columns, "value" => "name"},
510
+ {"key" => :query, "value" => "xml"},
511
+ ],
512
+ },
513
+ "operations" => [
514
+ {
515
+ "context" => "query: xml",
516
+ "name" => "filter",
517
+ "relative_elapsed" => 0.165177838,
518
+ "slow" => true,
519
+ },
520
+ {
521
+ "context" => nil,
522
+ "name" => "select",
523
+ "relative_elapsed" => 6.884999999999999e-06,
524
+ "slow" => false,
525
+ },
526
+ {
527
+ "context" => nil,
528
+ "name" => "output",
529
+ "relative_elapsed" => 0.93196871,
530
+ "slow" => true,
531
+ },
532
+ ],
533
+ }
534
+ event_stream = emit(<<-CONFIGURATION, messages)
535
+ timezone localtime
536
+ time_format sql
537
+ CONFIGURATION
538
+ assert_equal([[@now, statistic]], event_stream.to_a)
539
+ end
540
+
541
+ test "string and localtime" do
542
+ messages = [
543
+ "2015-08-12 15:50:40.130990|0x7fb07d113da0|>/d/select?table=Entries&match_columns=name&query=xml",
544
+ "2015-08-12 15:50:40.296165|0x7fb07d113da0|:000000165177838 filter(10)",
545
+ "2015-08-12 15:50:40.296172|0x7fb07d113da0|:000000165184723 select(10)",
546
+ "2015-08-12 15:50:41.228129|0x7fb07d113da0|:000001097153433 output(10)",
547
+ "2015-08-12 15:50:41.228317|0x7fb07d113da0|<000001097334986 rc=0",
548
+ ]
549
+ statistic = {
550
+ "start_time" => "2015-08-12 15:50:40.130990",
551
+ "last_time" => "2015-08-12 15:50:41.228324",
552
+ "elapsed" => 1.0973349860000001,
553
+ "return_code" => 0,
554
+ "slow" => true,
555
+ "command" => {
556
+ "raw" => "/d/select?table=Entries&match_columns=name&query=xml",
557
+ "name" => "select",
558
+ "parameters" => [
559
+ {"key" => :table, "value" => "Entries"},
560
+ {"key" => :match_columns, "value" => "name"},
561
+ {"key" => :query, "value" => "xml"},
562
+ ],
563
+ },
564
+ "operations" => [
565
+ {
566
+ "context" => "query: xml",
567
+ "name" => "filter",
568
+ "relative_elapsed" => 0.165177838,
569
+ "slow" => true,
570
+ },
571
+ {
572
+ "context" => nil,
573
+ "name" => "select",
574
+ "relative_elapsed" => 6.884999999999999e-06,
575
+ "slow" => false,
576
+ },
577
+ {
578
+ "context" => nil,
579
+ "name" => "output",
580
+ "relative_elapsed" => 0.93196871,
581
+ "slow" => true,
582
+ },
583
+ ],
584
+ }
585
+ event_stream = emit(<<-CONFIGURATION, messages)
586
+ timezone localtime
587
+ time_format %Y-%m-%d %H:%M:%S.%6N
588
+ CONFIGURATION
589
+ assert_equal([[@now, statistic]], event_stream.to_a)
590
+ end
591
+ end
326
592
  end
327
593
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-groonga-query-log
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kouhei Sutou
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-09 00:00:00.000000000 Z
11
+ date: 2019-02-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -132,7 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  requirements: []
135
- rubygems_version: 3.0.2
135
+ rubyforge_project:
136
+ rubygems_version: 2.5.2.1
136
137
  signing_key:
137
138
  specification_version: 4
138
139
  summary: Fluentd plugin to parse Groonga's query log.