prometheus-client-mmap 0.11.0 → 0.15.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: f2da1f2b3aafb4f99845a0d57a23b7ddd913cec6cd943ca18657c7743e309053
4
- data.tar.gz: 9a757f3213a28d9b21ef0999c1c1f7756ee827dc5303c22d5dd700626010a177
3
+ metadata.gz: 4a5499ad848cb63f9d28ec70e0c8e625362e3b0d88c39ec99bfb1f8063977225
4
+ data.tar.gz: 6eb5a5ac105cd8755dbd150e71d8438b29afd91528ecbc8687cb4d2c3f4fdc3d
5
5
  SHA512:
6
- metadata.gz: 4d1b4457931f0c557debce08e9478bbdc3b933b15aa59df56eac89d65be7091b116b2ebef5fd853b96daa76a61d404b4b9ebf86920b8fccdd4b9a0d92051f66f
7
- data.tar.gz: e64a0985943a3bd8460358ab905d9ac387e0b5b829b30ac652707915078d194fae84ab83a700ed6f702d5bae2576f669d983febc5d9479817cc1300926426d98
6
+ metadata.gz: 8937e83ed07d65c8b77128b12fb9df2e01950381b1f49bfacda43de81d1a087dfa97d646bac096002a4fcd151ecc6080454f1e6d8dd49b5b425b4ab49a0e908c
7
+ data.tar.gz: 7d63e7dc4965d3cf91efec8abe594c833483f4d2d54869916ba44a8a1b04419ff6eecb453d98f559fd15284c49d0a13d202ca86d2cf1b916933c505e417fe9b8
@@ -42,12 +42,8 @@ static VALUE mm_str(VALUE obj, int modify) {
42
42
  GET_MMAP(obj, i_mm, modify & ~MM_ORIGIN);
43
43
  if (modify & MM_MODIFY) {
44
44
  if (i_mm->t->flag & MM_FROZEN) rb_error_frozen("mmap");
45
- if (!OBJ_TAINTED(ret) && rb_safe_level() >= 4) rb_raise(rb_eSecurityError, "Insecure: can't modify mmap");
46
45
  }
47
46
  ret = rb_obj_alloc(rb_cString);
48
- if (rb_obj_tainted(obj)) {
49
- OBJ_TAINT(ret);
50
- }
51
47
  RSTRING(ret)->as.heap.ptr = i_mm->t->addr;
52
48
  RSTRING(ret)->as.heap.aux.capa = i_mm->t->len;
53
49
  RSTRING(ret)->as.heap.len = i_mm->t->real;
@@ -216,13 +212,6 @@ VALUE mm_init(VALUE obj, VALUE fname) {
216
212
  SafeStringValue(fname);
217
213
  path = StringValuePtr(fname);
218
214
 
219
- {
220
- if (rb_safe_level() > 0 && OBJ_TAINTED(fname)) {
221
- rb_raise(rb_eSecurityError, "Insecure operation");
222
- }
223
- rb_secure(1);
224
- }
225
-
226
215
  vscope = MAP_SHARED;
227
216
  size = 0;
228
217
  perm = 0666;
@@ -280,7 +269,6 @@ VALUE mm_init(VALUE obj, VALUE fname) {
280
269
  if (smode == O_WRONLY) {
281
270
  i_mm->t->flag |= MM_FIXED;
282
271
  }
283
- OBJ_TAINT(obj);
284
272
  return obj;
285
273
  }
286
274
 
@@ -31,6 +31,10 @@ module Prometheus
31
31
  def increment(labels, value)
32
32
  @values[label_set_for(labels)].increment(value)
33
33
  end
34
+
35
+ def decrement(labels, value)
36
+ @values[label_set_for(labels)].decrement(value)
37
+ end
34
38
  end
35
39
  end
36
40
  end
@@ -36,6 +36,10 @@ module Prometheus
36
36
  end
37
37
  end
38
38
 
39
+ def decrement(amount = 1)
40
+ increment(-amount)
41
+ end
42
+
39
43
  def set(value)
40
44
  @mutex.synchronize do
41
45
  initialize_file if pid_changed?
@@ -125,14 +129,10 @@ module Prometheus
125
129
 
126
130
 
127
131
  def rebuild_key
128
- labelnames = []
129
- labelvalues = []
130
- @labels.each do |k, v|
131
- labelnames << k
132
- labelvalues << v
133
- end
132
+ keys = @labels.keys.sort
133
+ values = @labels.values_at(*keys)
134
134
 
135
- [@metric_name, @name, labelnames, labelvalues].to_json
135
+ [@metric_name, @name, keys, values].to_json
136
136
  end
137
137
 
138
138
  def write_value(key, val)
@@ -1,7 +1,9 @@
1
1
  # encoding: UTF-8
2
2
 
3
+ require 'thread'
3
4
  require 'net/http'
4
5
  require 'uri'
6
+ require 'erb'
5
7
 
6
8
  require 'prometheus/client'
7
9
  require 'prometheus/client/formats/text'
@@ -13,31 +15,45 @@ module Prometheus
13
15
  # Pushgateway.
14
16
  class Push
15
17
  DEFAULT_GATEWAY = 'http://localhost:9091'.freeze
16
- PATH = '/metrics/jobs/%s'.freeze
17
- INSTANCE_PATH = '/metrics/jobs/%s/instances/%s'.freeze
18
- HEADER = { 'Content-Type' => Formats::Text::CONTENT_TYPE }.freeze
18
+ PATH = '/metrics/job/%s'.freeze
19
+ INSTANCE_PATH = '/metrics/job/%s/instance/%s'.freeze
20
+ SUPPORTED_SCHEMES = %w(http https).freeze
19
21
 
20
22
  attr_reader :job, :instance, :gateway, :path
21
23
 
22
- def initialize(job, instance = nil, gateway = nil)
24
+ def initialize(job:, instance: nil, gateway: DEFAULT_GATEWAY, **kwargs)
25
+ raise ArgumentError, "job cannot be nil" if job.nil?
26
+ raise ArgumentError, "job cannot be empty" if job.empty?
27
+
28
+ @mutex = Mutex.new
23
29
  @job = job
24
30
  @instance = instance
25
31
  @gateway = gateway || DEFAULT_GATEWAY
26
- @uri = parse(@gateway)
27
32
  @path = build_path(job, instance)
33
+ @uri = parse("#{@gateway}#{@path}")
34
+
28
35
  @http = Net::HTTP.new(@uri.host, @uri.port)
36
+ @http.use_ssl = (@uri.scheme == 'https')
37
+ @http.open_timeout = kwargs[:open_timeout] if kwargs[:open_timeout]
38
+ @http.read_timeout = kwargs[:read_timeout] if kwargs[:read_timeout]
29
39
  end
30
40
 
31
41
  def add(registry)
32
- request('POST', registry)
42
+ synchronize do
43
+ request(Net::HTTP::Post, registry)
44
+ end
33
45
  end
34
46
 
35
47
  def replace(registry)
36
- request('PUT', registry)
48
+ synchronize do
49
+ request(Net::HTTP::Put, registry)
50
+ end
37
51
  end
38
52
 
39
53
  def delete
40
- @http.send_request('DELETE', path)
54
+ synchronize do
55
+ request(Net::HTTP::Delete)
56
+ end
41
57
  end
42
58
 
43
59
  private
@@ -45,27 +61,34 @@ module Prometheus
45
61
  def parse(url)
46
62
  uri = URI.parse(url)
47
63
 
48
- if uri.scheme == 'http'
49
- uri
50
- else
64
+ unless SUPPORTED_SCHEMES.include?(uri.scheme)
51
65
  raise ArgumentError, 'only HTTP gateway URLs are supported currently.'
52
66
  end
67
+
68
+ uri
53
69
  rescue URI::InvalidURIError => e
54
70
  raise ArgumentError, "#{url} is not a valid URL: #{e}"
55
71
  end
56
72
 
57
73
  def build_path(job, instance)
58
- if instance
59
- format(INSTANCE_PATH, URI.escape(job), URI.escape(instance))
74
+ if instance && !instance.empty?
75
+ format(INSTANCE_PATH, ERB::Util::url_encode(job), ERB::Util::url_encode(instance))
60
76
  else
61
- format(PATH, URI.escape(job))
77
+ format(PATH, ERB::Util::url_encode(job))
62
78
  end
63
79
  end
64
80
 
65
- def request(method, registry)
66
- data = Formats::Text.marshal(registry)
81
+ def request(req_class, registry = nil)
82
+ req = req_class.new(@uri)
83
+ req.content_type = Formats::Text::CONTENT_TYPE
84
+ req.basic_auth(@uri.user, @uri.password) if @uri.user
85
+ req.body = Formats::Text.marshal(registry) if registry
86
+
87
+ @http.request(req)
88
+ end
67
89
 
68
- @http.send_request(method, path, data, HEADER)
90
+ def synchronize
91
+ @mutex.synchronize { yield }
69
92
  end
70
93
  end
71
94
  end
@@ -15,6 +15,10 @@ module Prometheus
15
15
  @value += by
16
16
  end
17
17
 
18
+ def decrement(by = 1)
19
+ @value -= by
20
+ end
21
+
18
22
  def get
19
23
  @value
20
24
  end
@@ -1,5 +1,5 @@
1
1
  module Prometheus
2
2
  module Client
3
- VERSION = '0.11.0'.freeze
3
+ VERSION = '0.15.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: prometheus-client-mmap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.0
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Schmidt
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-07-22 00:00:00.000000000 Z
12
+ date: 2021-08-31 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fuzzbert
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  - !ruby/object:Gem::Version
182
182
  version: '0'
183
183
  requirements: []
184
- rubygems_version: 3.0.3
184
+ rubygems_version: 3.1.4
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: A suite of instrumentation metric primitivesthat can be exposed through a