sq_detailed_metrics 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/extconf.rb +26 -0
  3. data/include/half.hpp +4575 -0
  4. data/include/msgpack.h +24 -0
  5. data/include/msgpack/fbuffer.h +42 -0
  6. data/include/msgpack/gcc_atomic.h +25 -0
  7. data/include/msgpack/object.h +118 -0
  8. data/include/msgpack/pack.h +174 -0
  9. data/include/msgpack/pack_define.h +18 -0
  10. data/include/msgpack/pack_template.h +952 -0
  11. data/include/msgpack/sbuffer.h +115 -0
  12. data/include/msgpack/sysdep.h +221 -0
  13. data/include/msgpack/timestamp.h +58 -0
  14. data/include/msgpack/unpack.h +281 -0
  15. data/include/msgpack/unpack_define.h +89 -0
  16. data/include/msgpack/unpack_template.h +471 -0
  17. data/include/msgpack/util.h +15 -0
  18. data/include/msgpack/version.h +38 -0
  19. data/include/msgpack/version_master.h +3 -0
  20. data/include/msgpack/vrefbuffer.h +144 -0
  21. data/include/msgpack/zbuffer.h +205 -0
  22. data/include/msgpack/zone.h +163 -0
  23. data/include/rapidjson/allocators.h +271 -0
  24. data/include/rapidjson/document.h +2575 -0
  25. data/include/rapidjson/encodedstream.h +299 -0
  26. data/include/rapidjson/encodings.h +716 -0
  27. data/include/rapidjson/error/en.h +74 -0
  28. data/include/rapidjson/error/error.h +155 -0
  29. data/include/rapidjson/filereadstream.h +99 -0
  30. data/include/rapidjson/filewritestream.h +104 -0
  31. data/include/rapidjson/fwd.h +151 -0
  32. data/include/rapidjson/internal/biginteger.h +290 -0
  33. data/include/rapidjson/internal/diyfp.h +258 -0
  34. data/include/rapidjson/internal/dtoa.h +245 -0
  35. data/include/rapidjson/internal/ieee754.h +78 -0
  36. data/include/rapidjson/internal/itoa.h +304 -0
  37. data/include/rapidjson/internal/meta.h +181 -0
  38. data/include/rapidjson/internal/pow10.h +55 -0
  39. data/include/rapidjson/internal/regex.h +701 -0
  40. data/include/rapidjson/internal/stack.h +230 -0
  41. data/include/rapidjson/internal/strfunc.h +55 -0
  42. data/include/rapidjson/internal/strtod.h +269 -0
  43. data/include/rapidjson/internal/swap.h +46 -0
  44. data/include/rapidjson/istreamwrapper.h +115 -0
  45. data/include/rapidjson/memorybuffer.h +70 -0
  46. data/include/rapidjson/memorystream.h +71 -0
  47. data/include/rapidjson/msinttypes/inttypes.h +316 -0
  48. data/include/rapidjson/msinttypes/stdint.h +300 -0
  49. data/include/rapidjson/ostreamwrapper.h +81 -0
  50. data/include/rapidjson/pointer.h +1358 -0
  51. data/include/rapidjson/prettywriter.h +255 -0
  52. data/include/rapidjson/rapidjson.h +615 -0
  53. data/include/rapidjson/reader.h +1879 -0
  54. data/include/rapidjson/schema.h +2006 -0
  55. data/include/rapidjson/stream.h +179 -0
  56. data/include/rapidjson/stringbuffer.h +117 -0
  57. data/include/rapidjson/writer.h +610 -0
  58. data/include/xxhash.h +328 -0
  59. data/json_conv.cpp +284 -0
  60. data/json_conv.hpp +17 -0
  61. data/metrics.cpp +239 -0
  62. data/metrics.hpp +84 -0
  63. data/msgpack/objectc.c +482 -0
  64. data/msgpack/unpack.c +703 -0
  65. data/msgpack/version.c +22 -0
  66. data/msgpack/vrefbuffer.c +250 -0
  67. data/msgpack/zone.c +222 -0
  68. data/sq_detailed_metrics.cpp +248 -0
  69. metadata +199 -0
