Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::zipkin_proto Namespace Reference

Classes

struct  annotation
 
struct  endpoint
 
struct  list_of_spans
 
struct  span
 

Enumerations

enum class  span_kind : std::int32_t {
  unspecified = 0 , client = 1 , server = 2 , producer = 3 ,
  consumer = 4
}
 

Functions

span_kind parse_kind (const std::string &value)
 Convert a textual Zipkin kind (e.g. "CLIENT") to its enum value.
 
std::vector< std::uint8_t > encode_endpoint (const endpoint &ep)
 
std::vector< std::uint8_t > encode_annotation (const annotation &ann)
 
std::vector< std::uint8_t > encode_string_map_entry (const std::string &key, const std::string &value)
 Encode a single entry of a map<string,string> field.
 
std::vector< std::uint8_t > encode_span (const span &s)
 
std::vector< std::uint8_t > encode_list_of_spans (const list_of_spans &list)
 
bool decode_endpoint (const std::uint8_t *data, std::size_t size, endpoint &out)
 
bool decode_annotation (const std::uint8_t *data, std::size_t size, annotation &out)
 
bool decode_map_entry (const std::uint8_t *data, std::size_t size, std::string &key, std::string &value)
 
bool decode_span (const std::uint8_t *data, std::size_t size, span &out)
 
bool decode_list_of_spans (const std::uint8_t *data, std::size_t size, list_of_spans &out)
 

Enumeration Type Documentation

◆ span_kind

enum class kcenon::monitoring::zipkin_proto::span_kind : std::int32_t
strong
Enumerator
unspecified 
client 
server 
producer 
consumer 

Definition at line 32 of file zipkin_proto.h.

Function Documentation

◆ decode_annotation()

bool kcenon::monitoring::zipkin_proto::decode_annotation ( const std::uint8_t * data,
std::size_t size,
annotation & out )
inline

Definition at line 205 of file zipkin_proto.h.

206 {
207 protobuf_wire::reader r(data, size);
208 while (!r.eof()) {
209 std::uint32_t field_number;
211 if (!protobuf_wire::decode_tag(r, field_number, wt)) return false;
212 switch (field_number) {
213 case 1: {
214 if (wt != protobuf_wire::wire_type::fixed64) return false;
215 auto v = r.read_fixed64();
216 if (!v) return false;
217 out.timestamp = *v;
218 break;
219 }
220 case 2:
221 if (wt != protobuf_wire::wire_type::length_delimited) return false;
222 if (!r.read_string(out.value)) return false;
223 break;
224 default:
225 if (!r.skip_field(wt)) return false;
226 }
227 }
228 return true;
229}
Minimal protobuf wire reader used for round-trip tests.

References kcenon::monitoring::protobuf_wire::decode_tag(), kcenon::monitoring::protobuf_wire::reader::eof(), kcenon::monitoring::protobuf_wire::fixed64, kcenon::monitoring::protobuf_wire::length_delimited, kcenon::monitoring::protobuf_wire::reader::read_fixed64(), kcenon::monitoring::protobuf_wire::reader::read_string(), kcenon::monitoring::protobuf_wire::reader::skip_field(), kcenon::monitoring::zipkin_proto::annotation::timestamp, and kcenon::monitoring::zipkin_proto::annotation::value.

Referenced by decode_span().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_endpoint()

bool kcenon::monitoring::zipkin_proto::decode_endpoint ( const std::uint8_t * data,
std::size_t size,
endpoint & out )
inline

Definition at line 171 of file zipkin_proto.h.

172 {
173 protobuf_wire::reader r(data, size);
174 while (!r.eof()) {
175 std::uint32_t field_number;
177 if (!protobuf_wire::decode_tag(r, field_number, wt)) return false;
178 switch (field_number) {
179 case 1:
180 if (wt != protobuf_wire::wire_type::length_delimited) return false;
181 if (!r.read_string(out.service_name)) return false;
182 break;
183 case 2:
184 if (wt != protobuf_wire::wire_type::length_delimited) return false;
185 if (!r.read_bytes(out.ipv4)) return false;
186 break;
187 case 3:
188 if (wt != protobuf_wire::wire_type::length_delimited) return false;
189 if (!r.read_bytes(out.ipv6)) return false;
190 break;
191 case 4: {
192 if (wt != protobuf_wire::wire_type::varint) return false;
193 auto v = r.read_varint();
194 if (!v) return false;
195 out.port = static_cast<std::int32_t>(*v);
196 break;
197 }
198 default:
199 if (!r.skip_field(wt)) return false;
200 }
201 }
202 return true;
203}

