vinted-prometheus-client-mmap 1.5.0-x86_64-linux

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +5 -0
  3. data/ext/fast_mmaped_file_rs/Cargo.toml +40 -0
  4. data/ext/fast_mmaped_file_rs/README.md +52 -0
  5. data/ext/fast_mmaped_file_rs/build.rs +7 -0
  6. data/ext/fast_mmaped_file_rs/extconf.rb +28 -0
  7. data/ext/fast_mmaped_file_rs/src/error.rs +174 -0
  8. data/ext/fast_mmaped_file_rs/src/exemplars.rs +25 -0
  9. data/ext/fast_mmaped_file_rs/src/file_entry.rs +1252 -0
  10. data/ext/fast_mmaped_file_rs/src/file_info.rs +240 -0
  11. data/ext/fast_mmaped_file_rs/src/lib.rs +89 -0
  12. data/ext/fast_mmaped_file_rs/src/macros.rs +14 -0
  13. data/ext/fast_mmaped_file_rs/src/map.rs +519 -0
  14. data/ext/fast_mmaped_file_rs/src/metrics.proto +153 -0
  15. data/ext/fast_mmaped_file_rs/src/mmap/inner.rs +775 -0
  16. data/ext/fast_mmaped_file_rs/src/mmap.rs +977 -0
  17. data/ext/fast_mmaped_file_rs/src/raw_entry.rs +547 -0
  18. data/ext/fast_mmaped_file_rs/src/testhelper.rs +222 -0
  19. data/ext/fast_mmaped_file_rs/src/util.rs +140 -0
  20. data/lib/.DS_Store +0 -0
  21. data/lib/2.7/fast_mmaped_file_rs.so +0 -0
  22. data/lib/3.0/fast_mmaped_file_rs.so +0 -0
  23. data/lib/3.1/fast_mmaped_file_rs.so +0 -0
  24. data/lib/3.2/fast_mmaped_file_rs.so +0 -0
  25. data/lib/3.3/fast_mmaped_file_rs.so +0 -0
  26. data/lib/prometheus/.DS_Store +0 -0
  27. data/lib/prometheus/client/configuration.rb +24 -0
  28. data/lib/prometheus/client/counter.rb +27 -0
  29. data/lib/prometheus/client/formats/protobuf.rb +93 -0
  30. data/lib/prometheus/client/formats/text.rb +85 -0
  31. data/lib/prometheus/client/gauge.rb +40 -0
  32. data/lib/prometheus/client/helper/entry_parser.rb +132 -0
  33. data/lib/prometheus/client/helper/file_locker.rb +50 -0
  34. data/lib/prometheus/client/helper/json_parser.rb +23 -0
  35. data/lib/prometheus/client/helper/metrics_processing.rb +45 -0
  36. data/lib/prometheus/client/helper/metrics_representation.rb +51 -0
  37. data/lib/prometheus/client/helper/mmaped_file.rb +64 -0
  38. data/lib/prometheus/client/helper/plain_file.rb +29 -0
  39. data/lib/prometheus/client/histogram.rb +80 -0
  40. data/lib/prometheus/client/label_set_validator.rb +85 -0
  41. data/lib/prometheus/client/metric.rb +80 -0
  42. data/lib/prometheus/client/mmaped_dict.rb +83 -0
  43. data/lib/prometheus/client/mmaped_value.rb +164 -0
  44. data/lib/prometheus/client/page_size.rb +17 -0
  45. data/lib/prometheus/client/push.rb +203 -0
  46. data/lib/prometheus/client/rack/collector.rb +88 -0
  47. data/lib/prometheus/client/rack/exporter.rb +102 -0
  48. data/lib/prometheus/client/registry.rb +65 -0
  49. data/lib/prometheus/client/simple_value.rb +31 -0
  50. data/lib/prometheus/client/summary.rb +69 -0
  51. data/lib/prometheus/client/support/puma.rb +44 -0
  52. data/lib/prometheus/client/support/unicorn.rb +35 -0
  53. data/lib/prometheus/client/uses_value_type.rb +20 -0
  54. data/lib/prometheus/client/version.rb +5 -0
  55. data/lib/prometheus/client.rb +58 -0
  56. data/lib/prometheus.rb +3 -0
  57. metadata +210 -0
