gitlab-labkit 0.3.0 → 0.4.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 +4 -0
- data/gitlab-labkit.gemspec +2 -1
- data/lib/labkit/tracing/rails.rb +1 -0
- data/lib/labkit/tracing/rails/active_support_subscriber.rb +86 -0
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 657224369b84dd7d1a8d64ee8096c5dfbcaaa7651772f91f3eea2b0efe9eb1f1
|
4
|
+
data.tar.gz: e37e97a6327e03e935efe210dc5ba04aa57adf52d0c78458bbf50e9fb6c44bd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 24f41c7c55ab3530bc62217e6b514c9d2d0ae63528569e12c8693094e3b6da0a8e9fc9679a17c5b281b4ab272b28752522f4d630c4d1e4a5c65cdbdf97c2c6ad
|
7
|
+
data.tar.gz: e2ab5c80c3bbc207e58a816a2f64d524043fc05c0bc4b8baca1124fb42a169bfe03dc89d0023dc383b654ef97a9df14d7d4f14dc045012d3e6ae0e8db7d9feeb
|
data/README.md
CHANGED
@@ -10,6 +10,10 @@ LabKit-Ruby and LabKit are intended to provide similar functionality, but use th
|
|
10
10
|
|
11
11
|
API Documentation is available at [the Rubydoc site](https://www.rubydoc.info/gems/gitlab-labkit/).
|
12
12
|
|
13
|
+
## Changelog
|
14
|
+
|
15
|
+
The changelog is available via [**tagged release notes**](https://gitlab.com/gitlab-org/labkit-ruby/tags)
|
16
|
+
|
13
17
|
## Functionality
|
14
18
|
|
15
19
|
LabKit-Ruby provides functionality in three areas:
|
data/gitlab-labkit.gemspec
CHANGED
@@ -10,7 +10,8 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.email = ["andrew@gitlab.com"]
|
11
11
|
|
12
12
|
spec.summary = "Instrumentation for GitLab"
|
13
|
-
spec.homepage = "
|
13
|
+
spec.homepage = "https://gitlab.com/gitlab-org/labkit-ruby"
|
14
|
+
spec.metadata = { "source_code_uri" => "https://gitlab.com/gitlab-org/labkit-ruby" }
|
14
15
|
spec.license = "MIT"
|
15
16
|
|
16
17
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|tools)/}) }
|
data/lib/labkit/tracing/rails.rb
CHANGED
@@ -6,6 +6,7 @@ module Labkit
|
|
6
6
|
module Rails
|
7
7
|
autoload :ActionViewSubscriber, "labkit/tracing/rails/action_view_subscriber"
|
8
8
|
autoload :ActiveRecordSubscriber, "labkit/tracing/rails/active_record_subscriber"
|
9
|
+
autoload :ActiveSupportSubscriber, "labkit/tracing/rails/active_support_subscriber"
|
9
10
|
autoload :RailsCommon, "labkit/tracing/rails/rails_common"
|
10
11
|
end
|
11
12
|
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Labkit
|
4
|
+
module Tracing
|
5
|
+
module Rails
|
6
|
+
# ActiveSupport bridges action active support notifications to
|
7
|
+
# the distributed tracing subsystem
|
8
|
+
class ActiveSupportSubscriber
|
9
|
+
include RailsCommon
|
10
|
+
|
11
|
+
COMPONENT_TAG = "ActiveSupport"
|
12
|
+
|
13
|
+
CACHE_READ_TOPIC = "cache_read.active_support"
|
14
|
+
CACHE_GENERATE_TOPIC = "cache_generate.active_support"
|
15
|
+
CACHE_FETCH_HIT_TOPIC = "cache_fetch_hit.active_support"
|
16
|
+
CACHE_WRITE_TOPIC = "cache_write.active_support"
|
17
|
+
CACHE_DELETE_TOPIC = "cache_delete.active_support"
|
18
|
+
|
19
|
+
# Instruments Rails ActiveSupport events for opentracing.
|
20
|
+
# Returns a lambda, which, when called will unsubscribe from the notifications
|
21
|
+
def self.instrument
|
22
|
+
subscriber = new
|
23
|
+
|
24
|
+
subscriptions = [
|
25
|
+
ActiveSupport::Notifications.subscribe(CACHE_READ_TOPIC) do |_, start, finish, _, payload|
|
26
|
+
subscriber.notify_cache_read(start, finish, payload)
|
27
|
+
end,
|
28
|
+
ActiveSupport::Notifications.subscribe(CACHE_GENERATE_TOPIC) do |_, start, finish, _, payload|
|
29
|
+
subscriber.notify_cache_generate(start, finish, payload)
|
30
|
+
end,
|
31
|
+
ActiveSupport::Notifications.subscribe(CACHE_FETCH_HIT_TOPIC) do |_, start, finish, _, payload|
|
32
|
+
subscriber.notify_cache_fetch_hit(start, finish, payload)
|
33
|
+
end,
|
34
|
+
ActiveSupport::Notifications.subscribe(CACHE_WRITE_TOPIC) do |_, start, finish, _, payload|
|
35
|
+
subscriber.notify_cache_write(start, finish, payload)
|
36
|
+
end,
|
37
|
+
ActiveSupport::Notifications.subscribe(CACHE_DELETE_TOPIC) do |_, start, finish, _, payload|
|
38
|
+
subscriber.notify_cache_delete(start, finish, payload)
|
39
|
+
end,
|
40
|
+
]
|
41
|
+
|
42
|
+
create_unsubscriber subscriptions
|
43
|
+
end
|
44
|
+
|
45
|
+
# For more information on the payloads: https://guides.rubyonrails.org/active_support_instrumentation.html#active-support
|
46
|
+
def notify_cache_read(start, finish, payload)
|
47
|
+
generate_span_for_notification("cache_read", start, finish, payload, tags_for_cache_read(payload))
|
48
|
+
end
|
49
|
+
|
50
|
+
def notify_cache_generate(start, finish, payload)
|
51
|
+
generate_span_for_notification("cache_generate", start, finish, payload, tags_for_key(payload))
|
52
|
+
end
|
53
|
+
|
54
|
+
def notify_cache_fetch_hit(start, finish, payload)
|
55
|
+
generate_span_for_notification("cache_fetch_hit", start, finish, payload, tags_for_key(payload))
|
56
|
+
end
|
57
|
+
|
58
|
+
def notify_cache_write(start, finish, payload)
|
59
|
+
generate_span_for_notification("cache_write", start, finish, payload, tags_for_key(payload))
|
60
|
+
end
|
61
|
+
|
62
|
+
def notify_cache_delete(start, finish, payload)
|
63
|
+
generate_span_for_notification("cache_delete", start, finish, payload, tags_for_key(payload))
|
64
|
+
end
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def tags_for_cache_read(payload)
|
69
|
+
{
|
70
|
+
"component" => COMPONENT_TAG,
|
71
|
+
"cache.key" => payload[:key],
|
72
|
+
"cache.hit" => payload[:hit],
|
73
|
+
"cache.super_operation" => payload[:super_operation],
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def tags_for_key(payload)
|
78
|
+
{
|
79
|
+
"component" => COMPONENT_TAG,
|
80
|
+
"cache.key" => payload[:key],
|
81
|
+
}
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
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.
|
4
|
+
version: 0.4.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: 2019-
|
11
|
+
date: 2019-07-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -226,16 +226,18 @@ files:
|
|
226
226
|
- lib/labkit/tracing/rails.rb
|
227
227
|
- lib/labkit/tracing/rails/action_view_subscriber.rb
|
228
228
|
- lib/labkit/tracing/rails/active_record_subscriber.rb
|
229
|
+
- lib/labkit/tracing/rails/active_support_subscriber.rb
|
229
230
|
- lib/labkit/tracing/rails/rails_common.rb
|
230
231
|
- lib/labkit/tracing/sidekiq.rb
|
231
232
|
- lib/labkit/tracing/sidekiq/client_middleware.rb
|
232
233
|
- lib/labkit/tracing/sidekiq/server_middleware.rb
|
233
234
|
- lib/labkit/tracing/sidekiq/sidekiq_common.rb
|
234
235
|
- lib/labkit/tracing/tracing_utils.rb
|
235
|
-
homepage:
|
236
|
+
homepage: https://gitlab.com/gitlab-org/labkit-ruby
|
236
237
|
licenses:
|
237
238
|
- MIT
|
238
|
-
metadata:
|
239
|
+
metadata:
|
240
|
+
source_code_uri: https://gitlab.com/gitlab-org/labkit-ruby
|
239
241
|
post_install_message:
|
240
242
|
rdoc_options: []
|
241
243
|
require_paths:
|