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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8b769c2f7953a5708eb342ce3956df980b6de344
4
- data.tar.gz: e1bfae5ba4e3b1c02aa18c31d57df702b2ab507d
3
+ metadata.gz: e40b877a2ebefa25b9cd6ed36c3e52602c559dee
4
+ data.tar.gz: 3d6bc2d863cc8d684ed89ba2dadeaf99072c8173
5
5
  SHA512:
6
- metadata.gz: 03f7a559a8b8eed3645838c7ace73f4a8c654190bf47523253f5941fe5ab6837e91127706779118a8d36e6e9ec56d3c1fb494fb982ada3e0d4ee86e1ee0154e4
7
- data.tar.gz: 0255295e1a48a42e81c9e69fd8c5e3d0b96d6bdc2285fa5d299126873b7bf105902d9f75f63c23f6448b2858e64e2103657b54b1eb944da075693c5a9c1d04c6
6
+ metadata.gz: 160aef4827c499c02965167cc72c23d9c06df9a100fc7d0e9e294ea2b0790ce84a07713a302ed1ff9bbb3aabc684fa196880e7b9a690cb0efc5609acb38a5b13
7
+ data.tar.gz: 22ff24a730e8a237d1949e01a0830f57617395f75e51e392f09b35f473c82ab2ac631855a65d847e1f4403ea9a1c3584081df639dccec96a8be589cfa1ae3c69
data/lib/af_elastic.rb CHANGED
@@ -1,5 +1,10 @@
1
- require "af_elastic/version"
2
- require 'elasticsearch'
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
- attr_accessor :es
22
+ attr_accessor :flask
18
23
  attr_accessor :index
19
24
  attr_accessor :capacity
20
25
 
21
26
  def initialize
22
- @es = Elasticsearch::Client.new
23
- @index = 'gem-test'
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
- unless @types.include? type
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 << {index: {_index: AfElastic.configuration.index, _type: type, data: data}}
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
- AfElastic.configuration.es.bulk body: events_to_report
98
- # puts "bulk suceeded"
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
- # puts "error bulk"
99
+ puts e
101
100
  Rails.logger.error("AfElastic::EventReporter::report_events: error doing bulk inserting")
102
101
  end
103
102
  end
@@ -1,3 +1,3 @@
1
1
  module AfElastic
2
- VERSION = "1.1.1"
2
+ VERSION = "2.0.0"
3
3
  end
@@ -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.es = Elasticsearch::Client.new host: '54.69.240.186'
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: 1.1.1
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-14 00:00:00.000000000 Z
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: []