| 1 |
|
| /* otel_meter.h - the meter: instruments, views, and collection. |
| 2 |
|
| * |
| 3 |
|
| * VIEWS. A view selects instruments and reshapes what they produce: rename |
| 4 |
|
| * it, drop it, keep only some attribute keys, change the aggregation. |
| 5 |
|
| * |
| 6 |
|
| * The part a naive implementation misses is that SEVERAL views may match one |
| 7 |
|
| * instrument, producing several streams from it - that is the point of views, |
| 8 |
|
| * not an edge case. And two streams that end up with the same name but |
| 9 |
|
| * different units, kinds or aggregations are a CONFLICT: the backend cannot |
| 10 |
|
| * store both under one name, so it stores whichever arrived last, silently. |
| 11 |
|
| * Detecting that and saying so - naming both - is the difference between a |
| 12 |
|
| * misconfiguration you fix in a minute and a dashboard that is subtly wrong |
| 13 |
|
| * for a quarter. |
| 14 |
|
| * |
| 15 |
|
| * Dropping attribute KEYS is the primary tool against cardinality, and is |
| 16 |
|
| * worth reaching for before the cap in otel_metric.h has to do its job. |
| 17 |
|
| */ |
| 18 |
|
| |
| 19 |
|
| #ifndef OTEL_METER_H |
| 20 |
|
| #define OTEL_METER_H |
| 21 |
|
| |
| 22 |
|
| #include "otel_metric.h" |
| 23 |
|
| |
| 24 |
|
| #define OTEL_MAX_VIEWS 32 |
| 25 |
|
| |
| 26 |
|
| typedef struct { |
| 27 |
|
| SV *match; /* instrument name to select; '*' suffix wildcards */ |
| 28 |
|
| SV *name; /* the output name, or NULL to keep it */ |
| 29 |
|
| int aggregation; /* -1 to keep the instrument's own */ |
| 30 |
|
| int has_keys; |
| 31 |
|
| HV *keys; /* attribute keys to KEEP, when has_keys */ |
| 32 |
|
| double bounds[OTEL_MAX_BOUNDS]; |
| 33 |
|
| int nbounds; /* 0 to keep */ |
| 34 |
|
| } otel_view; |
| 35 |
|
| |
| 36 |
|
| typedef struct { |
| 37 |
|
| otel_instrument *instruments; |
| 38 |
|
| otel_view views[OTEL_MAX_VIEWS]; |
| 39 |
|
| int nviews; |
| 40 |
|
| HV *resource; |
| 41 |
|
| SV *scope_name, *scope_version; |
| 42 |
|
| int temporality; /* the reader's preference */ |
| 43 |
|
| IV conflicts; |
| 44 |
|
| pid_t owner_pid; |
| 45 |
|
| } otel_meter; |
| 46 |
|
| |
| 47 |
58 |
| static otel_meter *otel_meter_new(pTHX) { |
| 48 |
|
| otel_meter *m; |
| 49 |
58 |
| Newxz(m, 1, otel_meter); |
| 50 |
58 |
| m->resource = newHV(); |
| 51 |
58 |
| m->temporality = OTEL_TEMP_CUMULATIVE; |
| 52 |
58 |
| m->owner_pid = getpid(); |
| 53 |
58 |
| return m; |
| 54 |
|
| } |
| 55 |
|
| |
| 56 |
54 |
| static void otel_instr_free(pTHX_ otel_instrument *in) { |
| 57 |
|
| otel_point *p; |
| 58 |
54 |
▶ | if (!in) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!in) return; |
0 |
54 |
54 |
|
| 59 |
4105 |
▶ | for (p = in->points; p; ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (p = in->points; p; ) { |
4051 |
54 |
4105 |
|
| 60 |
4051 |
| otel_point *n = p->next; |
| 61 |
4051 |
| otel_point_free(aTHX_ p); |
| 62 |
4051 |
| p = n; |
| 63 |
|
| } |
| 64 |
54 |
▶ | if (in->name) SvREFCNT_dec(in->name); |
Branch: 1 branch
| Branch | True | False | Total |
| if (in->name) SvREFCNT_dec(in->name); |
54 |
0 |
54 |
|
| 65 |
54 |
▶ | if (in->description) SvREFCNT_dec(in->description); |
Branch: 1 branch
| Branch | True | False | Total |
| if (in->description) SvREFCNT_dec(in->description); |
0 |
54 |
54 |
|
| 66 |
54 |
▶ | if (in->unit) SvREFCNT_dec(in->unit); |
Branch: 1 branch
| Branch | True | False | Total |
| if (in->unit) SvREFCNT_dec(in->unit); |
6 |
48 |
54 |
|
| 67 |
54 |
| Safefree(in); |
| 68 |
|
| } |
| 69 |
|
| |
| 70 |
58 |
| static void otel_meter_free(pTHX_ otel_meter *m) { |
| 71 |
|
| otel_instrument *in; |
| 72 |
|
| int i; |
| 73 |
58 |
▶ | if (!m) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!m) return; |
0 |
58 |
58 |
|
| 74 |
112 |
▶ | for (in = m->instruments; in; ) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (in = m->instruments; in; ) { |
54 |
58 |
112 |
|
| 75 |
54 |
| otel_instrument *n = in->next; |
| 76 |
54 |
| otel_instr_free(aTHX_ in); |
| 77 |
54 |
| in = n; |
| 78 |
|
| } |
| 79 |
70 |
▶ | for (i = 0; i < m->nviews; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < m->nviews; i++) { |
12 |
58 |
70 |
|
| 80 |
12 |
▶ | if (m->views[i].match) SvREFCNT_dec(m->views[i].match); |
Branch: 1 branch
| Branch | True | False | Total |
| if (m->views[i].match) SvREFCNT_dec(m->views[i].match); |
12 |
0 |
12 |
|
| 81 |
12 |
▶ | if (m->views[i].name) SvREFCNT_dec(m->views[i].name); |
Branch: 1 branch
| Branch | True | False | Total |
| if (m->views[i].name) SvREFCNT_dec(m->views[i].name); |
2 |
10 |
12 |
|
| 82 |
12 |
▶ | if (m->views[i].keys) SvREFCNT_dec((SV *)m->views[i].keys); |
Branch: 1 branch
| Branch | True | False | Total |
| if (m->views[i].keys) SvREFCNT_dec((SV *)m->views[i].keys); |
2 |
10 |
12 |
|
| 83 |
|
| } |
| 84 |
58 |
▶ | if (m->resource) SvREFCNT_dec((SV *)m->resource); |
Branch: 1 branch
| Branch | True | False | Total |
| if (m->resource) SvREFCNT_dec((SV *)m->resource); |
58 |
0 |
58 |
|
| 85 |
58 |
▶ | if (m->scope_name) SvREFCNT_dec(m->scope_name); |
Branch: 1 branch
| Branch | True | False | Total |
| if (m->scope_name) SvREFCNT_dec(m->scope_name); |
46 |
12 |
58 |
|
| 86 |
58 |
▶ | if (m->scope_version) SvREFCNT_dec(m->scope_version); |
Branch: 1 branch
| Branch | True | False | Total |
| if (m->scope_version) SvREFCNT_dec(m->scope_version); |
0 |
58 |
58 |
|
| 87 |
58 |
| Safefree(m); |
| 88 |
|
| } |
| 89 |
|
| |
| 90 |
|
| /* A worker that inherited accumulated points would export the parent's totals |
| 91 |
|
| * as its own - and under cumulative temporality that is not a duplicate, it |
| 92 |
|
| * is a contradictory series under the same identity. Everything resets. */ |
| 93 |
5440 |
| static void otel_meter_check_fork(pTHX_ otel_meter *m) { |
| 94 |
|
| otel_instrument *in; |
| 95 |
|
| otel_point *p; |
| 96 |
5440 |
| pid_t me = getpid(); |
| 97 |
5440 |
▶ | if (m->owner_pid == me) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (m->owner_pid == me) return; |
5439 |
1 |
5440 |
|
| 98 |
2 |
▶ | for (in = m->instruments; in; in = in->next) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (in = m->instruments; in; in = in->next) { |
1 |
1 |
2 |
|
| 99 |
2 |
▶ | for (p = in->points; p; p = p->next) otel_point_reset(p); |
Branch: 1 branch
| Branch | True | False | Total |
| for (p = in->points; p; p = p->next) otel_point_reset(p); |
1 |
1 |
2 |
|
| 100 |
1 |
| in->overflow = 0; |
| 101 |
|
| } |
| 102 |
1 |
| m->owner_pid = me; |
| 103 |
|
| } |
| 104 |
|
| |
| 105 |
218 |
| static int otel_view_matches(pTHX_ otel_view *v, SV *name) { |
| 106 |
|
| STRLEN ml, nl; |
| 107 |
|
| const char *ms, *ns; |
| 108 |
218 |
▶ | if (!v->match || !name) return 0; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v->match || !name) return 0; |
218 |
0 |
218 |
| if (!v->match || !name) return 0; |
0 |
218 |
218 |
|
| 109 |
436 |
▶ | ms = SvPV_const(v->match, ml); |
Branch: 1 branch
| Branch | True | False | Total |
| ms = SvPV_const(v->match, ml); |
218 |
0 |
218 |
|
| 110 |
218 |
| ns = SvPV_const(name, nl); |
| 111 |
218 |
▶ | if (ml && ms[ml - 1] == '*') /* prefix wildcard */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (ml && ms[ml - 1] == '*') /* prefix wildcard */ |
218 |
0 |
218 |
| if (ml && ms[ml - 1] == '*') /* prefix wildcard */ |
6 |
212 |
218 |
|
| 112 |
6 |
▶ | return nl >= ml - 1 && memEQ(ns, ms, ml - 1); |
Branch: 2 branches
| Branch | True | False | Total |
| return nl >= ml - 1 && memEQ(ns, ms, ml - 1); |
6 |
0 |
6 |
| return nl >= ml - 1 && memEQ(ns, ms, ml - 1); |
4 |
2 |
6 |
|
| 113 |
212 |
▶ | return ml == nl && memEQ(ns, ms, ml); |
Branch: 2 branches
| Branch | True | False | Total |
| return ml == nl && memEQ(ns, ms, ml); |
210 |
2 |
212 |
| return ml == nl && memEQ(ns, ms, ml); |
210 |
0 |
210 |
|
| 114 |
|
| } |
| 115 |
|
| |
| 116 |
|
| /* Find or create an instrument, applying any matching views. |
| 117 |
|
| * |
| 118 |
|
| * A conflict - the same output name with a different unit, kind or |
| 119 |
|
| * aggregation - is counted and reported rather than silently resolved, |
| 120 |
|
| * because the silent resolution is "whichever the backend saw last". */ |
| 121 |
5391 |
| static otel_instrument *otel_meter_instrument(pTHX_ otel_meter *m, SV *name, |
| 122 |
|
| int kind, SV *unit, |
| 123 |
|
| SV *description) { |
| 124 |
|
| otel_instrument *in; |
| 125 |
|
| int agg, i; |
| 126 |
|
| STRLEN nl; |
| 127 |
5391 |
| const char *ns = SvPV_const(name, nl); |
| 128 |
|
| |
| 129 |
5401 |
▶ | for (in = m->instruments; in; in = in->next) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (in = m->instruments; in; in = in->next) { |
5347 |
54 |
5401 |
|
| 130 |
|
| STRLEN il; |
| 131 |
5347 |
| const char *is = SvPV_const(in->name, il); |
| 132 |
5347 |
▶ | if (il == nl && memEQ(is, ns, nl)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (il == nl && memEQ(is, ns, nl)) { |
5339 |
8 |
5347 |
| if (il == nl && memEQ(is, ns, nl)) { |
5337 |
2 |
5339 |
|
| 133 |
|
| /* same name: is it the same stream? */ |
| 134 |
5337 |
▶ | if (in->kind != kind) m->conflicts++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (in->kind != kind) m->conflicts++; |
2 |
5335 |
5337 |
|
| 135 |
5335 |
▶ | else if (unit && in->unit) { |
Branch: 2 branches
| Branch | True | False | Total |
| else if (unit && in->unit) { |
1 |
5334 |
5335 |
| else if (unit && in->unit) { |
1 |
0 |
1 |
|
| 136 |
|
| STRLEN ul, iu; |
| 137 |
1 |
| const char *us = SvPV_const(unit, ul); |
| 138 |
1 |
▶ | const char *iv = SvPV_const(in->unit, iu); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *iv = SvPV_const(in->unit, iu); |
1 |
0 |
1 |
|
| 139 |
1 |
▶ | if (ul != iu || !memEQ(us, iv, ul)) m->conflicts++; |
Branch: 2 branches
| Branch | True | False | Total |
| if (ul != iu || !memEQ(us, iv, ul)) m->conflicts++; |
1 |
0 |
1 |
| if (ul != iu || !memEQ(us, iv, ul)) m->conflicts++; |
0 |
1 |
1 |
|
| 140 |
|
| } |
| 141 |
5337 |
| return in; |
| 142 |
|
| } |
| 143 |
|
| } |
| 144 |
|
| |
| 145 |
54 |
| agg = (kind == OTEL_INSTR_HISTOGRAM) ? OTEL_AGG_HISTOGRAM |
| 146 |
88 |
▶ | : (kind == OTEL_INSTR_GAUGE) ? OTEL_AGG_LASTVALUE |
Branch: 1 branch
| Branch | True | False | Total |
| : (kind == OTEL_INSTR_GAUGE) ? OTEL_AGG_LASTVALUE |
34 |
20 |
54 |
|
| 147 |
34 |
▶ | : OTEL_AGG_SUM; |
Branch: 1 branch
| Branch | True | False | Total |
| : OTEL_AGG_SUM; |
2 |
32 |
34 |
|
| 148 |
|
| |
| 149 |
54 |
| Newxz(in, 1, otel_instrument); |
| 150 |
54 |
| in->name = newSVsv(name); |
| 151 |
54 |
▶ | in->unit = unit ? newSVsv(unit) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| in->unit = unit ? newSVsv(unit) : NULL; |
6 |
48 |
54 |
|
| 152 |
54 |
▶ | in->description = description ? newSVsv(description) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| in->description = description ? newSVsv(description) : NULL; |
0 |
54 |
54 |
|
| 153 |
54 |
| in->kind = kind; |
| 154 |
54 |
| in->aggregation = agg; |
| 155 |
54 |
| in->temporality = m->temporality; |
| 156 |
54 |
▶ | if (kind == OTEL_INSTR_HISTOGRAM) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (kind == OTEL_INSTR_HISTOGRAM) { |
20 |
34 |
54 |
|
| 157 |
20 |
| in->nbounds = OTEL_DEFAULT_BOUNDS_N; |
| 158 |
300 |
▶ | for (i = 0; i < OTEL_DEFAULT_BOUNDS_N; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < OTEL_DEFAULT_BOUNDS_N; i++) |
280 |
20 |
300 |
|
| 159 |
280 |
| in->bounds[i] = OTEL_DEFAULT_BOUNDS[i]; |
| 160 |
|
| } |
| 161 |
|
| |
| 162 |
|
| /* views, applied in declaration order; the last matching one wins for |
| 163 |
|
| * each property it sets */ |
| 164 |
72 |
▶ | for (i = 0; i < m->nviews; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < m->nviews; i++) { |
18 |
54 |
72 |
|
| 165 |
18 |
| otel_view *v = &m->views[i]; |
| 166 |
18 |
▶ | if (!otel_view_matches(aTHX_ v, name)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!otel_view_matches(aTHX_ v, name)) continue; |
4 |
14 |
18 |
|
| 167 |
14 |
▶ | if (v->name) { SvREFCNT_dec(in->name); in->name = newSVsv(v->name); } |
Branch: 1 branch
| Branch | True | False | Total |
| if (v->name) { SvREFCNT_dec(in->name); in->name = newSVsv(v->name); } |
2 |
12 |
14 |
|
| 168 |
14 |
▶ | if (v->aggregation >= 0) in->aggregation = v->aggregation; |
Branch: 1 branch
| Branch | True | False | Total |
| if (v->aggregation >= 0) in->aggregation = v->aggregation; |
8 |
6 |
14 |
|
| 169 |
14 |
▶ | if (v->nbounds) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (v->nbounds) { |
2 |
12 |
14 |
|
| 170 |
|
| int j; |
| 171 |
2 |
| in->nbounds = v->nbounds; |
| 172 |
8 |
▶ | for (j = 0; j < v->nbounds; j++) in->bounds[j] = v->bounds[j]; |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < v->nbounds; j++) in->bounds[j] = v->bounds[j]; |
6 |
2 |
8 |
|
| 173 |
|
| } |
| 174 |
|
| } |
| 175 |
54 |
| in->next = m->instruments; |
| 176 |
54 |
| m->instruments = in; |
| 177 |
54 |
| return in; |
| 178 |
|
| } |
| 179 |
|
| |
| 180 |
|
| /* Attribute keys a view kept, or the set unchanged when it filtered none. |
| 181 |
|
| * Dropping keys is the primary tool against cardinality. */ |
| 182 |
5391 |
| static HV *otel_view_filter(pTHX_ otel_meter *m, SV *name, HV *attrs) { |
| 183 |
|
| int i; |
| 184 |
5525 |
▶ | for (i = 0; i < m->nviews; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < m->nviews; i++) { |
334 |
5191 |
5525 |
|
| 185 |
334 |
| otel_view *v = &m->views[i]; |
| 186 |
|
| HV *out; |
| 187 |
|
| HE *he; |
| 188 |
334 |
▶ | if (!v->has_keys || !otel_view_matches(aTHX_ v, name)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!v->has_keys || !otel_view_matches(aTHX_ v, name)) continue; |
200 |
134 |
334 |
| if (!v->has_keys || !otel_view_matches(aTHX_ v, name)) continue; |
0 |
200 |
200 |
|
| 189 |
200 |
| out = (HV *)sv_2mortal((SV *)newHV()); |
| 190 |
200 |
▶ | if (attrs) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (attrs) { |
200 |
0 |
200 |
|
| 191 |
200 |
| hv_iterinit(attrs); |
| 192 |
800 |
▶ | while ((he = hv_iternext(attrs))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(attrs))) { |
400 |
200 |
600 |
|
| 193 |
400 |
| SV *k = hv_iterkeysv(he); |
| 194 |
400 |
▶ | if (hv_exists_ent(v->keys, k, 0)) |
Branch: 1 branch
| Branch | True | False | Total |
| if (hv_exists_ent(v->keys, k, 0)) |
200 |
200 |
400 |
|
| 195 |
200 |
| (void)hv_store_ent(out, k, newSVsv(HeVAL(he)), 0); |
| 196 |
|
| } |
| 197 |
|
| } |
| 198 |
200 |
| return out; |
| 199 |
|
| } |
| 200 |
5191 |
| return attrs; |
| 201 |
|
| } |
| 202 |
|
| |
| 203 |
|
| /* ---- collection --------------------------------------------------------- * |
| 204 |
|
| * The payload shape mirrors the trace one: resource_metrics -> scope_metrics |
| 205 |
|
| * -> metrics, each metric carrying its data points. The encoder in |
| 206 |
|
| * otel_metric_pb.h turns this into protobuf; keeping the intermediate shape |
| 207 |
|
| * Perl-visible is what lets a test assert temporality and reset behaviour |
| 208 |
|
| * without decoding bytes. */ |
| 209 |
|
| |
| 210 |
4050 |
| static SV *otel_point_to_hv(pTHX_ otel_instrument *in, otel_point *p) { |
| 211 |
4050 |
| HV *h = newHV(); |
| 212 |
|
| int i; |
| 213 |
4050 |
| (void)hv_stores(h, "attributes", newRV_inc((SV *)p->attrs)); |
| 214 |
4050 |
| (void)hv_stores(h, "start_time_unix_nano", newSVuv((UV)p->start_nanos)); |
| 215 |
4050 |
| (void)hv_stores(h, "time_unix_nano", newSVuv((UV)p->time_nanos)); |
| 216 |
4050 |
| (void)hv_stores(h, "count", newSViv(p->count)); |
| 217 |
|
| |
| 218 |
4050 |
| switch (in->aggregation) { |
| 219 |
2 |
| case OTEL_AGG_LASTVALUE: |
| 220 |
2 |
| (void)hv_stores(h, "value", newSVnv(p->last)); |
| 221 |
2 |
| break; |
| 222 |
18 |
| case OTEL_AGG_HISTOGRAM: { |
| 223 |
18 |
| AV *bk = newAV(), *bd = newAV(); |
| 224 |
266 |
▶ | for (i = 0; i <= in->nbounds; i++) av_push(bk, newSViv(p->buckets[i])); |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i <= in->nbounds; i++) av_push(bk, newSViv(p->buckets[i])); |
248 |
18 |
266 |
|
| 225 |
248 |
▶ | for (i = 0; i < in->nbounds; i++) av_push(bd, newSVnv(in->bounds[i])); |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < in->nbounds; i++) av_push(bd, newSVnv(in->bounds[i])); |
230 |
18 |
248 |
|
| 226 |
18 |
| (void)hv_stores(h, "sum", newSVnv(p->sum)); |
| 227 |
18 |
| (void)hv_stores(h, "bucket_counts", newRV_noinc((SV *)bk)); |
| 228 |
18 |
| (void)hv_stores(h, "explicit_bounds", newRV_noinc((SV *)bd)); |
| 229 |
18 |
▶ | if (p->count) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->count) { |
18 |
0 |
18 |
|
| 230 |
18 |
| (void)hv_stores(h, "min", newSVnv(p->min)); |
| 231 |
18 |
| (void)hv_stores(h, "max", newSVnv(p->max)); |
| 232 |
|
| } |
| 233 |
18 |
| break; |
| 234 |
|
| } |
| 235 |
2 |
| case OTEL_AGG_EXPO: { |
| 236 |
2 |
| HV *pos = newHV(), *neg = newHV(); |
| 237 |
2 |
| AV *pc = newAV(), *nc = newAV(); |
| 238 |
194 |
▶ | for (i = 0; i < p->expo.pos.len; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < p->expo.pos.len; i++) |
192 |
2 |
194 |
|
| 239 |
192 |
| av_push(pc, newSViv(p->expo.pos.counts[i])); |
| 240 |
2 |
▶ | for (i = 0; i < p->expo.neg.len; i++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < p->expo.neg.len; i++) |
0 |
2 |
2 |
|
| 241 |
0 |
| av_push(nc, newSViv(p->expo.neg.counts[i])); |
| 242 |
2 |
| (void)hv_stores(pos, "offset", newSViv(p->expo.pos.offset)); |
| 243 |
2 |
| (void)hv_stores(pos, "bucket_counts", newRV_noinc((SV *)pc)); |
| 244 |
2 |
| (void)hv_stores(neg, "offset", newSViv(p->expo.neg.offset)); |
| 245 |
2 |
| (void)hv_stores(neg, "bucket_counts", newRV_noinc((SV *)nc)); |
| 246 |
2 |
| (void)hv_stores(h, "scale", newSViv(p->expo.scale)); |
| 247 |
2 |
| (void)hv_stores(h, "zero_count", newSViv(p->expo.zero_count)); |
| 248 |
2 |
| (void)hv_stores(h, "sum", newSVnv(p->expo.sum)); |
| 249 |
2 |
| (void)hv_stores(h, "positive", newRV_noinc((SV *)pos)); |
| 250 |
2 |
| (void)hv_stores(h, "negative", newRV_noinc((SV *)neg)); |
| 251 |
2 |
| break; |
| 252 |
|
| } |
| 253 |
4028 |
| default: |
| 254 |
4028 |
| (void)hv_stores(h, "value", newSVnv(p->sum)); |
| 255 |
4028 |
| (void)hv_stores(h, "sum", newSVnv(p->sum)); |
| 256 |
4028 |
| break; |
| 257 |
|
| } |
| 258 |
|
| |
| 259 |
4050 |
▶ | if (p->n_ex) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (p->n_ex) { |
6 |
4044 |
4050 |
|
| 260 |
6 |
| AV *ex = newAV(); |
| 261 |
12 |
▶ | for (i = 0; i < p->n_ex; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < p->n_ex; i++) { |
6 |
6 |
12 |
|
| 262 |
|
| HV *e; |
| 263 |
|
| char hex[32]; |
| 264 |
6 |
▶ | if (!p->ex[i].has_span) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!p->ex[i].has_span) continue; |
0 |
6 |
6 |
|
| 265 |
6 |
| e = newHV(); |
| 266 |
6 |
| (void)hv_stores(e, "value", newSVnv(p->ex[i].value)); |
| 267 |
6 |
| (void)hv_stores(e, "time_unix_nano", newSVuv((UV)p->ex[i].time)); |
| 268 |
6 |
| otel_bytes_to_hex(p->ex[i].trace_id, 16, hex); |
| 269 |
6 |
| (void)hv_stores(e, "trace_id", newSVpvn(hex, 32)); |
| 270 |
6 |
| otel_bytes_to_hex(p->ex[i].span_id, 8, hex); |
| 271 |
6 |
| (void)hv_stores(e, "span_id", newSVpvn(hex, 16)); |
| 272 |
6 |
| av_push(ex, newRV_noinc((SV *)e)); |
| 273 |
|
| } |
| 274 |
6 |
▶ | if (av_len(ex) >= 0) (void)hv_stores(h, "exemplars", newRV_noinc((SV *)ex)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(ex) >= 0) (void)hv_stores(h, "exemplars", newRV_noinc((SV *)ex)); |
6 |
0 |
6 |
|
| 275 |
0 |
| else SvREFCNT_dec((SV *)ex); |
| 276 |
|
| } |
| 277 |
4050 |
| return newRV_noinc((SV *)h); |
| 278 |
|
| } |
| 279 |
|
| |
| 280 |
49 |
| static SV *otel_meter_collect(pTHX_ otel_meter *m) { |
| 281 |
|
| HV *payload, *rm, *sm, *res, *scope; |
| 282 |
|
| AV *rms, *sms, *metrics; |
| 283 |
|
| otel_instrument *in; |
| 284 |
49 |
| int any = 0; |
| 285 |
|
| |
| 286 |
49 |
| metrics = newAV(); |
| 287 |
103 |
▶ | for (in = m->instruments; in; in = in->next) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (in = m->instruments; in; in = in->next) { |
54 |
49 |
103 |
|
| 288 |
|
| HV *mh; |
| 289 |
|
| AV *pts; |
| 290 |
|
| otel_point *p; |
| 291 |
54 |
▶ | if (in->aggregation == OTEL_AGG_DROP) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (in->aggregation == OTEL_AGG_DROP) continue; |
6 |
48 |
54 |
|
| 292 |
48 |
| pts = newAV(); |
| 293 |
4099 |
▶ | for (p = in->points; p; p = p->next) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (p = in->points; p; p = p->next) { |
4051 |
48 |
4099 |
|
| 294 |
4051 |
▶ | if (!p->count && in->aggregation != OTEL_AGG_LASTVALUE) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!p->count && in->aggregation != OTEL_AGG_LASTVALUE) continue; |
1 |
4050 |
4051 |
| if (!p->count && in->aggregation != OTEL_AGG_LASTVALUE) continue; |
1 |
0 |
1 |
|
| 295 |
4050 |
| av_push(pts, otel_point_to_hv(aTHX_ in, p)); |
| 296 |
4050 |
| any = 1; |
| 297 |
|
| } |
| 298 |
48 |
▶ | if (av_len(pts) < 0) { SvREFCNT_dec((SV *)pts); continue; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(pts) < 0) { SvREFCNT_dec((SV *)pts); continue; } |
1 |
47 |
48 |
|
| 299 |
47 |
| mh = newHV(); |
| 300 |
47 |
| (void)hv_stores(mh, "name", newSVsv(in->name)); |
| 301 |
47 |
▶ | if (in->unit) (void)hv_stores(mh, "unit", newSVsv(in->unit)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (in->unit) (void)hv_stores(mh, "unit", newSVsv(in->unit)); |
3 |
44 |
47 |
|
| 302 |
47 |
▶ | if (in->description) (void)hv_stores(mh, "description", |
Branch: 1 branch
| Branch | True | False | Total |
| if (in->description) (void)hv_stores(mh, "description", |
0 |
47 |
47 |
|
| 303 |
|
| newSVsv(in->description)); |
| 304 |
47 |
| (void)hv_stores(mh, "aggregation", newSViv(in->aggregation)); |
| 305 |
47 |
| (void)hv_stores(mh, "temporality", newSViv(in->temporality)); |
| 306 |
47 |
| (void)hv_stores(mh, "monotonic", |
| 307 |
|
| newSViv(in->kind == OTEL_INSTR_COUNTER ? 1 : 0)); |
| 308 |
47 |
| (void)hv_stores(mh, "data_points", newRV_noinc((SV *)pts)); |
| 309 |
47 |
▶ | if (in->overflow) (void)hv_stores(mh, "overflow", newSViv(in->overflow)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (in->overflow) (void)hv_stores(mh, "overflow", newSViv(in->overflow)); |
2 |
45 |
47 |
|
| 310 |
47 |
| av_push(metrics, newRV_noinc((SV *)mh)); |
| 311 |
|
| } |
| 312 |
49 |
▶ | if (!any) { SvREFCNT_dec((SV *)metrics); return NULL; } |
Branch: 1 branch
| Branch | True | False | Total |
| if (!any) { SvREFCNT_dec((SV *)metrics); return NULL; } |
4 |
45 |
49 |
|
| 313 |
|
| |
| 314 |
|
| /* DELTA resets every accumulator and restarts the interval; CUMULATIVE |
| 315 |
|
| * leaves both alone. That is the entire distinction. */ |
| 316 |
45 |
▶ | if (m->temporality == OTEL_TEMP_DELTA) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (m->temporality == OTEL_TEMP_DELTA) { |
6 |
39 |
45 |
|
| 317 |
|
| otel_point *p; |
| 318 |
12 |
▶ | for (in = m->instruments; in; in = in->next) |
Branch: 1 branch
| Branch | True | False | Total |
| for (in = m->instruments; in; in = in->next) |
6 |
6 |
12 |
|
| 319 |
12 |
▶ | for (p = in->points; p; p = p->next) otel_point_reset(p); |
Branch: 1 branch
| Branch | True | False | Total |
| for (p = in->points; p; p = p->next) otel_point_reset(p); |
6 |
6 |
12 |
|
| 320 |
|
| } |
| 321 |
|
| |
| 322 |
45 |
| scope = newHV(); |
| 323 |
45 |
▶ | if (m->scope_name) (void)hv_stores(scope, "name", newSVsv(m->scope_name)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (m->scope_name) (void)hv_stores(scope, "name", newSVsv(m->scope_name)); |
35 |
10 |
45 |
|
| 324 |
45 |
▶ | if (m->scope_version) (void)hv_stores(scope, "version", |
Branch: 1 branch
| Branch | True | False | Total |
| if (m->scope_version) (void)hv_stores(scope, "version", |
0 |
45 |
45 |
|
| 325 |
|
| newSVsv(m->scope_version)); |
| 326 |
45 |
| sm = newHV(); |
| 327 |
45 |
| (void)hv_stores(sm, "scope", newRV_noinc((SV *)scope)); |
| 328 |
45 |
| (void)hv_stores(sm, "metrics", newRV_noinc((SV *)metrics)); |
| 329 |
45 |
| sms = newAV(); |
| 330 |
45 |
| av_push(sms, newRV_noinc((SV *)sm)); |
| 331 |
|
| |
| 332 |
45 |
| res = newHV(); |
| 333 |
45 |
| (void)hv_stores(res, "attributes", newRV_inc((SV *)m->resource)); |
| 334 |
45 |
| rm = newHV(); |
| 335 |
45 |
| (void)hv_stores(rm, "resource", newRV_noinc((SV *)res)); |
| 336 |
45 |
| (void)hv_stores(rm, "scope_metrics", newRV_noinc((SV *)sms)); |
| 337 |
45 |
| rms = newAV(); |
| 338 |
45 |
| av_push(rms, newRV_noinc((SV *)rm)); |
| 339 |
|
| |
| 340 |
45 |
| payload = newHV(); |
| 341 |
45 |
| (void)hv_stores(payload, "resource_metrics", newRV_noinc((SV *)rms)); |
| 342 |
45 |
| return newRV_noinc((SV *)payload); |
| 343 |
|
| } |
| 344 |
|
| |
| 345 |
|
| #endif /* OTEL_METER_H */ |
| 346 |
|
| |