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.
Files changed (71) hide show
  1. checksums.yaml +4 -4
  2. data/.tool-versions +1 -0
  3. data/README.md +32 -17
  4. data/ext/fast_mmaped_file_rs/Cargo.toml +14 -9
  5. data/ext/fast_mmaped_file_rs/build.rs +5 -0
  6. data/ext/fast_mmaped_file_rs/extconf.rb +1 -3
  7. data/ext/fast_mmaped_file_rs/src/error.rs +2 -2
  8. data/ext/fast_mmaped_file_rs/src/file_entry.rs +222 -17
  9. data/ext/fast_mmaped_file_rs/src/file_info.rs +56 -6
  10. data/ext/fast_mmaped_file_rs/src/lib.rs +0 -1
  11. data/ext/fast_mmaped_file_rs/src/map.rs +12 -12
  12. data/ext/fast_mmaped_file_rs/src/mmap/inner.rs +6 -10
  13. data/ext/fast_mmaped_file_rs/src/mmap.rs +225 -47
  14. data/ext/fast_mmaped_file_rs/src/raw_entry.rs +1 -1
  15. data/ext/fast_mmaped_file_rs/src/testhelper.rs +1 -1
  16. data/lib/3.1/fast_mmaped_file_rs.so +0 -0
  17. data/lib/3.2/fast_mmaped_file_rs.so +0 -0
  18. data/lib/3.3/fast_mmaped_file_rs.so +0 -0
  19. data/lib/3.4/fast_mmaped_file_rs.so +0 -0
  20. data/lib/prometheus/client/formats/text.rb +1 -34
  21. data/lib/prometheus/client/helper/mmaped_file.rb +3 -3
  22. data/lib/prometheus/client/label_set_validator.rb +1 -2
  23. data/lib/prometheus/client/support/puma.rb +44 -0
  24. data/lib/prometheus/client/version.rb +1 -1
  25. metadata +62 -61
  26. data/ext/fast_mmaped_file/extconf.rb +0 -30
  27. data/ext/fast_mmaped_file/fast_mmaped_file.c +0 -122
  28. data/ext/fast_mmaped_file/file_format.c +0 -5
  29. data/ext/fast_mmaped_file/file_format.h +0 -11
  30. data/ext/fast_mmaped_file/file_parsing.c +0 -195
  31. data/ext/fast_mmaped_file/file_parsing.h +0 -27
  32. data/ext/fast_mmaped_file/file_reading.c +0 -102
  33. data/ext/fast_mmaped_file/file_reading.h +0 -30
  34. data/ext/fast_mmaped_file/globals.h +0 -14
  35. data/ext/fast_mmaped_file/mmap.c +0 -427
  36. data/ext/fast_mmaped_file/mmap.h +0 -61
  37. data/ext/fast_mmaped_file/rendering.c +0 -199
  38. data/ext/fast_mmaped_file/rendering.h +0 -8
  39. data/ext/fast_mmaped_file/utils.c +0 -56
  40. data/ext/fast_mmaped_file/utils.h +0 -22
  41. data/ext/fast_mmaped_file/value_access.c +0 -242
  42. data/ext/fast_mmaped_file/value_access.h +0 -15
  43. data/ext/fast_mmaped_file_rs/.cargo/config.toml +0 -23
  44. data/ext/fast_mmaped_file_rs/Cargo.lock +0 -790
  45. data/ext/fast_mmaped_file_rs/src/parser.rs +0 -346
  46. data/lib/2.7/fast_mmaped_file.so +0 -0
  47. data/lib/2.7/fast_mmaped_file_rs.so +0 -0
  48. data/lib/3.0/fast_mmaped_file.so +0 -0
  49. data/lib/3.0/fast_mmaped_file_rs.so +0 -0
  50. data/lib/3.1/fast_mmaped_file.so +0 -0
  51. data/lib/3.2/fast_mmaped_file.so +0 -0
  52. data/vendor/c/hashmap/.gitignore +0 -52
  53. data/vendor/c/hashmap/LICENSE +0 -21
  54. data/vendor/c/hashmap/README.md +0 -90
  55. data/vendor/c/hashmap/_config.yml +0 -1
  56. data/vendor/c/hashmap/src/hashmap.c +0 -692
  57. data/vendor/c/hashmap/src/hashmap.h +0 -267
  58. data/vendor/c/hashmap/test/Makefile +0 -22
  59. data/vendor/c/hashmap/test/hashmap_test.c +0 -608
  60. data/vendor/c/jsmn/.travis.yml +0 -4
  61. data/vendor/c/jsmn/LICENSE +0 -20
  62. data/vendor/c/jsmn/Makefile +0 -41
  63. data/vendor/c/jsmn/README.md +0 -168
  64. data/vendor/c/jsmn/example/jsondump.c +0 -126
  65. data/vendor/c/jsmn/example/simple.c +0 -76
  66. data/vendor/c/jsmn/jsmn.c +0 -314
  67. data/vendor/c/jsmn/jsmn.h +0 -76
  68. data/vendor/c/jsmn/library.json +0 -16
  69. data/vendor/c/jsmn/test/test.h +0 -27
  70. data/vendor/c/jsmn/test/tests.c +0 -407
  71. data/vendor/c/jsmn/test/testutil.h +0 -94
