-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add schema backends #47
Conversation
6787f1e
to
f94c78a
Compare
b28c10a
to
e360563
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
lib/deimos/active_record_consumer.rb
Outdated
false | ||
end | ||
|
||
if column.type == :datetime && is_integer | ||
return Time.zone.strptime(val.to_s, '%s') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you refactor is_integer, can probably use Time.at
and skip some of the string->int->string->int conversion here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Heh good catch - probably could have done that before :)
lib/deimos/message.rb
Outdated
@@ -18,23 +18,23 @@ def initialize(payload, producer, topic: nil, key: nil, partition_key: nil) | |||
|
|||
# Add message_id and timestamp default values if they are in the | |||
# schema and don't already have values. | |||
# @param schema [Avro::Schema] | |||
def add_fields(schema) | |||
# @param fields [Array<Name>] existing fields in the schema. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be Array<String> existing field names in the schema.
'type' => 'record', | ||
'name' => name, | ||
'namespace' => @namespace, | ||
'doc' => "Key for #{@namespace}.#{@schema}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if the docs should have some indication it was autogenerated from Deimos
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't see why not :)
# @param schema [String] | ||
# @return [String] | ||
def _key_schema_name(schema) | ||
"#{schema.gsub('-value', '')}_key" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't -key
more conventional? Or is there some other reason we're mixing _ and -
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember going back and forth with this a lot. Although the schema registry can register '-value' as a subject, '-value' is not a valid Avro schema name. This was one of the reasons that triggered this: apache/avro#732
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually I think I can get rid of the gsub here because the schema wouldn't have -value
in it to begin with - it would be in the subject but not the name.
begin | ||
true if Integer(val) | ||
rescue StandardError | ||
false | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation is wonky here and in _is_float_string
lib/deimos/schema_backends/base.rb
Outdated
end | ||
|
||
# Encode a message key. To be defined by subclass. | ||
# @param key [String] the value to use as the key. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be String|Hash?
lib/deimos/test_helpers.rb
Outdated
end | ||
end | ||
|
||
# Stub all already-loaded producers and consumers for unit testing purposes. | ||
# :nodoc: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mark these with YARD @deprecated
@@ -1,6 +1,6 @@ | |||
# frozen_string_literal: true | |||
|
|||
RSpec.describe Deimos::PublishBackend do | |||
RSpec.describe Deimos::Backends::Base do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May be worth renaming the file to make it easier to find
e360563
to
9e32f58
Compare
@colinmroberts changes made |
This introduces the concept of schema backends, allowing us to define different backends which we can swap in.
There are several main benefits of this:
TestHelpers
module does a lot of inconvenient stubbing which makes it very hard to debug. Decoupling this from testing allows us to write a separate "test backend" which doesn't involve RSpec stubbing.Note that as part of this change, to keep consistency with the new
SchemaBackends::Base
class, I renamedPublishBackend
toBackends::Base
.This also fixes #33, #10, part of #16, and part of #13.
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Unit tests, as well as ran locally both with and without schema registry. Still needs to be tested on a live system.
Checklist: