prometheus-client-mmap 0.7.0.beta43 → 0.7.0.beta44

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4521825ca75920135fbbaf6fb8e5c96bd0d191ee
4
- data.tar.gz: '06686cb19e896c65356e2ed44c6398adb69d4a01'
3
+ metadata.gz: dcb6db082557b7ed883ec9c4be354709f73e8b28
4
+ data.tar.gz: 6a31e7b0c550e70e970deafd5abd8a7d0d38e68c
5
5
  SHA512:
6
- metadata.gz: 262ea3d30cce8cc62b56c098cb983c0c43a55bad40b6374c7ea72df8c45404e0fc978bd9e0b0498ae512ee9818cd2742f823bf583dbcff02ae1be01e1591063d
7
- data.tar.gz: 7cd7db57d62f2f9bbf5da3940ce12d6ca849d17e09530a52ca351475a5eea7fbfadeacf65af2793613be20363ebff46696c8248af0019e10bc3b768d3bdd978c
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
- int r = jsmn_parse(&parser, entry->json, entry->json_size, tokens, sizeof(tokens) / sizeof(tokens[0]));
107
+ jsmntok_t *name_token = &tokens[2];
50
108
 
51
- if (r < 0) {
52
- save_exception(prom_eParsingError, "too many labels or malformed json: %s", entry->json);
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 "['name', 'name',['label_a','label_b'],['value_a', 'value_b']]"
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
- // [ "'name', 'name',['label_a','label_b'],['value_a', 'value_b']",
61
- // "name", "name",
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
- static int labels_start_offset = 4;
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 (r < labels_start_offset) {
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
- rb_str_cat(string, "\"", 1);
95
- if (valid_not_null(entry, &tokens[val])) {
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];
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({ :le => bucket.to_s }))
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
@@ -1,5 +1,5 @@
1
1
  module Prometheus
2
2
  module Client
3
- VERSION = '0.7.0.beta43'.freeze
3
+ VERSION = '0.7.0.beta44'.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.7.0.beta43
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-06 00:00:00.000000000 Z
12
+ date: 2017-12-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: fuzzbert