log_magic 0.0.2 → 0.0.3

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
2
  SHA1:
3
- metadata.gz: 9954218d1b500263e589e5db673d289a871ef149
4
- data.tar.gz: 1befbd958b7416c9dcfce6c7406900eebd62cd40
3
+ metadata.gz: 2995ed8296855e2b64a848d1c6be572f21b4c77d
4
+ data.tar.gz: bb267b3e7f42148109699f6a17ab9eb11e611823
5
5
  SHA512:
6
- metadata.gz: 61daa1cfd8b646a67ce3aa9d42e841b52b664689dfa1f9bc466367109e9e69b7e1e059dd1b781682c58b89e6f70f31f36e76d3eab41250422b0308698853b10e
7
- data.tar.gz: a9ca50d9b56b0cd28280938174de0195e4abf45bed0fda07578785745a9fa7bd8e977f1c43207ca59382b5925ff0c5e85173ac4f0de5c33b8f360c8ab9a20ddc
6
+ metadata.gz: ab06de5813d616854b69fedc6ffc98c0b138903fb6dfa0b9570ef98c914d2470eb40cc26973e91a56a9ea152f99ab1e532d0adfc8674802c18b1a78b022082a8
7
+ data.tar.gz: c13f6d63f49e2b393cfa82ed0e08c1772dfc792042cfbf9cab8350dec2f9fc13c330b4710944dc20b3d47a988d57f2d4d03be2e5b2130d3a1b6f81f1c112fd78
data/bin/rebuild CHANGED
@@ -1,2 +1,2 @@
1
1
  gem build log_magic.gemspec
2
- gem install log_magic-0.0.1.gem
2
+ gem install log_magic-0.0.3.gem
@@ -0,0 +1,4 @@
1
+ %h2
2
+ This query contains a
3
+ %a{href: 'https://www.elastic.co/guide/en/elasticsearch/guide/current/_boosting_query_clauses.html'}
4
+ Boost Query Clause
@@ -0,0 +1,4 @@
1
+ %h2
2
+ This query contains a
3
+ %a{href: 'https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-dis-max-query.html'}
4
+ Dis Max Query
@@ -0,0 +1,4 @@
1
+ %h2
2
+ This query contains a
3
+ %a{href: 'https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-match-query.html'}
4
+ Match query
@@ -1,4 +1,5 @@
1
- #h2 Query
1
+ - explainer_sections.each do |explainer_section|
2
+ = explainer_section.explanation
2
3
 
3
4
  %p
4
5
  = pretty_print_json(query_json)
@@ -0,0 +1,19 @@
1
+ class LogMagic::SearchkickExplainer::BoostExplainerSection
2
+ include ::LogMagic::TemplatingUtils
3
+
4
+ def initialize(query_json)
5
+ @query_json = query_json
6
+ end
7
+
8
+ def matches?
9
+ @query_json =~ /[^\w]boost[^\w]/
10
+ end
11
+
12
+ def explanation
13
+ rendered_template
14
+ end
15
+
16
+ def template_name
17
+ 'boost.haml'
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ class LogMagic::SearchkickExplainer::DisMaxExplainerSection
2
+ include ::LogMagic::TemplatingUtils
3
+
4
+ def initialize(query_json)
5
+ @query_json = query_json
6
+ end
7
+
8
+ def matches?
9
+ @query_json =~ /[^\w]dis_max[^\w]/
10
+ end
11
+
12
+ def explanation
13
+ rendered_template
14
+ end
15
+
16
+ def template_name
17
+ 'dis_max.haml'
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ class LogMagic::SearchkickExplainer::MatchExplainerSection
2
+ include ::LogMagic::TemplatingUtils
3
+
4
+ def initialize(query_json)
5
+ @query_json = query_json
6
+ end
7
+
8
+ def matches?
9
+ @query_json =~ /[^\w]match[^\w]/
10
+ end
11
+
12
+ def explanation
13
+ rendered_template
14
+ end
15
+
16
+ def template_name
17
+ 'match.haml'
18
+ end
19
+ end
@@ -4,6 +4,7 @@ require 'haml'
4
4
 
5
5
  class LogMagic::SearchkickExplainer
6
6
  include ::LogMagic::JSONUtils
7
+ include ::LogMagic::TemplatingUtils
7
8
 
8
9
  attr_accessor :database_name
9
10
 
@@ -15,6 +16,22 @@ class LogMagic::SearchkickExplainer
15
16
  @persistance_layer.retrieve_value(@uuid)
16
17
  end
17
18
 
