kubelink 0.1.0

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
+ SHA256:
3
+ metadata.gz: 822c6b2dc5aefd26ccb0ad0edc51d83934aca4031d91e1c768285f2a782ba9a2
4
+ data.tar.gz: 074d4552a27b5d36204db79263d9fd1aa428c4890c2552d26fa9011db68d2a58
5
+ SHA512:
6
+ metadata.gz: fbb3e32067fbe281021dcf191e5158d0c5c097fb34329a327c640846678eb700f25201387dc6e2fd5ad827c4039de67a1ec1a60b40c753b2b17240f3bc33f286
7
+ data.tar.gz: c34ade1bd0ad7ab8d28a80cac287e8d1269d1395c9409c44531548db6336672f765946b65ea434410c2f05ad11ed8dcf6acaedc057cd0a103202c85c7749bd4a
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /*.gem
2
+ /.bundle
3
+ /.yardoc
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /Gemfile.lock
8
+ /pkg/
9
+ /spec/reports/
10
+ /tmp/
11
+ /vendor/bundle/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at difilippo@shaman.xyz. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in kubelink.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Martino di Filippo
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,73 @@
1
+ # Description
2
+
3
+ This gem is intended for internal use at Shaman, though you may find it useful (if a bit opinionated) nonetheless.
4
+
5
+ # Prerequisites
6
+
7
+ - A Rails >= 5.0 application
8
+ - Ruby >= 2.3.0
9
+
10
+ # Installation
11
+
12
+ Add this line to your gemfile:
13
+
14
+ ```ruby
15
+ gem 'kubelink'
16
+ ```
17
+
18
+ Then run `bundle install`.
19
+
20
+ # Features
21
+
22
+ ## Configuration and logging
23
+
24
+ This gems sets a few configuration options in production:
25
+
26
+ - config.force_ssl = true
27
+ - config.log_level = :info
28
+
29
+ It also includes lograge to reduce logging to a manageable level.
30
+
31
+ ## Healthcheck endpoints
32
+
33
+ By including this gem two endpoints will be added to your routes:
34
+
35
+ - /healthz, which runs `SELECT 1` on the database and returns a 200 OK
36
+ - /statusz, which just returns a 200 OK
37
+
38
+ They are supposed to be used as liveness and readiness probes in Kubernetes.
39
+
40
+ ## Prometheus exporter
41
+
42
+ PrometheusExporter::Middleware is added to rack. You still need to run an exporter in a separate process:
43
+
44
+ ```ruby
45
+ bundle exec prometheus_exporter
46
+ ```
47
+
48
+ ## Sentry integration
49
+
50
+ This gem requires the presence of a `SENTRY_DSN` environment variable to enable Sentry integration in production.
51
+ You need to include the relevant script tag in your layout by using the appropriate helper:
52
+
53
+ ```erb
54
+ <%= sentry_include_tag %>
55
+ ```
56
+
57
+ ## Development
58
+
59
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
60
+
61
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
62
+
63
+ ## Contributing
64
+
65
+ Bug reports and pull requests are welcome at https://git.shaman.xyz/shaman/kubelink. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
66
+
67
+ ## License
68
+
69
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
70
+
71
+ ## Code of Conduct
72
+
73
+ Everyone interacting in the Kubelink project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/kubelink/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kubelink"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
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
data/kubelink.gemspec ADDED
@@ -0,0 +1,27 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'kubelink/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = 'kubelink'
7
+ s.version = Kubelink::VERSION
8
+ s.authors = ['Martino di Filippo']
9
+ s.email = ['difilippo@shaman.xyz']
10
+ s.homepage = 'https://git.shaman.xyz/shaman/kubelink'
11
+ s.summary = %q{Integrate a Rails app with our Kubernetes environment}
12
+ s.license = 'MIT'
13
+ s.required_ruby_version = '>= 2.3.0'
14
+
15
+ s.files = Dir.chdir(File.expand_path('..', __FILE__)) do
16
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ end
18
+ s.executables = s.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ s.require_paths = ['lib']
20
+
21
+ s.add_dependency 'lograge', '~> 0.10.0'
22
+ s.add_dependency 'prometheus_exporter', '~> 0.4.0'
23
+ s.add_dependency 'sentry-raven', '~> 2.7', '>= 2.7.4'
24
+
25
+ s.add_development_dependency 'bundler', '~> 1.16'
26
+ s.add_development_dependency 'rake', '~> 10.0'
27
+ end
data/lib/kubelink.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'kubelink/version'
2
+
3
+ if defined?(Rails)
4
+ require 'kubelink/config'
5
+ require 'kubelink/health'
6
+ require 'kubelink/prometheus'
7
+ require 'kubelink/sentry'
8
+ end
@@ -0,0 +1,15 @@
1
+ module Kubelink
2
+ class Config < Rails::Railtie
3
+ initializer "kubelink.config" do
4
+ if Rails.env.production?
5
+ require 'lograge'
6
+
7
+ Rails.application.configure do
8
+ config.force_ssl = true
9
+ config.log_level = :info
10
+ config.lograge.enabled = true
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,23 @@
1
+ module Kubelink
2
+ class Health < Rails::Railtie
3
+ initializer "kubelink.healthcheck_endpoints" do
4
+ ActiveSupport.on_load :action_controller do
5
+ class MonitoringController < ActionController::Base
6
+ def health
7
+ ActiveRecord::Base.connection.execute('SELECT 1')
8
+ render plain: "ok"
9
+ end
10
+
11
+ def status
12
+ render plain: "ok"
13
+ end
14
+ end
15
+
16
+ Rails.application.routes.prepend do
17
+ get 'healthz', to: 'monitoring#health'
18
+ get 'statusz', to: 'monitoring#status'
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,12 @@
1
+ module Kubelink
2
+ class Prometheus < Rails::Railtie
3
+ initializer 'kubelink.prometheus_exporter' do
4
+ unless Rails.env.development? || Rails.env.test?
5
+ require 'prometheus_exporter'
6
+ require 'prometheus_exporter/middleware'
7
+
8
+ Rails.application.middleware.unshift PrometheusExporter::Middleware
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,58 @@
1
+ module Kubelink
2
+ class Sentry < Rails::Railtie
3
+ initializer "kubelink.sentry_integration" do
4
+ ActiveSupport.on_load :action_view do
5
+ include Kubelink::Sentry::Helpers
6
+ end
7
+
8
+ if ENV.key?('RAVEN_DSN')
9
+ Raven.configure do |config|
10
+ config.dsn = ENV['RAVEN_DSN']
11
+ config.release = ENV['RAILS_COMMIT']
12
+ end
13
+
14
+ ActiveSupport.on_load :action_controller do
15
+ include Kubelink::Sentry::Controller
16
+ end
17
+ elsif Rails.env.production?
18
+ throw "This application cannot run in production without setting RAVEN_DSN"
19
+ end
20
+ end
21
+
22
+ module Helpers
23
+ def sentry_dsn
24
+ @dsn ||= begin
25
+ u = URI.parse(ENV['SENTRY_DSN'])
26
+ u.password = nil
27
+ u.to_s
28
+ rescue
29
+ nil
30
+ end
31
+ end
32
+
33
+ def sentry_include_tag
34
+ return unless sentry_dsn.present?
35
+
36
+ script = 'https://browser.sentry-cdn.com/4.2.0/bundle.min.js'
37
+
38
+ [ javascript_include_tag(script, crossorigin: :anonymous),
39
+ content_tag(:script, %Q{Raven.config("#{sentry_dsn}").install();}.html_safe)
40
+ ].join("\n").html_safe
41
+ end
42
+ end
43
+
44
+ module Controller
45
+ extend ActiveSupport::Concern
46
+
47
+ included do
48
+ before_action :set_raven_context
49
+ end
50
+
51
+ def set_raven_context
52
+ return unless helpers.sentry_dsn
53
+ Raven.extra_context(params: params.dup.permit!.to_hash, url: request.url)
54
+ Raven.user_context(ip_address: request.remote_ip)
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,3 @@
1
+ module Kubelink
2
+ VERSION = '0.1.0'
3
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kubelink
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Martino di Filippo
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-10-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lograge
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.10.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.10.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: prometheus_exporter
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.4.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.4.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: sentry-raven
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.7'
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: 2.7.4
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - "~>"
56
+ - !ruby/object:Gem::Version
57
+ version: '2.7'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.7.4
61
+ - !ruby/object:Gem::Dependency
62
+ name: bundler
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.16'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.16'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rake
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '10.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '10.0'
89
+ description:
90
+ email:
91
+ - difilippo@shaman.xyz
92
+ executables: []
93
+ extensions: []
94
+ extra_rdoc_files: []
95
+ files:
96
+ - ".gitignore"
97
+ - CODE_OF_CONDUCT.md
98
+ - Gemfile
99
+ - LICENSE.txt
100
+ - README.md
101
+ - Rakefile
102
+ - bin/console
103
+ - bin/setup
104
+ - kubelink.gemspec
105
+ - lib/kubelink.rb
106
+ - lib/kubelink/config.rb
107
+ - lib/kubelink/health.rb
108
+ - lib/kubelink/prometheus.rb
109
+ - lib/kubelink/sentry.rb
110
+ - lib/kubelink/version.rb
111
+ homepage: https://git.shaman.xyz/shaman/kubelink
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: 2.3.0
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.7.7
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Integrate a Rails app with our Kubernetes environment
135
+ test_files: []