gitlab-labkit 0.9.1 → 0.10.0

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: 4c6a4f92530f7662034e9a67cda9b6f1587cce729502a088ef9b6777659b0bdc
4
- data.tar.gz: 1f17a19f8e2f7a0f052c4474caaaf0fd1d3a291a77de67b4184000fb12a599de
3
+ metadata.gz: 198c31e6a0717be721e68fb8e68e145e24f66ae17338eccc80c0c4e94f638be6
4
+ data.tar.gz: e6ee6cf53603f78442d96b89bf8edf2720ee334d9441042dd9167fa9328a4406
5
5
  SHA512:
6
- metadata.gz: 2a50b5944898571c6fa9038eed5d35ec3d560c684c7363e1779aa8b4ec1363e8533e51667ae868b961562a3d3195cc9ac1f8b27e6e76204290439a735b61f5bc
7
- data.tar.gz: d96aeafefa46bb244fc7371165fed6f91e47326d60463f8d25685d50081b63a8651c2b5dee7656094d5fb87085a58dd44459aafc64621b32a083dde3eaf7180e
6
+ metadata.gz: 00544f82819064032c9bd3105ed265c56e078e9204702b9b91ed28f4ba760ae4481f1b766b9c0832a9648efa8c55212ef641d008d82912bb0dfab1ca8a9d2868
7
+ data.tar.gz: 0b195fec25f24758afb2df4d17dc639388e537258f08182bcc3a5162253b8efab493578e11a99d2bf86370ecd476ea467cce49ffeafe372e5be3def4f15141b3
data/README.md CHANGED
@@ -18,7 +18,8 @@ The changelog is available via [**tagged release notes**](https://gitlab.com/git
18
18
 
19
19
  LabKit-Ruby provides functionality in three areas:
20
20
 
21
- 1. `Labkit::Correlation` for handling and propagating Correlation-IDs.
21
+ 1. `Labkit::Context` used for providing context information to log messages.
22
+ 1. `Labkit::Correlation` For accessing the correlation id. (Generated and propagated by `Labkit::Context`)
22
23
  1. `Labkit::Logging` for sanitizing log messages.
23
24
  1. `Labkit::Tracing` for handling and propagating distributed traces.
24
25
 
@@ -41,3 +42,16 @@ $ bundle exec rake verify
41
42
  Note that LabKit-Ruby uses the [`rufo`](https://github.com/ruby-formatter/rufo) for auto-formatting. Please run `bundle exec rake fix` to auto-format your code before pushing.
42
43
 
43
44
  Please also review the [development section of the LabKit (go) README](https://gitlab.com/gitlab-org/labkit#developing-labkit) for details of the LabKit architectural philosophy.
45
+
46
+ ### Releasing a new version
47
+
48
+ Releasing a new version can be done by pushing a new tag, or creating
49
+ it from the
50
+ [interface](https://gitlab.com/gitlab-org/labkit-ruby/-/tags).
51
+
52
+ A new changelog will automatically be added to the release on Gitlab.
53
+
54
+ The new version will automatically be published to
55
+ [rubygems](https://rubygems.org/gems/gitlab-labkit) when the pipeline
56
+ for the tag completes. It might take a few minutes before the update
57
+ is available.
@@ -6,6 +6,8 @@ module Labkit
6
6
  module Sidekiq
7
7
  autoload :Client, "labkit/middleware/sidekiq/client"
8
8
  autoload :Server, "labkit/middleware/sidekiq/server"
9
+ autoload :Context, "labkit/middleware/sidekiq/context"
10
+ autoload :Tracing, "labkit/middleware/sidekiq/tracing"
9
11
  end
10
12
  end
11
13
  end
@@ -3,14 +3,21 @@
3
3
  module Labkit
4
4
  module Middleware
5
5
  module Sidekiq
6
- # This middleware for Sidekiq-client wraps scheduling jobs in a context
7
- # The context will also be added to the sidekiq job in redis so it can
8
- # be reinstantiated by Sidekiq-server when running the job.
6
+ # This is a wrapper around all the sidekiq client-middleware in labkit
7
+ # The only middleware that needs to be added to the chain in GitLab-rails
8
+ #
9
+ # It uses a new `Sidekiq::Middleware::Chain` to string multiple middlewares
10
+ # together.
9
11
  class Client
10
- def call(_worker_class, job, _queue, _redis_pool)
11
- Labkit::Context.with_context do |context|
12
- job.merge!(context.to_h)
12
+ def self.chain
13
+ @chain ||= ::Sidekiq::Middleware::Chain.new do |chain|
14
+ chain.add Labkit::Middleware::Sidekiq::Context::Client
15
+ chain.add Labkit::Middleware::Sidekiq::Tracing::Client if Labkit::Tracing.enabled?
16
+ end
17
+ end
13
18
 
19
+ def call(*args)
20
+ self.class.chain.invoke(*args) do
14
21
  yield
15
22
  end
16
23
  end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Middleware
5
+ module Sidekiq
6
+ # This module contains all the sidekiq middleware regarding application
7
+ # context
8
+ module Context
9
+ autoload :Client, "labkit/middleware/sidekiq/context/client"
10
+ autoload :Server, "labkit/middleware/sidekiq/context/server"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Middleware
5
+ module Sidekiq
6
+ module Context
7
+ # This middleware for Sidekiq-client wraps scheduling jobs in a context
8
+ # The context will also be added to the sidekiq job in redis so it can
9
+ # be reinstantiated by Sidekiq-server when running the job.
10
+ class Client
11
+ def call(_worker_class, job, _queue, _redis_pool)
12
+ Labkit::Context.with_context do |context|
13
+ job.merge!(context.to_h)
14
+
15
+ yield
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Middleware
5
+ module Sidekiq
6
+ module Context
7
+ # This middleware for Sidekiq-client uses the values stored on a job to
8
+ # reinstantiate a context in which the job will run.
9
+ class Server
10
+ def call(_worker_class, job, _queue)
11
+ data = job.merge(Labkit::Context.log_key(:caller_id) => job["class"])
12
+
13
+ Labkit::Context.with_context(data) do |_context|
14
+ yield
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -3,13 +3,21 @@
3
3
  module Labkit
4
4
  module Middleware
5
5
  module Sidekiq
6
- # This middleware for Sidekiq-client uses the values stored on a job to
7
- # reinstantiate a context in which the job will run.
6
+ # This is a wrapper around all the sidekiq server-middleware in labkit
7
+ # The only middleware that needs to be added to the chain in GitLab-rails
8
+ #
9
+ # It uses a new `Sidekiq::Middleware::Chain` to string multiple middlewares
10
+ # together.
8
11
  class Server
9
- def call(_worker_class, job, _queue)
10
- data = job.merge(Labkit::Context.log_key(:caller_id) => job["class"])
12
+ def self.chain
13
+ @chain ||= ::Sidekiq::Middleware::Chain.new do |chain|
14
+ chain.add Labkit::Middleware::Sidekiq::Context::Server
15
+ chain.add Labkit::Middleware::Sidekiq::Tracing::Server if Labkit::Tracing.enabled?
16
+ end
17
+ end
11
18
 
12
- Labkit::Context.with_context(data) do |_context|
19
+ def call(*args)
20
+ self.class.chain.invoke(*args) do
13
21
  yield
14
22
  end
15
23
  end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Middleware
5
+ module Sidekiq
6
+ # Sidekiq provides classes for instrumenting Sidekiq client and server
7
+ # functionality
8
+ module Tracing
9
+ autoload :Client, "labkit/middleware/sidekiq/tracing/client"
10
+ autoload :Server, "labkit/middleware/sidekiq/tracing/server"
11
+ autoload :SidekiqCommon, "labkit/middleware/sidekiq/tracing/sidekiq_common"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "opentracing"
4
+
5
+ module Labkit
6
+ module Middleware
7
+ module Sidekiq
8
+ module Tracing
9
+ # Client provides a sidekiq client middleware for
10
+ # instrumenting distributed tracing calls made from the client
11
+ # application
12
+ class Client
13
+ include SidekiqCommon
14
+
15
+ SPAN_KIND = "client"
16
+
17
+ def call(_worker_class, job, _queue, _redis_pool)
18
+ Labkit::Tracing::TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", tags: tags_from_job(job, SPAN_KIND)) do |span|
19
+ # Inject the details directly into the job
20
+ Labkit::Tracing::TracingUtils.tracer.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, job)
21
+
22
+ yield
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "opentracing"
4
+
5
+ module Labkit
6
+ module Middleware
7
+ module Sidekiq
8
+ module Tracing
9
+ # Server provides a sidekiq server middleware for
10
+ # instrumenting distributed tracing calls when they are
11
+ # executed by the Sidekiq server
12
+ class Server
13
+ include SidekiqCommon
14
+
15
+ SPAN_KIND = "server"
16
+
17
+ def call(_worker, job, _queue)
18
+ context = Labkit::Tracing::TracingUtils.tracer.extract(OpenTracing::FORMAT_TEXT_MAP, job)
19
+
20
+ Labkit::Tracing::TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", child_of: context, tags: tags_from_job(job, SPAN_KIND)) { |_span| yield }
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Labkit
4
+ module Middleware
5
+ module Sidekiq
6
+ module Tracing
7
+ # SidekiqCommon is a mixin for the sidekiq middleware components
8
+ module SidekiqCommon
9
+ def tags_from_job(job, kind)
10
+ {
11
+ "component" => "sidekiq",
12
+ "span.kind" => kind,
13
+ "sidekiq.queue" => job["queue"],
14
+ "sidekiq.jid" => job["jid"],
15
+ "sidekiq.retry" => job["retry"].to_s,
16
+ "sidekiq.args" => job["args"]&.join(", "),
17
+ }
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-labkit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Newdigate
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-01-20 00:00:00.000000000 Z
11
+ date: 2020-02-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack
@@ -284,7 +284,14 @@ files:
284
284
  - lib/labkit/middleware/rack.rb
285
285
  - lib/labkit/middleware/sidekiq.rb
286
286
  - lib/labkit/middleware/sidekiq/client.rb
287
+ - lib/labkit/middleware/sidekiq/context.rb
288
+ - lib/labkit/middleware/sidekiq/context/client.rb
289
+ - lib/labkit/middleware/sidekiq/context/server.rb
287
290
  - lib/labkit/middleware/sidekiq/server.rb
291
+ - lib/labkit/middleware/sidekiq/tracing.rb
292
+ - lib/labkit/middleware/sidekiq/tracing/client.rb
293
+ - lib/labkit/middleware/sidekiq/tracing/server.rb
294
+ - lib/labkit/middleware/sidekiq/tracing/sidekiq_common.rb
288
295
  - lib/labkit/tracing.rb
289
296
  - lib/labkit/tracing/factory.rb
290
297
  - lib/labkit/tracing/grpc.rb
@@ -301,10 +308,6 @@ files:
301
308
  - lib/labkit/tracing/redis.rb
302
309
  - lib/labkit/tracing/redis/redis_interceptor.rb
303
310
  - lib/labkit/tracing/redis/redis_interceptor_helper.rb
304
- - lib/labkit/tracing/sidekiq.rb
305
- - lib/labkit/tracing/sidekiq/client_middleware.rb
306
- - lib/labkit/tracing/sidekiq/server_middleware.rb
307
- - lib/labkit/tracing/sidekiq/sidekiq_common.rb
308
311
  - lib/labkit/tracing/tracing_utils.rb
309
312
  homepage: https://gitlab.com/gitlab-org/labkit-ruby
310
313
  licenses:
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Labkit
4
- module Tracing
5
- # Sidekiq provides classes for instrumenting Sidekiq client and server
6
- # functionality
7
- module Sidekiq
8
- autoload :ClientMiddleware, "labkit/tracing/sidekiq/client_middleware"
9
- autoload :ServerMiddleware, "labkit/tracing/sidekiq/server_middleware"
10
- autoload :SidekiqCommon, "labkit/tracing/sidekiq/sidekiq_common"
11
- end
12
- end
13
- end
@@ -1,27 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "opentracing"
4
-
5
- module Labkit
6
- module Tracing
7
- module Sidekiq
8
- # ClientMiddleware provides a sidekiq client middleware for
9
- # instrumenting distributed tracing calls made from the client
10
- # application
11
- class ClientMiddleware
12
- include SidekiqCommon
13
-
14
- SPAN_KIND = "client"
15
-
16
- def call(_worker_class, job, _queue, _redis_pool)
17
- TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", tags: tags_from_job(job, SPAN_KIND)) do |span|
18
- # Inject the details directly into the job
19
- TracingUtils.tracer.inject(span.context, OpenTracing::FORMAT_TEXT_MAP, job)
20
-
21
- yield
22
- end
23
- end
24
- end
25
- end
26
- end
27
- end
@@ -1,24 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "opentracing"
4
-
5
- module Labkit
6
- module Tracing
7
- module Sidekiq
8
- # ServerMiddleware provides a sidekiq server middleware for
9
- # instrumenting distributed tracing calls when they are
10
- # executed by the Sidekiq server
11
- class ServerMiddleware
12
- include SidekiqCommon
13
-
14
- SPAN_KIND = "server"
15
-
16
- def call(_worker, job, _queue)
17
- context = TracingUtils.tracer.extract(OpenTracing::FORMAT_TEXT_MAP, job)
18
-
19
- TracingUtils.with_tracing(operation_name: "sidekiq:#{job["class"]}", child_of: context, tags: tags_from_job(job, SPAN_KIND)) { |_span| yield }
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,21 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Labkit
4
- module Tracing
5
- module Sidekiq
6
- # SidekiqCommon is a mixin for the sidekiq middleware components
7
- module SidekiqCommon
8
- def tags_from_job(job, kind)
9
- {
10
- "component" => "sidekiq",
11
- "span.kind" => kind,
12
- "sidekiq.queue" => job["queue"],
13
- "sidekiq.jid" => job["jid"],
14
- "sidekiq.retry" => job["retry"].to_s,
15
- "sidekiq.args" => job["args"]&.join(", "),
16
- }
17
- end
18
- end
19
- end
20
- end
21
- end