19
+ def explainer_section_classes
20
+ [
21
+ DisMaxExplainerSection,
22
+ BoostExplainerSection,
23
+ MatchExplainerSection
24
+ ]
25
+ end
26
+
27
+ def explainer_sections
28
+ explainer_section_classes.map do |explainer_section_class|
29
+ explainer_section_class.new(query_json)
30
+ end.select do |explainer_section|
31
+ explainer_section.matches?
32
+ end
33
+ end
34
+
18
35
  def start
19
36
  app = Proc.new do |env|
20
37
  @uuid = env['PATH_INFO'][1..-1]
@@ -24,17 +41,10 @@ class LogMagic::SearchkickExplainer
24
41
  end
25
42
 
26
43
  Rack::Handler::WEBrick.run app, Port: 7467,
27
- Logger: WEBrick::Log::new('/dev/null')
28
- end
29
-
30
- def rendered_template
31
- engine = Haml::Engine.new(File.read(template_path))
32
- engine.render(self)
44
+ Logger: WEBrick::Log::new('/tmp/log_magic.log')
33
45
  end
34
46
 
35
- def template_path
36
- File.expand_path(
37
- File.join(__FILE__, '..', '..', 'explainer_templates', 'searchkick.haml')
38
- )
47
+ def template_name
48
+ 'searchkick.haml'
39
49
  end
40
50
  end
@@ -8,7 +8,7 @@ class LogMagic::PersistanceLayer
8
8
  end
9
9
 
10
10
  def add_value(value)
11
- uuid = SecureRandom.uuid
11
+ uuid = ::SecureRandom.uuid
12
12
 
13
13
  @redis.set(uuid, value)
14
14
 
@@ -8,4 +8,8 @@ module LogMagic::JSONUtils
8
8
  def parse_json(json)
9
9
  JSON.parse(json)
10
10
  end
11
+
12
+ def query_hash
13
+ JSON.parse(query_json)
14
+ end
11
15
  end
@@ -0,0 +1,12 @@
1
+ module LogMagic::TemplatingUtils
2
+ def rendered_template
3
+ engine = Haml::Engine.new(File.read(template_path))
4
+ engine.render(self)
5
+ end
6
+
7
+ def template_path
8
+ File.expand_path(
9
+ File.join(__FILE__, '..', '..', 'explainer_templates', template_name)
10
+ )
11
+ end
12
+ end
data/lib/log_magic.rb CHANGED
@@ -48,9 +48,12 @@ end
48
48
 
49
49
 
50
50
  require 'log_magic/utils/json_utils'
51
+ require 'log_magic/utils/templating_utils'
51
52
  require 'log_magic/log_listener'
52
53
  require 'log_magic/refiners/searchkick_refiner'
53
54
  require 'log_magic/printers/searchkick_printer'
54
-
55
55
  require 'log_magic/explainers/searchkick_explainer'
56
+ require 'log_magic/explainers/explainer_sections/dis_max_explainer'
57
+ require 'log_magic/explainers/explainer_sections/match_explainer'
58
+ require 'log_magic/explainers/explainer_sections/boost_explainer'
56
59
  require 'log_magic/persistance_layer'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_magic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Manuel Korfmann
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: minitest
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: "\n By analysing your development.log,\n log_magic gives you insights
84
98
  about your services.\n "
85
99
  email: manu@korfmann.info
@@ -91,14 +105,21 @@ files:
91
105
  - bin/log_magic
92
106
  - bin/rebuild
93
107
  - lib/log_magic.rb
108
+ - lib/log_magic/explainer_templates/boost.haml
109
+ - lib/log_magic/explainer_templates/dis_max.haml
110
+ - lib/log_magic/explainer_templates/match.haml
94
111
  - lib/log_magic/explainer_templates/searchkick.haml
112
+ - lib/log_magic/explainers/explainer_sections/boost_explainer.rb
113
+ - lib/log_magic/explainers/explainer_sections/dis_max_explainer.rb
114
+ - lib/log_magic/explainers/explainer_sections/match_explainer.rb
95
115
  - lib/log_magic/explainers/searchkick_explainer.rb
96
116
  - lib/log_magic/log_listener.rb
97
117
  - lib/log_magic/persistance_layer.rb
98
118
  - lib/log_magic/printers/searchkick_printer.rb
99
119
  - lib/log_magic/refiners/searchkick_refiner.rb
100
120
  - lib/log_magic/utils/json_utils.rb
101
- homepage: http://rubygems.org/gems/log_magick
121
+ - lib/log_magic/utils/templating_utils.rb
122
+ homepage: https://github.com/ManuelArno/log_magic
102
123
  licenses:
103
124
  - MIT
104
125
  metadata: {}