govuk_sidekiq 7.0.0 → 7.1.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/README.md +6 -32
- data/lib/govuk_sidekiq/api_headers.rb +3 -0
- data/lib/govuk_sidekiq/govuk_json_formatter.rb +19 -0
- data/lib/govuk_sidekiq/sidekiq_initializer.rb +2 -2
- data/lib/govuk_sidekiq/version.rb +1 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 07e39d37942f15f173005674d60471d56fbe3db4d59d35e67ba5c0e1a33155df
|
4
|
+
data.tar.gz: 3a68c0f33812e2558cb5374b9c56533d2573732702e15eb0e5bc38ef588b63ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1de3bd1211158830997a52e81f3ce1086732d66dc6534c6b4faf08709bd5b16d10555fcf4a571e17abb01b7cc68dea594c5ff07d348f6cea8ad927c1118311f6
|
7
|
+
data.tar.gz: 833611f37c06d5cd8cf621f0115650915aec9e69cf1dd37e3e48d6f66ea3347cf2600eefbe270a4d7e7e3dc783e35909c19d78d78aa13f873117bc4fa6c07dad
|
data/README.md
CHANGED
@@ -13,7 +13,7 @@ What does `govuk_sidekiq` do for you?
|
|
13
13
|
This means that for each request a unique ID (`govuk_request_id`) will be passed on to downstream applications.
|
14
14
|
[Read more about request tracing][req-tracing].
|
15
15
|
3. Makes sure that we use JSON logging, so that Sidekiq logs will end up
|
16
|
-
properly in Kibana.
|
16
|
+
properly in Logit and searchable through Kibana.
|
17
17
|
|
18
18
|
[req-tracing]: https://docs.publishing.service.gov.uk/manual/setting-up-request-tracing.html
|
19
19
|
|
@@ -37,46 +37,20 @@ gem "govuk_sidekiq"
|
|
37
37
|
This file also allows you to configure queues with priority.
|
38
38
|
[See the Sidekiq wiki for available options](https://github.com/mperham/sidekiq/wiki/Advanced-Options).
|
39
39
|
|
40
|
-
### 3.
|
40
|
+
### 3. Configure environment variables in EKS
|
41
41
|
|
42
|
-
|
42
|
+
For each environment ([integration](https://github.com/alphagov/govuk-helm-charts/blob/main/charts/app-config/values-integration.yaml), [staging](https://github.com/alphagov/govuk-helm-charts/blob/main/charts/app-config/values-staging.yaml) and [production](https://github.com/alphagov/govuk-helm-charts/blob/main/charts/app-config/values-production.yaml)), add a `REDIS_URL` environment variable for your application with a value of `redis://shared-redis-govuk.eks.{environment}.govuk-internal.digital`.
|
43
43
|
|
44
|
-
|
45
|
-
# Procfile
|
46
|
-
worker: bundle exec sidekiq -C ./config/sidekiq.yml
|
47
|
-
```
|
48
|
-
|
49
|
-
### 4. Configure puppet
|
50
|
-
|
51
|
-
- Set a `REDIS_URL` environment variable. `GOVUK_APP_NAME` should also be
|
52
|
-
set, but this is already done by the default `govuk::app::config`.
|
53
|
-
|
54
|
-
Apply redis variables for your app in [the default config](https://github.com/alphagov/govuk-puppet/blob/main/hieradata_aws/common.yaml). For example:
|
55
|
-
|
56
|
-
```
|
57
|
-
govuk::apps::your_app::redis_host: "%{hiera('sidekiq_host')}"
|
58
|
-
govuk::apps::your_app::redis_port: "%{hiera('sidekiq_port')}"
|
59
|
-
```
|
60
|
-
- Make sure puppet creates and starts the Procfile worker.
|
44
|
+
Additionally, set the value of `workerEnabled` to `true` for your application. This will [result in a `worker` process](https://github.com/alphagov/govuk-helm-charts/blob/8b008832b5e8f62f2f489d3b030be21945d2b08b/charts/generic-govuk-app/values.yaml#L16-L21) running alongside the web application. The queue length and max delay can be monitored using the [Sidekiq Grafana dashboard](https://grafana.eks.production.govuk.digital/d/sidekiq-queues), once the Sidekiq worker is initialised.
|
61
45
|
|
62
|
-
There's no step-by-step guide for this, but [you can copy the
|
63
|
-
|
64
|
-
### 5. Configure deployment scripts
|
65
|
-
|
66
|
-
Make sure you restart the worker after deploying by adding a hook to the [capistrano scripts in govuk-app-deployment](https://github.com/alphagov/govuk-app-deployment). Otherwise the worker will keep running old code.
|
46
|
+
There's no step-by-step guide for this, but [you can copy the changes made when Sidekiq was added to the release application](https://github.com/alphagov/govuk-helm-charts/pull/1117/files). You may also want to [resize resource requests](https://github.com/alphagov/govuk-helm-charts/pull/1121/files) for the app depending on the predicted request rate.
|
67
47
|
|
68
48
|
```ruby
|
69
49
|
# your-application/config/deploy.rb
|
70
50
|
after "deploy:restart", "deploy:restart_procfile_worker"
|
71
51
|
```
|
72
52
|
|
73
|
-
###
|
74
|
-
|
75
|
-
See the dev docs for a step-by-step guide: [Add sidekiq-monitoring to your application][monitoring]
|
76
|
-
|
77
|
-
[monitoring]: https://docs.publishing.service.gov.uk/manual/setting-up-new-sidekiq-monitoring-app.html
|
78
|
-
|
79
|
-
### 8. Create some jobs
|
53
|
+
### 4. Create some jobs
|
80
54
|
|
81
55
|
You can [use normal Sidekiq jobs](https://github.com/mperham/sidekiq/wiki/Getting-Started):
|
82
56
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require "gds_api/govuk_headers"
|
2
|
+
require "sidekiq"
|
2
3
|
|
3
4
|
module GovukSidekiq
|
4
5
|
module APIHeaders
|
@@ -16,6 +17,7 @@ module GovukSidekiq
|
|
16
17
|
else
|
17
18
|
job["args"] << header_arguments
|
18
19
|
end
|
20
|
+
Sidekiq::Context.add("govuk_request_id", job["args"].last["request_id"])
|
19
21
|
|
20
22
|
yield
|
21
23
|
end
|
@@ -45,6 +47,7 @@ module GovukSidekiq
|
|
45
47
|
authenticated_user = last_arg["authenticated_user"]
|
46
48
|
GdsApi::GovukHeaders.set_header(:govuk_request_id, request_id)
|
47
49
|
GdsApi::GovukHeaders.set_header(:x_govuk_authenticated_user, authenticated_user)
|
50
|
+
Sidekiq::Context.add("govuk_request_id", request_id)
|
48
51
|
end
|
49
52
|
|
50
53
|
yield
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "sidekiq"
|
2
|
+
require "govuk_sidekiq/api_headers"
|
3
|
+
|
4
|
+
module GovukSidekiq
|
5
|
+
class GovukJsonFormatter < Sidekiq::Logger::Formatters::Base
|
6
|
+
def call(severity, time, _, message)
|
7
|
+
hash = {
|
8
|
+
"@timestamp": time.utc.iso8601(3),
|
9
|
+
pid: ::Process.pid,
|
10
|
+
tid: tid,
|
11
|
+
level: severity,
|
12
|
+
message: message,
|
13
|
+
tags: %w[sidekiq],
|
14
|
+
}
|
15
|
+
ctx.each { |key, value| hash[key] = value unless hash[key] }
|
16
|
+
Sidekiq.dump_json(hash) << "\n"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "sidekiq"
|
2
2
|
require "govuk_sidekiq/api_headers"
|
3
|
+
require "govuk_sidekiq/govuk_json_formatter"
|
3
4
|
|
4
5
|
module GovukSidekiq
|
5
6
|
module SidekiqInitializer
|
@@ -10,8 +11,6 @@ module GovukSidekiq
|
|
10
11
|
)
|
11
12
|
|
12
13
|
Sidekiq.configure_server do |config|
|
13
|
-
config.log_formatter = Sidekiq::Logger::Formatters::JSON.new if ENV["GOVUK_SIDEKIQ_JSON_LOGGING"]
|
14
|
-
|
15
14
|
# $real_stdout is defined by govuk_app_config and is used to point to
|
16
15
|
# STDOUT as that redirects $stdout to actually be $stderr.
|
17
16
|
# When govuk_app_config does this we need to use $real_stdout to output logs to STDOUT.
|
@@ -20,6 +19,7 @@ module GovukSidekiq
|
|
20
19
|
# rubocop:disable Style/GlobalVars
|
21
20
|
config.logger = Sidekiq::Logger.new($real_stdout) if defined?($real_stdout)
|
22
21
|
# rubocop:enable Style/GlobalVars
|
22
|
+
config.log_formatter = GovukSidekiq::GovukJsonFormatter.new if ENV["GOVUK_SIDEKIQ_JSON_LOGGING"]
|
23
23
|
|
24
24
|
config.redis = redis_config
|
25
25
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: govuk_sidekiq
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 7.
|
4
|
+
version: 7.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- GOV.UK Dev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-06-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gds-api-adapters
|
@@ -147,6 +147,7 @@ files:
|
|
147
147
|
- README.md
|
148
148
|
- lib/govuk_sidekiq.rb
|
149
149
|
- lib/govuk_sidekiq/api_headers.rb
|
150
|
+
- lib/govuk_sidekiq/govuk_json_formatter.rb
|
150
151
|
- lib/govuk_sidekiq/railtie.rb
|
151
152
|
- lib/govuk_sidekiq/sidekiq_initializer.rb
|
152
153
|
- lib/govuk_sidekiq/testing.rb
|
@@ -170,7 +171,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
170
171
|
- !ruby/object:Gem::Version
|
171
172
|
version: '0'
|
172
173
|
requirements: []
|
173
|
-
rubygems_version: 3.4.
|
174
|
+
rubygems_version: 3.4.14
|
174
175
|
signing_key:
|
175
176
|
specification_version: 4
|
176
177
|
summary: Provides standard setup and behaviour for Sidekiq in GOV.UK applications.
|