af_elastic 1.1.1 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/af_elastic.rb +23 -24
- data/lib/af_elastic/version.rb +1 -1
- data/lib/generators/templates/af_elastic_initializer.rb +2 -4
- metadata +3 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e40b877a2ebefa25b9cd6ed36c3e52602c559dee
|
4
|
+
data.tar.gz: 3d6bc2d863cc8d684ed89ba2dadeaf99072c8173
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 160aef4827c499c02965167cc72c23d9c06df9a100fc7d0e9e294ea2b0790ce84a07713a302ed1ff9bbb3aabc684fa196880e7b9a690cb0efc5609acb38a5b13
|
7
|
+
data.tar.gz: 22ff24a730e8a237d1949e01a0830f57617395f75e51e392f09b35f473c82ab2ac631855a65d847e1f4403ea9a1c3584081df639dccec96a8be589cfa1ae3c69
|
data/lib/af_elastic.rb
CHANGED
@@ -1,5 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require '
|
1
|
+
require 'af_elastic/version'
|
2
|
+
require 'set'
|
3
|
+
require 'uri'
|
4
|
+
require 'net/http'
|
5
|
+
require 'net/https'
|
6
|
+
require 'json'
|
7
|
+
require 'timeout'
|
3
8
|
|
4
9
|
module AfElastic
|
5
10
|
|
@@ -14,13 +19,13 @@ module AfElastic
|
|
14
19
|
end
|
15
20
|
|
16
21
|
class Configuration
|
17
|
-
|
22
|
+
attr_accessor :flask
|
18
23
|
attr_accessor :index
|
19
24
|
attr_accessor :capacity
|
20
25
|
|
21
26
|
def initialize
|
22
|
-
|
23
|
-
|
27
|
+
@flask = 'http://54.69.74.245/myapi'
|
28
|
+
@index = 'gem-test'
|
24
29
|
@capacity = 1000
|
25
30
|
end
|
26
31
|
end
|
@@ -57,24 +62,11 @@ module AfElastic
|
|
57
62
|
def add_event(type, data={})
|
58
63
|
begin
|
59
64
|
@types ||= Set.new
|
60
|
-
|
61
|
-
# check mapping through network
|
62
|
-
unless AfElastic.configuration.es.indices.exists_type? index: AfElastic.configuration.index, type: type
|
63
|
-
dynamic = [{:simple_def=>{:match=>"*",:match_mapping_type=> "string",:mapping=> {:type=> "string",:index=> "not_analyzed"}}}]
|
64
|
-
map = {}
|
65
|
-
map[type] = {properties:{timestamp:{type:"date"}},dynamic_templates:dynamic}
|
66
|
-
unless AfElastic.configuration.es.indices.exists? index: AfElastic.configuration.index
|
67
|
-
AfElastic.configuration.es.indices.create index: AfElastic.configuration.index
|
68
|
-
end
|
69
|
-
AfElastic.configuration.es.indices.put_mapping index: AfElastic.configuration.index, type: type, body: map
|
70
|
-
end
|
71
|
-
@types.add type
|
72
|
-
end
|
73
|
-
|
65
|
+
@types << type
|
74
66
|
@events ||= []
|
75
67
|
# add timestamp
|
76
68
|
data['timestamp'] = Time.now.to_i
|
77
|
-
@events << {
|
69
|
+
@events << {_index: AfElastic.configuration.index, _type: type, _source: data}
|
78
70
|
rescue Exception => e
|
79
71
|
puts e
|
80
72
|
Rails.logger.error("AfElastic::EventReporter::add_event: something wrong with elasticsearch")
|
@@ -90,14 +82,21 @@ module AfElastic
|
|
90
82
|
events_to_report = AfElastic::EventStore.events || []
|
91
83
|
return if events_to_report.length < AfElastic.configuration.capacity
|
92
84
|
AfElastic::EventStore.events = []
|
93
|
-
# puts "about to bulk"
|
94
85
|
|
95
86
|
th = Thread.new do
|
96
87
|
begin
|
97
|
-
|
98
|
-
|
88
|
+
Timeout::timeout(3) {
|
89
|
+
uri = URI.parse(AfElastic.configuration.flask)
|
90
|
+
params = {credential: "kqjD93ZJoSkAVNW0pjTqrVNubLCLK3pP",
|
91
|
+
types: AfElastic::EventStore.types.to_a,
|
92
|
+
index: AfElastic.configuration.index,
|
93
|
+
data: events_to_report}
|
94
|
+
header = {"Content-Type" => "application/json"}
|
95
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
96
|
+
response = http.post(uri.path, params.to_json, header)
|
97
|
+
}
|
99
98
|
rescue Exception => e
|
100
|
-
|
99
|
+
puts e
|
101
100
|
Rails.logger.error("AfElastic::EventReporter::report_events: error doing bulk inserting")
|
102
101
|
end
|
103
102
|
end
|
data/lib/af_elastic/version.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
require 'elasticsearch'
|
2
|
-
|
3
1
|
AfElastic.configure do |config|
|
4
2
|
# Set the elastic search client to receive data
|
5
|
-
# config.
|
3
|
+
# config.flask = 'http://54.69.74.245/myapi'
|
6
4
|
|
7
5
|
# Set the database name to store the data
|
8
6
|
# config.index = 'gem-test'
|
9
7
|
|
10
8
|
# Set the capacity of events to store before pushing to elastic search
|
11
9
|
# config.capacity = 1000
|
12
|
-
end
|
10
|
+
end
|
metadata
CHANGED
@@ -1,29 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: af_elastic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Appfolio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-08-
|
12
|
-
dependencies:
|
13
|
-
- !ruby/object:Gem::Dependency
|
14
|
-
name: elasticsearch
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
-
requirements:
|
17
|
-
- - "~>"
|
18
|
-
- !ruby/object:Gem::Version
|
19
|
-
version: '1.0'
|
20
|
-
type: :runtime
|
21
|
-
prerelease: false
|
22
|
-
version_requirements: !ruby/object:Gem::Requirement
|
23
|
-
requirements:
|
24
|
-
- - "~>"
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.0'
|
11
|
+
date: 2015-08-31 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
27
13
|
description:
|
28
14
|
email:
|
29
15
|
executables: []
|