kumonos 0.2.0 → 0.3.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 +4 -4
- data/.rubocop.yml +1 -0
- data/Rakefile +15 -2
- data/{bump.rb → bump} +3 -2
- data/example/book.yml +3 -3
- data/exe/kumonos +26 -0
- data/lib/kumonos/schemas.rb +6 -0
- data/lib/kumonos/version.rb +1 -1
- data/lib/kumonos.rb +2 -4
- data/lib/schemas/service_definition.json +131 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4c5bcbbfe1bf50df5f3ca86866224f841ff22215
|
4
|
+
data.tar.gz: bd670f7af51eec530a2b038bcd6308d32d93dbbf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 38dc408e5f62ef628f557d604c7c2d2f41225b7e4155bce923e4dd5ab534205913f714a12f234d5630ee5f4a54789c66c69587119adef7cb6bd9db85b391a7ca
|
7
|
+
data.tar.gz: b310762a15b754e011d4e1aa8b8c95a9cfb4c0745ce471573fa339ae6ae745c78d6a3660973509229bb6cc6a81754ae29c8c7e4d6c3b0a3df9ad69d12e33f1b1
|
data/.rubocop.yml
CHANGED
data/Rakefile
CHANGED
@@ -1,6 +1,19 @@
|
|
1
1
|
require 'bundler/gem_tasks'
|
2
|
-
require 'rspec/core/rake_task'
|
3
2
|
|
3
|
+
require 'rspec/core/rake_task'
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
5
5
|
|
6
|
-
|
6
|
+
require 'rubocop/rake_task'
|
7
|
+
RuboCop::RakeTask.new
|
8
|
+
|
9
|
+
task default: %i[spec rubocop]
|
10
|
+
|
11
|
+
desc 'Run integration test'
|
12
|
+
task :integration_test do
|
13
|
+
Dir.chdir('test') do
|
14
|
+
sh './run_test'
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Run all tests'
|
19
|
+
task all: %i[spec rubocop integration_test]
|
data/{bump.rb → bump}
RENAMED
@@ -1,6 +1,7 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
1
2
|
level = ARGV.first
|
2
3
|
if level.nil?
|
3
|
-
warn "Example:
|
4
|
+
warn "Example: #{__FILE__} (tiny|minor|major)"
|
4
5
|
exit 1
|
5
6
|
end
|
6
7
|
|
@@ -25,7 +26,7 @@ when 'major'
|
|
25
26
|
version_strs[1] = 0
|
26
27
|
version_strs[2] = 0
|
27
28
|
else
|
28
|
-
warn "Example:
|
29
|
+
warn "Example: #{__FILE__} (tiny|minor|major)"
|
29
30
|
exit 1
|
30
31
|
end
|
31
32
|
|
data/example/book.yml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# A definition for book service.
|
2
2
|
# The book service uses user service and ab-testing service.
|
3
3
|
version: 1
|
4
|
-
|
4
|
+
dependencies:
|
5
5
|
- name: 'user'
|
6
6
|
lb: 'user:8080'
|
7
7
|
connect_timeout_ms: 250
|
@@ -15,7 +15,7 @@ services:
|
|
15
15
|
retry_policy:
|
16
16
|
retry_on: '5xx,connect-failure,refused-stream'
|
17
17
|
num_retries: 3
|
18
|
-
per_try_timeout_ms:
|
18
|
+
per_try_timeout_ms: 1000
|
19
19
|
- name: 'ab-testing'
|
20
20
|
lb: 'ab-testing:8080'
|
21
21
|
connect_timeout_ms: 250
|
@@ -29,4 +29,4 @@ services:
|
|
29
29
|
retry_policy:
|
30
30
|
retry_on: '5xx,connect-failure,refused-stream'
|
31
31
|
num_retries: 3
|
32
|
-
per_try_timeout_ms:
|
32
|
+
per_try_timeout_ms: 1000
|
data/exe/kumonos
CHANGED
@@ -29,6 +29,7 @@ class KumonosCli < Thor
|
|
29
29
|
def clusters(filepath, output_dir)
|
30
30
|
name = File.basename(filepath, '.*')
|
31
31
|
definition = YAML.load_file(filepath)
|
32
|
+
validate_service_definition!(definition, filepath)
|
32
33
|
out = JSON.dump(Kumonos.generate_clusters(definition))
|
33
34
|
|
34
35
|
output_dir = Pathname.new(output_dir)
|
@@ -42,6 +43,7 @@ class KumonosCli < Thor
|
|
42
43
|
def routes(filepath, output_dir)
|
43
44
|
name = File.basename(filepath, '.*')
|
44
45
|
definition = YAML.load_file(filepath)
|
46
|
+
validate_service_definition!(definition, filepath)
|
45
47
|
out = JSON.dump(Kumonos.generate_routes(definition))
|
46
48
|
|
47
49
|
output_dir = Pathname.new(output_dir)
|
@@ -50,6 +52,30 @@ class KumonosCli < Thor
|
|
50
52
|
target.write(out)
|
51
53
|
puts target
|
52
54
|
end
|
55
|
+
|
56
|
+
desc 'init NAME', 'Generate a service definition'
|
57
|
+
def init(name)
|
58
|
+
definition = YAML.load_file(File.expand_path('../example/book.yml', __dir__))
|
59
|
+
definition['dependencies'] = definition.fetch('dependencies')[0..0]
|
60
|
+
dep = definition['dependencies'][0]
|
61
|
+
dep['name'] = 'target-service-name'
|
62
|
+
dep['lb'] = 'hostname-for-load-balancer:port'
|
63
|
+
path = "#{name}.yml"
|
64
|
+
File.open(path, 'w') { |f| YAML.dump(definition, f) }
|
65
|
+
puts path
|
66
|
+
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def validate_service_definition!(definition, filepath)
|
71
|
+
result = Kumonos::Schemas.validate_service_definition(definition)
|
72
|
+
return if result.empty?
|
73
|
+
|
74
|
+
warn("#{filepath} has invalid format:")
|
75
|
+
warn(result)
|
76
|
+
warn("A schema file is #{Kumonos::Schemas::SERVIVE_DEFINITION_PATH}")
|
77
|
+
exit 1
|
78
|
+
end
|
53
79
|
end
|
54
80
|
|
55
81
|
KumonosCli.start(ARGV)
|
data/lib/kumonos/schemas.rb
CHANGED
@@ -6,6 +6,7 @@ module Kumonos
|
|
6
6
|
module Schemas
|
7
7
|
ROOT = Pathname.new(File.expand_path('../schemas', __dir__))
|
8
8
|
CONFIG_SCHEMA_PATH = ROOT.join('kumonos_config.json')
|
9
|
+
SERVIVE_DEFINITION_PATH = ROOT.join('service_definition.json')
|
9
10
|
|
10
11
|
class << self
|
11
12
|
def validate_kumonos_config(hash)
|
@@ -13,6 +14,11 @@ module Kumonos
|
|
13
14
|
JSON::Validator.fully_validate(schema, hash)
|
14
15
|
end
|
15
16
|
|
17
|
+
def validate_service_definition(hash)
|
18
|
+
schema = load_schema(SERVIVE_DEFINITION_PATH)
|
19
|
+
JSON::Validator.fully_validate(schema, hash)
|
20
|
+
end
|
21
|
+
|
16
22
|
private
|
17
23
|
|
18
24
|
def load_schema(path)
|
data/lib/kumonos/version.rb
CHANGED
data/lib/kumonos.rb
CHANGED
@@ -46,16 +46,15 @@ module Kumonos
|
|
46
46
|
end
|
47
47
|
|
48
48
|
def generate_routes(definition)
|
49
|
-
virtual_hosts = definition['services'].map { |s| service_to_vhost(s) }
|
50
49
|
{
|
51
50
|
validate_clusters: false,
|
52
|
-
virtual_hosts:
|
51
|
+
virtual_hosts: definition['dependencies'].map { |s| service_to_vhost(s) }
|
53
52
|
}
|
54
53
|
end
|
55
54
|
|
56
55
|
def generate_clusters(definition)
|
57
56
|
{
|
58
|
-
clusters: definition['
|
57
|
+
clusters: definition['dependencies'].map { |s| service_to_cluster(s) }
|
59
58
|
}
|
60
59
|
end
|
61
60
|
|
@@ -63,7 +62,6 @@ module Kumonos
|
|
63
62
|
|
64
63
|
def service_to_vhost(service)
|
65
64
|
name = service['name']
|
66
|
-
|
67
65
|
{
|
68
66
|
name: name,
|
69
67
|
domains: [name],
|
@@ -0,0 +1,131 @@
|
|
1
|
+
{
|
2
|
+
"definitions": {},
|
3
|
+
"$schema": "http://json-schema.org/draft-04/schema#",
|
4
|
+
"type": "object",
|
5
|
+
"id": "service-definition",
|
6
|
+
"additionalProperties": false,
|
7
|
+
"required": [
|
8
|
+
"version",
|
9
|
+
"dependencies"
|
10
|
+
],
|
11
|
+
"properties": {
|
12
|
+
"version": {
|
13
|
+
"type": "integer",
|
14
|
+
"id": "/properties/version",
|
15
|
+
"default": 1
|
16
|
+
},
|
17
|
+
"dependencies": {
|
18
|
+
"type": "array",
|
19
|
+
"id": "/properties/dependencies",
|
20
|
+
"items": {
|
21
|
+
"type": "object",
|
22
|
+
"id": "/properties/dependencies/items",
|
23
|
+
"additionalProperties": false,
|
24
|
+
"required": [
|
25
|
+
"name",
|
26
|
+
"lb",
|
27
|
+
"connect_timeout_ms",
|
28
|
+
"circuit_breaker",
|
29
|
+
"routes"
|
30
|
+
],
|
31
|
+
"properties": {
|
32
|
+
"name": {
|
33
|
+
"type": "string",
|
34
|
+
"id": "/properties/dependencies/items/properties/name",
|
35
|
+
"default": "dependency-service-name"
|
36
|
+
},
|
37
|
+
"lb": {
|
38
|
+
"type": "string",
|
39
|
+
"id": "/properties/dependencies/items/properties/lb",
|
40
|
+
"default": "host:port"
|
41
|
+
},
|
42
|
+
"connect_timeout_ms": {
|
43
|
+
"type": "integer",
|
44
|
+
"id": "/properties/dependencies/items/properties/connect_timeout_ms",
|
45
|
+
"default": 250
|
46
|
+
},
|
47
|
+
"circuit_breaker": {
|
48
|
+
"type": "object",
|
49
|
+
"id": "/properties/dependencies/items/properties/circuit_breaker",
|
50
|
+
"additionalProperties": false,
|
51
|
+
"required": [
|
52
|
+
"max_connections",
|
53
|
+
"max_pending_requests",
|
54
|
+
"max_retries"
|
55
|
+
],
|
56
|
+
"properties": {
|
57
|
+
"max_connections": {
|
58
|
+
"type": "integer",
|
59
|
+
"id": "/properties/dependencies/items/properties/circuit_breaker/properties/max_connections",
|
60
|
+
"default": 64
|
61
|
+
},
|
62
|
+
"max_pending_requests": {
|
63
|
+
"type": "integer",
|
64
|
+
"id": "/properties/dependencies/items/properties/circuit_breaker/properties/max_pending_requests",
|
65
|
+
"default": 128
|
66
|
+
},
|
67
|
+
"max_retries": {
|
68
|
+
"type": "integer",
|
69
|
+
"id": "/properties/dependencies/items/properties/circuit_breaker/properties/max_retries",
|
70
|
+
"default": 3
|
71
|
+
}
|
72
|
+
}
|
73
|
+
},
|
74
|
+
"routes": {
|
75
|
+
"type": "array",
|
76
|
+
"id": "/properties/dependencies/items/properties/routes",
|
77
|
+
"items": {
|
78
|
+
"type": "object",
|
79
|
+
"id": "/properties/dependencies/items/properties/routes/items",
|
80
|
+
"additionalProperties": false,
|
81
|
+
"required": [
|
82
|
+
"prefix",
|
83
|
+
"timeout_ms",
|
84
|
+
"retry_policy"
|
85
|
+
],
|
86
|
+
"properties": {
|
87
|
+
"prefix": {
|
88
|
+
"type": "string",
|
89
|
+
"id": "/properties/dependencies/items/properties/routes/items/properties/prefix",
|
90
|
+
"default": "/"
|
91
|
+
},
|
92
|
+
"timeout_ms": {
|
93
|
+
"type": "integer",
|
94
|
+
"id": "/properties/dependencies/items/properties/routes/items/properties/timeout_ms",
|
95
|
+
"default": 3000
|
96
|
+
},
|
97
|
+
"retry_policy": {
|
98
|
+
"type": "object",
|
99
|
+
"id": "/properties/dependencies/items/properties/routes/items/properties/retry_policy",
|
100
|
+
"additionalProperties": false,
|
101
|
+
"required": [
|
102
|
+
"retry_on",
|
103
|
+
"num_retries",
|
104
|
+
"per_try_timeout_ms"
|
105
|
+
],
|
106
|
+
"properties": {
|
107
|
+
"retry_on": {
|
108
|
+
"type": "string",
|
109
|
+
"id": "/properties/dependencies/items/properties/routes/items/properties/retry_policy/properties/retry_on",
|
110
|
+
"default": "5xx,connect-failure,refused-stream"
|
111
|
+
},
|
112
|
+
"num_retries": {
|
113
|
+
"type": "integer",
|
114
|
+
"id": "/properties/dependencies/items/properties/routes/items/properties/retry_policy/properties/num_retries",
|
115
|
+
"default": 3
|
116
|
+
},
|
117
|
+
"per_try_timeout_ms": {
|
118
|
+
"type": "integer",
|
119
|
+
"id": "/properties/dependencies/items/properties/routes/items/properties/retry_policy/properties/per_try_timeout_ms",
|
120
|
+
"default": 1000
|
121
|
+
}
|
122
|
+
}
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
}
|
127
|
+
}
|
128
|
+
}
|
129
|
+
}
|
130
|
+
}
|
131
|
+
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kumonos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Taiki Ono
|
@@ -126,7 +126,7 @@ files:
|
|
126
126
|
- Rakefile
|
127
127
|
- bin/console
|
128
128
|
- bin/setup
|
129
|
-
- bump
|
129
|
+
- bump
|
130
130
|
- example/book.yml
|
131
131
|
- example/kumonos.json
|
132
132
|
- exe/kumonos
|
@@ -136,6 +136,7 @@ files:
|
|
136
136
|
- lib/kumonos/schemas.rb
|
137
137
|
- lib/kumonos/version.rb
|
138
138
|
- lib/schemas/kumonos_config.json
|
139
|
+
- lib/schemas/service_definition.json
|
139
140
|
homepage: https://github.com/taiki45/kumonos
|
140
141
|
licenses:
|
141
142
|
- MIT
|