avrolution 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cbf0fc83c28860289887a88b8e789f5217f2c365
4
- data.tar.gz: 54e25410dffeb032b364f5cd0568c679b56eae5a
3
+ metadata.gz: 44d01ea587ccbb464a081d3376aa5744b1d8c152
4
+ data.tar.gz: 431e8de8391b220872e68ce3927e830583fa85a5
5
5
  SHA512:
6
- metadata.gz: 33fbbf8d76a0f753d6271d20ef08cf3dff2700f7b2b266fe4c3fb3f7e4748ae0bf529afda8411ad37b25c2460f6acf8a5bc2f0cf59191121854ae4512dcbbb7e
7
- data.tar.gz: ad9c8d2f67de145deafb60ee1b7199bb64db193b78ccdda78c938d843b0b40441609c69c7e5a746fc8dd899aa6b0e579907ca1344b08527d881b147f46b38605
6
+ metadata.gz: 0a0bfe0ffc2609847a4fb606aa5065857fe7513fbbde5fd44bf1372263826122dd292b468741a0d99714f3a20bf8d8188a19c78c80eab819f6232ed1c0bb6aba
7
+ data.tar.gz: 8a2b82eced1d43966a21207df5d5575d3818513eb7f2f9aa348c36de903776af3875297d302d856b270f3a750a70149d70211c9ca6571bb254f408dbaf2fba6c
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # avrolution
2
2
 
3
+ ## v0.3.0
4
+ - Add rake task to register new schema versions.
5
+
3
6
  ## v0.2.0
4
7
  - Add Rails generator to create `avro_compatibility_breaks.txt` file.
5
8
  - Replace the dependency on `avromatic` with `avro_schema_registry-client`.
data/README.md CHANGED
@@ -39,8 +39,11 @@ The gem supports the following configuration:
39
39
  * `compatibility_breaks_file` - The path to the compability breaks file. Defaults
40
40
  to `#{Avrolution}.root/avro_compatibility_breaks.txt`.
41
41
  * `compatibility_schema_registry_url` - The URL for the schema registry to use
42
- for compatibility checking. `ENV['COMPATIBILITY_SCHEMA_REGISTRY_URL]` is used
42
+ for compatibility checking. `ENV['COMPATIBILITY_SCHEMA_REGISTRY_URL']` is used
43
43
  as the default.
44
+ * `deployment_schema_registry_url` - The URL for the schema registry to use
45
+ when registering new schema version. `ENV['DEPLOYMENT_SCHEMA_REGISTRY_URL']`
46
+ is used as the default.
44
47
  * `logger` - A logger used by the rake tasks in this gem. This does _NOT_ default
45
48
  to `Rails.logger` in Rails applications.
46
49
 
@@ -57,7 +60,7 @@ defined via a Railtie.
57
60
  This task does not require any arguments. It checks the
58
61
  compatibility of all Avro JSON schemas found recursively under `Avrolution.root`
59
62
  against the schema registry `Avroluion.compatibility_schema_registry_url` or
60
- `ENV['COMPATIBILITY_SCHEMA_REGISTRY_URL]`.
63
+ `ENV['COMPATIBILITY_SCHEMA_REGISTRY_URL']`.
61
64
 
62
65
  ```bash
63
66
  rake avro:check_compatibility
@@ -75,6 +78,34 @@ require 'avrolution/rake/check_compatibility_task'
75
78
  Avrolution::Rake::CheckCompatibilityTask.define
76
79
  ```
77
80
 
81
+ ### Avro Register Schemas Rake Task
82
+
83
+ There is a rake task to register new schemas.
84
+
85
+ For Rails applications, the `avro:register_schemas` task is automatically
86
+ defined via a Railtie.
87
+
88
+ This rake task requires a comma-separated list of files for the schemas to register.
89
+
90
+ ```bash
91
+ rake avro:register_schemas schemas=/app/avro/schemas/one.avsc,/app/avro/schema/two.avsc
92
+ ```
93
+
94
+ Schemas are registered against the schema registry
95
+ `Avroluion.deployment_schema_registry_url` or
96
+ `ENV['DEPLOYMENT_SCHEMA_REGISTRY_URL']`.
97
+
98
+ The `Avrolution.compatibility_breaks_file` is consulted prior to registering the
99
+ schema, and if an entry is found then the specified compatibility settings are
100
+ used.
101
+
102
+ For non-Rails projects, tasks can be defined as:
103
+
104
+ ```ruby
105
+ require 'avroluation/rake/register_schemas_task'
106
+ Avrolution::Rake::RegisterSchemasTask.define
107
+ ```
108
+
78
109
  ### Avro Add Compatibility Break Rake Task
79
110
 
80
111
  There is a rake task add an entry to the `Avrolution.compatibility_breaks_file`.
@@ -86,8 +117,6 @@ This rake task accepts the following arguments:
86
117
  during registration.
