prometheus-client-mmap 0.24.5 → 0.26.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 +13 -6
- data/ext/fast_mmaped_file/mmap.c +13 -2
- data/ext/fast_mmaped_file_rs/Cargo.lock +10 -8
- data/ext/fast_mmaped_file_rs/Cargo.toml +3 -0
- data/ext/fast_mmaped_file_rs/build.rs +5 -0
- data/ext/fast_mmaped_file_rs/src/mmap.rs +15 -6
- data/lib/prometheus/client/configuration.rb +1 -1
- data/lib/prometheus/client/formats/text.rb +1 -1
- data/lib/prometheus/client/helper/mmaped_file.rb +1 -1
- data/lib/prometheus/client/version.rb +1 -1
- metadata +7 -6
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 94ad1d9acceaff1f75911cfe6665b1ed016916305e51865d5c4b49c22c81b880
         | 
| 4 | 
            +
              data.tar.gz: 990a2ebcdf397bf025b8cd11eb3dc49227733b4590ab2cfff5a1b564e882362f
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 4d6919e8a5c0c61fc3cbfce2a2e09ba9f5eb71e9bca9710533c950d6a93c6ba2f9539e6e194b08707f5e0722a1d65d7d85c152cf007e893957f35f6135d5695c
         | 
| 7 | 
            +
              data.tar.gz: 90ddef5880f7f48f82488abe9a4dd124d6520af0c42fc2f25fab8bb3599cd38258755737c2a0eb1fdf23c8a8d7982b1a8ae6bcffddfffb31f624178ba042c177
         | 
    
        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 | 
| 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 | 
            -
             | 
| 206 | 
            -
             | 
| 207 | 
            -
             | 
| 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 | 
            -
             | 
| 212 | 
            -
             | 
| 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 |  | 
    
        data/ext/fast_mmaped_file/mmap.c
    CHANGED
    
    | @@ -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 | 
            -
                 | 
| 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 | 
            -
                 | 
| 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. | 
| 33 | 
            +
            version = "0.62.0"
         | 
| 34 34 | 
             
            source = "registry+https://github.com/rust-lang/crates.io-index"
         | 
| 35 | 
            -
            checksum = " | 
| 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# | 
| 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# | 
| 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. | 
| 448 | 
            +
            version = "0.9.79"
         | 
| 447 449 | 
             
            source = "registry+https://github.com/rust-lang/crates.io-index"
         | 
| 448 | 
            -
            checksum = " | 
| 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. | 
| 457 | 
            +
            version = "0.9.79"
         | 
| 456 458 | 
             
            source = "registry+https://github.com/rust-lang/crates.io-index"
         | 
| 457 | 
            -
            checksum = " | 
| 459 | 
            +
            checksum = "335a95eb0420d52fa94ef12019df3c2c250c6b19cbb3c60bd05cb7e9c362072c"
         | 
| 458 460 | 
             
            dependencies = [
         | 
| 459 461 | 
             
             "bindgen",
         | 
| 460 462 | 
             
             "lazy_static",
         | 
| @@ -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 =  | 
| 421 | 
            +
                                let current_len = str.len() as c_long;
         | 
| 422 422 | 
             
                                let new_shared_len = old_cap + current_len;
         | 
| 423 423 |  | 
| 424 | 
            -
                                 | 
| 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 | 
            -
                             | 
| 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,  | 
| 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 |  | 
| @@ -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',  | 
| 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:  | 
| 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',  | 
| 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
         | 
    
        metadata
    CHANGED
    
    | @@ -1,17 +1,17 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: prometheus-client-mmap
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 0. | 
| 4 | 
            +
              version: 0.26.0
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Tobias Schmidt
         | 
| 8 8 | 
             
            - Paweł Chojnacki
         | 
| 9 9 | 
             
            - Stan Hu
         | 
| 10 10 | 
             
            - Will Chandler
         | 
| 11 | 
            -
            autorequire: | 
| 11 | 
            +
            autorequire:
         | 
| 12 12 | 
             
            bindir: bin
         | 
| 13 13 | 
             
            cert_chain: []
         | 
| 14 | 
            -
            date: 2023-06- | 
| 14 | 
            +
            date: 2023-06-20 00:00:00.000000000 Z
         | 
| 15 15 | 
             
            dependencies:
         | 
| 16 16 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 17 17 | 
             
              name: rb_sys
         | 
| @@ -117,7 +117,7 @@ dependencies: | |
| 117 117 | 
             
                - - "~>"
         | 
| 118 118 | 
             
                  - !ruby/object:Gem::Version
         | 
| 119 119 | 
             
                    version: 0.16.2
         | 
| 120 | 
            -
            description: | 
| 120 | 
            +
            description:
         | 
| 121 121 | 
             
            email:
         | 
| 122 122 | 
             
            - ts@soundcloud.com
         | 
| 123 123 | 
             
            - pawel@gitlab.com
         | 
| @@ -152,6 +152,7 @@ files: | |
| 152 152 | 
             
            - ext/fast_mmaped_file_rs/Cargo.lock
         | 
| 153 153 | 
             
            - ext/fast_mmaped_file_rs/Cargo.toml
         | 
| 154 154 | 
             
            - ext/fast_mmaped_file_rs/README.md
         | 
| 155 | 
            +
            - ext/fast_mmaped_file_rs/build.rs
         | 
| 155 156 | 
             
            - ext/fast_mmaped_file_rs/extconf.rb
         | 
| 156 157 | 
             
            - ext/fast_mmaped_file_rs/src/error.rs
         | 
| 157 158 | 
             
            - ext/fast_mmaped_file_rs/src/file_entry.rs
         | 
| @@ -217,7 +218,7 @@ homepage: https://gitlab.com/gitlab-org/prometheus-client-mmap | |
| 217 218 | 
             
            licenses:
         | 
| 218 219 | 
             
            - Apache-2.0
         | 
| 219 220 | 
             
            metadata: {}
         | 
| 220 | 
            -
            post_install_message: | 
| 221 | 
            +
            post_install_message:
         | 
| 221 222 | 
             
            rdoc_options: []
         | 
| 222 223 | 
             
            require_paths:
         | 
| 223 224 | 
             
            - lib
         | 
| @@ -233,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 233 234 | 
             
                  version: '0'
         | 
| 234 235 | 
             
            requirements: []
         | 
| 235 236 | 
             
            rubygems_version: 3.3.26
         | 
| 236 | 
            -
            signing_key: | 
| 237 | 
            +
            signing_key:
         | 
| 237 238 | 
             
            specification_version: 4
         | 
| 238 239 | 
             
            summary: A suite of instrumentation metric primitivesthat can be exposed through a
         | 
| 239 240 | 
             
              web services interface.
         |