soar_status 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f614d97cc6591109387990846914a883667741c6
4
+ data.tar.gz: 7234baf0bff8e990473996f3b4c9a88d569c59ab
5
+ SHA512:
6
+ metadata.gz: d643b77bfdedee9637fa4f17b9fc5364e3f4f277559179e125117b0c01a016fff878479df8f9528feb95267e5c935ded2c23ffecc2e2775f6aefca8ac739c6ae
7
+ data.tar.gz: a42ffb0ab7e98203499367c5744943a637450de0cafa6cc2decc40ccd22ce9441d57f902c631d7224f09e574a13c2f8e55711e60490464ad5684feeb8b4c3ada
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ .byebug_history
2
+ *tgz
3
+ left
4
+ test_tfa.sh
5
+ test_production.sh
6
+ iut-list
7
+ juddi-distro-*
8
+ *.swo
9
+ *.zip
10
+ *.tar.gz
11
+ *.swp
12
+ *.gem
13
+ *.rbc
14
+ Gemfile.lock
15
+ /.config
16
+ /coverage/
17
+ /InstalledFiles
18
+ /pkg/
19
+ /spec/reports/
20
+ /spec/examples.txt
21
+ /test/tmp/
22
+ /test/version_tmp/
23
+ /tmp/
24
+ .DS_Store
25
+
26
+ ## Specific to RubyMotion:
27
+ .dat*
28
+ .repl_history
29
+ build/
30
+
31
+ ## Documentation cache and generated files:
32
+ /.yardoc/
33
+ /_yardoc/
34
+ /doc/
35
+ /rdoc/
36
+
37
+ ## Environment normalisation:
38
+ /.bundle/
39
+ /vendor/bundle
40
+ /lib/bundler/man/
41
+
42
+ # for a library or gem, you might want to ignore these files since the code is
43
+ # intended to run in multiple environments; otherwise, check them in:
44
+ # Gemfile.lock
45
+ # .ruby-version
46
+ # .ruby-gemset
47
+
48
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
49
+ .rvmrc
50
+
51
+ /spec/support/certificates/**/*.pem
52
+ /spec/support/certificates/**/*.pkcs12
53
+ /spec/support/certificates/**/index*
54
+ /spec/support/certificates/**/serial*
55
+ /spec/support/certificates/**/crlnumber
56
+ /spec/support/certificates/**/*.jks
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ soar_status
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.3
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in soar_status.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Barney de Villiers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,186 @@
1
+ # SoarStatus
2
+
3
+ This gem provides a functional and detailed status aggregator that allows decoupling of status providers in the SOAR architecture. Functional and detailed status endpoints can then source the information from this single gem.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'soar_status'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ ```bash
16
+ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+
21
+ ```bash
22
+ gem install soar_status
23
+ ```
24
+
25
+ ## Testing
26
+
27
+ Behavioural driven testing can be performed by testing as follows:
28
+
29
+ ```bash
30
+ bundle exec rspec -cfd spec/*
31
+ ```
32
+
33
+ ## Usage
34
+
35
+ ### Registering release information
36
+
37
+ Simply register your release information as follow on startup:
38
+
39
+ ```ruby
40
+ SoarStatus::Status.release_commit_hash = '123abc'
41
+ SoarStatus::Status.release_version = '1.2.3'
42
+ ```
43
+
44
+ ### Registering environment and configuration information
45
+
46
+ Simply register your environment and configuration information on startup. Note that any secrets contained in here will also be exposed and must only be used in non-production modes.
47
+
48
+ ```ruby
49
+ SoarStatus::Status.configuration = @my_configuration
50
+ SoarStatus::Status.environment = @my_environment
51
+ ```
52
+
53
+ ### Creating a function status provider
54
+
55
+ Create/Enhance a class that can provide a functional status of the service. This is done in two parts:
56
+ * The instance must be registered with SoarStatus. This can be done in the initializer as shown below or later by simply passing in a reference to the object.
57
+ * It must provide a method called "functional_status" that will be called (via IOC) by SoarStatus in order to retrieve the functional status.
58
+
59
+ ```ruby
60
+ class ClassThatHasFunctionalStatus
61
+ def initialize
62
+ SoarStatus::Status.register_functional_status_provider(self)
63
+ end
64
+
65
+ def functional_status
66
+ "100"
67
+ end
68
+ end
69
+ ```
70
+
71
+ ### Creating a detailed status provider
72
+
73
+ Create/Enhance a class that can provide a detailed status of the service. This is done in two parts:
74
+ * The instance must be registered with SoarStatus. This can be done in the initializer as shown below or later by simply passing in a reference to the object.
75
+ * It must provide a method called "detailed_status" that will be called (via IOC) by SoarStatus in order to retrieve the detailed status.
76
+
77
+ ```ruby
78
+ class ClassThatHasDetailedStatus
79
+ def initialize
80
+ SoarStatus::Status.register_detailed_status_provider('class_1',self)
81
+ end
82
+
83
+ def detailed_status
84
+ { 'stuff' => 'from_class1'}
85
+ end
86
+ end
87
+ ```
88
+
89
+ ### Accessing the functional and detailed statuses
90
+
91
+ All the information can be provided via endpoints in your service.
92
+
93
+ ```ruby
94
+ class Status
95
+ def serve(request)
96
+ [200, SoarStatus::Status.functional_status.to_json]
97
+ end
98
+ end
99
+
100
+ class StatusDetail
101
+ def serve(request)
102
+ [200, SoarStatus::Status.detailed_status.to_json]
103
+ end
104
+ end
105
+ ```
106
+
107
+ ## Detailed example
108
+
109
+ ```ruby
110
+
111
+ require 'soar_status'
112
+
113
+ class ClassThatHasFunctionalStatus
114
+ def initialize
115
+ SoarStatus::Status.register_functional_status_provider(self)
116
+ @status = "100"
117
+ end
118
+
119
+ def functional_status
120
+ @status
121
+ end
122
+
123
+ def set_functional_status(status)
124
+ @status = status
125
+ end
126
+ end
127
+
128
+ class ClassThatHasDetailedStatus1
129
+ def initialize
130
+ SoarStatus::Status.register_detailed_status_provider('class_1',self)
131
+ end
132
+
133
+ def detailed_status
134
+ { 'stuff' => 'from_class1'}
135
+ end
136
+ end
137
+
138
+ class ClassThatHasDetailedStatus2
139
+ def initialize
140
+ SoarStatus::Status.register_detailed_status_provider('class_2',self)
141
+ end
142
+
143
+ def detailed_status
144
+ { 'stuff' => 'from_class2'}
145
+ end
146
+ end
147
+
148
+ class Main
149
+ def test_sanity
150
+ @test_configuration = { 'some' => 'configuration' }
151
+ @test_environment = { 'some' => 'environment' }
152
+
153
+ #registration of release information
154
+ SoarStatus::Status.release_commit_hash = '123abc'
155
+ SoarStatus::Status.release_version = '1.2.3'
156
+
157
+ #registration of configuration and environment detail
158
+ SoarStatus::Status.configuration = @test_configuration
159
+ SoarStatus::Status.environment = @test_environment
160
+
161
+ #registration of functional and detailed status providers
162
+ functional_status_provider = ClassThatHasFunctionalStatus.new
163
+ detailed_status_provider1 = ClassThatHasDetailedStatus1.new
164
+ detailed_status_provider2 = ClassThatHasDetailedStatus2.new
165
+
166
+ #retrieval of functional status
167
+ puts "Functional Status: #{SoarStatus::Status.functional_status}"
168
+
169
+ #retrieval of detailed status
170
+ puts "Detailed status: #{SoarStatus::Status.detailed_status}"
171
+ end
172
+ end
173
+
174
+ main = Main.new
175
+ main.test_sanity
176
+
177
+
178
+ ```
179
+
180
+ ## Contributing
181
+
182
+ Bug reports and feature requests are welcome by email to barney dot de dot villiers at hetzner dot co dot za. This gem is sponsored by Hetzner (Pty) Ltd (http://hetzner.co.za)
183
+
184
+ ## License
185
+
186
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
4
+
5
+ require "bundler/setup"
6
+ require 'soar_status'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require "irb"
16
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+ require 'soar_status/version'
2
+ require 'soar_status/status'
3
+
4
+ module SoarStatus
5
+ end
@@ -0,0 +1,83 @@
1
+ module SoarStatus
2
+ class Status
3
+ @@detailed_status_providers = {}
4
+ @@release_version = ''
5
+ @@release_commit_hash = ''
6
+ @@detailed_status_providers = {}
7
+ @@functional_status_provider = nil
8
+ @@configuration = {}
9
+ @@environment = {}
10
+
11
+ def self.configuration=(configuration)
12
+ @@configuration = configuration
13
+ end
14
+
15
+ def self.configuration
16
+ @@configuration
17
+ end
18
+
19
+ def self.environment=(environment)
20
+ @@environment = environment
21
+ end
22
+
23
+ def self.environment
24
+ @@environment
25
+ end
26
+
27
+ def self.release_version=(release_version)
28
+ @@release_version = release_version
29
+ end
30
+
31
+ def self.release_version
32
+ @@release_version
33
+ end
34
+
35
+ def self.release_commit_hash=(release_commit_hash)
36
+ @@release_commit_hash = release_commit_hash
37
+ end
38
+
39
+ def self.release_commit_hash
40
+ @@release_commit_hash
41
+ end
42
+
43
+ def self.register_detailed_status_provider(name,provider)
44
+ @@detailed_status_providers[name] = provider
45
+ end
46
+
47
+ def self.register_functional_status_provider(provider)
48
+ @@functional_status_provider = provider
49
+ end
50
+
51
+ def self.functional_status
52
+ return @@functional_status_provider.functional_status if @@functional_status_provider
53
+ 'no registered functional status provider'
54
+ end
55
+
56
+ def self.detailed_status
57
+ {
58
+ 'release' => self.compile_release_information,
59
+ 'configuration' => @@configuration,
60
+ 'environment' => @@environment,
61
+ 'functional' => self.functional_status,
62
+ 'detail' => self.aggregate_detailed_statuses
63
+ }
64
+ end
65
+
66
+ private
67
+
68
+ def self.aggregate_detailed_statuses
69
+ aggregated_statuses = {}
70
+ @@detailed_status_providers.each do |name, object|
71
+ aggregated_statuses[name] = object.detailed_status if object.detailed_status.is_a?(Hash)
72
+ end
73
+ aggregated_statuses
74
+ end
75
+
76
+ def self.compile_release_information
77
+ {
78
+ 'commit_hash' => @@release_commit_hash,
79
+ 'version' => @@release_version
80
+ }
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,3 @@
1
+ module SoarStatus
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ sanity
@@ -0,0 +1 @@
1
+ ruby-2.3
data/sanity/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'soar_status', path: '../'
data/sanity/sanity.rb ADDED
@@ -0,0 +1,65 @@
1
+ require 'soar_status'
2
+
3
+ class ClassThatHasFunctionalStatus
4
+ def initialize
5
+ SoarStatus::Status.register_functional_status_provider(self)
6
+ @status = "100"
7
+ end
8
+
9
+ def functional_status
10
+ @status
11
+ end
12
+
13
+ def set_functional_status(status)
14
+ @status = status
15
+ end
16
+ end
17
+
18
+ class ClassThatHasDetailedStatus1
19
+ def initialize
20
+ SoarStatus::Status.register_detailed_status_provider('class_1',self)
21
+ end
22
+
23
+ def detailed_status
24
+ { 'stuff' => 'from_class1'}
25
+ end
26
+ end
27
+
28
+ class ClassThatHasDetailedStatus2
29
+ def initialize
30
+ SoarStatus::Status.register_detailed_status_provider('class_2',self)
31
+ end
32
+
33
+ def detailed_status
34
+ { 'stuff' => 'from_class2'}
35
+ end
36
+ end
37
+
38
+ class Main
39
+ def test_sanity
40
+ @test_configuration = { 'some' => 'configuration' }
41
+ @test_environment = { 'some' => 'environment' }
42
+
43
+ #registration of release information
44
+ SoarStatus::Status.release_commit_hash = '123abc'
45
+ SoarStatus::Status.release_version = '1.2.3'
46
+
47
+ #registration of configuration and environment detail
48
+ SoarStatus::Status.configuration = @test_configuration
49
+ SoarStatus::Status.environment = @test_environment
50
+
51
+ #registration of functional and detailed status providers
52
+ functional_status_provider = ClassThatHasFunctionalStatus.new
53
+ detailed_status_provider1 = ClassThatHasDetailedStatus1.new
54
+ detailed_status_provider2 = ClassThatHasDetailedStatus2.new
55
+
56
+ #retrieval of functional status
57
+ puts "Functional Status: #{SoarStatus::Status.functional_status}"
58
+
59
+ #retrieval of detailed status
60
+ puts "Detailed status: #{SoarStatus::Status.detailed_status}"
61
+ end
62
+ end
63
+
64
+ main = Main.new
65
+ main.test_sanity
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'soar_status/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "soar_status"
8
+ spec.version = SoarStatus::VERSION
9
+ spec.authors = ["Barney de Villiers"]
10
+ spec.email = ["barney.de.villiers@hetzner.co.za"]
11
+
12
+ spec.summary = %q{Status aggregation for service components}
13
+ spec.description = %q{Status aggregation for service components in order to publish detailed aggregated status}
14
+ spec.homepage = "https://github.com/hetznerZA/soar_status"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1"
23
+ spec.add_development_dependency "rake", "~> 10"
24
+ spec.add_development_dependency "rspec", "~> 3"
25
+ spec.add_development_dependency "byebug", "~> 9"
26
+
27
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: soar_status
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Barney de Villiers
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '9'
69
+ description: Status aggregation for service components in order to publish detailed
70
+ aggregated status
71
+ email:
72
+ - barney.de.villiers@hetzner.co.za
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".rspec"
79
+ - ".ruby-gemset"
80
+ - ".ruby-version"
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - bin/console
86
+ - bin/setup
87
+ - lib/soar_status.rb
88
+ - lib/soar_status/status.rb
89
+ - lib/soar_status/version.rb
90
+ - sanity/.ruby-gemset
91
+ - sanity/.ruby-version
92
+ - sanity/Gemfile
93
+ - sanity/sanity.rb
94
+ - soar_status.gemspec
95
+ homepage: https://github.com/hetznerZA/soar_status
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.5.1
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Status aggregation for service components
119
+ test_files: []