racecar 2.3.0.alpha1 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/Gemfile.lock +3 -3
- data/README.md +83 -73
- data/lib/racecar/heroku.rb +49 -0
- data/lib/racecar/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6ace90fc8d6ce4eca70ff85fcfbc414f97c9d00d10a9b9a6f1bac49e3741ec61
|
4
|
+
data.tar.gz: a92ae22281bf3a9ac797413cef79f30e4a0ea8e316afb6444abe4ab95bf33372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fefe0c546f36549a4fe0e4f4293534389b2136c68ea4e90c19c769c0cba713abde96ae5acab9a471d0385948a6056349519b2a38547f9f56a5eae1dfe4f79f13
|
7
|
+
data.tar.gz: ca062ec3985f6d5c8099f32c1f70eb5d7a86edfbb12b176f5485509aa5b61468db074e34c1b77d7b327d63cab8b32be66310fcd330c14b1c6fc3474f10a4518d
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,9 @@
|
|
2
2
|
|
3
3
|
## Unreleased
|
4
4
|
|
5
|
+
## racecar v2.3.0
|
6
|
+
|
7
|
+
* Add native support for Heroku (#248)
|
5
8
|
* [Racecar::Consumer] When messages fail to deliver, an extended error with hints is now raised. Instead of `Rdkafka::RdkafkaError` you'll get a `Racecar::MessageDeliveryError` instead. ([#219](https://github.com/zendesk/racecar/pull/219)). If you have set a `Racecar.config.error_handler`, it might need to be updated.
|
6
9
|
* [Racecar::Consumer] When message delivery times out, Racecar will reset the producer in an attempt to fix some of the potential causes for this error. ([#219](https://github.com/zendesk/racecar/pull/219))
|
7
10
|
* Validate the `process` and `process_batch` method signature on consumer classes when initializing (#236)
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
racecar (2.
|
4
|
+
racecar (2.3.0.alpha1)
|
5
5
|
king_konf (~> 1.0.0)
|
6
6
|
rdkafka (~> 0.8.0)
|
7
7
|
|
@@ -18,12 +18,12 @@ GEM
|
|
18
18
|
concurrent-ruby (1.1.7)
|
19
19
|
diff-lcs (1.4.4)
|
20
20
|
dogstatsd-ruby (4.8.2)
|
21
|
-
ffi (1.
|
21
|
+
ffi (1.15.0)
|
22
22
|
i18n (1.8.5)
|
23
23
|
concurrent-ruby (~> 1.0)
|
24
24
|
king_konf (1.0.0)
|
25
25
|
method_source (1.0.0)
|
26
|
-
mini_portile2 (2.5.
|
26
|
+
mini_portile2 (2.5.1)
|
27
27
|
minitest (5.14.2)
|
28
28
|
pry (0.13.1)
|
29
29
|
coderay (~> 1.1)
|
data/README.md
CHANGED
@@ -10,22 +10,21 @@ The framework is based on [rdkafka-ruby](https://github.com/appsignal/rdkafka-ru
|
|
10
10
|
|
11
11
|
1. [Installation](#installation)
|
12
12
|
2. [Usage](#usage)
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
13
|
+
1. [Creating consumers](#creating-consumers)
|
14
|
+
2. [Running consumers](#running-consumers)
|
15
|
+
3. [Producing messages](#producing-messages)
|
16
|
+
4. [Configuration](#configuration)
|
17
|
+
5. [Testing consumers](#testing-consumers)
|
18
|
+
6. [Deploying consumers](#deploying-consumers)
|
19
|
+
7. [Handling errors](#handling-errors)
|
20
|
+
8. [Logging](#logging)
|
21
|
+
9. [Operations](#operations)
|
22
|
+
10. [Upgrading from v1 to v2](#upgrading-from-v1-to-v2)
|
23
23
|
3. [Development](#development)
|
24
24
|
4. [Contributing](#contributing)
|
25
25
|
5. [Support and Discussion](#support-and-discussion)
|
26
26
|
6. [Copyright and license](#copyright-and-license)
|
27
27
|
|
28
|
-
|
29
28
|
## Installation
|
30
29
|
|
31
30
|
Add this line to your application's Gemfile:
|
@@ -77,7 +76,7 @@ In order to create your own consumer, run the Rails generator `racecar:consumer`
|
|
77
76
|
|
78
77
|
$ bundle exec rails generate racecar:consumer TapDance
|
79
78
|
|
80
|
-
This will create a file at `app/consumers/tap_dance_consumer.rb` which you can modify to your liking. Add one or more calls to
|
79
|
+
This will create a file at `app/consumers/tap_dance_consumer.rb` which you can modify to your liking. Add one or more calls to `subscribes_to` in order to have the consumer subscribe to Kafka topics.
|
81
80
|
|
82
81
|
Now run your consumer with `bundle exec racecar TapDanceConsumer`.
|
83
82
|
|
@@ -88,13 +87,15 @@ Note: if you're not using Rails, you'll have to add the file yourself. No-one wi
|
|
88
87
|
Warning - limited battle testing in production environments; use at your own risk!
|
89
88
|
|
90
89
|
If you want to process different partitions in parallel, and don't want to deploy a number of instances matching the total partitions of the topic, you can specify the number of workers to spin up - that number of processes will be forked, and each will register its own consumer in the group. Some things to note:
|
90
|
+
|
91
91
|
- This would make no difference on a single partitioned topic - only one consumer would ever be assigned a partition. A couple of example configurations to process all partitions in parallel (we'll assume a 15 partition topic):
|
92
92
|
- Parallel workers set to 3, 5 separate instances / replicas running in your container orchestrator
|
93
93
|
- Parallel workers set to 5, 3 separate instances / replicas running in your container orchestrator
|
94
94
|
- Since we're forking new processes, the memory demands are a little higher
|
95
|
-
- From some initial testing, running 5 parallel workers requires no more than double the memory of running a Racecar consumer without parallelism.
|
95
|
+
- From some initial testing, running 5 parallel workers requires no more than double the memory of running a Racecar consumer without parallelism.
|
96
96
|
|
97
97
|
The number of parallel workers is configured per consumer class; you may only want to take advantage of this for busier consumers:
|
98
|
+
|
98
99
|
```ruby
|
99
100
|
class ParallelProcessingConsumer < Racecar::Consumer
|
100
101
|
subscribes_to "some-topic"
|
@@ -182,9 +183,9 @@ message.headers #=> { "Header-A" => 42, ... }
|
|
182
183
|
|
183
184
|
In order to avoid your consumer being kicked out of its group during long-running message processing operations, you'll need to let Kafka regularly know that the consumer is still healthy. There's two mechanisms in place to ensure that:
|
184
185
|
|
185
|
-
|
186
|
+
_Heartbeats:_ They are automatically sent in the background and ensure the broker can still talk to the consumer. This will detect network splits, ungraceful shutdowns, etc.
|
186
187
|
|
187
|
-
|
188
|
+
_Message Fetch Interval:_ Kafka expects the consumer to query for new messages within this time limit. This will detect situations with slow IO or the consumer being stuck in an infinite loop without making actual progress. This limit applies to a whole batch if you do batch processing. Use `max_poll_interval` to increase the default 5 minute timeout, or reduce batching with `fetch_messages`.
|
188
189
|
|
189
190
|
#### Tearing down resources when stopping
|
190
191
|
|
@@ -263,35 +264,35 @@ end
|
|
263
264
|
|
264
265
|
#### Basic configuration
|
265
266
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
267
|
+
- `brokers` – A list of Kafka brokers in the cluster that you're consuming from. Defaults to `localhost` on port 9092, the default Kafka port.
|
268
|
+
- `client_id` – A string used to identify the client in logs and metrics.
|
269
|
+
- `group_id` – The group id to use for a given group of consumers. Note that this _must_ be different for each consumer class. If left blank a group id is generated based on the consumer class name such that (for example) a consumer with the class name `BaconConsumer` would default to a group id of `bacon-consumer`.
|
270
|
+
- `group_id_prefix` – A prefix used when generating consumer group names. For instance, if you set the prefix to be `kevin.` and your consumer class is named `BaconConsumer`, the resulting consumer group will be named `kevin.bacon-consumer`.
|
270
271
|
|
271
272
|
#### Logging
|
272
273
|
|
273
|
-
|
274
|
-
|
274
|
+
- `logfile` – A filename that log messages should be written to. Default is `nil`, which means logs will be written to standard output.
|
275
|
+
- `log_level` – The log level for the Racecar logs, one of `debug`, `info`, `warn`, or `error`. Default is `info`.
|
275
276
|
|
276
277
|
#### Consumer checkpointing
|
277
278
|
|
278
279
|
The consumers will checkpoint their positions from time to time in order to be able to recover from failures. This is called _committing offsets_, since it's done by tracking the offset reached in each partition being processed, and committing those offset numbers to the Kafka offset storage API. If you can tolerate more double-processing after a failure, you can increase the interval between commits in order to better performance. You can also do the opposite if you prefer less chance of double-processing.
|
279
280
|
|
280
|
-
|
281
|
+
- `offset_commit_interval` – How often to save the consumer's position in Kafka. Default is every 10 seconds.
|
281
282
|
|
282
283
|
#### Timeouts & intervals
|
283
284
|
|
284
285
|
All timeouts are defined in number of seconds.
|
285
286
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
287
|
+
- `session_timeout` – The idle timeout after which a consumer is kicked out of the group. Consumers must send heartbeats with at least this frequency.
|
288
|
+
- `heartbeat_interval` – How often to send a heartbeat message to Kafka.
|
289
|
+
- `max_poll_interval` – The maximum time between two message fetches before the consumer is kicked out of the group. Put differently, your (batch) processing must finish earlier than this.
|
290
|
+
- `pause_timeout` – How long to pause a partition for if the consumer raises an exception while processing a message. Default is to pause for 10 seconds. Set this to `0` in order to disable automatic pausing of partitions or to `-1` to pause indefinitely.
|
291
|
+
- `pause_with_exponential_backoff` – Set to `true` if you want to double the `pause_timeout` on each consecutive failure of a particular partition.
|
292
|
+
- `socket_timeout` – How long to wait when trying to communicate with a Kafka broker. Default is 30 seconds.
|
293
|
+
- `max_wait_time` – How long to allow the Kafka brokers to wait before returning messages. A higher number means larger batches, at the cost of higher latency. Default is 1 second.
|
294
|
+
- `message_timeout` – How long to try to deliver a produced message before finally giving up. Default is 5 minutes. Transient errors are automatically retried. If a message delivery fails, the current read message batch is retried.
|
295
|
+
- `statistics_interval` – How frequently librdkafka should publish statistics about its consumers and producers; you must also add a `statistics_callback` method to your processor, otherwise the stats are disabled. The default is 1 second, however this can be quite memory hungry, so you may want to tune this and monitor.
|
295
296
|
|
296
297
|
#### Memory & network usage
|
297
298
|
|
@@ -299,55 +300,55 @@ Kafka is _really_ good at throwing data at consumers, so you may want to tune th
|
|
299
300
|
|
300
301
|
Racecar uses [rdkafka-ruby](https://github.com/appsignal/rdkafka-ruby) under the hood, which fetches messages from the Kafka brokers in a background thread. This thread pushes fetch responses, possible containing messages from many partitions, into a queue that is read by the processing thread (AKA your code). The main way to control the fetcher thread is to control the size of those responses and the size of the queue.
|
301
302
|
|
302
|
-
|
303
|
-
|
303
|
+
- `max_bytes` — Maximum amount of data the broker shall return for a Fetch request.
|
304
|
+
- `min_message_queue_size` — The minimum number of messages in the local consumer queue.
|
304
305
|
|
305
306
|
The memory usage limit is roughly estimated as `max_bytes * min_message_queue_size`, plus whatever your application uses.
|
306
307
|
|
307
308
|
#### SSL encryption, authentication & authorization
|
308
309
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
310
|
+
- `security_protocol` – Protocol used to communicate with brokers (`:ssl`)
|
311
|
+
- `ssl_ca_location` – File or directory path to CA certificate(s) for verifying the broker's key
|
312
|
+
- `ssl_crl_location` – Path to CRL for verifying broker's certificate validity
|
313
|
+
- `ssl_keystore_location` – Path to client's keystore (PKCS#12) used for authentication
|
314
|
+
- `ssl_keystore_password` – Client's keystore (PKCS#12) password
|
315
|
+
- `ssl_certificate_location` – Path to the certificate
|
316
|
+
- `ssl_key_location` – Path to client's certificate used for authentication
|
317
|
+
- `ssl_key_password` – Client's certificate password
|
317
318
|
|
318
319
|
#### SASL encryption, authentication & authorization
|
319
320
|
|
320
321
|
Racecar has support for using SASL to authenticate clients using either the GSSAPI or PLAIN mechanism either via plaintext or SSL connection.
|
321
322
|
|
322
|
-
|
323
|
-
|
323
|
+
- `security_protocol` – Protocol used to communicate with brokers (`:sasl_plaintext` `:sasl_ssl`)
|
324
|
+
- `sasl_mechanism` – SASL mechanism to use for authentication (`GSSAPI` `PLAIN` `SCRAM-SHA-256` `SCRAM-SHA-512`)
|
324
325
|
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
326
|
+
- `sasl_kerberos_principal` – This client's Kerberos principal name
|
327
|
+
- `sasl_kerberos_kinit_cmd` – Full kerberos kinit command string, `%{config.prop.name}` is replaced by corresponding config object value, `%{broker.name}` returns the broker's hostname
|
328
|
+
- `sasl_kerberos_keytab` – Path to Kerberos keytab file. Uses system default if not set
|
329
|
+
- `sasl_kerberos_min_time_before_relogin` – Minimum time in milliseconds between key refresh attempts
|
330
|
+
- `sasl_username` – SASL username for use with the PLAIN and SASL-SCRAM-.. mechanism
|
331
|
+
- `sasl_password` – SASL password for use with the PLAIN and SASL-SCRAM-.. mechanism
|
331
332
|
|
332
333
|
#### Producing messages
|
333
334
|
|
334
335
|
These settings are related to consumers that _produce messages to Kafka_.
|
335
336
|
|
336
|
-
|
337
|
+
- `producer_compression_codec` – If defined, Racecar will compress messages before writing them to Kafka. The codec needs to be one of `gzip`, `lz4`, or `snappy`, either as a Symbol or a String.
|
337
338
|
|
338
339
|
#### Datadog monitoring
|
339
340
|
|
340
341
|
Racecar supports [Datadog](https://www.datadoghq.com/) monitoring integration. If you're running a normal Datadog agent on your host, you just need to set `datadog_enabled` to `true`, as the rest of the settings come with sane defaults.
|
341
342
|
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
343
|
+
- `datadog_enabled` – Whether Datadog monitoring is enabled (defaults to `false`).
|
344
|
+
- `datadog_host` – The host running the Datadog agent.
|
345
|
+
- `datadog_port` – The port of the Datadog agent.
|
346
|
+
- `datadog_namespace` – The namespace to use for Datadog metrics.
|
347
|
+
- `datadog_tags` – Tags that should always be set on Datadog metrics.
|
347
348
|
|
348
349
|
Furthermore, there's a [standard Datadog dashboard configution file](https://raw.githubusercontent.com/zendesk/racecar/master/extra/datadog-dashboard.json) that you can import to get started with a Racecar dashboard for all of your consumers.
|
349
350
|
|
350
|
-
#### Consumers Without Rails
|
351
|
+
#### Consumers Without Rails
|
351
352
|
|
352
353
|
By default, if Rails is detected, it will be automatically started when the consumer is started. There are cases where you might not want or need Rails. You can pass the `--without-rails` option when starting the consumer and Rails won't be started.
|
353
354
|
|
@@ -385,7 +386,6 @@ describe CreateContactsConsumer do
|
|
385
386
|
end
|
386
387
|
```
|
387
388
|
|
388
|
-
|
389
389
|
### Deploying consumers
|
390
390
|
|
391
391
|
If you're already deploying your Rails application using e.g. [Capistrano](http://capistranorb.com/), all you need to do to run your Racecar consumers in production is to have some _process supervisor_ start the processes and manage them for you.
|
@@ -397,7 +397,7 @@ racecar-process-payments: bundle exec racecar ProcessPaymentsConsumer
|
|
397
397
|
racecar-resize-images: bundle exec racecar ResizeImagesConsumer
|
398
398
|
```
|
399
399
|
|
400
|
-
If you've ever used Heroku you'll recognize the format – indeed, deploying to Heroku should just work if you add Racecar invocations to your Procfile
|
400
|
+
If you've ever used Heroku you'll recognize the format – indeed, deploying to Heroku should just work if you add Racecar invocations to your Procfile and [enable the Heroku integration](#deploying-to-heroku)
|
401
401
|
|
402
402
|
With Foreman, you can easily run these processes locally by executing `foreman run`; in production you'll want to _export_ to another process management format such as Upstart or Runit. [capistrano-foreman](https://github.com/hyperoslo/capistrano-foreman) allows you to do this with Capistrano.
|
403
403
|
|
@@ -425,20 +425,37 @@ spec:
|
|
425
425
|
app: my-racecar
|
426
426
|
spec:
|
427
427
|
containers:
|
428
|
-
|
429
|
-
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
428
|
+
- name: my-racecar
|
429
|
+
image: my-racecar-image
|
430
|
+
command: ["bundle", "exec", "racecar", "MyConsumer"]
|
431
|
+
env: # <-- you can configure the consumer using environment variables!
|
432
|
+
- name: RACECAR_BROKERS
|
433
|
+
value: kafka1,kafka2,kafka3
|
434
|
+
- name: RACECAR_OFFSET_COMMIT_INTERVAL
|
435
|
+
value: 5
|
436
436
|
```
|
437
437
|
|
438
438
|
The important part is the `strategy.type` value, which tells Kubernetes how to upgrade from one version of your Deployment to another. Many services use so-called _rolling updates_, where some but not all containers are replaced with the new version. This is done so that, if the new version doesn't work, the old version is still there to serve most of the requests. For Kafka consumers, this doesn't work well. The reason is that every time a consumer joins or leaves a group, every other consumer in the group needs to stop and synchronize the list of partitions assigned to each group member. So if the group is updated in a rolling fashion, this synchronization would occur over and over again, causing undesirable double-processing of messages as consumers would start only to be synchronized shortly after.
|
439
439
|
|
440
440
|
Instead, the `Recreate` update strategy should be used. It completely tears down the existing containers before starting all of the new containers simultaneously, allowing for a single synchronization stage and a much faster, more stable deployment update.
|
441
441
|
|
442
|
+
#### Deploying to Heroku
|
443
|
+
|
444
|
+
If you run your applications in Heroku and/or use the Heroku Kafka add-on, you application will be provided with 4 ENV variables that allow connecting to the cluster: `KAFKA_URL`, `KAFKA_TRUSTED_CERT`, `KAFKA_CLIENT_CERT`, and `KAFKA_CLIENT_CERT_KEY`.
|
445
|
+
|
446
|
+
Racecar has a built-in helper for configuring your application based on these variables – just add `require "racecar/heroku"` and everything should just work.
|
447
|
+
|
448
|
+
Please note aliasing the Heroku Kafka add-on will break this integration. If you have a need to do that, please ask on [the discussion board](https://github.com/zendesk/racecar/discussions).
|
449
|
+
|
450
|
+
```ruby
|
451
|
+
# This takes care of setting up your consumer based on the ENV
|
452
|
+
# variables provided by Heroku.
|
453
|
+
require "racecar/heroku"
|
454
|
+
|
455
|
+
class SomeConsumer < Racecar::Consumer
|
456
|
+
# ...
|
457
|
+
end
|
458
|
+
```
|
442
459
|
|
443
460
|
#### Running consumers in the background
|
444
461
|
|
@@ -456,7 +473,6 @@ Since the process is daemonized, you need to know the process id (PID) in order
|
|
456
473
|
|
457
474
|
Again, the recommended approach is to manage the processes using process managers. Only do this if you have to.
|
458
475
|
|
459
|
-
|
460
476
|
### Handling errors
|
461
477
|
|
462
478
|
When processing messages from a Kafka topic, your code may encounter an error and raise an exception. The cause is typically one of two things:
|
@@ -494,26 +510,22 @@ end
|
|
494
510
|
|
495
511
|
It is highly recommended that you set up an error handler. Please note that the `info` object contains different keys and values depending on whether you are using `process` or `process_batch`. See the `instrumentation_payload` object in the `process` and `process_batch` methods in the `Runner` class for the complete list.
|
496
512
|
|
497
|
-
|
498
513
|
### Logging
|
499
514
|
|
500
515
|
By default, Racecar will log to `STDOUT`. If you're using Rails, your application code will use whatever logger you've configured there.
|
501
516
|
|
502
517
|
In order to make Racecar log its own operations to a log file, set the `logfile` configuration variable or pass `--log filename.log` to the `racecar` command.
|
503
518
|
|
504
|
-
|
505
519
|
### Operations
|
506
520
|
|
507
521
|
In order to gracefully shut down a Racecar consumer process, send it the `SIGTERM` signal. Most process supervisors such as Runit and Kubernetes send this signal when shutting down a process, so using those systems will make things easier.
|
508
522
|
|
509
523
|
In order to introspect the configuration of a consumer process, send it the `SIGUSR1` signal. This will make Racecar print its configuration to the standard error file descriptor associated with the consumer process, so you'll need to know where that is written to.
|
510
524
|
|
511
|
-
|
512
525
|
### Upgrading from v1 to v2
|
513
526
|
|
514
527
|
In order to safely upgrade from Racecar v1 to v2, you need to completely shut down your consumer group before starting it up again with the v2 Racecar dependency. In general, you should avoid rolling deploys for consumers groups, so it is likely the case that this will just work for you, but it's a good idea to check first.
|
515
528
|
|
516
|
-
|
517
529
|
## Development
|
518
530
|
|
519
531
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -535,14 +547,12 @@ Please note - your code directory is mounted as a volume, so you can make code c
|
|
535
547
|
|
536
548
|
Bug reports and pull requests are welcome on [GitHub](https://github.com/zendesk/racecar). Feel free to [join our Slack team](https://ruby-kafka-slack.herokuapp.com/) and ask how best to contribute!
|
537
549
|
|
538
|
-
|
539
550
|
## Support and Discussion
|
540
551
|
|
541
552
|
If you've discovered a bug, please file a [Github issue](https://github.com/zendesk/racecar/issues/new), and make sure to include all the relevant information, including the version of Racecar, rdkafka-ruby, and Kafka that you're using.
|
542
553
|
|
543
554
|
If you have other questions, or would like to discuss best practises, or how to contribute to the project, [join our Slack team](https://ruby-kafka-slack.herokuapp.com/)!
|
544
555
|
|
545
|
-
|
546
556
|
## Copyright and license
|
547
557
|
|
548
558
|
Copyright 2017 Daniel Schierbeck & Zendesk
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
# Heroku Kafka addon provides 4 ENVs to connect to their Kafka Broker
|
6
|
+
# KAFKA_TRUSTED_CERT, KAFKA_CLIENT_CERT, KAFKA_CLIENT_CERT_KEY, KAFKA_URL
|
7
|
+
# This will work only if the Heroku Kafka add-on is aliased to "KAFKA"
|
8
|
+
|
9
|
+
$stderr.puts "=> Loading configuration from Heroku Kafka ENVs"
|
10
|
+
|
11
|
+
module Racecar
|
12
|
+
module Heroku
|
13
|
+
def self.load_configuration!
|
14
|
+
[
|
15
|
+
"KAFKA_URL",
|
16
|
+
"KAFKA_TRUSTED_CERT",
|
17
|
+
"KAFKA_CLIENT_CERT",
|
18
|
+
"KAFKA_CLIENT_CERT_KEY"
|
19
|
+
]. each do |env_name|
|
20
|
+
if ENV[env_name].nil?
|
21
|
+
$stderr.puts "Error: ENV #{env_name} is not set"
|
22
|
+
exit 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
Racecar.configure do |config|
|
27
|
+
ca_cert = ENV["KAFKA_TRUSTED_CERT"]
|
28
|
+
client_cert = ENV["KAFKA_CLIENT_CERT"]
|
29
|
+
client_cert_key = ENV["KAFKA_CLIENT_CERT_KEY"]
|
30
|
+
|
31
|
+
tmp_file_path = lambda do |data|
|
32
|
+
tempfile = Tempfile.new(['', '.pem'])
|
33
|
+
tempfile << data
|
34
|
+
tempfile.close
|
35
|
+
tempfile.path
|
36
|
+
end
|
37
|
+
|
38
|
+
config.security_protocol = :ssl
|
39
|
+
config.ssl_ca_location = tmp_file_path.call(ca_cert)
|
40
|
+
config.ssl_certificate_location = tmp_file_path.call(client_cert)
|
41
|
+
config.ssl_key_location = tmp_file_path.call(client_cert_key)
|
42
|
+
|
43
|
+
config.brokers = ENV["KAFKA_URL"].to_s.gsub('kafka+ssl://', '').split(',')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
Racecar::Heroku.load_configuration!
|
data/lib/racecar/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: racecar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.3.0
|
4
|
+
version: 2.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-06-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: king_konf
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- lib/racecar/ctl.rb
|
200
200
|
- lib/racecar/daemon.rb
|
201
201
|
- lib/racecar/datadog.rb
|
202
|
+
- lib/racecar/heroku.rb
|
202
203
|
- lib/racecar/instrumenter.rb
|
203
204
|
- lib/racecar/message.rb
|
204
205
|
- lib/racecar/message_delivery_error.rb
|
@@ -224,9 +225,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
224
225
|
version: '0'
|
225
226
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
226
227
|
requirements:
|
227
|
-
- - "
|
228
|
+
- - ">="
|
228
229
|
- !ruby/object:Gem::Version
|
229
|
-
version:
|
230
|
+
version: '0'
|
230
231
|
requirements: []
|
231
232
|
rubygems_version: 3.1.2
|
232
233
|
signing_key:
|