References kcenon::monitoring::protobuf_wire::decode_tag(), kcenon::monitoring::protobuf_wire::reader::eof(), kcenon::monitoring::zipkin_proto::endpoint::ipv4, kcenon::monitoring::zipkin_proto::endpoint::ipv6, kcenon::monitoring::protobuf_wire::length_delimited, kcenon::monitoring::zipkin_proto::endpoint::port, kcenon::monitoring::protobuf_wire::reader::read_bytes(), kcenon::monitoring::protobuf_wire::reader::read_string(), kcenon::monitoring::protobuf_wire::reader::read_varint(), kcenon::monitoring::zipkin_proto::endpoint::service_name, kcenon::monitoring::protobuf_wire::reader::skip_field(), and kcenon::monitoring::protobuf_wire::varint.

Referenced by decode_span().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_list_of_spans()

bool kcenon::monitoring::zipkin_proto::decode_list_of_spans ( const std::uint8_t * data,
std::size_t size,
list_of_spans & out )
inline

Definition at line 351 of file zipkin_proto.h.

352 {
353 protobuf_wire::reader r(data, size);
354 while (!r.eof()) {
355 std::uint32_t field_number;
357 if (!protobuf_wire::decode_tag(r, field_number, wt)) return false;
358 if (field_number == 1 && wt == protobuf_wire::wire_type::length_delimited) {
359 const std::uint8_t* ptr; std::size_t len;
360 if (!r.read_length_delimited(&ptr, &len)) return false;
361 span s;
362 if (!decode_span(ptr, len, s)) return false;
363 out.spans.push_back(std::move(s));
364 } else {
365 if (!r.skip_field(wt)) return false;
366 }
367 }
368 return true;
369}

References decode_span(), kcenon::monitoring::protobuf_wire::decode_tag(), kcenon::monitoring::protobuf_wire::reader::eof(), kcenon::monitoring::protobuf_wire::length_delimited, kcenon::monitoring::protobuf_wire::reader::read_length_delimited(), kcenon::monitoring::protobuf_wire::reader::skip_field(), and kcenon::monitoring::zipkin_proto::list_of_spans::spans.

Referenced by TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_map_entry()

bool kcenon::monitoring::zipkin_proto::decode_map_entry ( const std::uint8_t * data,
std::size_t size,
std::string & key,
std::string & value )
inline

Definition at line 231 of file zipkin_proto.h.

232 {
233 protobuf_wire::reader r(data, size);
234 while (!r.eof()) {
235 std::uint32_t field_number;
237 if (!protobuf_wire::decode_tag(r, field_number, wt)) return false;
238 if (wt != protobuf_wire::wire_type::length_delimited) {
239 if (!r.skip_field(wt)) return false;
240 continue;
241 }
242 if (field_number == 1) {
243 if (!r.read_string(key)) return false;
244 } else if (field_number == 2) {
245 if (!r.read_string(value)) return false;
246 } else {
247 const std::uint8_t* ptr; std::size_t len;
248 if (!r.read_length_delimited(&ptr, &len)) return false;
249 }
250 }
251 return true;
252}

References kcenon::monitoring::protobuf_wire::decode_tag(), kcenon::monitoring::protobuf_wire::reader::eof(), kcenon::monitoring::protobuf_wire::length_delimited, kcenon::monitoring::protobuf_wire::reader::read_length_delimited(), kcenon::monitoring::protobuf_wire::reader::read_string(), and kcenon::monitoring::protobuf_wire::reader::skip_field().

Referenced by decode_span().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ decode_span()

bool kcenon::monitoring::zipkin_proto::decode_span ( const std::uint8_t * data,
std::size_t size,
span & out )
inline

Definition at line 254 of file zipkin_proto.h.