@@ -0,0 +1,248 @@
1
+ extern "C" {
2
+ #include <ruby.h>
3
+ #include <ruby/version.h>
4
+ #include <ruby/encoding.h>
5
+ #include "extconf.h"
6
+ }
7
+
8
+ #include <sstream>
9
+ #include "metrics.hpp"
10
+ #include "json_conv.hpp"
11
+
12
+ using namespace sq_detailed_metrics;
13
+
14
+ namespace sq_detailed_metrics {
15
+ MetricsIndex *metrics_index;
16
+ }
17
+
18
+ static void request_free(void *ptr);
19
+ static size_t request_dsize(const void *ptr);
20
+
21
+ #if RUBY_API_VERSION_CODE < 20200
22
+ static inline VALUE rb_utf8_str_new(const char *ptr, long len)
23
+ {
24
+ return rb_enc_str_new(ptr, len, rb_utf8_encoding());
25
+ }
26
+ #endif
27
+
28
+ static const rb_data_type_t request_type = {
29
+ "SqDetailedMetrics::Request",
30
+ {
31
+ nullptr, // dmark
32
+ request_free,
33
+ request_dsize
34
+ },
35
+ nullptr,
36
+ nullptr
37
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
38
+ , RUBY_TYPED_FREE_IMMEDIATELY
39
+ #endif
40
+ };
41
+
42
+ // RequestCollection
43
+
44
+ static void request_collection_free(void *ptr);
45
+ static size_t request_collection_dsize(const void *ptr);
46
+
47
+ static const rb_data_type_t request_collection_type = {
48
+ "SqDetailedMetrics::RequestCollection",
49
+ {
50
+ nullptr, // dmark
51
+ request_collection_free,
52
+ request_collection_dsize
53
+ },
54
+ nullptr, // parent
55
+ nullptr // arbitrary data
56
+ #ifdef RUBY_TYPED_FREE_IMMEDIATELY
57
+ , RUBY_TYPED_FREE_IMMEDIATELY
58
+ #endif
59
+ };
60
+
61
+ static void request_collection_free(void *ptr) {
62
+ RequestCollection *coll = static_cast<RequestCollection*>(ptr);
63
+ delete coll;
64
+ }
65
+
66
+ static size_t request_collection_dsize(const void *ptr) {
67
+ RequestCollection const* coll = static_cast<RequestCollection const*>(ptr);
68
+ return coll->mem_size();
69
+ }
70
+
71
+ static VALUE request_collection_alloc(VALUE klass) {
72
+ RequestCollection *coll = new RequestCollection();
73
+ VALUE obj = TypedData_Wrap_Struct(klass, &request_collection_type, coll);
74
+
75
+ return obj;
76
+ }
77
+
78
+ static VALUE request_collection_serialize(VALUE self) {
79
+ RequestCollection *coll;
80
+ TypedData_Get_Struct(self, RequestCollection,
81
+ &request_collection_type, coll);
82
+ std::string str;
83
+ bool res = coll->flush(str);
84
+ if (!res) {
85
+ return Qnil;
86
+ }
87
+ return rb_enc_str_new(&str[0], static_cast<long>(str.length()),
88
+ rb_ascii8bit_encoding());
89
+ }
90
+
91
+ static VALUE request_collection_add(VALUE self, VALUE req_arg) {
92
+ RequestCollection *coll;
93
+ TypedData_Get_Struct(self, RequestCollection,
94
+ &request_collection_type, coll);
95
+
96
+ Request *req;
97
+ TypedData_Get_Struct(req_arg, Request,
98
+ &request_type, req);
99
+
100
+ coll->operator<<(std::move(*req));
101
+
102
+ return Qnil;
103
+ }
104
+
105
+ // Request
106
+
107
+ static void request_free(void *ptr) {
108
+ Request *req = static_cast<Request*>(ptr);
109
+ delete req;
110
+ }
111
+
112
+ static size_t request_dsize(const void *ptr) {
113
+ Request const *req = static_cast<Request const*>(ptr);
114
+ return req->mem_size();
115
+ }
116
+
117
+ static VALUE request_alloc(VALUE klass) {
118
+ Request *req = new Request();
119
+ VALUE obj = TypedData_Wrap_Struct(klass, &request_type, req);
120
+
121
+ return obj;
122
+ }
123
+
124
+ static VALUE request_set_route(VALUE self, VALUE route_arg) {
125
+ Request *req;
126
+ TypedData_Get_Struct(self, Request,
127
+ &request_type, req);
128
+
129
+ if (route_arg == Qnil) {
130
+ req->set_route({});
131
+ return Qnil;
132
+ }
133
+
134
+ Check_Type(route_arg, T_STRING);
135
+
136
+ long route_arg_len = RSTRING_LEN(route_arg);
137
+ std::string route{
138
+ RSTRING_PTR(route_arg),
139
+ static_cast<size_t>(route_arg_len)};
140
+
141
+ req->set_route(std::move(route));
142
+
143
+ return Qnil;
144
+ }
145
+
146
+ static VALUE request_set_overtime_cb(VALUE self, VALUE cb_arg) {
147
+ Request *req;
148
+ TypedData_Get_Struct(self, Request,
149
+ &request_type, req);
150
+
151
+ if (cb_arg == Qnil) {
152
+ req->set_overtime_cb({});
153
+ return Qnil;
154
+ }
155
+
156
+ Check_Type(cb_arg, T_STRING);
157
+
158
+ long cb_arg_len = RSTRING_LEN(cb_arg);
159
+ std::string cb{
160
+ RSTRING_PTR(cb_arg),
161
+ static_cast<size_t>(cb_arg_len)};
162
+
163
+ req->set_overtime_cb(cb);
164
+
165
+ return Qnil;
166
+ }
167
+
168
+ static VALUE request_add_measurement(VALUE self,
169
+ VALUE category_arg,
170
+ VALUE flowt_arg) {
171
+ Check_Type(category_arg, T_STRING);
172
+ Check_Type(flowt_arg, T_FLOAT);
173
+
174
+ Request *req;
175
+ TypedData_Get_Struct(self, Request,
176
+ &request_type, req);
177
+
178
+ long categ_arg_len = RSTRING_LEN(category_arg);
179
+ std::string category{
180
+ RSTRING_PTR(category_arg),
181
+ static_cast<size_t>(categ_arg_len)};
182
+
183
+ req->add(category, NUM2DBL(flowt_arg));
184
+
185
+ return Qnil;
186
+ }
187
+
188
+ static VALUE to_json(VALUE self, VALUE data) {
189
+ (void)self;
190
+
191
+ Check_Type(data, T_STRING);
192
+
193
+ VALUE err_msg = Qnil;
194
+
195
+ {
196
+ std::ostringstream stream;
197
+ JsonConv conv{stream};
198
+
199
+ long data_len = RSTRING_LEN(data);
200
+ try {
201
+ conv.parse(RSTRING_PTR(data), static_cast<size_t>(data_len));
202
+ std::string s = stream.str();
203
+ return rb_utf8_str_new(&s[0], static_cast<long>(s.size()));
204
+ } catch (const std::exception& e) {
205
+ err_msg = rb_str_buf_new_cstr(e.what());
206
+ }
207
+ } // all C++ objects must be destroyed before rb_raise is called
208
+
209
+ if (err_msg != Qnil) {
210
+ rb_raise(rb_eRuntimeError, "%s", RSTRING_PTR(err_msg));
211
+ }
212
+ return Qnil; // never reached
213
+ }
214
+
215
+ extern "C" void Init_sq_detailed_metrics(void);
216
+ extern "C" void Init_sq_detailed_metrics()
217
+ {
218
+ metrics_index = MetricsIndex_create();
219
+
220
+ VALUE mSqlDetailedMetrics = rb_define_module("SqDetailedMetrics");
221
+ VALUE cRequestCollection = rb_define_class_under(
222
+ mSqlDetailedMetrics, "RequestCollection", rb_cData);
223
+ rb_define_alloc_func(cRequestCollection, request_collection_alloc);
224
+ rb_define_method(cRequestCollection, "serialize",
225
+ reinterpret_cast<VALUE (*)(...)>(request_collection_serialize),
226
+ 0);
227
+ rb_define_method(cRequestCollection, "<<",
228
+ reinterpret_cast<VALUE (*)(...)>(request_collection_add),
229
+ 1);
230
+
231
+ VALUE cRequest = rb_define_class_under(
232
+ mSqlDetailedMetrics, "Request", rb_cData);
233
+ rb_define_alloc_func(cRequest, request_alloc);
234
+
235
+ rb_define_method(cRequest, "route=",
236
+ reinterpret_cast<VALUE (*)(...)>(request_set_route),
237
+ 1);
238
+ rb_define_method(cRequest, "overtime_cb=",
239
+ reinterpret_cast<VALUE (*)(...)>(request_set_overtime_cb),
240
+ 1);
241
+ rb_define_method(cRequest, "add_measurement",
242
+ reinterpret_cast<VALUE (*)(...)>(request_add_measurement),
243
+ 2);
244
+
245
+ rb_define_singleton_method(mSqlDetailedMetrics, "to_json",
246
+ reinterpret_cast<VALUE (*)(...)>(to_json),
247
+ 1);
248
+ }
metadata ADDED
@@ -0,0 +1,199 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sq_detailed_metrics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gustavo Lopes
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest-junit
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.2.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake-compiler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: hashdiff
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '1.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '1.0'
97
+ description: Detailed per-request metrics for Sqreen
98
+ email:
99
+ - gustavo@sqreen.io
100
+ executables: []
101
+ extensions:
102
+ - extconf.rb
103
+ extra_rdoc_files: []
104
+ files:
105
+ - extconf.rb
106
+ - include/half.hpp
107
+ - include/msgpack.h
108
+ - include/msgpack/fbuffer.h
109
+ - include/msgpack/gcc_atomic.h
110
+ - include/msgpack/object.h
111
+ - include/msgpack/pack.h
112
+ - include/msgpack/pack_define.h
113
+ - include/msgpack/pack_template.h
114
+ - include/msgpack/sbuffer.h
115
+ - include/msgpack/sysdep.h
116
+ - include/msgpack/timestamp.h
117
+ - include/msgpack/unpack.h
118
+ - include/msgpack/unpack_define.h
119
+ - include/msgpack/unpack_template.h
120
+ - include/msgpack/util.h
121
+ - include/msgpack/version.h
122
+ - include/msgpack/version_master.h
123
+ - include/msgpack/vrefbuffer.h
124
+ - include/msgpack/zbuffer.h
125
+ - include/msgpack/zone.h
126
+ - include/rapidjson/allocators.h
127
+ - include/rapidjson/document.h
128
+ - include/rapidjson/encodedstream.h
129
+ - include/rapidjson/encodings.h
130
+ - include/rapidjson/error/en.h
131
+ - include/rapidjson/error/error.h
132
+ - include/rapidjson/filereadstream.h
133
+ - include/rapidjson/filewritestream.h
134
+ - include/rapidjson/fwd.h
135
+ - include/rapidjson/internal/biginteger.h
136
+ - include/rapidjson/internal/diyfp.h
137
+ - include/rapidjson/internal/dtoa.h
138
+ - include/rapidjson/internal/ieee754.h
139
+ - include/rapidjson/internal/itoa.h
140
+ - include/rapidjson/internal/meta.h
141
+ - include/rapidjson/internal/pow10.h
142
+ - include/rapidjson/internal/regex.h
143
+ - include/rapidjson/internal/stack.h
144
+ - include/rapidjson/internal/strfunc.h
145
+ - include/rapidjson/internal/strtod.h
146
+ - include/rapidjson/internal/swap.h
147
+ - include/rapidjson/istreamwrapper.h
148
+ - include/rapidjson/memorybuffer.h
149
+ - include/rapidjson/memorystream.h
150
+ - include/rapidjson/msinttypes/inttypes.h
151
+ - include/rapidjson/msinttypes/stdint.h
152
+ - include/rapidjson/ostreamwrapper.h
153
+ - include/rapidjson/pointer.h
154
+ - include/rapidjson/prettywriter.h
155
+ - include/rapidjson/rapidjson.h
156
+ - include/rapidjson/reader.h
157
+ - include/rapidjson/schema.h
158
+ - include/rapidjson/stream.h
159
+ - include/rapidjson/stringbuffer.h
160
+ - include/rapidjson/writer.h
161
+ - include/xxhash.h
162
+ - json_conv.cpp
163
+ - json_conv.hpp
164
+ - metrics.cpp
165
+ - metrics.hpp
166
+ - msgpack/objectc.c
167
+ - msgpack/unpack.c
168
+ - msgpack/version.c
169
+ - msgpack/vrefbuffer.c
170
+ - msgpack/zone.c
171
+ - sq_detailed_metrics.cpp
172
+ homepage:
173
+ licenses:
174
+ - Proprietary
175
+ metadata:
176
+ homepage_uri: https://sqreen.com
177
+ documentation_uri: https://docs.sqreen.com/
178
+ changelog_uri: https://docs.sqreen.com/ruby/release-notes/
179
+ post_install_message:
180
+ rdoc_options: []
181
+ require_paths:
182
+ - lib
183
+ - ext
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: 1.9.3
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubygems_version: 3.1.2
196
+ signing_key:
197
+ specification_version: 4
198
+ summary: Detailed per-request metrics for Sqreen
199
+ test_files: []