deimos-ruby 1.24.3 → 2.0.0.pre.alpha1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (118) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop_todo.yml +0 -17
  3. data/.tool-versions +1 -0
  4. data/CHANGELOG.md +1 -1
  5. data/README.md +287 -498
  6. data/deimos-ruby.gemspec +4 -4
  7. data/docs/CONFIGURATION.md +133 -227
  8. data/docs/UPGRADING.md +237 -0
  9. data/lib/deimos/active_record_consume/batch_consumption.rb +28 -29
  10. data/lib/deimos/active_record_consume/message_consumption.rb +15 -21
  11. data/lib/deimos/active_record_consumer.rb +36 -26
  12. data/lib/deimos/active_record_producer.rb +28 -9
  13. data/lib/deimos/backends/base.rb +4 -35
  14. data/lib/deimos/backends/kafka.rb +6 -22
  15. data/lib/deimos/backends/kafka_async.rb +6 -22
  16. data/lib/deimos/backends/{db.rb → outbox.rb} +13 -9
  17. data/lib/deimos/config/configuration.rb +116 -385
  18. data/lib/deimos/consume/batch_consumption.rb +24 -124
  19. data/lib/deimos/consume/message_consumption.rb +36 -63
  20. data/lib/deimos/consumer.rb +16 -75
  21. data/lib/deimos/ext/consumer_route.rb +35 -0
  22. data/lib/deimos/ext/producer_middleware.rb +94 -0
  23. data/lib/deimos/ext/producer_route.rb +22 -0
  24. data/lib/deimos/ext/redraw.rb +29 -0
  25. data/lib/deimos/ext/routing_defaults.rb +72 -0
  26. data/lib/deimos/ext/schema_route.rb +70 -0
  27. data/lib/deimos/kafka_message.rb +2 -2
  28. data/lib/deimos/kafka_source.rb +2 -7
  29. data/lib/deimos/kafka_topic_info.rb +1 -1
  30. data/lib/deimos/logging.rb +71 -0
  31. data/lib/deimos/message.rb +2 -11
  32. data/lib/deimos/metrics/datadog.rb +40 -1
  33. data/lib/deimos/metrics/provider.rb +4 -4
  34. data/lib/deimos/producer.rb +39 -116
  35. data/lib/deimos/railtie.rb +6 -0
  36. data/lib/deimos/schema_backends/avro_base.rb +21 -21
  37. data/lib/deimos/schema_backends/avro_schema_registry.rb +1 -2
  38. data/lib/deimos/schema_backends/avro_validation.rb +2 -2
  39. data/lib/deimos/schema_backends/base.rb +19 -12
  40. data/lib/deimos/schema_backends/mock.rb +6 -1
  41. data/lib/deimos/schema_backends/plain.rb +47 -0
  42. data/lib/deimos/schema_class/base.rb +2 -2
  43. data/lib/deimos/schema_class/enum.rb +1 -1
  44. data/lib/deimos/schema_class/record.rb +2 -2
  45. data/lib/deimos/test_helpers.rb +95 -320
  46. data/lib/deimos/tracing/provider.rb +6 -6
  47. data/lib/deimos/transcoder.rb +88 -0
  48. data/lib/deimos/utils/db_poller/base.rb +16 -14
  49. data/lib/deimos/utils/db_poller/state_based.rb +3 -3
  50. data/lib/deimos/utils/db_poller/time_based.rb +4 -4
  51. data/lib/deimos/utils/db_poller.rb +1 -1
  52. data/lib/deimos/utils/deadlock_retry.rb +1 -1
  53. data/lib/deimos/utils/{db_producer.rb → outbox_producer.rb} +16 -47
  54. data/lib/deimos/utils/schema_class.rb +0 -7
  55. data/lib/deimos/version.rb +1 -1
  56. data/lib/deimos.rb +79 -26
  57. data/lib/generators/deimos/{db_backend_generator.rb → outbox_backend_generator.rb} +4 -4
  58. data/lib/generators/deimos/schema_class_generator.rb +0 -1
  59. data/lib/generators/deimos/v2/templates/karafka.rb.tt +149 -0
  60. data/lib/generators/deimos/v2_generator.rb +193 -0
  61. data/lib/tasks/deimos.rake +5 -7
  62. data/spec/active_record_batch_consumer_association_spec.rb +22 -13
  63. data/spec/active_record_batch_consumer_spec.rb +84 -65
  64. data/spec/active_record_consume/batch_consumption_spec.rb +10 -10
  65. data/spec/active_record_consume/batch_slicer_spec.rb +12 -12
  66. data/spec/active_record_consumer_spec.rb +29 -13
  67. data/spec/active_record_producer_spec.rb +36 -26
  68. data/spec/backends/base_spec.rb +0 -23
  69. data/spec/backends/kafka_async_spec.rb +1 -3
  70. data/spec/backends/kafka_spec.rb +1 -3
  71. data/spec/backends/{db_spec.rb → outbox_spec.rb} +14 -20
  72. data/spec/batch_consumer_spec.rb +66 -116
  73. data/spec/consumer_spec.rb +53 -147
  74. data/spec/deimos_spec.rb +10 -126
  75. data/spec/kafka_source_spec.rb +19 -52
  76. data/spec/karafka/karafka.rb +69 -0
  77. data/spec/karafka_config/karafka_spec.rb +97 -0
  78. data/spec/logging_spec.rb +25 -0
  79. data/spec/message_spec.rb +9 -9
  80. data/spec/producer_spec.rb +112 -254
  81. data/spec/rake_spec.rb +1 -3
  82. data/spec/schema_backends/avro_validation_spec.rb +1 -1
  83. data/spec/schemas/com/my-namespace/MySchemaWithTitle.avsc +22 -0
  84. data/spec/snapshots/consumers-no-nest.snap +49 -0
  85. data/spec/snapshots/consumers.snap +49 -0
  86. data/spec/snapshots/consumers_and_producers-no-nest.snap +49 -0
  87. data/spec/snapshots/consumers_and_producers.snap +49 -0
  88. data/spec/snapshots/consumers_circular-no-nest.snap +49 -0
  89. data/spec/snapshots/consumers_circular.snap +49 -0
  90. data/spec/snapshots/consumers_complex_types-no-nest.snap +49 -0
  91. data/spec/snapshots/consumers_complex_types.snap +49 -0
  92. data/spec/snapshots/consumers_nested-no-nest.snap +49 -0
  93. data/spec/snapshots/consumers_nested.snap +49 -0
  94. data/spec/snapshots/namespace_folders.snap +49 -0
  95. data/spec/snapshots/namespace_map.snap +49 -0
  96. data/spec/snapshots/producers_with_key-no-nest.snap +49 -0
  97. data/spec/snapshots/producers_with_key.snap +49 -0
  98. data/spec/spec_helper.rb +61 -29
  99. data/spec/utils/db_poller_spec.rb +49 -39
  100. data/spec/utils/{db_producer_spec.rb → outbox_producer_spec.rb} +17 -184
  101. metadata +58 -67
  102. data/lib/deimos/batch_consumer.rb +0 -7
  103. data/lib/deimos/config/phobos_config.rb +0 -164
  104. data/lib/deimos/instrumentation.rb +0 -95
  105. data/lib/deimos/monkey_patches/phobos_cli.rb +0 -35
  106. data/lib/deimos/utils/inline_consumer.rb +0 -158
  107. data/lib/deimos/utils/lag_reporter.rb +0 -186
  108. data/lib/deimos/utils/schema_controller_mixin.rb +0 -129
  109. data/spec/config/configuration_spec.rb +0 -329
  110. data/spec/kafka_listener_spec.rb +0 -55
  111. data/spec/phobos.bad_db.yml +0 -73
  112. data/spec/phobos.yml +0 -77
  113. data/spec/utils/inline_consumer_spec.rb +0 -31
  114. data/spec/utils/lag_reporter_spec.rb +0 -76
  115. data/spec/utils/platform_schema_validation_spec.rb +0 -0
  116. data/spec/utils/schema_controller_mixin_spec.rb +0 -84
  117. /data/lib/generators/deimos/{db_backend → outbox_backend}/templates/migration +0 -0
  118. /data/lib/generators/deimos/{db_backend → outbox_backend}/templates/rails3_migration +0 -0