254 {
255 protobuf_wire::reader r(data, size);
256 while (!r.eof()) {
257 std::uint32_t field_number;
259 if (!protobuf_wire::decode_tag(r, field_number, wt)) return false;
260 switch (field_number) {
261 case 1:
262 if (wt != protobuf_wire::wire_type::length_delimited) return false;
263 if (!r.read_bytes(out.trace_id)) return false;
264 break;
265 case 2:
266 if (wt != protobuf_wire::wire_type::length_delimited) return false;
267 if (!r.read_bytes(out.parent_id)) return false;
268 break;
269 case 3:
270 if (wt != protobuf_wire::wire_type::length_delimited) return false;
271 if (!r.read_bytes(out.id)) return false;
272 break;
273 case 4: {
274 if (wt != protobuf_wire::wire_type::varint) return false;
275 auto v = r.read_varint();
276 if (!v) return false;
277 out.kind = static_cast<span_kind>(*v);
278 break;
279 }
280 case 5:
281 if (wt != protobuf_wire::wire_type::length_delimited) return false;
282 if (!r.read_string(out.name)) return false;
283 break;
284 case 6: {
285 if (wt != protobuf_wire::wire_type::fixed64) return false;
286 auto v = r.read_fixed64();
287 if (!v) return false;
288 out.timestamp = *v;
289 break;
290 }
291 case 7: {
292 if (wt != protobuf_wire::wire_type::varint) return false;
293 auto v = r.read_varint();
294 if (!v) return false;
295 out.duration = *v;
296 break;
297 }
298 case 8: {
299 if (wt != protobuf_wire::wire_type::length_delimited) return false;
300 const std::uint8_t* ptr; std::size_t len;
301 if (!r.read_length_delimited(&ptr, &len)) return false;
302 if (!decode_endpoint(ptr, len, out.local_endpoint)) return false;
303 break;
304 }
305 case 9: {
306 if (wt != protobuf_wire::wire_type::length_delimited) return false;
307 const std::uint8_t* ptr; std::size_t len;
308 if (!r.read_length_delimited(&ptr, &len)) return false;
309 if (!decode_endpoint(ptr, len, out.remote_endpoint)) return false;
310 break;
311 }
312 case 10: {
313 if (wt != protobuf_wire::wire_type::length_delimited) return false;
314 const std::uint8_t* ptr; std::size_t len;
315 if (!r.read_length_delimited(&ptr, &len)) return false;
316 annotation ann;
317 if (!decode_annotation(ptr, len, ann)) return false;
318 out.annotations.push_back(std::move(ann));
319 break;
320 }
321 case 11: {
322 if (wt != protobuf_wire::wire_type::length_delimited) return false;
323 const std::uint8_t* ptr; std::size_t len;
324 if (!r.read_length_delimited(&ptr, &len)) return false;
325 std::string key, value;
326 if (!decode_map_entry(ptr, len, key, value)) return false;
327 out.tags.emplace_back(std::move(key), std::move(value));
328 break;
329 }
330 case 12: {
331 if (wt != protobuf_wire::wire_type::varint) return false;
332 auto v = r.read_varint();
333 if (!v) return false;
334 out.debug = (*v != 0);
335 break;
336 }
337 case 13: {
338 if (wt != protobuf_wire::wire_type::varint) return false;
339 auto v = r.read_varint();
340 if (!v) return false;
341 out.shared = (*v != 0);
342 break;
343 }
344 default:
345 if (!r.skip_field(wt)) return false;
346 }
347 }
348 return true;
349}
bool decode_annotation(const std::uint8_t *data, std::size_t size, annotation &out)
bool decode_map_entry(const std::uint8_t *data, std::size_t size, std::string &key, std::string &value)
bool decode_endpoint(const std::uint8_t *data, std::size_t size, endpoint &out)
std::vector< std::uint8_t > trace_id
std::vector< std::uint8_t > id
std::vector< std::uint8_t > parent_id
std::vector< std::pair< std::string, std::string > > tags
std::vector< annotation > annotations