@@ -0,0 +1,65 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'thread'
4
+
5
+ require 'prometheus/client/counter'
6
+ require 'prometheus/client/summary'
7
+ require 'prometheus/client/gauge'
8
+ require 'prometheus/client/histogram'
9
+
10
+ module Prometheus
11
+ module Client
12
+ # Registry
13
+ class Registry
14
+ class AlreadyRegisteredError < StandardError; end
15
+
16
+ def initialize
17
+ @metrics = {}
18
+ @mutex = Mutex.new
19
+ end
20
+
21
+ def register(metric)
22
+ name = metric.name
23
+
24
+ @mutex.synchronize do
25
+ if exist?(name.to_sym)
26
+ raise AlreadyRegisteredError, "#{name} has already been registered"
27
+ else
28
+ @metrics[name.to_sym] = metric
29
+ end
30
+ end
31
+
32
+ metric
33
+ end
34
+
35
+ def counter(name, docstring, base_labels = {})
36
+ register(Counter.new(name, docstring, base_labels))
37
+ end
38
+
39
+ def summary(name, docstring, base_labels = {})
40
+ register(Summary.new(name, docstring, base_labels))
41
+ end
42
+
43
+ def gauge(name, docstring, base_labels = {}, multiprocess_mode = :all)
44
+ register(Gauge.new(name, docstring, base_labels, multiprocess_mode))
45
+ end
46
+
47
+ def histogram(name, docstring, base_labels = {},
48
+ buckets = Histogram::DEFAULT_BUCKETS)
49
+ register(Histogram.new(name, docstring, base_labels, buckets))
50
+ end
51
+
52
+ def exist?(name)
53
+ @metrics.key?(name)
54
+ end
55
+
56
+ def get(name)
57
+ @metrics[name.to_sym]
58
+ end
59
+
60
+ def metrics
61
+ @metrics.values
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,31 @@
1
+ require 'json'
2
+
3
+ module Prometheus
4
+ module Client
5
+ class SimpleValue
6
+ def initialize(_type, _metric_name, _name, _labels, *_args)
7
+ @value = 0.0
8
+ end
9
+
10
+ def set(value)
11
+ @value = value
12
+ end
13
+
14
+ def increment(by = 1, exemplar_name = '', exemplar_value = '')
15
+ @value += by
16
+ end
17
+
18
+ def decrement(by = 1)
19
+ @value -= by
20
+ end
21
+
22
+ def get
23
+ @value
24
+ end
25
+
26
+ def self.multiprocess
27
+ false
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,69 @@
1
+ require 'prometheus/client/metric'
2
+ require 'prometheus/client/uses_value_type'
3
+
4
+ module Prometheus
5
+ module Client
6
+ # Summary is an accumulator for samples. It captures Numeric data and
7
+ # provides an efficient quantile calculation mechanism.
8
+ class Summary < Metric
9
+ extend Gem::Deprecate
10
+
11
+ # Value represents the state of a Summary at a given point.
12
+ class Value < Hash
13
+ include UsesValueType
14
+ attr_accessor :sum, :total
15
+
16
+ def initialize(type, name, labels)
17
+ @sum = value_object(type, name, "#{name}_sum", labels)
18
+ @total = value_object(type, name, "#{name}_count", labels)
19
+ end
20
+
21
+ def observe(value)
22
+ @sum.increment(value)
23
+ @total.increment
24
+ end
25
+ end
26
+
27
+ def initialize(name, docstring, base_labels = {})
28
+ super(name, docstring, base_labels)
29
+ end
30
+
31
+ def type
32
+ :summary
33
+ end
34
+
35
+ # Records a given value.
36
+ def observe(labels, value)
37
+ label_set = label_set_for(labels)
38
+ synchronize { @values[label_set].observe(value) }
39
+ end
40
+
41
+ alias add observe
42
+ deprecate :add, :observe, 2016, 10
43
+
44
+ # Returns the value for the given label set
45
+ def get(labels = {})
46
+ @validator.valid?(labels)
47
+
48
+ synchronize do
49
+ @values[labels].sum.get
50
+ end
51
+ end
52
+
53
+ # Returns all label sets with their values
54
+ def values
55
+ synchronize do
56
+ @values.each_with_object({}) do |(labels, value), memo|
57
+ memo[labels] = value.sum
58
+ end
59
+ end
60
+ end
61
+
62
+ private
63
+
64
+ def default(labels)
65
+ Value.new(type, @name, labels)
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,44 @@
1
+ module Prometheus
2
+ module Client
3
+ module Support
4
+ module Puma
5
+ extend self
6
+
7
+ def worker_pid_provider
8
+ wid = worker_id
9
+ if wid = worker_id
10
+ wid
11
+ else
12
+ "process_id_#{Process.pid}"
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def object_based_worker_id
19
+ return unless defined?(::Puma::Cluster::Worker)
20
+
21
+ workers = ObjectSpace.each_object(::Puma::Cluster::Worker)
22
+ return if workers.nil?
23
+
24
+ workers_first = workers.first
25
+ workers_first.index unless workers_first.nil?
26
+ end
27
+
28
+ def program_name
29
+ $PROGRAM_NAME
30
+ end
31
+
32
+ def worker_id
33
+ if matchdata = program_name.match(/puma.*cluster worker ([0-9]+):/)
34
+ "puma_#{matchdata[1]}"
35
+ elsif object_worker_id = object_based_worker_id
36
+ "puma_#{object_worker_id}"
37
+ elsif program_name.include?('puma')
38
+ 'puma_master'
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,35 @@
1
+ module Prometheus
2
+ module Client
3
+ module Support
4
+ module Unicorn
5
+ def self.worker_pid_provider
6
+ wid = worker_id
7
+ if wid.nil?
8
+ "process_id_#{Process.pid}"
9
+ else
10
+ "worker_id_#{wid}"
11
+ end
12
+ end
13
+
14
+ def self.worker_id
15
+ match = $0.match(/worker\[([^\]]+)\]/)
16
+ if match
17
+ match[1]
18
+ else
19
+ object_based_worker_id
20
+ end
21
+ end
22
+
23
+ def self.object_based_worker_id
24
+ return unless defined?(::Unicorn::Worker)
25
+
26
+ workers = ObjectSpace.each_object(::Unicorn::Worker)
27
+ return if workers.nil?
28
+
29
+ workers_first = workers.first
30
+ workers_first.nr unless workers_first.nil?
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ require 'prometheus/client/simple_value'
2
+
3
+ module Prometheus
4
+ module Client
5
+ # Module providing convenience methods for creating value_object
6
+ module UsesValueType
7
+ def value_class
8
+ Prometheus::Client.configuration.value_class
9
+ end
10
+
11
+ def value_object(type, metric_name, name, labels, *args)
12
+ value_class.new(type, metric_name, name, labels, *args)
13
+ rescue StandardError => e
14
+ Prometheus::Client.logger.info("error #{e} while creating instance of #{value_class} defaulting to SimpleValue")
15
+ Prometheus::Client.logger.debug("error #{e} backtrace #{e.backtrace.join("\n")}")
16
+ Prometheus::Client::SimpleValue.new(type, metric_name, name, labels)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,5 @@
1
+ module Prometheus
2
+ module Client
3
+ VERSION = '1.5.0'.freeze
4
+ end
5
+ end
@@ -0,0 +1,58 @@
1
+ require 'prometheus/client/registry'
2
+ require 'prometheus/client/configuration'
3
+ require 'prometheus/client/mmaped_value'
4
+
5
+ module Prometheus
6
+ # Client is a ruby implementation for a Prometheus compatible client.
7
+ module Client
8
+ class << self
9
+ attr_writer :configuration
10
+
11
+ def configuration
12
+ @configuration ||= Configuration.new
13
+ end
14
+
15
+ def configure
16
+ yield(configuration)
17
+ end
18
+
19
+ # Returns a default registry object
20
+ def registry
21
+ @registry ||= Registry.new
22
+ end
23
+
24
+ def logger
25
+ configuration.logger
26
+ end
27
+
28
+ def pid
29
+ configuration.pid_provider.call
30
+ end
31
+
32
+ # Resets the registry and reinitializes all metrics files.
33
+ # Use case: clean up everything in specs `before` block,
34
+ # to prevent leaking the state between specs which are updating metrics.
35
+ def reset!
36
+ @registry = nil
37
+ ::Prometheus::Client::MmapedValue.reset_and_reinitialize
38
+ end
39
+
40
+ def cleanup!
41
+ Dir.glob("#{configuration.multiprocess_files_dir}/*.db").each { |f| File.unlink(f) if File.exist?(f) }
42
+ end
43
+
44
+ # With `force: false`: reinitializes metric files only for processes with the changed PID.
45
+ # With `force: true`: reinitializes all metrics files.
46
+ # Always keeps the registry.
47
+ # Use case (`force: false`): pick up new metric files on each worker start,
48
+ # without resetting already registered files for the master or previously initialized workers.
49
+ def reinitialize_on_pid_change(force: false)
50
+ if force
51
+ ::Prometheus::Client::MmapedValue.reset_and_reinitialize
52
+ else
53
+ ::Prometheus::Client::MmapedValue.reinitialize_on_pid_change
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
data/lib/prometheus.rb ADDED
@@ -0,0 +1,3 @@
1
+ # Prometheus is a generic time-series collection and computation server.
2
+ module Prometheus
3
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vinted-prometheus-client-mmap
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.5.0
5
+ platform: x86_64-linux
6
+ authors:
7
+ - Tobias Schmidt
8
+ - Paweł Chojnacki
9
+ - Stan Hu
10
+ - Will Chandler
11
+ autorequire:
12
+ bindir: bin
13
+ cert_chain: []
14
+ date: 2024-03-27 00:00:00.000000000 Z
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: rb_sys
18
+ requirement: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "~>"
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.86
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.86
30
+ - !ruby/object:Gem::Dependency
31
+ name: fuzzbert
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '1.0'
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 1.0.4
40
+ type: :development
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.0.4
50
+ - !ruby/object:Gem::Dependency
51
+ name: gem_publisher
52
+ requirement: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - "~>"
55
+ - !ruby/object:Gem::Version
56
+ version: '1'
57
+ type: :development
58
+ prerelease: false
59
+ version_requirements: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - "~>"
62
+ - !ruby/object:Gem::Version
63
+ version: '1'
64
+ - !ruby/object:Gem::Dependency
65
+ name: pry
66
+ requirement: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - "~>"
69
+ - !ruby/object:Gem::Version
70
+ version: 0.12.2
71
+ type: :development
72
+ prerelease: false
73
+ version_requirements: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - "~>"
76
+ - !ruby/object:Gem::Version
77
+ version: 0.12.2
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake-compiler
80
+ requirement: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - "~>"
83
+ - !ruby/object:Gem::Version
84
+ version: 1.2.1
85
+ type: :development
86
+ prerelease: false
87
+ version_requirements: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - "~>"
90
+ - !ruby/object:Gem::Version
91
+ version: 1.2.1
92
+ - !ruby/object:Gem::Dependency
93
+ name: rake-compiler-dock
94
+ requirement: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - "~>"
97
+ - !ruby/object:Gem::Version
98
+ version: 1.4.0
99
+ type: :development
100
+ prerelease: false
101
+ version_requirements: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - "~>"
104
+ - !ruby/object:Gem::Version
105
+ version: 1.4.0
106
+ - !ruby/object:Gem::Dependency
107
+ name: ruby-prof
108
+ requirement: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - "~>"
111
+ - !ruby/object:Gem::Version
112
+ version: 0.16.2
113
+ type: :development
114
+ prerelease: false
115
+ version_requirements: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: 0.16.2
120
+ description:
121
+ email:
122
+ - backend@vinted.com
123
+ executables: []
124
+ extensions: []
125
+ extra_rdoc_files: []
126
+ files:
127
+ - README.md
128
+ - ext/fast_mmaped_file_rs/Cargo.toml
129
+ - ext/fast_mmaped_file_rs/README.md
130
+ - ext/fast_mmaped_file_rs/build.rs
131
+ - ext/fast_mmaped_file_rs/extconf.rb
132
+ - ext/fast_mmaped_file_rs/src/error.rs
133
+ - ext/fast_mmaped_file_rs/src/exemplars.rs
134
+ - ext/fast_mmaped_file_rs/src/file_entry.rs
135
+ - ext/fast_mmaped_file_rs/src/file_info.rs
136
+ - ext/fast_mmaped_file_rs/src/lib.rs
137
+ - ext/fast_mmaped_file_rs/src/macros.rs
138
+ - ext/fast_mmaped_file_rs/src/map.rs
139
+ - ext/fast_mmaped_file_rs/src/metrics.proto
140
+ - ext/fast_mmaped_file_rs/src/mmap.rs
141
+ - ext/fast_mmaped_file_rs/src/mmap/inner.rs
142
+ - ext/fast_mmaped_file_rs/src/raw_entry.rs
143
+ - ext/fast_mmaped_file_rs/src/testhelper.rs
144
+ - ext/fast_mmaped_file_rs/src/util.rs
145
+ - lib/.DS_Store
146
+ - lib/2.7/fast_mmaped_file_rs.so
147
+ - lib/3.0/fast_mmaped_file_rs.so
148
+ - lib/3.1/fast_mmaped_file_rs.so
149
+ - lib/3.2/fast_mmaped_file_rs.so
150
+ - lib/3.3/fast_mmaped_file_rs.so
151
+ - lib/prometheus.rb
152
+ - lib/prometheus/.DS_Store
153
+ - lib/prometheus/client.rb
154
+ - lib/prometheus/client/configuration.rb
155
+ - lib/prometheus/client/counter.rb
156
+ - lib/prometheus/client/formats/protobuf.rb
157
+ - lib/prometheus/client/formats/text.rb
158
+ - lib/prometheus/client/gauge.rb
159
+ - lib/prometheus/client/helper/entry_parser.rb
160
+ - lib/prometheus/client/helper/file_locker.rb
161
+ - lib/prometheus/client/helper/json_parser.rb
162
+ - lib/prometheus/client/helper/metrics_processing.rb
163
+ - lib/prometheus/client/helper/metrics_representation.rb
164
+ - lib/prometheus/client/helper/mmaped_file.rb
165
+ - lib/prometheus/client/helper/plain_file.rb
166
+ - lib/prometheus/client/histogram.rb
167
+ - lib/prometheus/client/label_set_validator.rb
168
+ - lib/prometheus/client/metric.rb
169
+ - lib/prometheus/client/mmaped_dict.rb
170
+ - lib/prometheus/client/mmaped_value.rb
171
+ - lib/prometheus/client/page_size.rb
172
+ - lib/prometheus/client/push.rb
173
+ - lib/prometheus/client/rack/collector.rb
174
+ - lib/prometheus/client/rack/exporter.rb
175
+ - lib/prometheus/client/registry.rb
176
+ - lib/prometheus/client/simple_value.rb
177
+ - lib/prometheus/client/summary.rb
178
+ - lib/prometheus/client/support/puma.rb
179
+ - lib/prometheus/client/support/unicorn.rb
180
+ - lib/prometheus/client/uses_value_type.rb
181
+ - lib/prometheus/client/version.rb
182
+ homepage: https://gitlab.com/gitlab-org/prometheus-client-mmap
183
+ licenses:
184
+ - Apache-2.0
185
+ metadata:
186
+ allowed_push_host: https://rubygems.org
187
+ post_install_message:
188
+ rdoc_options: []
189
+ require_paths:
190
+ - lib
191
+ required_ruby_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '2.7'
196
+ - - "<"
197
+ - !ruby/object:Gem::Version
198
+ version: 3.4.dev
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubygems_version: 3.4.4
206
+ signing_key:
207
+ specification_version: 4
208
+ summary: A suite of instrumentation metric primitives that can be exposed through
209
+ a web services interface.
210
+ test_files: []