nexus_semantic_logger 1.11.6 → 1.12.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: c3f367c4597a558ce34338e3378f03c014de4745b3fa3b107629eb28c4be03d0
4
- data.tar.gz: 06b199a9c633825110cefdc2bd10272dff2d6e88340b1fd91296994108236b6e
3
+ metadata.gz: 903718bb8acb37308fee8d2b0739ae7a708538a6372029d50f198229646cca93
4
+ data.tar.gz: 4c40fdfa07c84b82938b4ca185aec63840d35f86222fdd3cdf058a0e4c453c27
5
5
  SHA512:
6
- metadata.gz: a071e056de2fd4a4a86112b382b3de49a3d6b0d80beca2a430141fbef69aa3075a3082d9a59f211c10040c4999a4d7eca4c7e72470275ef1f229011842a794c3
7
- data.tar.gz: 2814af602f6693ab6076cbf2d1c922c5cbefb8b8ae5520bf03efc6860c8448fb95e7cee81325aae98d1bcf707ff8dc23ec4fc309ea77ab4ae7e41274501da7f3
6
+ metadata.gz: 7d30a09cc0440a01ea89fc0cc48e04e883ec955e05749c5b7b406dd2b1013dc540f1e9a2e2a95befba6f8248b2f970440bdb53ab28dce572fb6f2c45794cd3d1
7
+ data.tar.gz: 15ae5d8e3bfad2eab8f81649a27b2755a302f04e00eea1248738edba543ab2824d56bd6298608c13a1a7eb8953eac6bf88183fe8530fa6eacb753a351a4583eb
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
  module NexusSemanticLogger
3
- # Leave this as 1.11.6 in order for CI process to replace with the tagged version.
4
- VERSION = '1.11.6'
3
+ # Leave this as 1.12.1 in order for CI process to replace with the tagged version.
4
+ VERSION = '1.12.1'
5
5
  end