References kcenon::monitoring::zipkin_proto::span::annotations, kcenon::monitoring::zipkin_proto::span::debug, decode_annotation(), decode_endpoint(), decode_map_entry(), kcenon::monitoring::protobuf_wire::decode_tag(), kcenon::monitoring::zipkin_proto::span::duration, kcenon::monitoring::protobuf_wire::reader::eof(), kcenon::monitoring::protobuf_wire::fixed64, kcenon::monitoring::zipkin_proto::span::id, kcenon::monitoring::zipkin_proto::span::kind, kcenon::monitoring::protobuf_wire::length_delimited, kcenon::monitoring::zipkin_proto::span::local_endpoint, kcenon::monitoring::zipkin_proto::span::name, kcenon::monitoring::zipkin_proto::span::parent_id, kcenon::monitoring::protobuf_wire::reader::read_bytes(), kcenon::monitoring::protobuf_wire::reader::read_fixed64(), kcenon::monitoring::protobuf_wire::reader::read_length_delimited(), kcenon::monitoring::protobuf_wire::reader::read_string(), kcenon::monitoring::protobuf_wire::reader::read_varint(), kcenon::monitoring::zipkin_proto::span::remote_endpoint, kcenon::monitoring::zipkin_proto::span::shared, kcenon::monitoring::protobuf_wire::reader::skip_field(), kcenon::monitoring::zipkin_proto::span::tags, kcenon::monitoring::zipkin_proto::span::timestamp, kcenon::monitoring::zipkin_proto::span::trace_id, and kcenon::monitoring::protobuf_wire::varint.

Referenced by decode_list_of_spans(), TEST_F(), and TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_annotation()

std::vector< std::uint8_t > kcenon::monitoring::zipkin_proto::encode_annotation ( const annotation & ann)
inline

Definition at line 104 of file zipkin_proto.h.

104 {
105 std::vector<std::uint8_t> out;
106 if (ann.timestamp != 0) {
107 protobuf_wire::encode_tag(out, 1, protobuf_wire::wire_type::fixed64);
108 protobuf_wire::encode_fixed64(out, ann.timestamp);
109 }
110 protobuf_wire::encode_string_field(out, 2, ann.value);
111 return out;
112}

References kcenon::monitoring::protobuf_wire::encode_fixed64(), kcenon::monitoring::protobuf_wire::encode_string_field(), kcenon::monitoring::protobuf_wire::encode_tag(), kcenon::monitoring::protobuf_wire::fixed64, kcenon::monitoring::zipkin_proto::annotation::timestamp, and kcenon::monitoring::zipkin_proto::annotation::value.

Referenced by encode_span().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_endpoint()

std::vector< std::uint8_t > kcenon::monitoring::zipkin_proto::encode_endpoint ( const endpoint & ep)
inline

Definition at line 95 of file zipkin_proto.h.

95 {
96 std::vector<std::uint8_t> out;
97 protobuf_wire::encode_string_field(out, 1, ep.service_name);
98 protobuf_wire::encode_bytes_field(out, 2, ep.ipv4);
99 protobuf_wire::encode_bytes_field(out, 3, ep.ipv6);
100 protobuf_wire::encode_uint64_field(out, 4, static_cast<std::uint64_t>(ep.port));
101 return out;
102}

References kcenon::monitoring::protobuf_wire::encode_bytes_field(), kcenon::monitoring::protobuf_wire::encode_string_field(), kcenon::monitoring::protobuf_wire::encode_uint64_field(), kcenon::monitoring::zipkin_proto::endpoint::ipv4, kcenon::monitoring::zipkin_proto::endpoint::ipv6, kcenon::monitoring::zipkin_proto::endpoint::port, and kcenon::monitoring::zipkin_proto::endpoint::service_name.

Referenced by encode_span().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_list_of_spans()

std::vector< std::uint8_t > kcenon::monitoring::zipkin_proto::encode_list_of_spans ( const list_of_spans & list)
inline

Definition at line 158 of file zipkin_proto.h.

158 {
159 std::vector<std::uint8_t> out;
160 for (const auto& s : list.spans) {
161 auto serialized = encode_span(s);
162 protobuf_wire::encode_message_field(out, 1, serialized);
163 }
164 return out;
165}

References kcenon::monitoring::protobuf_wire::encode_message_field(), encode_span(), and kcenon::monitoring::zipkin_proto::list_of_spans::spans.

Referenced by kcenon::monitoring::encode_zipkin_list_of_spans().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_span()

std::vector< std::uint8_t > kcenon::monitoring::zipkin_proto::encode_span ( const span & s)
inline

Definition at line 128 of file zipkin_proto.h.