@@ -1,84 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'deimos/utils/schema_controller_mixin'
4
- require 'deimos/schema_backends/avro_local'
5
-
6
- RSpec.describe Deimos::Utils::SchemaControllerMixin, type: :controller do
7
-
8
- before(:each) do
9
- Deimos.configure do
10
- schema.backend(:avro_local)
11
- end
12
- end
13
-
14
- controller(ActionController::Base) do
15
- include Deimos::Utils::SchemaControllerMixin # rubocop:disable RSpec/DescribedClass
16
-
17
- request_namespace 'com.my-namespace.request'
18
- response_namespace 'com.my-namespace.response'
19
- schemas :index, :show
20
- schemas create: 'CreateTopic'
21
- schemas :update, request: 'UpdateRequest', response: 'UpdateResponse'
22
-
23
- # :nodoc:
24
- def index
25
- render_schema({ 'response_id' => payload[:request_id] + ' mom' })
26
- end
27
-
28
- # :nodoc:
29
- def show
30
- render_schema({ 'response_id' => payload[:request_id] + ' dad' })
31
- end
32
-
33
- # :nodoc:
34
- def create
35
- render_schema({ 'response_id' => payload[:request_id] + ' bro' })
36
- end
37
-
38
- # :nodoc:
39
- def update
40
- render_schema({ 'update_response_id' => payload[:update_request_id] + ' sis' })
41
- end
42
- end
43
-
44
- it 'should render the correct response for index' do
45
- request_backend = Deimos.schema_backend(schema: 'Index',
46
- namespace: 'com.my-namespace.request')
47
- response_backend = Deimos.schema_backend(schema: 'Index',
48
- namespace: 'com.my-namespace.response')
49
- request.content_type = 'avro/binary'
50
- get :index, body: request_backend.encode({ 'request_id' => 'hi' })
51
- expect(response_backend.decode(response.body)).to eq({ 'response_id' => 'hi mom' })
52
- end
53
-
54
- it 'should render the correct response for show' do
55
- request_backend = Deimos.schema_backend(schema: 'Index',
56
- namespace: 'com.my-namespace.request')
57
- response_backend = Deimos.schema_backend(schema: 'Index',
58
- namespace: 'com.my-namespace.response')
59
- request.content_type = 'avro/binary'
60
- get :show, params: { id: 1 }, body: request_backend.encode({ 'request_id' => 'hi' })
61
- expect(response_backend.decode(response.body)).to eq({ 'response_id' => 'hi dad' })
62
- end
63
-
64
- it 'should render the correct response for update' do
65
- request_backend = Deimos.schema_backend(schema: 'UpdateRequest',
66
- namespace: 'com.my-namespace.request')
67
- response_backend = Deimos.schema_backend(schema: 'UpdateResponse',
68
- namespace: 'com.my-namespace.response')
69
- request.content_type = 'avro/binary'
70
- post :update, params: { id: 1 }, body: request_backend.encode({ 'update_request_id' => 'hi' })
71
- expect(response_backend.decode(response.body)).to eq({ 'update_response_id' => 'hi sis' })
72
- end
73
-
74
- it 'should render the correct response for create' do
75
- request_backend = Deimos.schema_backend(schema: 'CreateTopic',
76
- namespace: 'com.my-namespace.request')
77
- response_backend = Deimos.schema_backend(schema: 'CreateTopic',
78
- namespace: 'com.my-namespace.response')
79
- request.content_type = 'avro/binary'
80
- post :create, params: { id: 1 }, body: request_backend.encode({ 'request_id' => 'hi' })
81
- expect(response_backend.decode(response.body)).to eq({ 'response_id' => 'hi bro' })
82
- end
83
-
84
- end