govuk_sidekiq 7.0.0 → 7.1.1

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
  SHA256:
3
- metadata.gz: b7dcf56fdac303296683242e648f7d5870dffdc4d635bba94e248850c09e8012
4
- data.tar.gz: 82db38cec99745be8126a12009baaae8358bb16b1c580bb6f6755fe4ffffd36f
3
+ metadata.gz: 56054924f4361476e4bcb29b2d0011f8044a2d70ff1219893ae2379302ebf205
4
+ data.tar.gz: 46f695eb3cb5f8591d5bb63714119667c10f4cbce39ff856c42302bdf1420a9d
5
5
  SHA512:
6
- metadata.gz: 8cce38baca997da9cf804ebe2a1021fd29f7f8a5a9b770b3eef02167bfd308d09cb1ce82e262be7c83e83a4fce54dbef7cb42b5dd89fb6aaf9e914671d7e18a0
7
- data.tar.gz: 7905fdb2c6b155fdbaf539df1d8b27539758641173475512c93370832eb1131fd2aee23e42c54d984c5b8e28d711779f036af65d550d779d4c80fa0e2f8c8f89
6
+ metadata.gz: 96f130529933bd9e0b15ba0b3f397d30d431e5af6c81d617d0992c29f6e4da0dcd82e9a5dcc600b949466ee387758217c914fba9e90fb1a6574805be3f3410af
7
+ data.tar.gz: 6641da6afb6e10d8ac310ad0cf416d7b94243d68f0bc09ccfa0e5e97f042cce5095c2cd22cf0436f78a255753c3007eddc8b44b6fe065afccebd3c76065f3a27
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. Add a Procfile
40
+ ### 3. Configure environment variables in EKS
41
41
 
42
- This is what puppet uses to create the process.
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
- ```sh
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 config from collections-publisher](https://github.com/alphagov/govuk-puppet/blob/main/modules/govuk/manifests/apps/collections_publisher.pp).
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
- ### 6. Add app to sidekiq-monitoring
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
@@ -9,14 +10,12 @@ module GovukSidekiq
9
10
  class ClientMiddleware
10
11
  def call(_worker_class, job, _queue, _redis_pool)
11
12
  last_arg = job["args"].last
12
-
13
13
  if is_header_hash(last_arg)
14
14
  job["args"].pop
15
15
  job["args"] << header_arguments.merge(last_arg)
16
16
  else
17
17
  job["args"] << header_arguments
18
18
  end
19
-
20
19
  yield
21
20
  end
22
21
 
@@ -45,6 +44,7 @@ module GovukSidekiq
45
44
  authenticated_user = last_arg["authenticated_user"]
46
45
  GdsApi::GovukHeaders.set_header(:govuk_request_id, request_id)
47
46
  GdsApi::GovukHeaders.set_header(:x_govuk_authenticated_user, authenticated_user)
47
+ Sidekiq::Context.add("govuk_request_id", request_id)
48
48
  end
49
49
 
50
50
  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
 
@@ -1,3 +1,3 @@
1
1
  module GovukSidekiq
2
- VERSION = "7.0.0".freeze
2
+ VERSION = "7.1.1".freeze
3
3
  end
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.0.0
4
+ version: 7.1.1
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-05-23 00:00:00.000000000 Z
11
+ date: 2023-06-22 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.13
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.