128 {
129 std::vector<std::uint8_t> out;
130 protobuf_wire::encode_bytes_field(out, 1, s.trace_id);
131 protobuf_wire::encode_bytes_field(out, 2, s.parent_id);
132 protobuf_wire::encode_bytes_field(out, 3, s.id);
133 protobuf_wire::encode_enum_field(out, 4, static_cast<std::int32_t>(s.kind));
134 protobuf_wire::encode_string_field(out, 5, s.name);
135 protobuf_wire::encode_fixed64_field(out, 6, s.timestamp);
136 protobuf_wire::encode_uint64_field(out, 7, s.duration);
137 if (!s.local_endpoint.empty()) {
138 auto serialized = encode_endpoint(s.local_endpoint);
139 protobuf_wire::encode_message_field(out, 8, serialized);
140 }
141 if (!s.remote_endpoint.empty()) {
142 auto serialized = encode_endpoint(s.remote_endpoint);
143 protobuf_wire::encode_message_field(out, 9, serialized);
144 }
145 for (const auto& ann : s.annotations) {
146 auto serialized = encode_annotation(ann);
147 protobuf_wire::encode_message_field(out, 10, serialized);
148 }
149 for (const auto& [key, value] : s.tags) {
150 auto entry = encode_string_map_entry(key, value);
151 protobuf_wire::encode_message_field(out, 11, entry);
152 }
153 protobuf_wire::encode_bool_field(out, 12, s.debug);
154 protobuf_wire::encode_bool_field(out, 13, s.shared);
155 return out;
156}
std::vector< std::uint8_t > encode_endpoint(const endpoint &ep)

References kcenon::monitoring::zipkin_proto::span::annotations, kcenon::monitoring::zipkin_proto::span::debug, kcenon::monitoring::zipkin_proto::span::duration, kcenon::monitoring::zipkin_proto::endpoint::empty(), encode_annotation(), kcenon::monitoring::protobuf_wire::encode_bool_field(), kcenon::monitoring::protobuf_wire::encode_bytes_field(), encode_endpoint(), kcenon::monitoring::protobuf_wire::encode_enum_field(), kcenon::monitoring::protobuf_wire::encode_fixed64_field(), kcenon::monitoring::protobuf_wire::encode_message_field(), kcenon::monitoring::protobuf_wire::encode_string_field(), encode_string_map_entry(), kcenon::monitoring::protobuf_wire::encode_uint64_field(), kcenon::monitoring::zipkin_proto::span::id, kcenon::monitoring::zipkin_proto::span::kind, kcenon::monitoring::zipkin_proto::span::local_endpoint, kcenon::monitoring::zipkin_proto::span::name, kcenon::monitoring::zipkin_proto::span::parent_id, kcenon::monitoring::zipkin_proto::span::remote_endpoint, kcenon::monitoring::zipkin_proto::span::shared, kcenon::monitoring::zipkin_proto::span::tags, kcenon::monitoring::zipkin_proto::span::timestamp, and kcenon::monitoring::zipkin_proto::span::trace_id.

Referenced by encode_list_of_spans(), and kcenon::monitoring::zipkin_span_data::to_protobuf().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ encode_string_map_entry()

std::vector< std::uint8_t > kcenon::monitoring::zipkin_proto::encode_string_map_entry ( const std::string & key,
const std::string & value )
inline

Encode a single entry of a map<string,string> field.

Protobuf encodes map fields as a repeated synthetic message with field 1 = key and field 2 = value.

Definition at line 120 of file zipkin_proto.h.

121 {
122 std::vector<std::uint8_t> out;
123 protobuf_wire::encode_string_field(out, 1, key);
124 protobuf_wire::encode_string_field(out, 2, value);
125 return out;
126}

References kcenon::monitoring::protobuf_wire::encode_string_field().

Referenced by encode_span().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ parse_kind()

span_kind kcenon::monitoring::zipkin_proto::parse_kind ( const std::string & value)
inline

Convert a textual Zipkin kind (e.g. "CLIENT") to its enum value.

Definition at line 41 of file zipkin_proto.h.

41 {
42 std::string upper;
43 upper.reserve(value.size());
44 for (char c : value) {
45 if (c >= 'a' && c <= 'z') upper.push_back(static_cast<char>(c - 'a' + 'A'));
46 else upper.push_back(c);
47 }
48 if (upper == "CLIENT") return span_kind::client;
49 if (upper == "SERVER") return span_kind::server;
50 if (upper == "PRODUCER") return span_kind::producer;
51 if (upper == "CONSUMER") return span_kind::consumer;
52 return span_kind::unspecified;
53}

References client, consumer, producer, server, and unspecified.

Referenced by kcenon::monitoring::encode_zipkin_list_of_spans(), TEST(), and kcenon::monitoring::zipkin_span_data::to_protobuf().

Here is the caller graph for this function: