prometheus-client-mmap 0.24.5-x86_64-darwin → 0.26.0-x86_64-darwin

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: c288a4602307bbeedfe916df669c95d80d555f1c95beb7a2c946c58368c0f86b
4
- data.tar.gz: 41b3bc2a51e0aee5de6d1511a9feb7285270c1d8366e683befdb1564a025f3f3
3
+ metadata.gz: f779bcb82f005c123a3e3d157cb670ff919282fdd7ef9063067d39b275603ef6
4
+ data.tar.gz: 965803881aeb4cf51d3b58dc9e04809d1be8e6cb04469681c4468ef8c8dc9f71
5
5
  SHA512:
6
- metadata.gz: 7c4bb28ac28b8ca1b12716fe291516aeb9404b1fb553ce8c6aee0126554e2bcec8a9372cef93f2be4b429b09b32c7096f9c0fe8fbeb52876ccdd44d1d179a411
7
- data.tar.gz: 1fce85abecdbdd8c0f85090eae0294b39f6cf00524dd67d950a046f8890ed31bb52ea0a5c9952c2c6b2aabc66918d766356c72683b4116731002e298b16fbac4
6
+ metadata.gz: 8263efb8e95eeb872870350c60d4dc96392edff1d44e42270ae4f38ad82916e2c05f8aeb8c022210cd9dd3a480093f4dc5f089e208ac7eaeaf4df5060e35db35
7
+ data.tar.gz: bf7b153d56928526a968e87cc2acc14d45e860052a8db91f776ccb334f159b7e27808468f9e5cee76b6ba74f5be9529206fbb9a60fbb3ecffe1c05b9ccd8309b
data/README.md CHANGED
@@ -34,7 +34,7 @@ http_requests = prometheus.counter(:http_requests, 'A counter of HTTP requests m
34
34
  http_requests.increment
35
35
  ```
36
36
 
37
- ## Rust extension (experimental)
37
+ ## Rust extension
38
38
 
39
39
  In an effort to improve maintainability, there is now an optional Rust
40
40
  implementation that reads the metric files and outputs the multiprocess
@@ -202,14 +202,21 @@ prometheus_multiproc_dir=/tmp
202
202
 
203
203
  ### Multiprocess metrics via Rust extension
204
204
 
205
- If the environment variable `prometheus_rust_multiprocess_metrics=true` is set or if the `rust_multiprocess_metrics`
206
- configuration setting is `true` and the `fast_mmaped_file_rs` extension is available, it will be used to generate
207
- multiprocess metrics. This should be significantly faster than the C extension.
205
+ By default, the Rust extension will be used to read and write multiprocess
206
+ metrics if the `fast_mmaped_file_rs` extension is available. This should
207
+ be significantly faster than the C extension.
208
+
209
+ If the environment variable `prometheus_rust_multiprocess_metrics=false`
210
+ is set or if the `rust_multiprocess_metrics` configuration setting is
211
+ `false` , the C extension will be used.
208
212
 
209
213
  ### Read and write metrics via Rust extension
210
214
 
211
- If the environment variable `prometheus_rust_mmaped_file=true` is set then if the `fast_mmaped_file_rs`
212
- extension is available it will be used to read and write metrics from the mmapped file.
215
+ By default, the Rust extension will be used to read and write metrics
216
+ from the mmaped file if the `fast_mmaped_file_rs` extension is available.
217
+
218
+ To use the C extension, set the environment variable
219
+ `prometheus_rust_mmaped_file=false`.
213
220
 
214
221
  ## Pitfalls
215
222
 
@@ -3,6 +3,7 @@
3
3
  #include <errno.h>
4
4
  #include <fcntl.h>
5
5
  #include <ruby/util.h>
6
+ #include <ruby/version.h>
6
7
  #include <sys/mman.h>
7
8
 
8
9
  #include "file_format.h"
@@ -27,6 +28,16 @@
27
28
  */
28
29
  static VALUE weak_obj_tracker_get_key(VALUE val) { return val; }
29
30
 
31
+ static void update_rstring_len(VALUE val, size_t len) {
32
+ #if defined(RUBY_API_VERSION_MAJOR) && defined(RUBY_API_VERSION_MINOR) && (RUBY_API_VERSION_MAJOR == 3) && \
33
+ (RUBY_API_VERSION_MINOR >= 3)
34
+
35
+ RSTRING(val)->len = len;
36
+ #else
37
+ RSTRING(val)->as.heap.len = len;
38
+ #endif
39
+ }
40
+
30
41
  /**
31
42
  * Adds a T_STRING type to the WeakMap. The WeakMap should be stored
32
43
  * as an instance variable.
@@ -52,7 +63,7 @@ VALUE mm_update_obj_i(RB_BLOCK_CALL_FUNC_ARGLIST(i, self)) {
52
63
  GET_MMAP(self, i_mm, MM_MODIFY);
53
64
 
54
65
  RSTRING(i)->as.heap.ptr = i_mm->t->addr;
55
- RSTRING(i)->as.heap.len = i_mm->t->real;
66
+ update_rstring_len(i, i_mm->t->real);
56
67
 
57
68
  return Qtrue;
58
69
  }
@@ -98,7 +109,7 @@ static VALUE mm_str(VALUE obj, int modify) {
98
109
  ret = rb_obj_alloc(rb_cString);
99
110
  RSTRING(ret)->as.heap.ptr = i_mm->t->addr;
100
111
  RSTRING(ret)->as.heap.aux.capa = i_mm->t->len;
101
- RSTRING(ret)->as.heap.len = i_mm->t->real;
112
+ update_rstring_len(ret, i_mm->t->real);
102
113
 
103
114
  weak_obj_tracker_add(obj, ret);
104
115
 
@@ -30,9 +30,9 @@ checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa"
30
30
 
31
31
  [[package]]
32
32
  name = "bindgen"
33
- version = "0.60.1"
33
+ version = "0.62.0"
34
34
  source = "registry+https://github.com/rust-lang/crates.io-index"
35
- checksum = "062dddbc1ba4aca46de6338e2bf87771414c335f7b2f2036e8f3e9befebf88e6"
35
+ checksum = "c6720a8b7b2d39dd533285ed438d458f65b31b5c257e6ac7bb3d7e82844dd722"
36
36
  dependencies = [
37
37
  "bitflags",
38
38
  "cexpr",
@@ -45,6 +45,7 @@ dependencies = [
45
45
  "regex",
46
46
  "rustc-hash",
47
47
  "shlex",
48
+ "syn 1.0.109",
48
49
  ]
49
50
 
50
51
  [[package]]
@@ -169,6 +170,7 @@ dependencies = [
169
170
  "nix",
170
171
  "rand",
171
172
  "rb-sys",
173
+ "rb-sys-env",
172
174
  "serde",
173
175
  "serde_json",
174
176
  "sha2",
@@ -297,7 +299,7 @@ checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f"
297
299
  [[package]]
298
300
  name = "magnus"
299
301
  version = "0.5.0"
300
- source = "git+https://github.com/matsadler/magnus?branch=main#b10aab48119eb87a872bf0bb4480b1fcebe5d1b9"
302
+ source = "git+https://github.com/matsadler/magnus?branch=main#50cab2380103c39c14765a10bdc4b38a74082285"
301
303
  dependencies = [
302
304
  "magnus-macros",
303
305
  "rb-sys",
@@ -308,7 +310,7 @@ dependencies = [
308
310
  [[package]]
309
311
  name = "magnus-macros"
310
312
  version = "0.4.0"
311
- source = "git+https://github.com/matsadler/magnus?branch=main#b10aab48119eb87a872bf0bb4480b1fcebe5d1b9"
313
+ source = "git+https://github.com/matsadler/magnus?branch=main#50cab2380103c39c14765a10bdc4b38a74082285"
312
314
  dependencies = [
313
315
  "proc-macro2",
314
316
  "quote",
@@ -443,18 +445,18 @@ dependencies = [
443
445
 
444
446
  [[package]]
445
447
  name = "rb-sys"
446
- version = "0.9.71"
448
+ version = "0.9.79"
447
449
  source = "registry+https://github.com/rust-lang/crates.io-index"
448
- checksum = "156bfedced1e236600bcaad538477097ff2ed5c6b474e411d15b791e1d24c0f1"
450
+ checksum = "939fb78db3e4f26665c1d4c7b91ca66d3578335a19aba552d4a6445811d07072"
449
451
  dependencies = [
450
452
  "rb-sys-build",
451
453
  ]
452
454
 
453
455
  [[package]]
454
456
  name = "rb-sys-build"
455
- version = "0.9.71"
457
+ version = "0.9.79"
456
458
  source = "registry+https://github.com/rust-lang/crates.io-index"
457
- checksum = "5cb2e4a32cbc290b543a74567072ad24b708aff7bb5dde5a68d5690379cd7938"
459
+ checksum = "335a95eb0420d52fa94ef12019df3c2c250c6b19cbb3c60bd05cb7e9c362072c"
458
460
  dependencies = [
459
461
  "bindgen",
460
462
  "lazy_static",
@@ -27,6 +27,9 @@ rand = "0.8"
27
27
  sha2 = "0.10"
28
28
  tempfile = "3.5"
29
29
 
30
+ [build-dependencies]
31
+ rb-sys-env = "0.1"
32
+
30
33
  [lib]
31
34
  # Integration tests won't work if crate is only `cdylib`.
32
35
  crate-type = ["cdylib","lib"]
@@ -0,0 +1,5 @@
1
+ fn main() -> Result<(), Box<dyn std::error::Error>> {
2
+ let _ = rb_sys_env::activate()?;
3
+
4
+ Ok(())
5
+ }
@@ -418,10 +418,10 @@ impl MmapedFile {
418
418
 
419
419
  raw_str.as_mut().as_.heap.ptr = self.as_mut_ptr().offset(offset);
420
420
 
421
- let current_len = raw_str.as_ref().as_.heap.len;
421
+ let current_len = str.len() as c_long;
422
422
  let new_shared_len = old_cap + current_len;
423
423
 
424
- raw_str.as_mut().as_.heap.len = new_shared_len;
424
+ self.update_rstring_len(raw_str, new_shared_len);
425
425
  continue;
426
426
  }
427
427
 
@@ -436,7 +436,7 @@ impl MmapedFile {
436
436
  //
437
437
  // See https://gitlab.com/gitlab-org/ruby/gems/prometheus-client-mmap/-/issues/45
438
438
  raw_str.as_mut().as_.heap.ptr = self.as_mut_ptr();
439
- raw_str.as_mut().as_.heap.len = new_len;
439
+ self.update_rstring_len(raw_str, new_len);
440
440
  }
441
441
  }
442
442
 
@@ -632,6 +632,16 @@ impl MmapedFile {
632
632
  unsafe fn rb_string_internal(rb_str: RString) -> NonNull<rb_sys::RString> {
633
633
  mem::transmute::<RString, NonNull<rb_sys::RString>>(rb_str)
634
634
  }
635
+
636
+ #[cfg(ruby_lte_3_2)]
637
+ unsafe fn update_rstring_len(&self, mut raw_str: NonNull<rb_sys::RString>, new_len: c_long) {
638
+ raw_str.as_mut().as_.heap.len = new_len;
639
+ }
640
+
641
+ #[cfg(ruby_gte_3_3)]
642
+ unsafe fn update_rstring_len(&self, mut raw_str: NonNull<rb_sys::RString>, new_len: c_long) {
643
+ raw_str.as_mut().len = new_len;
644
+ }
635
645
  }
636
646
 
637
647
  #[cfg(test)]
@@ -772,8 +782,7 @@ mod test {
772
782
  if str.as_raw() == child_id {
773
783
  assert_eq!(parent_id, raw_str.as_ref().as_.heap.aux.shared);
774
784
 
775
- let child_offset =
776
- mmap_len as isize - raw_str.as_ref().as_.heap.len as isize;
785
+ let child_offset = mmap_len as isize - str.len() as isize;
777
786
  assert_eq!(mmap_ptr.offset(child_offset), raw_str.as_ref().as_.heap.ptr);
778
787
 
779
788
  child_checked = true;
@@ -781,7 +790,7 @@ mod test {
781
790
  assert_eq!(parent_id, str.as_raw());
782
791
 
783
792
  assert_eq!(mmap_ptr, raw_str.as_ref().as_.heap.ptr);
784
- assert_eq!(mmap_len as c_long, raw_str.as_ref().as_.heap.len);
793
+ assert_eq!(mmap_len as c_long, str.len() as c_long);
785
794
  assert!(raw_str.as_ref().basic.flags & (STR_SHARED | STR_NOEMBED) > 0);
786
795
  assert!(str.is_frozen());
787
796
 
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -14,7 +14,7 @@ module Prometheus
14
14
  @initial_mmap_file_size = ::Prometheus::Client::PageSize.page_size(fallback_page_size: 4096)
15
15
  @logger = Logger.new($stdout)
16
16
  @pid_provider = Process.method(:pid)
17
- @rust_multiprocess_metrics = ENV.fetch('prometheus_rust_multiprocess_metrics', nil) == 'true'
17
+ @rust_multiprocess_metrics = ENV.fetch('prometheus_rust_multiprocess_metrics', 'true') == 'true'
18
18
  @multiprocess_files_dir = ENV.fetch('prometheus_multiproc_dir') do
19
19
  Dir.mktmpdir("prometheus-mmap")
20
20
  end
@@ -27,7 +27,7 @@ module Prometheus
27
27
  Helper::MetricsRepresentation.to_text(metrics)
28
28
  end
29
29
 
30
- def marshal_multiprocess(path = Prometheus::Client.configuration.multiprocess_files_dir, use_rust: false)
30
+ def marshal_multiprocess(path = Prometheus::Client.configuration.multiprocess_files_dir, use_rust: true)
31
31
  file_list = Dir.glob(File.join(path, '*.db')).sort
32
32
  .map {|f| Helper::PlainFile.new(f) }
33
33
  .map {|f| [f.filepath, f.multiprocess_mode.to_sym, f.type.to_sym, f.pid] }
@@ -14,7 +14,7 @@ module Prometheus
14
14
  module Client
15
15
  module Helper
16
16
  # We can't check `Prometheus::Client.configuration` as this creates a circular dependency
17
- if (ENV.fetch('prometheus_rust_mmaped_file', nil) == "true" &&
17
+ if (ENV.fetch('prometheus_rust_mmaped_file', 'true') == "true" &&
18
18
  Prometheus::Client::Helper::Loader.rust_impl_available?)
19
19
  class MmapedFile < FastMmapedFileRs
20
20
  end
@@ -1,5 +1,5 @@
1
1
  module Prometheus
2
2
  module Client
3
- VERSION = '0.24.5'.freeze
3
+ VERSION = '0.26.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.24.5
4
+ version: 0.26.0
5
5
  platform: x86_64-darwin
6
6
  authors:
7
7
  - Tobias Schmidt
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2023-06-13 00:00:00.000000000 Z
14
+ date: 2023-06-20 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: rb_sys
@@ -150,6 +150,7 @@ files:
150
150
  - ext/fast_mmaped_file_rs/Cargo.lock
151
151
  - ext/fast_mmaped_file_rs/Cargo.toml
152
152
  - ext/fast_mmaped_file_rs/README.md
153
+ - ext/fast_mmaped_file_rs/build.rs
153
154
  - ext/fast_mmaped_file_rs/extconf.rb
154
155
  - ext/fast_mmaped_file_rs/src/error.rs
155
156
  - ext/fast_mmaped_file_rs/src/file_entry.rs