@@ -1,346 +0,0 @@
1
- use smallvec::SmallVec;
2
- use std::str;
3
-
4
- /// String slices pointing to the fields of a borrowed `Entry`'s JSON data.
5
- #[derive(PartialEq, Debug)]
6
- pub struct MetricText<'a> {
7
- pub family_name: &'a str,
8
- pub metric_name: &'a str,
9
- pub labels: SmallVec<[&'a str; 4]>,
10
- pub values: SmallVec<[&'a str; 4]>,
11
- }
12
-
13
- #[derive(PartialEq, Debug)]
14
- struct MetricNames<'a> {
15
- label_json: &'a str,
16
- family_name: &'a str,
17
- metric_name: &'a str,
18
- }
19
-
20
- #[derive(PartialEq, Debug)]
21
- struct MetricLabelVals<'a> {
22
- labels: SmallVec<[&'a str; 4]>,
23
- values: SmallVec<[&'a str; 4]>,
24
- }
25
-
26
- /// Parse Prometheus metric data stored in the following format:
27
- ///
28
- /// ["metric","name",["label_a","label_b"],["value_a","value_b"]]
29
- ///
30
- /// There will be 1-8 trailing spaces to ensure at least a one-byte
31
- /// gap between the json and value, and to pad to an 8-byte alignment.
32
- /// We strip the surrounding double quotes from all items. Values may
33
- /// or may not have surrounding double quotes, depending on their type.
34
- pub fn parse_metrics(json: &str) -> Option<MetricText> {
35
- // It would be preferable to use `serde_json` here, but the values
36
- // may be strings, numbers, or null, and so don't parse easily to a
37
- // defined struct. Using `serde_json::Value` is an option, but since
38
- // we're just copying the literal values into a buffer this will be
39
- // inefficient and verbose.
40
-
41
- // Trim trailing spaces from string before processing. We use
42
- // `trim_end_matches()` instead of `trim_end()` because we know the
43
- // trailing bytes are always ASCII 0x20 bytes. `trim_end()` will also
44
- // check for unicode spaces and consume a few more CPU cycles.
45
- let trimmed = json.trim_end_matches(' ');
46
-
47
- let names = parse_names(trimmed)?;
48
- let label_json = names.label_json;
49
-
50
- let label_vals = parse_label_values(label_json)?;
51
-
52
- Some(MetricText {
53
- family_name: names.family_name,
54
- metric_name: names.metric_name,
55
- labels: label_vals.labels,
56
- values: label_vals.values,
57
- })
58
- }
59
-
60
- fn parse_names(json: &str) -> Option<MetricNames> {
61
- // Starting with: ["family_name","metric_name",[...
62
- if !json.starts_with("[\"") {
63
- return None;
64
- }
65
-
66
- // Now: family_name","metric_name",[...
67
- let remainder = json.get(2..)?;
68
-
69
- let names_end = remainder.find('[')?;
70
-
71
- // Save the rest of the slice to parse for labels later.
72
- let label_json = remainder.get(names_end..)?;
73
-
74
- // Now: family_name","metric_name",
75
- let remainder = remainder.get(..names_end)?;
76
-
77
- // Split on commas into:
78
- // family_name","metric_name",
79
- // ^^^^one^^^^^ ^^^^^two^^^^^
80
- let mut token_iter = remainder.split(',');
81
-
82
- // Captured: family_name","metric_name",
83
- // ^^^^^^^^^^^
84
- let family_name = token_iter.next()?.trim_end_matches('"');
85
-
86
- // Captured: "family_name","metric_name",
87
- // ^^^^^^^^^^^
88
- let metric_name = token_iter.next()?.trim_matches('"');
89
-
90
- // Confirm the final entry of the iter is empty, the the trailing ','.
91
- if !token_iter.next()?.is_empty() {
92
- return None;
93
- }
94
-
95
- Some(MetricNames {
96
- label_json,
97
- family_name,
98
- metric_name,
99
- })
100
- }
101
-
102
- fn parse_label_values(json: &str) -> Option<MetricLabelVals> {
103
- // Starting with: ["label_a","label_b"],["value_a", "value_b"]]
104
- if !(json.starts_with('[') && json.ends_with("]]")) {
105
- return None;
106
- }
107
-
108
- // Validate we either have the start of a label string or an
109
- // empty array, e.g. `["` or `[]`.
110
- if !matches!(json.as_bytes().get(1)?, b'"' | b']') {
111
- return None;
112
- }
113
-
114
- // Now: "label_a","label_b"
115
- let labels_end = json.find(']')?;
116
- let label_range = json.get(1..labels_end)?;
117
-
118
- let mut labels = SmallVec::new();
119
-
120
- // Split on commas into:
121
- // "label_a","label_b"
122
- // ^^^one^^^ ^^^two^^^
123
- for label in label_range.split(',') {
124
- // Captured: "label_a","label_b"
125
- // ^^^^^^^
126
- // If there are no labels, e.g. `[][]`, then don't capture anything.
127
- if !label.is_empty() {
128
- labels.push(label.trim_matches('"'));
129
- }
130
- }
131
-
132
- // Now: ],["value_a", "value_b"]]
133
- let mut values_range = json.get(labels_end..)?;
134
-
135
- // Validate we have a separating comma with one and only one leading bracket.
136
- if !(values_range.starts_with("],[") && values_range.as_bytes().get(3)? != &b'[') {
137
- return None;
138
- }
139
-
140
- // Now: "value_a", "value_b"]]
141
- values_range = values_range.get(3..)?;
142
-
143
- let values_end = values_range.find(']')?;
144
-
145
- // Validate we have only two trailing brackets.
146
- if values_range.get(values_end..)?.len() > 2 {
147
- return None;
148
- }
149
-
150
- // Now: "value_a", "value_b"
151
- values_range = values_range.get(..values_end)?;
152
-
153
- let mut values = SmallVec::new();
154
-
155
- // Split on commas into:
156
- // "value_a","value_b"
157
- // ^^^one^^^ ^^^two^^^
158
- for value in values_range.split(',') {
159
- // Captured: "value_a","value_b"
160
- // ^^^^^^^^^
161
- // If there are no values, e.g. `[][]`, then don't capture anything.
162
- if !value.is_empty() {
163
- values.push(value.trim_matches('"'));
164
- }
165
- }
166
-
167
- if values.len() != labels.len() {
168
- return None;
169
- }
170
-
171
- Some(MetricLabelVals { labels, values })
172
- }
173
-
174
- #[cfg(test)]
175
- mod test {
176
- use smallvec::smallvec;
177
-
178
- use super::*;
179
-
180
- struct TestCase {
181
- name: &'static str,
182
- input: &'static str,
183
- expected: Option<MetricText<'static>>,
184
- }
185
-
186
- #[test]
187
- fn valid_json() {
188
- let tc = vec![
189
- TestCase {
190
- name: "basic",
191
- input: r#"["metric","name",["label_a","label_b"],["value_a","value_b"]]"#,
192
- expected: Some(MetricText {
193
- family_name: "metric",
194
- metric_name: "name",
195
- labels: smallvec!["label_a", "label_b"],
196
- values: smallvec!["value_a", "value_b"],
197
- }),
198
- },
199
- TestCase {
200
- name: "many labels",
201
- input: r#"["metric","name",["label_a","label_b","label_c","label_d","label_e"],["value_a","value_b","value_c","value_d","value_e"]]"#,
202
-
203
- expected: Some(MetricText {
204
- family_name: "metric",
205
- metric_name: "name",
206
- labels: smallvec!["label_a", "label_b", "label_c", "label_d", "label_e"],
207
- values: smallvec!["value_a", "value_b", "value_c", "value_d", "value_e"],
208
- }),
209
- },
210
- TestCase {
211
- name: "numeric value",
212
- input: r#"["metric","name",["label_a","label_b"],["value_a",403]]"#,
213
- expected: Some(MetricText {
214
- family_name: "metric",
215
- metric_name: "name",
216
- labels: smallvec!["label_a", "label_b"],
217
- values: smallvec!["value_a", "403"],
218
- }),
219
- },
220
- TestCase {
221
- name: "null value",
222
- input: r#"["metric","name",["label_a","label_b"],[null,"value_b"]]"#,
223
- expected: Some(MetricText {
224
- family_name: "metric",
225
- metric_name: "name",
226
- labels: smallvec!["label_a", "label_b"],
227
- values: smallvec!["null", "value_b"],
228
- }),
229
- },
230
- TestCase {
231
- name: "no labels",
232
- input: r#"["metric","name",[],[]]"#,
233
- expected: Some(MetricText {
234
- family_name: "metric",
235
- metric_name: "name",
236
- labels: smallvec![],
237
- values: smallvec![],
238
- }),
239
- },
240
- ];
241
-
242
- for case in tc {
243
- assert_eq!(
244
- parse_metrics(case.input),
245
- case.expected,
246
- "test case: {}",
247
- case.name,
248
- );
249
- }
250
- }
251
-
252
- #[test]
253
- fn invalid_json() {
254
- let tc = vec![
255
- TestCase {
256
- name: "not json",
257
- input: "hello, world",
258
- expected: None,
259
- },
260
- TestCase {
261
- name: "no names",
262
- input: r#"[["label_a","label_b"],["value_a","value_b"]]"#,
263
- expected: None,
264
- },
265
- TestCase {
266
- name: "too many names",
267
- input: r#"["metric","name","unexpected_name",["label_a","label_b"],["value_a","value_b"]]"#,
268
- expected: None,
269
- },
270
- TestCase {
271
- name: "too many labels",
272
- input: r#"["metric","name","unexpected_name",["label_a","label_b","label_c"],["value_a","value_b"]]"#,
273
- expected: None,
274
- },
275
- TestCase {
276
- name: "too many values",
277
- input: r#"["metric","name",["label_a","label_b"],["value_a","value_b",null]]"#,
278
- expected: None,
279
- },
280
- TestCase {
281
- name: "no values",
282
- input: r#"["metric","name",["label_a","label_b"]"#,
283
- expected: None,
284
- },
285
- TestCase {
286
- name: "no arrays",
287
- input: r#"["metric","name","label_a","value_a"]"#,
288
- expected: None,
289
- },
290
- TestCase {
291
- name: "too many leading brackets",
292
- input: r#"[["metric","name",["label_a","label_b"],["value_a","value_b"]]"#,
293
- expected: None,
294
- },
295
- TestCase {
296
- name: "too many trailing brackets",
297
- input: r#"["metric","name",["label_a","label_b"],["value_a","value_b"]]]"#,
298
- expected: None,
299
- },
300
- TestCase {
301
- name: "too many leading label brackets",
302
- input: r#"["metric","name",[["label_a","label_b"],["value_a","value_b"]]"#,
303
- expected: None,
304
- },
305
- TestCase {
306
- name: "too many trailing label brackets",
307
- input: r#"["metric","name",["label_a","label_b"]],["value_a","value_b"]]"#,
308
- expected: None,
309
- },
310
- TestCase {
311
- name: "too many leading value brackets",
312
- input: r#"["metric","name",["label_a","label_b"],[["value_a","value_b"]]"#,
313
- expected: None,
314
- },
315
- TestCase {
316
- name: "comma in family name",
317
- input: r#"["met,ric","name",["label_a","label_b"],["value_a","value_b"]]"#,
318
- expected: None,
319
- },
320
- TestCase {
321
- name: "comma in metric name",
322
- input: r#"["metric","na,me",["label_a","label_b"],["value_a","value_b"]]"#,
323
- expected: None,
324
- },
325
- TestCase {
326
- name: "comma in value",
327
- input: r#"["metric","na,me",["label_a","label_b"],["val,ue_a","value_b"]]"#,
328
- expected: None,
329
- },
330
- TestCase {
331
- name: "comma in numeric value",
332
- input: r#"["metric","name",["label_a","label_b"],[400,0,"value_b"]]"#,
333
- expected: None,
334
- },
335
- ];
336
-
337
- for case in tc {
338
- assert_eq!(
339
- case.expected,
340
- parse_metrics(case.input),
341
- "test case: {}",
342
- case.name,
343
- );
344
- }
345
- }
346
- }
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -1,52 +0,0 @@
1
- # Prerequisites
2
- *.d
3
-
4
- # Object files
5
- *.o
6
- *.ko
7
- *.obj
8
- *.elf
9
-
10
- # Linker output
11
- *.ilk
12
- *.map
13
- *.exp
14
-
15
- # Precompiled Headers
16
- *.gch
17
- *.pch
18
-
19
- # Libraries
20
- *.lib
21
- *.a
22
- *.la
23
- *.lo
24
-
25
- # Shared objects (inc. Windows DLLs)
26
- *.dll
27
- *.so
28
- *.so.*
29
- *.dylib
30
-
31
- # Executables
32
- *.exe
33
- *.out
34
- *.app
35
- *.i*86
36
- *.x86_64
37
- *.hex
38
-
39
- # Debug files
40
- *.dSYM/
41
- *.su
42
- *.idb
43
- *.pdb
44
-
45
- # Kernel Module Compile Results
46
- *.mod*
47
- *.cmd
48
- .tmp_versions/
49
- modules.order
50
- Module.symvers
51
- Mkfile.old
52
- dkms.conf
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2016 David Leeds
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
@@ -1,90 +0,0 @@
1
- # hashmap
2
- Flexible hashmap implementation in C using open addressing and linear probing for collision resolution.
3
-
4
- ### Summary
5
- This project came into existence because there are a notable lack of flexible and easy to use data structures available in C. Sure, higher level languages have built-in libraries, but plenty of embedded projects or higher level libraries start with core C code. It was undesirable to add a bulky library like Glib as a dependency to my projects, or grapple with a restrictive license agreement. Searching for "C hashmap" yielded results with questionable algorithms and code quality, projects with difficult or inflexible interfaces, or projects with less desirable licenses. I decided it was time to create my own.
6
-
7
-
8
- ### Goals
9
- * **To scale gracefully to the full capacity of the numeric primitives in use.** E.g. on a 32-bit machine, you should be able to load a billion+ entries without hitting any bugs relating to integer overflows. Lookups on a hashtable with a billion entries should be performed in close to constant time, no different than lookups in a hashtable with 20 entries. Automatic rehashing occurs and maintains a load factor of 0.75 or less.
10
- * **To provide a clean and easy-to-use interface.** C data structures often struggle to strike a balance between flexibility and ease of use. To this end, I provided a generic interface using void pointers for keys and data, and macros to generate type-specific wrapper functions, if desired.
11
- * **To enable easy iteration and safe entry removal during iteration.** Applications often need these features, and the data structure should not hold them back. Both an iterator interface and a foreach function was provided to satisfy various use-cases. This hashmap also uses an open addressing scheme, which has superior iteration performance to a similar hashmap implemented using separate chaining (buckets with linked lists). This is because fewer instructions are needed per iteration, and array traversal has superior cache performance than linked list traversal.
12
- * **To use a very unrestrictive software license.** Using no license was an option, but I wanted to allow the code to be tracked, simply for my own edification. I chose the MIT license because it is the most common open source license in use, and it grants full rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell the code. Basically, take this code and do what you want with it. Just be nice and leave the license comment and my name at top of the file. Feel free to add your name if you are modifying and redistributing.
13
-
14
- ### Code Example
15
- ```C
16
- #include <stdlib.h>
17
- #include <stdio.h>
18
-
19
- #include <hashmap.h>
20
-
21
- /* Some sample data structure with a string key */
22
- struct blob {
23
- char key[32];
24
- size_t data_len;
25
- unsigned char data[1024];
26
- };
27
-
28
- /* Declare type-specific blob_hashmap_* functions with this handy macro */
29
- HASHMAP_FUNCS_CREATE(blob, const char, struct blob)
30
-
31
- struct blob *blob_load(void)
32
- {
33
- struct blob *b;
34
- /*
35
- * Hypothetical function that allocates and loads blob structures
36
- * from somewhere. Returns NULL when there are no more blobs to load.
37
- */
38
- return b;
39
- }
40
-
41
- /* Hashmap structure */
42
- struct hashmap map;
43
-
44
- int main(int argc, char **argv)
45
- {
46
- struct blob *b;
47
- struct hashmap_iter *iter;
48
-
49
- /* Initialize with default string key functions and init size */
50
- hashmap_init(&map, hashmap_hash_string, hashmap_compare_string, 0);
51
-
52
- /* Load some sample data into the map and discard duplicates */
53
- while ((b = blob_load()) != NULL) {
54
- if (blob_hashmap_put(&map, b->key, b) != b) {
55
- printf("discarding blob with duplicate key: %s\n", b->key);
56
- free(b);
57
- }
58
- }
59
-
60
- /* Lookup a blob with key "AbCdEf" */
61
- b = blob_hashmap_get(&map, "AbCdEf");
62
- if (b) {
63
- printf("Found blob[%s]\n", b->key);
64
- }
65
-
66
- /* Iterate through all blobs and print each one */
67
- for (iter = hashmap_iter(&map); iter; iter = hashmap_iter_next(&map, iter)) {
68
- printf("blob[%s]: data_len %zu bytes\n", blob_hashmap_iter_get_key(iter),
69
- blob_hashmap_iter_get_data(iter)->data_len);
70
- }
71
-
72
- /* Remove all blobs with no data */
73
- iter = hashmap_iter(&map);
74
- while (iter) {
75
- b = blob_hashmap_iter_get_data(iter);
76
- if (b->data_len == 0) {
77
- iter = hashmap_iter_remove(&map, iter);
78
- free(b);
79
- } else {
80
- iter = hashmap_iter_next(&map, iter);
81
- }
82
- }
83
-
84
- /* Free all allocated resources associated with map and reset its state */
85
- hashmap_destroy(&map);
86
-
87
- return 0;
88
- }
89
-
90
- ```
@@ -1 +0,0 @@
1
- theme: jekyll-theme-slate