kumonos 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
+ SHA1:
3
+ metadata.gz: b1c6b3644e754690e6ee2fba82f9a709442eabbb
4
+ data.tar.gz: 8dcc5a060d2a29d248e409d8b248b8253611fcc3
5
+ SHA512:
6
+ metadata.gz: '0408e86373950df921c58276ba93b76b3429f0ad9a3dbea2068a104b6cfde44fd59e903a0874c2f6edbdf9efe70e67449356b047a1e2e2b6aeb44b399440df8a'
7
+ data.tar.gz: 3fc7fed7add9ff302c6e9ec7931055989d0265cda8af3180e0db955394b5cd683ef15181a9965dd9fb23c573cbeb16d24e2fe9e5543b344a60f549c59e3926da
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ Gemfile.lock
14
+ test/config.json
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.5
5
+ before_install: gem install bundler -v 1.16.0
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 kumonos.gemspec
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Taiki Ono
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,39 @@
1
+ # Kumonos
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/kumonos`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'kumonos'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install kumonos
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ 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).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/kumonos.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "kumonos"
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/example/book.yml ADDED
@@ -0,0 +1,28 @@
1
+ # A configuration for book service.
2
+ # The book service uses user service and ab-testing service.
3
+ version: 1
4
+ services:
5
+ - name: 'user'
6
+ lb: 'user:8080'
7
+ connect_timeout_ms: 250
8
+ circuit_breaker:
9
+ max_connections: 64
10
+ max_pending_requests: 128
11
+ max_retries: 3
12
+ routes:
13
+ - prefix: '/'
14
+ timeout_ms: 3000
15
+ retry_policy:
16
+ retry_on: '5xx,connect-failure,refused-stream'
17
+ num_retries: 3
18
+ per_try_timeout_ms: 250
19
+ - name: 'ab-testing'
20
+ lb: 'ab-testing:8080'
21
+ connect_timeout_ms: 250
22
+ routes:
23
+ - prefix: '/'
24
+ timeout_ms: 3000
25
+ retry_policy:
26
+ retry_on: '5xx,connect-failure,refused-stream'
27
+ num_retries: 3
28
+ per_try_timeout_ms: 250
data/exe/kumonos ADDED
@@ -0,0 +1,9 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $:.unshift(File.expand_path('../lib', __dir__))
5
+ require 'kumonos'
6
+
7
+ filename = ARGV[0]
8
+ config = YAML.load_file(filename)
9
+ puts JSON.dump(Kumonos.generate(config))
data/kumonos.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path('../lib', __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require 'kumonos/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'kumonos'
7
+ spec.version = Kumonos::VERSION
8
+ spec.authors = ['Taiki Ono']
9
+ spec.email = ['taiks.4559@gmail.com']
10
+
11
+ spec.summary = %q{Manage configuration for Service Mesh.}
12
+ spec.description = spec.summary
13
+ spec.homepage = 'https://github.com/taiki45/kumonos'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = 'exe'
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ['lib']
22
+
23
+ spec.add_development_dependency 'bundler'
24
+ spec.add_development_dependency 'pry'
25
+ spec.add_development_dependency 'rake'
26
+ spec.add_development_dependency 'rspec', '~> 3.0'
27
+ spec.add_development_dependency 'rspec-json_matcher'
28
+ end
@@ -0,0 +1,3 @@
1
+ module Kumonos
2
+ VERSION = "0.1.0"
3
+ end
data/lib/kumonos.rb ADDED
@@ -0,0 +1,77 @@
1
+ require 'json'
2
+ require 'yaml'
3
+ require 'kumonos/version'
4
+
5
+ module Kumonos
6
+ class << self
7
+ def generate(config)
8
+ virtual_hosts = config['services'].map {|s| service_to_vhost(s) }
9
+ clusters = config['services'].map {|s| service_to_cluster(s) }
10
+ {
11
+ listeners: [
12
+ {
13
+ address: 'tcp://0.0.0.0:9211',
14
+ filters: [
15
+ type: 'read',
16
+ name: 'http_connection_manager',
17
+ config: {
18
+ codec_type: 'auto',
19
+ stat_prefix: 'ingress_http',
20
+ access_log: [{ path: '/dev/stdout' }],
21
+ route_config: {
22
+ virtual_hosts: virtual_hosts,
23
+ },
24
+ filters: [{ type: 'decoder', name: 'router', config: {} }],
25
+ }
26
+ ],
27
+ }
28
+ ],
29
+ admin: {
30
+ access_log_path: "/dev/stdout",
31
+ address: "tcp://0.0.0.0:9901"
32
+ },
33
+ cluster_manager: {
34
+ clusters: clusters,
35
+ }
36
+ }
37
+ end
38
+
39
+ private
40
+
41
+ def service_to_vhost(service)
42
+ name = service['name']
43
+
44
+ {
45
+ name: name,
46
+ domains: [name],
47
+ routes: service['routes'].flat_map {|r| split_route(r, name) }
48
+ }
49
+ end
50
+
51
+ # Split route config to apply retry config only to GET/HEAD requests.
52
+ def split_route(route, name)
53
+ base = {
54
+ prefix: route['prefix'],
55
+ timeout_ms: route['timeout_ms'],
56
+ cluster: name,
57
+ }
58
+ with_retry = base.merge(
59
+ retry_policy: route['retry_policy'],
60
+ headers: [{ name: ':method', value: '(GET|HEAD)', regex: true }],
61
+ )
62
+ [with_retry, base]
63
+ end
64
+
65
+ def service_to_cluster(service)
66
+ out = {
67
+ name: service['name'],
68
+ connect_timeout_ms: service['connect_timeout_ms'],
69
+ type: 'logical_dns',
70
+ lb_type: 'round_robin',
71
+ hosts: [ { url: "tcp://#{service['lb']}" }],
72
+ }
73
+ out.merge(circuit_breakers: [default: service['circuit_breaker']]) if service['circuit_breaker']
74
+ out
75
+ end
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kumonos
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Taiki Ono
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-11-05 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: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-json_matcher
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Manage configuration for Service Mesh.
84
+ email:
85
+ - taiks.4559@gmail.com
86
+ executables:
87
+ - kumonos
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - Gemfile
95
+ - LICENSE.txt
96
+ - README.md
97
+ - Rakefile
98
+ - bin/console
99
+ - bin/setup
100
+ - example/book.yml
101
+ - exe/kumonos
102
+ - kumonos.gemspec
103
+ - lib/kumonos.rb
104
+ - lib/kumonos/version.rb
105
+ homepage: https://github.com/taiki45/kumonos
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ requirements:
120
+ - - ">="
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 2.5.2.1
126
+ signing_key:
127
+ specification_version: 4
128
+ summary: Manage configuration for Service Mesh.
129
+ test_files: []