@@ -0,0 +1 @@
1
+ Forked from https://github.com/yob/puma-plugin-statsd
@@ -0,0 +1,174 @@
1
+ # frozen_string_literal: true
2
+ require 'puma'
3
+ require 'puma/plugin'
4
+ require 'socket'
5
+ require 'nexus_semantic_logger'
6
+
7
+ # Forked from puma-plugin-statsd.
8
+ # Uses the same datadog settings as nexus_semantic_logger.
9
+ # To use, add to puma.rb:
10
+ # plugin :nexus_puma_statsd
11
+
12
+ # Wrap puma's stats in a safe API
13
+ class PumaStats
14
+ def initialize(stats)
15
+ @stats = stats
16
+ end
17
+
18
+ def clustered?
19
+ @stats.key?(:workers)
20
+ end
21
+
22
+ def workers
23
+ @stats.fetch(:workers, 1)
24
+ end
25
+
26
+ def booted_workers
27
+ @stats.fetch(:booted_workers, 1)
28
+ end
29
+
30
+ def old_workers
31
+ @stats.fetch(:old_workers, 0)
32
+ end
33
+
34
+ def running
35
+ if clustered?
36
+ @stats[:worker_status].map { |s| s[:last_status].fetch(:running, 0) }.inject(0, &:+)
37
+ else
38
+ @stats.fetch(:running, 0)
39
+ end
40
+ end
41
+
42
+ def backlog
43
+ if clustered?
44
+ @stats[:worker_status].map { |s| s[:last_status].fetch(:backlog, 0) }.inject(0, &:+)
45
+ else
46
+ @stats.fetch(:backlog, 0)
47
+ end
48
+ end
49
+
50
+ def pool_capacity
51
+ if clustered?
52
+ @stats[:worker_status].map { |s| s[:last_status].fetch(:pool_capacity, 0) }.inject(0, &:+)
53
+ else
54
+ @stats.fetch(:pool_capacity, 0)
55
+ end
56
+ end
57
+
58
+ def max_threads
59
+ if clustered?
60
+ @stats[:worker_status].map { |s| s[:last_status].fetch(:max_threads, 0) }.inject(0, &:+)
61
+ else
62
+ @stats.fetch(:max_threads, 0)
63
+ end
64
+ end
65
+
66
+ def requests_count
67
+ if clustered?
68
+ @stats[:worker_status].map { |s| s[:last_status].fetch(:requests_count, 0) }.inject(0, &:+)
69
+ else
70
+ @stats.fetch(:requests_count, 0)
71
+ end
72
+ end
73
+ end
74
+
75
+ Puma::Plugin.create do
76
+ # We can start doing something when we have a launcher:
77
+ def start(launcher)
78
+ @launcher = launcher
79
+ @log_writer =
80
+ if Gem::Version.new(Puma::Const::PUMA_VERSION) >= Gem::Version.new(6)
81
+ @launcher.log_writer
82
+ else
83
+ @launcher.events
84
+ end
85
+
86
+ @log_writer.debug('statsd: enabled')
87
+
88
+ register_hooks
89
+ end
90
+
91
+ private
92
+
93
+ def register_hooks
94
+ in_background(&method(:stats_loop))
95
+ end
96
+
97
+ def environment_variable_tags
98
+ # Tags are separated by spaces, and while they are normally a tag and
99
+ # value separated by a ':', they can also just be tagged without any
100
+ # associated value.
101
+ #
102
+ # Examples: simple-tag-0 tag-key-1:tag-value-1
103
+ #
104
+ tags = []
105
+
106
+ if ENV.key?('HOSTNAME')
107
+ tags << "pod_name:#{ENV['HOSTNAME']}"
108
+ end
109
+
110
+ # Standardised datadog tag attributes, so that we can share the metric
111
+ # tags with the application running
112
+ #
113
+ # https://docs.datadoghq.com/agent/docker/?tab=standard#global-options
114
+ #
115
+ if ENV.key?("DD_TAGS")
116
+ ENV["DD_TAGS"].split(/\s+|,/).each do |t|
117
+ tags << t
118
+ end
119
+ end
120
+
121
+ # Support the Unified Service Tagging from Datadog, so that we can share
122
+ # the metric tags with the application running
123
+ #
124
+ # https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging
125
+ if ENV.key?('DD_ENV')
126
+ tags << "env:#{ENV['DD_ENV']}"
127
+ end
128
+
129
+ if ENV.key?('DD_SERVICE')
130
+ tags << "service:#{ENV['DD_SERVICE']}"
131
+ end
132
+
133
+ if ENV.key?('DD_VERSION')
134
+ tags << "version:#{ENV['DD_VERSION']}"
135
+ end
136
+
137
+ # Support the origin detection over UDP from Datadog, it allows DogStatsD
138
+ # to detect where the container metrics come from, and tag metrics automatically.
139
+ #
140
+ # https://docs.datadoghq.com/developers/dogstatsd/?tab=kubernetes#origin-detection-over-udp
141
+ if ENV.key?('DD_ENTITY_ID')
142
+ tags << "dd.internal.entity_id:#{ENV['DD_ENTITY_ID']}"
143
+ end
144
+
145
+ return nil if tags.empty?
146
+
147
+ tags
148
+ end
149
+
150
+ # Send data to statsd every few seconds
151
+ def stats_loop
152
+ tags = environment_variable_tags
153
+
154
+ sleep(5)
155
+ loop do
156
+ @log_writer.debug('statsd: notify statsd')
157
+ begin
158
+ stats = ::PumaStats.new(Puma.stats_hash)
159
+ NexusSemanticLogger.metrics.gauge('puma.workers', stats.workers, tags: tags)
160
+ NexusSemanticLogger.metrics.gauge('puma.booted_workers', stats.booted_workers, tags: tags)
161
+ NexusSemanticLogger.metrics.gauge('puma.old_workers', stats.old_workers, tags: tags)
162
+ NexusSemanticLogger.metrics.gauge('puma.running', stats.running, tags: tags)
163
+ NexusSemanticLogger.metrics.gauge('puma.backlog', stats.backlog, tags: tags)
164
+ NexusSemanticLogger.metrics.gauge('puma.pool_capacity', stats.pool_capacity, tags: tags)
165
+ NexusSemanticLogger.metrics.gauge('puma.max_threads', stats.max_threads, tags: tags)
166
+ NexusSemanticLogger.metrics.gauge('puma.requests_count', stats.requests_count, tags: tags)
167
+ rescue StandardError => e
168
+ @log_writer.unknown_error(e, nil, '! statsd: notify stats failed')
169
+ ensure
170
+ sleep(2)
171
+ end
172
+ end
173
+ end
174
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nexus_semantic_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.6
4
+ version: 1.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johnathon Harris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-03-01 00:00:00.000000000 Z
11
+ date: 2023-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: amazing_print
@@ -116,6 +116,8 @@ files:
116
116
  - lib/nexus_semantic_logger/logger_metrics_subscriber.rb
117
117
  - lib/nexus_semantic_logger/sneakers_metrics.rb
118
118
  - lib/nexus_semantic_logger/version.rb
119
+ - lib/puma/plugin/README.md
120
+ - lib/puma/plugin/nexus_puma_statsd.rb
119
121
  - nexus_semantic_logger.gemspec
120
122
  homepage:
121
123
  licenses: []
@@ -135,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
137
  - !ruby/object:Gem::Version
136
138
  version: '0'
137
139
  requirements: []
138
- rubygems_version: 3.4.7
140
+ rubygems_version: 3.4.13
139
141
  signing_key:
140
142
  specification_version: 4
141
143
  summary: semantic_logger usage for nexus