prometheus-client-mmap 0.22.0-x86_64-linux-musl → 1.2.4-x86_64-linux-musl
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.tool-versions +1 -0
- data/README.md +32 -17
- data/ext/fast_mmaped_file_rs/Cargo.toml +14 -9
- data/ext/fast_mmaped_file_rs/build.rs +5 -0
- data/ext/fast_mmaped_file_rs/extconf.rb +1 -3
- data/ext/fast_mmaped_file_rs/src/error.rs +2 -2
- data/ext/fast_mmaped_file_rs/src/file_entry.rs +222 -17
- data/ext/fast_mmaped_file_rs/src/file_info.rs +56 -6
- data/ext/fast_mmaped_file_rs/src/lib.rs +0 -1
- data/ext/fast_mmaped_file_rs/src/map.rs +12 -12
- data/ext/fast_mmaped_file_rs/src/mmap/inner.rs +6 -10
- data/ext/fast_mmaped_file_rs/src/mmap.rs +225 -47
- data/ext/fast_mmaped_file_rs/src/raw_entry.rs +1 -1
- data/ext/fast_mmaped_file_rs/src/testhelper.rs +1 -1
- data/lib/3.1/fast_mmaped_file_rs.so +0 -0
- data/lib/3.2/fast_mmaped_file_rs.so +0 -0
- data/lib/3.3/fast_mmaped_file_rs.so +0 -0
- data/lib/3.4/fast_mmaped_file_rs.so +0 -0
- data/lib/prometheus/client/formats/text.rb +1 -34
- data/lib/prometheus/client/helper/mmaped_file.rb +3 -3
- data/lib/prometheus/client/label_set_validator.rb +1 -2
- data/lib/prometheus/client/support/puma.rb +44 -0
- data/lib/prometheus/client/version.rb +1 -1
- metadata +62 -61
- data/ext/fast_mmaped_file/extconf.rb +0 -30
- data/ext/fast_mmaped_file/fast_mmaped_file.c +0 -122
- data/ext/fast_mmaped_file/file_format.c +0 -5
- data/ext/fast_mmaped_file/file_format.h +0 -11
- data/ext/fast_mmaped_file/file_parsing.c +0 -195
- data/ext/fast_mmaped_file/file_parsing.h +0 -27
- data/ext/fast_mmaped_file/file_reading.c +0 -102
- data/ext/fast_mmaped_file/file_reading.h +0 -30
- data/ext/fast_mmaped_file/globals.h +0 -14
- data/ext/fast_mmaped_file/mmap.c +0 -427
- data/ext/fast_mmaped_file/mmap.h +0 -61
- data/ext/fast_mmaped_file/rendering.c +0 -199
- data/ext/fast_mmaped_file/rendering.h +0 -8
- data/ext/fast_mmaped_file/utils.c +0 -56
- data/ext/fast_mmaped_file/utils.h +0 -22
- data/ext/fast_mmaped_file/value_access.c +0 -242
- data/ext/fast_mmaped_file/value_access.h +0 -15
- data/ext/fast_mmaped_file_rs/.cargo/config.toml +0 -23
- data/ext/fast_mmaped_file_rs/Cargo.lock +0 -790
- data/ext/fast_mmaped_file_rs/src/parser.rs +0 -346
- data/lib/2.7/fast_mmaped_file.so +0 -0
- data/lib/2.7/fast_mmaped_file_rs.so +0 -0
- data/lib/3.0/fast_mmaped_file.so +0 -0
- data/lib/3.0/fast_mmaped_file_rs.so +0 -0
- data/lib/3.1/fast_mmaped_file.so +0 -0
- data/lib/3.2/fast_mmaped_file.so +0 -0
- data/vendor/c/hashmap/.gitignore +0 -52
- data/vendor/c/hashmap/LICENSE +0 -21
- data/vendor/c/hashmap/README.md +0 -90
- data/vendor/c/hashmap/_config.yml +0 -1
- data/vendor/c/hashmap/src/hashmap.c +0 -692
- data/vendor/c/hashmap/src/hashmap.h +0 -267
- data/vendor/c/hashmap/test/Makefile +0 -22
- data/vendor/c/hashmap/test/hashmap_test.c +0 -608
- data/vendor/c/jsmn/.travis.yml +0 -4
- data/vendor/c/jsmn/LICENSE +0 -20
- data/vendor/c/jsmn/Makefile +0 -41
- data/vendor/c/jsmn/README.md +0 -168
- data/vendor/c/jsmn/example/jsondump.c +0 -126
- data/vendor/c/jsmn/example/simple.c +0 -76
- data/vendor/c/jsmn/jsmn.c +0 -314
- data/vendor/c/jsmn/jsmn.h +0 -76
- data/vendor/c/jsmn/library.json +0 -16
- data/vendor/c/jsmn/test/test.h +0 -27
- data/vendor/c/jsmn/test/tests.c +0 -407
- data/vendor/c/jsmn/test/testutil.h +0 -94
@@ -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
|
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:
|
4
|
+
version: 1.2.4
|
5
5
|
platform: x86_64-linux-musl
|
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:
|
14
|
+
date: 2024-12-29 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: rb_sys
|
@@ -19,14 +19,42 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - "~>"
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version:
|
22
|
+
version: 0.9.86
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - "~>"
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version:
|
29
|
+
version: 0.9.86
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: base64
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
requirements:
|
34
|
+
- - ">="
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '0'
|
37
|
+
type: :runtime
|
38
|
+
prerelease: false
|
39
|
+
version_requirements: !ruby/object:Gem::Requirement
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
- !ruby/object:Gem::Dependency
|
45
|
+
name: bigdecimal
|
46
|
+
requirement: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '0'
|
51
|
+
type: :runtime
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '0'
|
30
58
|
- !ruby/object:Gem::Dependency
|
31
59
|
name: fuzzbert
|
32
60
|
requirement: !ruby/object:Gem::Requirement
|
@@ -81,42 +109,56 @@ dependencies:
|
|
81
109
|
requirements:
|
82
110
|
- - "~>"
|
83
111
|
- !ruby/object:Gem::Version
|
84
|
-
version: 1.2.
|
112
|
+
version: 1.2.7
|
85
113
|
type: :development
|
86
114
|
prerelease: false
|
87
115
|
version_requirements: !ruby/object:Gem::Requirement
|
88
116
|
requirements:
|
89
117
|
- - "~>"
|
90
118
|
- !ruby/object:Gem::Version
|
91
|
-
version: 1.2.
|
119
|
+
version: 1.2.7
|
92
120
|
- !ruby/object:Gem::Dependency
|
93
121
|
name: rake-compiler-dock
|
94
122
|
requirement: !ruby/object:Gem::Requirement
|
95
123
|
requirements:
|
96
124
|
- - "~>"
|
97
125
|
- !ruby/object:Gem::Version
|
98
|
-
version: 1.
|
126
|
+
version: 1.7.0
|
127
|
+
type: :development
|
128
|
+
prerelease: false
|
129
|
+
version_requirements: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - "~>"
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: 1.7.0
|
134
|
+
- !ruby/object:Gem::Dependency
|
135
|
+
name: rspec
|
136
|
+
requirement: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - "~>"
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '3.2'
|
99
141
|
type: :development
|
100
142
|
prerelease: false
|
101
143
|
version_requirements: !ruby/object:Gem::Requirement
|
102
144
|
requirements:
|
103
145
|
- - "~>"
|
104
146
|
- !ruby/object:Gem::Version
|
105
|
-
version:
|
147
|
+
version: '3.2'
|
106
148
|
- !ruby/object:Gem::Dependency
|
107
149
|
name: ruby-prof
|
108
150
|
requirement: !ruby/object:Gem::Requirement
|
109
151
|
requirements:
|
110
152
|
- - "~>"
|
111
153
|
- !ruby/object:Gem::Version
|
112
|
-
version:
|
154
|
+
version: '1.7'
|
113
155
|
type: :development
|
114
156
|
prerelease: false
|
115
157
|
version_requirements: !ruby/object:Gem::Requirement
|
116
158
|
requirements:
|
117
159
|
- - "~>"
|
118
160
|
- !ruby/object:Gem::Version
|
119
|
-
version:
|
161
|
+
version: '1.7'
|
120
162
|
description:
|
121
163
|
email:
|
122
164
|
- ts@soundcloud.com
|
@@ -127,28 +169,11 @@ executables: []
|
|
127
169
|
extensions: []
|
128
170
|
extra_rdoc_files: []
|
129
171
|
files:
|
172
|
+
- ".tool-versions"
|
130
173
|
- README.md
|
131
|
-
- ext/fast_mmaped_file/extconf.rb
|
132
|
-
- ext/fast_mmaped_file/fast_mmaped_file.c
|
133
|
-
- ext/fast_mmaped_file/file_format.c
|
134
|
-
- ext/fast_mmaped_file/file_format.h
|
135
|
-
- ext/fast_mmaped_file/file_parsing.c
|
136
|
-
- ext/fast_mmaped_file/file_parsing.h
|
137
|
-
- ext/fast_mmaped_file/file_reading.c
|
138
|
-
- ext/fast_mmaped_file/file_reading.h
|
139
|
-
- ext/fast_mmaped_file/globals.h
|
140
|
-
- ext/fast_mmaped_file/mmap.c
|
141
|
-
- ext/fast_mmaped_file/mmap.h
|
142
|
-
- ext/fast_mmaped_file/rendering.c
|
143
|
-
- ext/fast_mmaped_file/rendering.h
|
144
|
-
- ext/fast_mmaped_file/utils.c
|
145
|
-
- ext/fast_mmaped_file/utils.h
|
146
|
-
- ext/fast_mmaped_file/value_access.c
|
147
|
-
- ext/fast_mmaped_file/value_access.h
|
148
|
-
- ext/fast_mmaped_file_rs/.cargo/config.toml
|
149
|
-
- ext/fast_mmaped_file_rs/Cargo.lock
|
150
174
|
- ext/fast_mmaped_file_rs/Cargo.toml
|
151
175
|
- ext/fast_mmaped_file_rs/README.md
|
176
|
+
- ext/fast_mmaped_file_rs/build.rs
|
152
177
|
- ext/fast_mmaped_file_rs/extconf.rb
|
153
178
|
- ext/fast_mmaped_file_rs/src/error.rs
|
154
179
|
- ext/fast_mmaped_file_rs/src/file_entry.rs
|
@@ -158,18 +183,13 @@ files:
|
|
158
183
|
- ext/fast_mmaped_file_rs/src/map.rs
|
159
184
|
- ext/fast_mmaped_file_rs/src/mmap.rs
|
160
185
|
- ext/fast_mmaped_file_rs/src/mmap/inner.rs
|
161
|
-
- ext/fast_mmaped_file_rs/src/parser.rs
|
162
186
|
- ext/fast_mmaped_file_rs/src/raw_entry.rs
|
163
187
|
- ext/fast_mmaped_file_rs/src/testhelper.rs
|
164
188
|
- ext/fast_mmaped_file_rs/src/util.rs
|
165
|
-
- lib/2.7/fast_mmaped_file.so
|
166
|
-
- lib/2.7/fast_mmaped_file_rs.so
|
167
|
-
- lib/3.0/fast_mmaped_file.so
|
168
|
-
- lib/3.0/fast_mmaped_file_rs.so
|
169
|
-
- lib/3.1/fast_mmaped_file.so
|
170
189
|
- lib/3.1/fast_mmaped_file_rs.so
|
171
|
-
- lib/3.2/fast_mmaped_file.so
|
172
190
|
- lib/3.2/fast_mmaped_file_rs.so
|
191
|
+
- lib/3.3/fast_mmaped_file_rs.so
|
192
|
+
- lib/3.4/fast_mmaped_file_rs.so
|
173
193
|
- lib/prometheus.rb
|
174
194
|
- lib/prometheus/client.rb
|
175
195
|
- lib/prometheus/client/configuration.rb
|
@@ -195,29 +215,10 @@ files:
|
|
195
215
|
- lib/prometheus/client/registry.rb
|
196
216
|
- lib/prometheus/client/simple_value.rb
|
197
217
|
- lib/prometheus/client/summary.rb
|
218
|
+
- lib/prometheus/client/support/puma.rb
|
198
219
|
- lib/prometheus/client/support/unicorn.rb
|
199
220
|
- lib/prometheus/client/uses_value_type.rb
|
200
221
|
- lib/prometheus/client/version.rb
|
201
|
-
- vendor/c/hashmap/.gitignore
|
202
|
-
- vendor/c/hashmap/LICENSE
|
203
|
-
- vendor/c/hashmap/README.md
|
204
|
-
- vendor/c/hashmap/_config.yml
|
205
|
-
- vendor/c/hashmap/src/hashmap.c
|
206
|
-
- vendor/c/hashmap/src/hashmap.h
|
207
|
-
- vendor/c/hashmap/test/Makefile
|
208
|
-
- vendor/c/hashmap/test/hashmap_test.c
|
209
|
-
- vendor/c/jsmn/.travis.yml
|
210
|
-
- vendor/c/jsmn/LICENSE
|
211
|
-
- vendor/c/jsmn/Makefile
|
212
|
-
- vendor/c/jsmn/README.md
|
213
|
-
- vendor/c/jsmn/example/jsondump.c
|
214
|
-
- vendor/c/jsmn/example/simple.c
|
215
|
-
- vendor/c/jsmn/jsmn.c
|
216
|
-
- vendor/c/jsmn/jsmn.h
|
217
|
-
- vendor/c/jsmn/library.json
|
218
|
-
- vendor/c/jsmn/test/test.h
|
219
|
-
- vendor/c/jsmn/test/tests.c
|
220
|
-
- vendor/c/jsmn/test/testutil.h
|
221
222
|
homepage: https://gitlab.com/gitlab-org/prometheus-client-mmap
|
222
223
|
licenses:
|
223
224
|
- Apache-2.0
|
@@ -230,19 +231,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
230
231
|
requirements:
|
231
232
|
- - ">="
|
232
233
|
- !ruby/object:Gem::Version
|
233
|
-
version: '
|
234
|
+
version: '3.1'
|
234
235
|
- - "<"
|
235
236
|
- !ruby/object:Gem::Version
|
236
|
-
version: 3.
|
237
|
+
version: 3.5.dev
|
237
238
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
239
|
requirements:
|
239
240
|
- - ">="
|
240
241
|
- !ruby/object:Gem::Version
|
241
242
|
version: 3.3.22
|
242
243
|
requirements: []
|
243
|
-
rubygems_version: 3.
|
244
|
+
rubygems_version: 3.5.23
|
244
245
|
signing_key:
|
245
246
|
specification_version: 4
|
246
|
-
summary: A suite of instrumentation metric
|
247
|
-
web services interface.
|
247
|
+
summary: A suite of instrumentation metric primitives that can be exposed through
|
248
|
+
a web services interface.
|
248
249
|
test_files: []
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'mkmf'
|
2
|
-
require 'fileutils'
|
3
|
-
|
4
|
-
$CFLAGS << ' -std=c99 -D_POSIX_C_SOURCE=200809L -Wall -Wextra'
|
5
|
-
|
6
|
-
if enable_config('fail-on-warning')
|
7
|
-
$CFLAGS << ' -Werror'
|
8
|
-
end
|
9
|
-
|
10
|
-
if enable_config('debug')
|
11
|
-
$CFLAGS << ' -O0 -g'
|
12
|
-
end
|
13
|
-
|
14
|
-
if enable_config('address-sanitizer')
|
15
|
-
$CFLAGS << ' -O -fsanitize=address -fno-omit-frame-pointer -g'
|
16
|
-
end
|
17
|
-
|
18
|
-
CONFIG['warnflags'].slice!(/ -Wdeclaration-after-statement/)
|
19
|
-
|
20
|
-
cwd = File.expand_path(File.dirname(__FILE__))
|
21
|
-
vendor_dir = File.join(cwd, '../../vendor/c')
|
22
|
-
src_dir = File.join(cwd, '../../ext/fast_mmaped_file')
|
23
|
-
|
24
|
-
src_files = %W[#{vendor_dir}/jsmn/jsmn.c #{vendor_dir}/hashmap/src/hashmap.c]
|
25
|
-
FileUtils.cp(src_files, src_dir)
|
26
|
-
|
27
|
-
$INCFLAGS << " -I#{vendor_dir}/jsmn -I#{vendor_dir}/hashmap/src"
|
28
|
-
|
29
|
-
dir_config('fast_mmaped_file')
|
30
|
-
create_makefile('fast_mmaped_file')
|
@@ -1,122 +0,0 @@
|
|
1
|
-
#include <errno.h>
|
2
|
-
#include <hashmap.h>
|
3
|
-
#include <jsmn.h>
|
4
|
-
#include <ruby.h>
|
5
|
-
#include <ruby/intern.h>
|
6
|
-
#include <sys/mman.h>
|
7
|
-
|
8
|
-
#include "file_parsing.h"
|
9
|
-
#include "file_reading.h"
|
10
|
-
#include "globals.h"
|
11
|
-
#include "mmap.h"
|
12
|
-
#include "rendering.h"
|
13
|
-
#include "utils.h"
|
14
|
-
#include "value_access.h"
|
15
|
-
|
16
|
-
VALUE MMAPED_FILE = Qnil;
|
17
|
-
|
18
|
-
ID sym_min;
|
19
|
-
ID sym_max;
|
20
|
-
ID sym_livesum;
|
21
|
-
ID sym_gauge;
|
22
|
-
ID sym_pid;
|
23
|
-
ID sym_samples;
|
24
|
-
|
25
|
-
VALUE prom_eParsingError;
|
26
|
-
|
27
|
-
int aggregate_files(struct hashmap *map, VALUE list_of_files) {
|
28
|
-
buffer_t reading_buffer;
|
29
|
-
memset(&reading_buffer, 0, sizeof(buffer_t));
|
30
|
-
|
31
|
-
for (int i = 0; i < RARRAY_LEN(list_of_files); i++) {
|
32
|
-
VALUE params = RARRAY_PTR(list_of_files)[i];
|
33
|
-
file_t file;
|
34
|
-
|
35
|
-
if (!file_open_from_params(&file, params)) {
|
36
|
-
buffer_dispose(&reading_buffer);
|
37
|
-
return 0;
|
38
|
-
}
|
39
|
-
|
40
|
-
if (!read_from_file(&file, &reading_buffer)) {
|
41
|
-
buffer_dispose(&reading_buffer);
|
42
|
-
file_close(&file);
|
43
|
-
return 0;
|
44
|
-
}
|
45
|
-
|
46
|
-
if (!process_buffer(&file, &reading_buffer, map)) {
|
47
|
-
buffer_dispose(&reading_buffer);
|
48
|
-
file_close(&file);
|
49
|
-
return 0;
|
50
|
-
}
|
51
|
-
|
52
|
-
if (!file_close(&file)) {
|
53
|
-
buffer_dispose(&reading_buffer);
|
54
|
-
return 0;
|
55
|
-
}
|
56
|
-
}
|
57
|
-
|
58
|
-
buffer_dispose(&reading_buffer);
|
59
|
-
return 1;
|
60
|
-
}
|
61
|
-
|
62
|
-
VALUE method_to_metrics(VALUE UNUSED(self), VALUE file_list) {
|
63
|
-
struct hashmap map;
|
64
|
-
hashmap_setup(&map);
|
65
|
-
|
66
|
-
if (!aggregate_files(&map, file_list)) { // all entries in map are now copies that need to be disposed
|
67
|
-
hashmap_destroy(&map);
|
68
|
-
raise_last_exception();
|
69
|
-
return Qnil;
|
70
|
-
}
|
71
|
-
|
72
|
-
entry_t **sorted_entries;
|
73
|
-
|
74
|
-
if (!sort_map_entries(&map, &sorted_entries)) {
|
75
|
-
hashmap_destroy(&map);
|
76
|
-
|
77
|
-
raise_last_exception();
|
78
|
-
return Qnil;
|
79
|
-
}
|
80
|
-
|
81
|
-
VALUE rv = rb_str_new("", 0);
|
82
|
-
if (!entries_to_string(rv, sorted_entries, hashmap_size(&map))) {
|
83
|
-
free(sorted_entries);
|
84
|
-
hashmap_destroy(&map);
|
85
|
-
|
86
|
-
raise_last_exception();
|
87
|
-
return Qnil;
|
88
|
-
}
|
89
|
-
|
90
|
-
RB_GC_GUARD(file_list); // ensure file list is not GCed before this point
|
91
|
-
free(sorted_entries);
|
92
|
-
hashmap_destroy(&map);
|
93
|
-
return rv;
|
94
|
-
}
|
95
|
-
|
96
|
-
void Init_fast_mmaped_file() {
|
97
|
-
sym_gauge = rb_intern("gauge");
|
98
|
-
sym_min = rb_intern("min");
|
99
|
-
sym_max = rb_intern("max");
|
100
|
-
sym_livesum = rb_intern("livesum");
|
101
|
-
sym_pid = rb_intern("pid");
|
102
|
-
sym_samples = rb_intern("samples");
|
103
|
-
|
104
|
-
prom_eParsingError = rb_define_class("PrometheusParsingError", rb_eRuntimeError);
|
105
|
-
|
106
|
-
MMAPED_FILE = rb_define_class("FastMmapedFile", rb_cObject);
|
107
|
-
rb_define_const(MMAPED_FILE, "MAP_SHARED", INT2FIX(MAP_SHARED));
|
108
|
-
|
109
|
-
rb_define_singleton_method(MMAPED_FILE, "to_metrics", method_to_metrics, 1);
|
110
|
-
|
111
|
-
rb_define_alloc_func(MMAPED_FILE, mm_s_alloc);
|
112
|
-
rb_define_singleton_method(MMAPED_FILE, "new", mm_s_new, -1);
|
113
|
-
rb_define_method(MMAPED_FILE, "initialize", mm_init, 1);
|
114
|
-
rb_define_method(MMAPED_FILE, "slice", mm_aref_m, -1);
|
115
|
-
rb_define_method(MMAPED_FILE, "sync", mm_msync, -1);
|
116
|
-
rb_define_method(MMAPED_FILE, "munmap", mm_unmap, 0);
|
117
|
-
|
118
|
-
rb_define_method(MMAPED_FILE, "used", method_load_used, 0);
|
119
|
-
rb_define_method(MMAPED_FILE, "used=", method_save_used, 1);
|
120
|
-
rb_define_method(MMAPED_FILE, "fetch_entry", method_fetch_entry, 3);
|
121
|
-
rb_define_method(MMAPED_FILE, "upsert_entry", method_upsert_entry, 3);
|
122
|
-
}
|
@@ -1,195 +0,0 @@
|
|
1
|
-
#include "file_parsing.h"
|
2
|
-
|
3
|
-
#include <hashmap.h>
|
4
|
-
#include <jsmn.h>
|
5
|
-
|
6
|
-
#include "file_format.h"
|
7
|
-
#include "globals.h"
|
8
|
-
#include "utils.h"
|
9
|
-
|
10
|
-
HASHMAP_FUNCS_CREATE(entry, const entry_t, entry_t)
|
11
|
-
|
12
|
-
typedef int (*compare_fn)(const void *a, const void *b);
|
13
|
-
|
14
|
-
static size_t hashmap_hash_entry(const entry_t *entry) { return hashmap_hash_string(entry->json); }
|
15
|
-
|
16
|
-
static int hashmap_compare_entry(const entry_t *a, const entry_t *b) {
|
17
|
-
if (a->json_size != b->json_size) {
|
18
|
-
return -1;
|
19
|
-
}
|
20
|
-
|
21
|
-
if (is_pid_significant(a) && (rb_str_equal(a->pid, b->pid) == Qfalse)) {
|
22
|
-
return -1;
|
23
|
-
}
|
24
|
-
|
25
|
-
return strncmp(a->json, b->json, a->json_size);
|
26
|
-
}
|
27
|
-
|
28
|
-
static void entry_free(entry_t *entry) {
|
29
|
-
free(entry->json);
|
30
|
-
free(entry);
|
31
|
-
}
|
32
|
-
|
33
|
-
static inline double min(double a, double b) { return a < b ? a : b; }
|
34
|
-
|
35
|
-
static inline double max(double a, double b) { return a > b ? a : b; }
|
36
|
-
|
37
|
-
static void merge_entry(entry_t *found, const entry_t *entry) {
|
38
|
-
if (entry->type == sym_gauge) {
|
39
|
-
if (entry->multiprocess_mode == sym_min) {
|
40
|
-
found->value = min(found->value, entry->value);
|
41
|
-
} else if (entry->multiprocess_mode == sym_max) {
|
42
|
-
found->value = max(found->value, entry->value);
|
43
|
-
} else if (entry->multiprocess_mode == sym_livesum) {
|
44
|
-
found->value += entry->value;
|
45
|
-
} else {
|
46
|
-
found->value = entry->value;
|
47
|
-
}
|
48
|
-
} else {
|
49
|
-
found->value += entry->value;
|
50
|
-
}
|
51
|
-
}
|
52
|
-
|
53
|
-
void merge_or_store(struct hashmap *map, entry_t *entry) {
|
54
|
-
entry_t *found = entry_hashmap_get(map, entry);
|
55
|
-
if (found) {
|
56
|
-
merge_entry(found, entry);
|
57
|
-
entry_free(entry);
|
58
|
-
} else {
|
59
|
-
entry_hashmap_put(map, entry, entry); // use the hashmap like hashset actually
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
entry_t *entry_new(buffer_t *source, uint32_t pos, uint32_t encoded_len, file_t *file_info) {
|
64
|
-
entry_t *entry = calloc(1, sizeof(entry_t));
|
65
|
-
if (entry == NULL) {
|
66
|
-
return NULL;
|
67
|
-
}
|
68
|
-
|
69
|
-
entry->json = malloc(encoded_len + 1);
|
70
|
-
if (entry->json == NULL) {
|
71
|
-
free(entry);
|
72
|
-
return NULL;
|
73
|
-
}
|
74
|
-
|
75
|
-
memcpy(entry->json, source->buffer + pos, encoded_len);
|
76
|
-
entry->json[encoded_len] = '\0';
|
77
|
-
entry->json_size = encoded_len;
|
78
|
-
|
79
|
-
entry->pid = file_info->pid;
|
80
|
-
entry->multiprocess_mode = file_info->multiprocess_mode;
|
81
|
-
entry->type = file_info->type;
|
82
|
-
|
83
|
-
char *value_ptr = source->buffer + pos + encoded_len + padding_length(encoded_len);
|
84
|
-
memcpy(&(entry->value), value_ptr, sizeof(double));
|
85
|
-
|
86
|
-
return entry;
|
87
|
-
}
|
88
|
-
|
89
|
-
static int add_parsed_name(entry_t *entry) {
|
90
|
-
jsmn_parser parser;
|
91
|
-
jsmn_init(&parser);
|
92
|
-
|
93
|
-
jsmntok_t tokens[2];
|
94
|
-
memset(&tokens, 0, sizeof(tokens));
|
95
|
-
|
96
|
-
jsmn_parse(&parser, entry->json, entry->json_size, tokens, 2);
|
97
|
-
jsmntok_t *name_token = &tokens[1];
|
98
|
-
|
99
|
-
if (name_token->start < name_token->end && name_token->start > 0) {
|
100
|
-
entry->name = entry->json + name_token->start;
|
101
|
-
entry->name_len = name_token->end - name_token->start;
|
102
|
-
return 1;
|
103
|
-
}
|
104
|
-
return 0;
|
105
|
-
}
|
106
|
-
|
107
|
-
static int entry_lexical_comparator(const entry_t **a, const entry_t **b) {
|
108
|
-
size_t size_a = (*a)->json_size;
|
109
|
-
size_t size_b = (*b)->json_size;
|
110
|
-
size_t min_length = size_a < size_b ? size_a : size_b;
|
111
|
-
|
112
|
-
return strncmp((*a)->json, (*b)->json, min_length);
|
113
|
-
}
|
114
|
-
|
115
|
-
void hashmap_setup(struct hashmap *map) {
|
116
|
-
hashmap_init(map, (size_t(*)(const void *))hashmap_hash_entry,
|
117
|
-
(int (*)(const void *, const void *))hashmap_compare_entry, 1000);
|
118
|
-
hashmap_set_key_alloc_funcs(map, NULL, (void (*)(void *))entry_free);
|
119
|
-
}
|
120
|
-
|
121
|
-
int process_buffer(file_t *file_info, buffer_t *source, struct hashmap *map) {
|
122
|
-
if (source->size < START_POSITION) {
|
123
|
-
// nothing to read
|
124
|
-
return 1;
|
125
|
-
}
|
126
|
-
uint32_t used;
|
127
|
-
memcpy(&used, source->buffer, sizeof(uint32_t));
|
128
|
-
|
129
|
-
if (used > source->size) {
|
130
|
-
save_exception(prom_eParsingError, "source file %s corrupted, used %u > file size %u", file_info->path, used,
|
131
|
-
source->size);
|
132
|
-
return 0;
|
133
|
-
}
|
134
|
-
|
135
|
-
uint32_t pos = START_POSITION;
|
136
|
-
while (pos + sizeof(uint32_t) < used) {
|
137
|
-
uint32_t encoded_len;
|
138
|
-
memcpy(&encoded_len, source->buffer + pos, sizeof(uint32_t));
|
139
|
-
pos += sizeof(uint32_t);
|
140
|
-
|
141
|
-
uint32_t value_offset = encoded_len + padding_length(encoded_len);
|
142
|
-
|
143
|
-
if (pos + value_offset + sizeof(double) > used) {
|
144
|
-
save_exception(prom_eParsingError, "source file %s corrupted, used %u < stored data length %u",
|
145
|
-
file_info->path, used, pos + value_offset + sizeof(double));
|
146
|
-
return 0;
|
147
|
-
}
|
148
|
-
|
149
|
-
entry_t *entry = entry_new(source, pos, encoded_len, file_info);
|
150
|
-
if (entry == NULL) {
|
151
|
-
save_exception(rb_eNoMemError, "Failed creating metrics entry");
|
152
|
-
return 0;
|
153
|
-
}
|
154
|
-
|
155
|
-
merge_or_store(map, entry);
|
156
|
-
|
157
|
-
pos += value_offset + sizeof(double);
|
158
|
-
}
|
159
|
-
return 1;
|
160
|
-
}
|
161
|
-
|
162
|
-
int sort_map_entries(const struct hashmap *map, entry_t ***sorted_entries) {
|
163
|
-
size_t num = hashmap_size(map);
|
164
|
-
|
165
|
-
entry_t **list = calloc(num, sizeof(entry_t *));
|
166
|
-
|
167
|
-
if (list == NULL) {
|
168
|
-
save_exception(rb_eNoMemError, "Couldn't allocate for %zu memory", num * sizeof(entry_t *));
|
169
|
-
return 0;
|
170
|
-
}
|
171
|
-
|
172
|
-
size_t cnt = 0;
|
173
|
-
struct hashmap_iter *iter;
|
174
|
-
for (iter = hashmap_iter(map); iter; iter = hashmap_iter_next(map, iter)) {
|
175
|
-
entry_t *entry = (entry_t *)entry_hashmap_iter_get_key(iter);
|
176
|
-
if (add_parsed_name(entry)) {
|
177
|
-
list[cnt] = entry;
|
178
|
-
cnt++;
|
179
|
-
}
|
180
|
-
}
|
181
|
-
if (cnt != num) {
|
182
|
-
save_exception(rb_eRuntimeError, "Processed entries %zu != map entries %zu", cnt, num);
|
183
|
-
free(list);
|
184
|
-
return 0;
|
185
|
-
}
|
186
|
-
|
187
|
-
qsort(list, cnt, sizeof(entry_t *), (compare_fn)&entry_lexical_comparator);
|
188
|
-
*sorted_entries = list;
|
189
|
-
return 1;
|
190
|
-
}
|
191
|
-
|
192
|
-
int is_pid_significant(const entry_t *e) {
|
193
|
-
ID mp = e->multiprocess_mode;
|
194
|
-
return e->type == sym_gauge && !(mp == sym_min || mp == sym_max || mp == sym_livesum);
|
195
|
-
}
|
@@ -1,27 +0,0 @@
|
|
1
|
-
#ifndef FILE_PARSING_H
|
2
|
-
#define FILE_PARSING_H
|
3
|
-
#include <file_reading.h>
|
4
|
-
#include <hashmap.h>
|
5
|
-
#include <ruby.h>
|
6
|
-
|
7
|
-
typedef struct {
|
8
|
-
char *json;
|
9
|
-
size_t json_size;
|
10
|
-
char *name;
|
11
|
-
size_t name_len;
|
12
|
-
|
13
|
-
ID multiprocess_mode;
|
14
|
-
ID type;
|
15
|
-
VALUE pid;
|
16
|
-
|
17
|
-
double value;
|
18
|
-
} entry_t;
|
19
|
-
|
20
|
-
void hashmap_setup(struct hashmap *map);
|
21
|
-
|
22
|
-
int process_buffer(file_t *file_info, buffer_t *source, struct hashmap *map);
|
23
|
-
int sort_map_entries(const struct hashmap *map, entry_t ***sorted_entries);
|
24
|
-
|
25
|
-
int is_pid_significant(const entry_t *e);
|
26
|
-
|
27
|
-
#endif
|