exologging 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c32b4fe10fd3809052c96bb221871149b5715812a42c574a5dadeecc0ebe8b43
4
+ data.tar.gz: c25cfcfbd7860970733fc597a38ac1dccda5d1b69ee72d88d5c6e1674cadf638
5
+ SHA512:
6
+ metadata.gz: 66b6e3231ab131e42b752f5df79de2aa080049303be38ae3e75b8ccd11f0454dad9f55d71633712406c3c685f3912a48c1c8a0b4c289b70764bea22f6e7633b8
7
+ data.tar.gz: 9a8f3babd786648dd98f099c3d26ec7c2b94b82dff80080cce4102db37c1e503855cdc9f059681bc65d1e74a9dd9353c726e3934c568f90d8b8b4007add7b23d
data/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # ExoLogging
2
+
3
+ LoggingHelpers: This gem provides helpers for the event logging in a Mongoid Ruby project.
4
+
5
+ - Integrations requests + failures
6
+ - Provider requests + failures
7
+
8
+ [reference for gem creation: [newgem-template](https://github.com/wycats/newgem-template)]
9
+
10
+ [reference for git init: [github init](https://gist.github.com/seankross/8830032)]
11
+
12
+
13
+ ## Getting started
14
+
15
+ ### Requirements
16
+
17
+ - Ruby 2.5+
18
+ - Mongoid 7.3.0
19
+ - BSON_Ext 1.5.1
@@ -0,0 +1,44 @@
1
+ require 'json'
2
+
3
+ module ExoLogging
4
+ class IntegrationFailure
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+
8
+ field :name, type: String
9
+ field :integration_id, type: String
10
+ field :url, type: String
11
+ index({ url: 1 }, {})
12
+
13
+ validates_length_of :url, minimum: 1
14
+
15
+ @@app_name = 'Untitled'
16
+
17
+ def self.set_app_name(appname)
18
+ @@app_name = appname
19
+ end
20
+
21
+ def self.mk!(integration_id, url)
22
+ x = IntegrationFailure.new
23
+ x.name = @@app_name
24
+ x.integration_id = integration_id
25
+ x.url = url
26
+
27
+ x.save!
28
+ x
29
+ end
30
+
31
+ def self.mtbf(url, from=0, mtbf_type='decaying')
32
+ from_time = ExoBasic::Timer.from_epoch(from).to_datetime
33
+ failed_ts = IntegrationFailure.where(name: @@app_name,
34
+ url: url,
35
+ :created_at.gte => from_time)
36
+ .map { |i| ExoBasic::Timer.to_epoch(i.created_at) }
37
+ .to_a
38
+ .sort
39
+
40
+ ProviderFailure.mtbf_helper(failed_ts, mtbf_type)
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ module ExoLogging
2
+ class IntegrationRequest
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ field :name, type: String
7
+ field :integration_id, type: String
8
+ field :cost, type: Float
9
+
10
+ validates_presence_of :cost
11
+
12
+ @@app_name = 'Untitled'
13
+
14
+ def self.set_app_name(appname)
15
+ @@app_name = appname
16
+ end
17
+
18
+ def self.between(from, to)
19
+ IntegrationRequest.where(name: @@app_name,
20
+ :created_at.gte => from,
21
+ :created_at.lte => to)
22
+ end
23
+
24
+ def self.mk!(integration_id, cost)
25
+ x = IntegrationRequest.new
26
+ x.name = @@app_name
27
+ x.integration_id = integration_id
28
+ x.cost = cost.to_f
29
+
30
+ x.save!
31
+ x
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,68 @@
1
+ require 'json'
2
+
3
+ module ExoLogging
4
+ class ProviderFailure
5
+ include Mongoid::Document
6
+ include Mongoid::Timestamps
7
+
8
+ field :name, type: String
9
+ field :provider, type: String
10
+
11
+ validates_length_of :provider, minimum: 1
12
+
13
+ @@app_name = 'Untitled'
14
+
15
+ def self.set_app_name(appname)
16
+ @@app_name = appname
17
+ end
18
+
19
+ def self.mk!(provider)
20
+ x = ProviderFailure.new
21
+ x.name = @@app_name
22
+ x.provider = provider
23
+
24
+ x.save!
25
+ x
26
+ end
27
+
28
+ def self.mtbf_helper(failed_ts, mtbf_type)
29
+ failed_count = failed_ts.length
30
+
31
+ last = -1
32
+ mtbf = 0.0
33
+ if failed_count > 0
34
+ last = failed_ts[-1]
35
+ tbf = failed_ts[1..-1].zip(failed_ts).map { |pair| pair[0] - pair[1] }
36
+ mtbf = nil
37
+ case mtbf_type
38
+ when 'mean'
39
+ mtbf = ExoBasic::MeanAvg.new
40
+ when 'short_term'
41
+ mtbf = ExoBasic::ShortTermAvg.new
42
+ else
43
+ mtbf = ExoBasic::DecayingAvg.new
44
+ end
45
+ mtbf.offer_many(tbf)
46
+ end
47
+
48
+ {
49
+ :count => failed_count,
50
+ :last => last,
51
+ :mtbf => mtbf.as_json
52
+ }
53
+ end
54
+
55
+ def self.mtbf(provider, from=0, mtbf_type='decaying')
56
+ from_time = ExoBasic::Timer.from_epoch(from).to_datetime
57
+ failed_ts = ProviderFailure.where(name: @@app_name,
58
+ provider: provider,
59
+ :created_at.gte => from_time)
60
+ .map { |i| ExoBasic::Timer.to_epoch(i.created_at) }
61
+ .to_a
62
+ .sort
63
+
64
+ ProviderFailure.mtbf_helper(failed_ts, mtbf_type)
65
+ end
66
+
67
+ end
68
+ end
@@ -0,0 +1,36 @@
1
+ module ExoLogging
2
+ class ProviderRequest
3
+ include Mongoid::Document
4
+ include Mongoid::Timestamps
5
+
6
+ field :name, type: String
7
+ field :provider, type: String
8
+ field :cost, type: Float
9
+
10
+ validates_presence_of :cost
11
+ validates_length_of :provider, minimum: 1
12
+
13
+ @@app_name = 'Untitled'
14
+
15
+ def self.set_app_name(appname)
16
+ @@app_name = appname
17
+ end
18
+
19
+ def self.between(from, to)
20
+ ProviderRequest.where(name: @@app_name,
21
+ :created_at.gte => from,
22
+ :created_at.lte => to)
23
+ end
24
+
25
+ def self.mk!(provider, cost)
26
+ x = ProviderRequest.new
27
+ x.name = @@app_name
28
+ x.provider = provider
29
+ x.cost = cost.to_f
30
+
31
+ x.save!
32
+ x
33
+ end
34
+
35
+ end
36
+ end
@@ -0,0 +1,11 @@
1
+ module ExoLogging
2
+ class EventLogSettings
3
+ def self.set_app_name(appname)
4
+ IntegrationFailure.set_app_name(appname)
5
+ IntegrationRequest.set_app_name(appname)
6
+ ProviderFailure.set_app_name(appname)
7
+ ProviderRequest.set_app_name(appname)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ module ExoLogging
2
+ VERSION = "0.1.0"
3
+ end
data/lib/exologging.rb ADDED
@@ -0,0 +1,5 @@
1
+ require 'exologging/integration_failure'
2
+ require 'exologging/integration_request'
3
+ require 'exologging/provider_failure'
4
+ require 'exologging/provider_request'
5
+ require 'exologging/settings'
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: exologging
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dionysios Kakolyris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-10-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: mongoid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 7.3.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 7.3.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bson_ext
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: exobasic
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.0
55
+ description: Exotic Logging Helpers
56
+ email:
57
+ - contact@exotic.industries
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - README.md
63
+ - lib/exologging.rb
64
+ - lib/exologging/integration_failure.rb
65
+ - lib/exologging/integration_request.rb
66
+ - lib/exologging/provider_failure.rb
67
+ - lib/exologging/provider_request.rb
68
+ - lib/exologging/settings.rb
69
+ - lib/exologging/version.rb
70
+ homepage: https://bitbucket.org/vertigoindustries/exotic-logging
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: 1.3.6
88
+ requirements: []
89
+ rubygems_version: 3.0.6
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: LoggingHelpers
93
+ test_files: []