87
118
  * `after_compatibility` - Optional compatibility level to set after registration.
88
119
 
89
- (The registration support will be available in a future version of this gem.)
90
-
91
120
  ```bash
92
121
  rake avro:add_compatibility_break name=com.salsify.alerts.example_value \
93
122
  fingerprint=36a2035c15c1bbbfe895494697d1f760171d00ab4fd39d0616261bf6854374f9 \
data/avrolution.gemspec CHANGED
@@ -29,16 +29,18 @@ Gem::Specification.new do |spec|
29
29
 
30
30
  spec.add_development_dependency 'bundler', '~> 1.12'
31
31
  spec.add_development_dependency 'rake', '~> 10.0'
32
- spec.add_development_dependency 'rspec', '~> 3.4'
32
+ spec.add_development_dependency 'rspec', '~> 3.5'
33
+ spec.add_development_dependency 'rspec-its'
33
34
  spec.add_development_dependency 'salsify_rubocop', '~> 0.47.2'
34
35
  spec.add_development_dependency 'overcommit'
35
36
  spec.add_development_dependency 'fakefs'
36
37
  spec.add_development_dependency 'simplecov'
37
38
 
38
39
  spec.add_runtime_dependency 'avro-salsify-fork', '1.9.0.5'
39
- spec.add_runtime_dependency 'avro_schema_registry-client'
40
+ spec.add_runtime_dependency 'avro_schema_registry-client', '>= 0.2.0'
40
41
  spec.add_runtime_dependency 'diffy'
41
42
  spec.add_runtime_dependency 'private_attr'
42
43
  spec.add_runtime_dependency 'activesupport'
43
44
  spec.add_runtime_dependency 'activemodel'
45
+ spec.add_runtime_dependency 'procto'
44
46
  end
@@ -35,5 +35,11 @@ module Avrolution
35
35
  def line
36
36
  [name, fingerprint, with_compatibility, after_compatibility].compact.join(' ')
37
37
  end
38
+
39
+ def register_options
40
+ { with_compatibility: with_compatibility }.tap do |options|
41
+ options[:after_compatibility] = after_compatibility if after_compatibility.present?
42
+ end
43
+ end
38
44
  end
39
45
  end
@@ -1,6 +1,7 @@
1
1
  module Avrolution
2
2
 
3
3
  COMPATIBILITY_SCHEMA_REGISTRY_URL = 'COMPATIBILITY_SCHEMA_REGISTRY_URL'.freeze
4
+ DEPLOYMENT_SCHEMA_REGISTRY_URL = 'DEPLOYMENT_SCHEMA_REGISTRY_URL'.freeze
4
5
 
5
6
  class << self
6
7
  # Root directory to search for schemas, and default location for
@@ -15,6 +16,10 @@ module Avrolution
15
16
  # compatibility checks
16
17
  attr_writer :compatibility_schema_registry_url
17
18
 
19
+ # The URL (including any Basic Auth) for the schema registry to use for
20
+ # deployment
21
+ attr_writer :deployment_schema_registry_url
22
+
18
23
  attr_accessor :logger
19
24
  end
20
25
 
@@ -29,9 +34,14 @@ module Avrolution
29
34
  end
30
35
 
31
36
  def self.compatibility_schema_registry_url
32
- @compatibility_schema_registry_url ||= begin
33
- raise 'compatibility_schema_registry_url must be set' unless ENV[COMPATIBILITY_SCHEMA_REGISTRY_URL]
34
- ENV[COMPATIBILITY_SCHEMA_REGISTRY_URL]
37
+ @compatibility_schema_registry_url ||= ENV.fetch(COMPATIBILITY_SCHEMA_REGISTRY_URL) do
38
+ raise 'compatibility_schema_registry_url must be set'
39
+ end
40
+ end
41
+
42
+ def self.deployment_schema_registry_url
43
+ @deployment_schema_registry_url ||= ENV.fetch(DEPLOYMENT_SCHEMA_REGISTRY_URL) do
44
+ raise 'deployment_schema_registry_url must be set'
35
45
  end
36
46
  end
37
47
 
@@ -1,5 +1,7 @@
1
1
  require 'avrolution/rake/check_compatibility_task'
2
2
  require 'avrolution/rake/add_compatibility_break_task'
3
+ require 'avrolution/rake/register_schemas_task'
3
4
 
4
5
  Avrolution::Rake::AddCompatibilityBreakTask.define(dependencies: %i(environment))
5
6
  Avrolution::Rake::CheckCompatibilityTask.define(dependencies: %i(environment))
7
+ Avrolution::Rake::RegisterSchemasTask.define(dependencies: %i(environment))
@@ -0,0 +1,24 @@
1
+ require 'avrolution/rake/base_task'
2
+
3
+ module Avrolution
4
+ module Rake
5
+ class RegisterSchemasTask < BaseTask
6
+
7
+ def initialize(*)
8
+ super
9
+ @name ||= :register_schemas
10
+ @task_desc ||= 'Register the specified Avro JSON schemas'
11
+ end
12
+
13
+ private
14
+
15
+ def perform
16
+ raise 'schemas must be specified' if ENV['schemas'].blank?
17
+
18
+ schemas = ENV['schemas'].split(',')
19
+
20
+ Avrolution::RegisterSchemas.call(schemas)
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,63 @@
1
+ require 'avro_schema_registry-client'
2
+ require 'private_attr'
3
+ require 'procto'
4
+
5
+ module Avrolution
6
+ class RegisterSchemas
7
+ extend PrivateAttr
8
+ include Procto.call
9
+
10
+ attr_reader :schema_files
11
+
12
+ private_attr_reader :compatibility_breaks, :schema_registry
13
+
14
+ class IncompatibleSchemaError < StandardError
15
+ def initialize(name)
16
+ super("incompatible schema #{name}")
17
+ end
18
+ end
19
+
20
+ def initialize(schema_files)
21
+ @schema_files = Array(schema_files)
22
+ @compatibility_breaks = Avrolution::CompatibilityBreaksFile.load
23
+ @schema_registry = build_schema_registry
24
+ end
25
+
26
+ def call
27
+ schemas.each do |(json, schema)|
28
+ register_schema(schema, json)
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def register_schema(schema, json)
35
+ fullname = schema.fullname
36
+ fingerprint = schema.sha256_resolution_fingerprint.to_s(16)
37
+
38
+ compatibility_break = compatibility_breaks[[fullname, fingerprint]]
39
+
40
+ begin
41
+ schema_registry.register_without_lookup(
42
+ fullname,
43
+ json,
44
+ compatibility_break.try(:register_options) || {}
45
+ )
46
+ rescue Excon::Error::Conflict
47
+ raise IncompatibleSchemaError.new(fullname)
48
+ end
49
+ end
50
+
51
+ def schemas
52
+ @schemas ||= schema_files.map do |schema_file|
53
+ json = File.read(schema_file)
54
+ [json, Avro::Schema.parse(json)]
55
+ end
56
+ end
57
+
58
+ def build_schema_registry
59
+ AvroSchemaRegistry::Client.new(Avrolution.deployment_schema_registry_url,
60
+ logger: Avrolution.logger)
61
+ end
62
+ end
63
+ end
@@ -1,3 +1,3 @@
1
1
  module Avrolution
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
data/lib/avrolution.rb CHANGED
@@ -15,5 +15,6 @@ require 'avrolution/configuration'
15
15
  require 'avrolution/compatibility_break'
16
16
  require 'avrolution/compatibility_breaks_file'
17
17
  require 'avrolution/compatibility_check'
18
+ require 'avrolution/register_schemas'
18
19
 
19
20
  require 'avrolution/railtie' if defined?(Rails)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: avrolution
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salsify, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-11 00:00:00.000000000 Z
11
+ date: 2017-04-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -44,14 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.4'
47
+ version: '3.5'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.4'
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-its
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: salsify_rubocop
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -128,14 +142,14 @@ dependencies:
128
142
  requirements:
129
143
  - - ">="
130
144
  - !ruby/object:Gem::Version
131
- version: '0'
145
+ version: 0.2.0
132
146
  type: :runtime
133
147
  prerelease: false
134
148
  version_requirements: !ruby/object:Gem::Requirement
135
149
  requirements:
136
150
  - - ">="
137
151
  - !ruby/object:Gem::Version
138
- version: '0'
152
+ version: 0.2.0
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: diffy
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -192,6 +206,20 @@ dependencies:
192
206
  - - ">="
193
207
  - !ruby/object:Gem::Version
194
208
  version: '0'
209
+ - !ruby/object:Gem::Dependency
210
+ name: procto
211
+ requirement: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - ">="
214
+ - !ruby/object:Gem::Version
215
+ version: '0'
216
+ type: :runtime
217
+ prerelease: false
218
+ version_requirements: !ruby/object:Gem::Requirement
219
+ requirements:
220
+ - - ">="
221
+ - !ruby/object:Gem::Version
222
+ version: '0'
195
223
  description: Support for the evolution of Avro schemas stored in a schema registry.
196
224
  email:
197
225
  - engineering@salsify.com
@@ -224,6 +252,8 @@ files:
224
252
  - lib/avrolution/rake/base_task.rb
225
253
  - lib/avrolution/rake/check_compatibility_task.rb
226
254
  - lib/avrolution/rake/rails_avrolution.rake
255
+ - lib/avrolution/rake/register_schemas_task.rb
256
+ - lib/avrolution/register_schemas.rb
227
257
  - lib/avrolution/version.rb
228
258
  - lib/generators/avrolution/install_generator.rb
229
259
  - lib/generators/avrolution/templates/avro_compatibility_breaks.txt