prometheus-client-mmap 0.7.0.beta43 → 0.7.0.beta44
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/ext/fast_mmaped_file/rendering.c +71 -48
- data/lib/fast_mmaped_file.bundle +0 -0
- data/lib/prometheus/client/histogram.rb +4 -3
- data/lib/prometheus/client/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dcb6db082557b7ed883ec9c4be354709f73e8b28
|
4
|
+
data.tar.gz: 6a31e7b0c550e70e970deafd5abd8a7d0d38e68c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 713b6f7a0e91092fe37394ec7c17f1f6754ab88cf71662b20fafc093e51a7d90455d736bd3670dca1c6ae4cee71413c67bd5bf5a5fea684da3d8fee0ab6a72e0
|
7
|
+
data.tar.gz: 69b124138852ff02e07c6d5f278dbc74da4e7800a202958fa019f38c2f3f601e55acca79d0590be81042ac5c17bfdecb69fe6e813df0fefa673cc2a065af71ad
|
@@ -10,6 +10,8 @@
|
|
10
10
|
#define DBL_DECIMAL_DIG 17
|
11
11
|
#endif
|
12
12
|
|
13
|
+
#define LABELS_START_OFFSET 4
|
14
|
+
|
13
15
|
static inline int is_valid(const jsmntok_t *token) { return token->start < token->end && token->start >= 0; }
|
14
16
|
static inline int valid_not_null(const entry_t *entry, const jsmntok_t *token) {
|
15
17
|
static const char null_s[] = "null";
|
@@ -41,74 +43,95 @@ static inline int append_token(VALUE string, const entry_t *entry, const jsmntok
|
|
41
43
|
return 1;
|
42
44
|
}
|
43
45
|
|
46
|
+
static int append_labels(VALUE string, const entry_t *entry, const int label_count, const jsmntok_t *tokens) {
|
47
|
+
if (label_count <= 0) {
|
48
|
+
return 1;
|
49
|
+
}
|
50
|
+
|
51
|
+
rb_str_cat(string, "{", 1);
|
52
|
+
|
53
|
+
for (int i = 0; i < label_count; i++) {
|
54
|
+
int key = LABELS_START_OFFSET + i;
|
55
|
+
int val = LABELS_START_OFFSET + label_count + 1 + i;
|
56
|
+
|
57
|
+
if (!append_token(string, entry, &tokens[key])) {
|
58
|
+
return 0;
|
59
|
+
}
|
60
|
+
rb_str_cat(string, "=", 1);
|
61
|
+
|
62
|
+
rb_str_cat(string, "\"", 1);
|
63
|
+
if (valid_not_null(entry, &tokens[val])) {
|
64
|
+
append_token(string, entry, &tokens[val]);
|
65
|
+
}
|
66
|
+
rb_str_cat(string, "\"", 1);
|
67
|
+
|
68
|
+
if (i < label_count - 1) {
|
69
|
+
rb_str_cat(string, ",", 1);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
|
73
|
+
if (is_pid_significant(entry)) {
|
74
|
+
rb_str_cat(string, ",pid=\"", 6);
|
75
|
+
rb_str_append(string, entry->pid);
|
76
|
+
rb_str_cat(string, "\"", 1);
|
77
|
+
}
|
78
|
+
|
79
|
+
rb_str_cat(string, "}", 1);
|
80
|
+
return 1;
|
81
|
+
}
|
82
|
+
|
83
|
+
static int validate_token_count(const int token_count, const entry_t *entry) {
|
84
|
+
if (token_count < 0) {
|
85
|
+
save_exception(prom_eParsingError, "too many labels or malformed json: %s", entry->json);
|
86
|
+
return 0;
|
87
|
+
}
|
88
|
+
|
89
|
+
if (token_count < LABELS_START_OFFSET) {
|
90
|
+
save_exception(prom_eParsingError, "malformed json: %s", entry->json);
|
91
|
+
return 0;
|
92
|
+
}
|
93
|
+
|
94
|
+
if ((token_count - (LABELS_START_OFFSET + 1)) % 2 != 0) {
|
95
|
+
save_exception(prom_eParsingError, "mismatched number of labels: %s", entry->json);
|
96
|
+
return 0;
|
97
|
+
}
|
98
|
+
|
99
|
+
return 1;
|
100
|
+
}
|
101
|
+
|
44
102
|
static int append_entry(VALUE string, const entry_t *entry) {
|
45
103
|
jsmn_parser parser;
|
46
104
|
jsmn_init(&parser);
|
47
105
|
|
48
106
|
jsmntok_t tokens[200];
|
49
|
-
|
107
|
+
jsmntok_t *name_token = &tokens[2];
|
50
108
|
|
51
|
-
|
52
|
-
|
53
|
-
return 0;
|
54
|
-
}
|
109
|
+
int token_count = jsmn_parse(&parser, entry->json, entry->json_size, tokens, sizeof(tokens) / sizeof(tokens[0]));
|
110
|
+
int label_count = (token_count - (LABELS_START_OFFSET + 1)) / 2;
|
55
111
|
|
56
112
|
//
|
57
|
-
// Example JSON "['
|
113
|
+
// Example JSON "['metric', 'name',['label_a','label_b'],['value_a', 'value_b']]"
|
58
114
|
// will be parsed into following token list:
|
59
115
|
//
|
60
|
-
// [ "'
|
61
|
-
// "
|
116
|
+
// [ "'metric', 'name',['label_a','label_b'],['value_a', 'value_b']",
|
117
|
+
// "metric", "name",
|
62
118
|
// "['label_a','label_b']", "label_a", "label_b",
|
63
119
|
// "['value_a', 'value_b']", "value_a", "value_b" ]
|
64
|
-
|
120
|
+
//
|
121
|
+
// where 'metric' is the name of the metric, while 'name'
|
122
|
+
// is in summaries and histograms to store names of "submetrics" like:
|
123
|
+
// histogram_name_bucket or histogram_name_sum
|
65
124
|
|
66
|
-
if (
|
67
|
-
save_exception(prom_eParsingError, "malformed json: %s", entry->json);
|
125
|
+
if (!validate_token_count(token_count, entry)) {
|
68
126
|
return 0;
|
69
127
|
}
|
70
128
|
|
71
|
-
int label_cnt = (r - 5) / 2;
|
72
|
-
jsmntok_t *name_token = &tokens[2];
|
73
|
-
|
74
129
|
if (!append_token(string, entry, name_token)) {
|
75
130
|
return 0;
|
76
131
|
}
|
77
|
-
if (label_cnt > 0) {
|
78
|
-
if ((r - 5) % 2 != 0) {
|
79
|
-
save_exception(prom_eParsingError, "mismatched number of labels: %s", entry->json);
|
80
|
-
return 0;
|
81
|
-
}
|
82
|
-
|
83
|
-
rb_str_cat(string, "{", 1);
|
84
|
-
|
85
|
-
for (int i = 0; i < label_cnt; i++) {
|
86
|
-
int key = labels_start_offset + i;
|
87
|
-
int val = labels_start_offset + label_cnt + 1 + i;
|
88
|
-
|
89
|
-
if (!append_token(string, entry, &tokens[key])) {
|
90
|
-
return 0;
|
91
|
-
}
|
92
|
-
rb_str_cat(string, "=", 1);
|
93
132
|
|
94
|
-
|
95
|
-
|
96
|
-
append_token(string, entry, &tokens[val]);
|
97
|
-
}
|
98
|
-
rb_str_cat(string, "\"", 1);
|
99
|
-
|
100
|
-
if (i < label_cnt - 1) {
|
101
|
-
rb_str_cat(string, ",", 1);
|
102
|
-
}
|
103
|
-
}
|
104
|
-
|
105
|
-
if (is_pid_significant(entry)) {
|
106
|
-
rb_str_cat(string, ",pid=\"", 6);
|
107
|
-
rb_str_append(string, entry->pid);
|
108
|
-
rb_str_cat(string, "\"", 1);
|
109
|
-
}
|
110
|
-
|
111
|
-
rb_str_cat(string, "}", 1);
|
133
|
+
if (!append_labels(string, entry, label_count, tokens)) {
|
134
|
+
return 0;
|
112
135
|
}
|
113
136
|
|
114
137
|
char value[255];
|
data/lib/fast_mmaped_file.bundle
CHANGED
Binary file
|
@@ -10,21 +10,22 @@ module Prometheus
|
|
10
10
|
# Value represents the state of a Histogram at a given point.
|
11
11
|
class Value < Hash
|
12
12
|
include UsesValueType
|
13
|
-
attr_accessor :sum, :total
|
13
|
+
attr_accessor :sum, :total, :total_inf
|
14
14
|
|
15
15
|
def initialize(type, name, labels, buckets)
|
16
16
|
@sum = value_object(type, name, "#{name}_sum", labels)
|
17
|
-
# TODO: get rid of total and use +Inf bucket instead.
|
18
17
|
@total = value_object(type, name, "#{name}_count", labels)
|
18
|
+
@total_inf = value_object(type, name, "#{name}_bucket", labels.merge(le: "+Inf"))
|
19
19
|
|
20
20
|
buckets.each do |bucket|
|
21
|
-
self[bucket] = value_object(type, name, "#{name}_bucket", labels.merge(
|
21
|
+
self[bucket] = value_object(type, name, "#{name}_bucket", labels.merge(le: bucket.to_s))
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
25
|
def observe(value)
|
26
26
|
@sum.increment(value)
|
27
27
|
@total.increment()
|
28
|
+
@total_inf.increment()
|
28
29
|
|
29
30
|
each_key do |bucket|
|
30
31
|
self[bucket].increment() if value <= bucket
|
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.7.0.
|
4
|
+
version: 0.7.0.beta44
|
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: 2017-12-
|
12
|
+
date: 2017-12-19 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: fuzzbert
|