| 1 |
|
| /* otel_schema.h - schema-version conversion. |
| 2 |
|
| * |
| 3 |
|
| * A schema file records what CHANGED going up to each version. Converting a |
| 4 |
|
| * payload between two versions is therefore a walk over the versions between |
| 5 |
|
| * them, applying each one's rename maps in turn. |
| 6 |
|
| * |
| 7 |
|
| * The YAML parse is the one thing here that is not C: the format needs a |
| 8 |
|
| * parser, which parser is a runtime question (the feature is opt-in and most |
| 9 |
|
| * deployments never touch it, so a hard dependency would tax everyone for the |
| 10 |
|
| * few), and the result is ordinary Perl data that the rest of this file walks. |
| 11 |
|
| * So the parser is called by name, as the exporter calls HTTP::Date. |
| 12 |
|
| * |
| 13 |
|
| * Needs otel_trace.h (otel_h / otel_h_hv / otel_h_av). |
| 14 |
|
| */ |
| 15 |
|
| |
| 16 |
|
| #ifndef OTEL_SCHEMA_H |
| 17 |
|
| #define OTEL_SCHEMA_H |
| 18 |
|
| |
| 19 |
|
| /* The marker a metric rename is stored under, so one map can carry both |
| 20 |
|
| * attribute and metric renames without them colliding: no attribute name |
| 21 |
|
| * contains a NUL. */ |
| 22 |
|
| #define OTEL_METRIC_MARK "\0metric\0" |
| 23 |
|
| #define OTEL_METRIC_MARK_LEN 8 |
| 24 |
|
| |
| 25 |
|
| /* ---- semantic version ordering ------------------------------------------ * |
| 26 |
|
| * |
| 27 |
|
| * Versions are applied ONE AT A TIME, in order, so this has to be right: |
| 28 |
|
| * comparing "1.10.0" and "1.9.0" as strings puts them the wrong way round and |
| 29 |
|
| * silently applies the changes backwards. */ |
| 30 |
416 |
| static int otel_schema_vcmp(pTHX_ SV *a, SV *b) { |
| 31 |
|
| STRLEN al, bl; |
| 32 |
832 |
▶ | const char *ap = SvOK(a) ? SvPV_const(a, al) : ""; |
Branch: 1 branch
| Branch | True | False | Total |
| const char *ap = SvOK(a) ? SvPV_const(a, al) : ""; |
416 |
0 |
416 |
|
| 33 |
832 |
▶ | const char *bp = SvOK(b) ? SvPV_const(b, bl) : ""; |
Branch: 1 branch
| Branch | True | False | Total |
| const char *bp = SvOK(b) ? SvPV_const(b, bl) : ""; |
416 |
0 |
416 |
|
| 34 |
416 |
| STRLEN ai = 0, bi = 0; |
| 35 |
|
| int part; |
| 36 |
416 |
▶ | if (!SvOK(a)) al = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(a)) al = 0; |
0 |
416 |
416 |
|
| 37 |
416 |
▶ | if (!SvOK(b)) bl = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!SvOK(b)) bl = 0; |
0 |
416 |
416 |
|
| 38 |
897 |
▶ | for (part = 0; part < 3; part++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (part = 0; part < 3; part++) { |
866 |
31 |
897 |
|
| 39 |
866 |
| IV av = 0, bv = 0; |
| 40 |
1995 |
▶ | while (ai < al && ap[ai] != '.') { |
Branch: 2 branches
| Branch | True | False | Total |
| while (ai < al && ap[ai] != '.') { |
1960 |
35 |
1995 |
| while (ai < al && ap[ai] != '.') { |
1129 |
831 |
1960 |
|
| 41 |
1129 |
▶ | if (isDIGIT(ap[ai])) av = av * 10 + (ap[ai] - '0'); |
Branch: 1 branch
| Branch | True | False | Total |
| if (isDIGIT(ap[ai])) av = av * 10 + (ap[ai] - '0'); |
1129 |
0 |
1129 |
|
| 42 |
1129 |
| ai++; |
| 43 |
|
| } |
| 44 |
866 |
▶ | if (ai < al) ai++; /* step over the dot */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (ai < al) ai++; /* step over the dot */ |
831 |
35 |
866 |
|
| 45 |
2015 |
▶ | while (bi < bl && bp[bi] != '.') { |
Branch: 2 branches
| Branch | True | False | Total |
| while (bi < bl && bp[bi] != '.') { |
1980 |
35 |
2015 |
| while (bi < bl && bp[bi] != '.') { |
1149 |
831 |
1980 |
|
| 46 |
1149 |
▶ | if (isDIGIT(bp[bi])) bv = bv * 10 + (bp[bi] - '0'); |
Branch: 1 branch
| Branch | True | False | Total |
| if (isDIGIT(bp[bi])) bv = bv * 10 + (bp[bi] - '0'); |
1149 |
0 |
1149 |
|
| 47 |
1149 |
| bi++; |
| 48 |
|
| } |
| 49 |
866 |
▶ | if (bi < bl) bi++; |
Branch: 1 branch
| Branch | True | False | Total |
| if (bi < bl) bi++; |
831 |
35 |
866 |
|
| 50 |
866 |
▶ | if (av != bv) return av < bv ? -1 : 1; |
Branch: 2 branches
| Branch | True | False | Total |
| if (av != bv) return av < bv ? -1 : 1; |
385 |
481 |
866 |
| if (av != bv) return av < bv ? -1 : 1; |
209 |
176 |
385 |
|
| 51 |
|
| } |
| 52 |
31 |
| return 0; |
| 53 |
|
| } |
| 54 |
|
| |
| 55 |
|
| /* sortsv comparator over the version keys */ |
| 56 |
204 |
| static I32 otel_schema_sortcmp(pTHX_ SV *a, SV *b) { |
| 57 |
204 |
| return (I32)otel_schema_vcmp(aTHX_ a, b); |
| 58 |
|
| } |
| 59 |
|
| |
| 60 |
|
| /* ---- the version string inside a schema URL ------------------------------ * |
| 61 |
|
| * m{([0-9]+(?:\.[0-9]+)*)/?\z} - the trailing version, with an optional |
| 62 |
|
| * trailing slash. Mortal SV, or NULL. */ |
| 63 |
5 |
| static SV *otel_schema_url_version(pTHX_ SV *url) { |
| 64 |
|
| STRLEN l; |
| 65 |
|
| const char *p; |
| 66 |
|
| STRLEN end, start; |
| 67 |
5 |
▶ | if (!url || !SvOK(url)) return NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!url || !SvOK(url)) return NULL; |
5 |
0 |
5 |
| if (!url || !SvOK(url)) return NULL; |
0 |
5 |
5 |
|
| 68 |
5 |
| p = SvPV_const(url, l); |
| 69 |
5 |
| end = l; |
| 70 |
5 |
▶ | if (end && p[end - 1] == '/') end--; /* the optional slash */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (end && p[end - 1] == '/') end--; /* the optional slash */ |
5 |
0 |
5 |
| if (end && p[end - 1] == '/') end--; /* the optional slash */ |
0 |
5 |
5 |
|
| 71 |
5 |
▶ | if (!end) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!end) return NULL; |
0 |
5 |
5 |
|
| 72 |
5 |
▶ | if (!isDIGIT(p[end - 1])) return NULL; /* must end in a digit */ |
Branch: 1 branch
| Branch | True | False | Total |
| if (!isDIGIT(p[end - 1])) return NULL; /* must end in a digit */ |
0 |
5 |
5 |
|
| 73 |
5 |
| start = end; |
| 74 |
33 |
▶ | while (start > 0 && (isDIGIT(p[start - 1]) || p[start - 1] == '.')) start--; |
Branch: 3 branches
| Branch | True | False | Total |
| while (start > 0 && (isDIGIT(p[start - 1]) || p[start - 1] == '.')) start--; |
33 |
0 |
33 |
| while (start > 0 && (isDIGIT(p[start - 1]) || p[start - 1] == '.')) start--; |
18 |
15 |
33 |
| while (start > 0 && (isDIGIT(p[start - 1]) || p[start - 1] == '.')) start--; |
10 |
5 |
15 |
|
| 75 |
|
| /* the match is anchored on a digit run, so step over any leading dots */ |
| 76 |
5 |
▶ | while (start < end && p[start] == '.') start++; |
Branch: 2 branches
| Branch | True | False | Total |
| while (start < end && p[start] == '.') start++; |
5 |
0 |
5 |
| while (start < end && p[start] == '.') start++; |
0 |
5 |
5 |
|
| 77 |
5 |
▶ | if (start >= end) return NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| if (start >= end) return NULL; |
0 |
5 |
5 |
|
| 78 |
5 |
| return sv_2mortal(newSVpvn(p + start, end - start)); |
| 79 |
|
| } |
| 80 |
|
| |
| 81 |
|
| /* ---- the rename map for one version -------------------------------------- * |
| 82 |
|
| * |
| 83 |
|
| * A version's `all` section applies to every signal, and its per-signal |
| 84 |
|
| * section to that one. Both are merged, `all` first so a signal-specific |
| 85 |
|
| * rename wins. Attribute renames go in under their own name; metric renames |
| 86 |
|
| * go in under the NUL marker. Mortal HV. */ |
| 87 |
42 |
| static HV *otel_schema_renames(pTHX_ HV *self, SV *version, const char *signal, |
| 88 |
|
| STRLEN siglen) { |
| 89 |
42 |
| HV *out = (HV *)sv_2mortal((SV *)newHV()); |
| 90 |
42 |
| HV *versions = otel_h_hv(aTHX_ self, "versions"); |
| 91 |
|
| HE *he; |
| 92 |
|
| HV *v; |
| 93 |
|
| int pass; |
| 94 |
42 |
▶ | if (!versions) return out; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!versions) return out; |
0 |
42 |
42 |
|
| 95 |
42 |
| he = hv_fetch_ent(versions, version, 0, 0); |
| 96 |
42 |
▶ | if (!(he && HeVAL(he))) return out; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(he && HeVAL(he))) return out; |
42 |
0 |
42 |
| if (!(he && HeVAL(he))) return out; |
0 |
42 |
42 |
|
| 97 |
42 |
| v = otel_hv_of(aTHX_ HeVAL(he)); |
| 98 |
42 |
▶ | if (!v) return out; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!v) return out; |
3 |
39 |
42 |
|
| 99 |
|
| |
| 100 |
117 |
▶ | for (pass = 0; pass < 2; pass++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (pass = 0; pass < 2; pass++) { |
78 |
39 |
117 |
|
| 101 |
39 |
| SV **sp = (pass == 0) ? hv_fetchs(v, "all", 0) |
| 102 |
78 |
▶ | : hv_fetch(v, signal, (I32)siglen, 0); |
Branch: 1 branch
| Branch | True | False | Total |
| : hv_fetch(v, signal, (I32)siglen, 0); |
39 |
39 |
78 |
|
| 103 |
78 |
▶ | HV *sect = (sp && *sp) ? otel_hv_of(aTHX_ *sp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *sect = (sp && *sp) ? otel_hv_of(aTHX_ *sp) : NULL; |
43 |
35 |
78 |
| HV *sect = (sp && *sp) ? otel_hv_of(aTHX_ *sp) : NULL; |
43 |
0 |
43 |
|
| 104 |
|
| AV *changes; |
| 105 |
|
| SSize_t i, n; |
| 106 |
78 |
▶ | if (!sect) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sect) continue; |
35 |
43 |
78 |
|
| 107 |
43 |
| changes = otel_h_av(aTHX_ sect, "changes"); |
| 108 |
43 |
▶ | if (!changes) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!changes) continue; |
0 |
43 |
43 |
|
| 109 |
43 |
| n = av_len(changes) + 1; |
| 110 |
125 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
82 |
43 |
125 |
|
| 111 |
82 |
| SV **cp = av_fetch(changes, i, 0); |
| 112 |
82 |
▶ | HV *ch = (cp && *cp) ? otel_hv_of(aTHX_ *cp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *ch = (cp && *cp) ? otel_hv_of(aTHX_ *cp) : NULL; |
82 |
0 |
82 |
| HV *ch = (cp && *cp) ? otel_hv_of(aTHX_ *cp) : NULL; |
82 |
0 |
82 |
|
| 113 |
|
| SV **mp; |
| 114 |
|
| HV *m; |
| 115 |
82 |
▶ | if (!ch) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ch) continue; |
0 |
82 |
82 |
|
| 116 |
|
| |
| 117 |
82 |
| mp = hv_fetchs(ch, "rename_attributes", 0); |
| 118 |
82 |
▶ | m = (mp && *mp) ? otel_hv_of(aTHX_ *mp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| m = (mp && *mp) ? otel_hv_of(aTHX_ *mp) : NULL; |
80 |
2 |
82 |
| m = (mp && *mp) ? otel_hv_of(aTHX_ *mp) : NULL; |
80 |
0 |
80 |
|
| 119 |
82 |
▶ | if (m) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (m) { |
80 |
2 |
82 |
|
| 120 |
|
| /* the spec nests the map under attribute_map; a file that |
| 121 |
|
| * writes it flat is accepted too */ |
| 122 |
80 |
| SV **inner = hv_fetchs(m, "attribute_map", 0); |
| 123 |
80 |
▶ | HV *im = (inner && *inner) ? otel_hv_of(aTHX_ *inner) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *im = (inner && *inner) ? otel_hv_of(aTHX_ *inner) : NULL; |
80 |
0 |
80 |
| HV *im = (inner && *inner) ? otel_hv_of(aTHX_ *inner) : NULL; |
80 |
0 |
80 |
|
| 124 |
80 |
▶ | if (im) m = im; |
Branch: 1 branch
| Branch | True | False | Total |
| if (im) m = im; |
80 |
0 |
80 |
|
| 125 |
80 |
| hv_iterinit(m); |
| 126 |
232 |
▶ | while ((he = hv_iternext(m))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(m))) { |
152 |
80 |
232 |
|
| 127 |
|
| STRLEN kl; |
| 128 |
152 |
▶ | const char *k = HePV(he, kl); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *k = HePV(he, kl); |
0 |
152 |
152 |
|
| 129 |
152 |
| (void)hv_store(out, k, (I32)kl, newSVsv(HeVAL(he)), 0); |
| 130 |
|
| } |
| 131 |
|
| } |
| 132 |
|
| |
| 133 |
|
| /* a metric rename renames the METRIC as well as its attributes */ |
| 134 |
82 |
| mp = hv_fetchs(ch, "rename_metrics", 0); |
| 135 |
82 |
▶ | m = (mp && *mp) ? otel_hv_of(aTHX_ *mp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| m = (mp && *mp) ? otel_hv_of(aTHX_ *mp) : NULL; |
2 |
80 |
82 |
| m = (mp && *mp) ? otel_hv_of(aTHX_ *mp) : NULL; |
2 |
0 |
2 |
|
| 136 |
82 |
▶ | if (m) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (m) { |
2 |
80 |
82 |
|
| 137 |
2 |
| hv_iterinit(m); |
| 138 |
4 |
▶ | while ((he = hv_iternext(m))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(m))) { |
2 |
2 |
4 |
|
| 139 |
|
| STRLEN kl; |
| 140 |
2 |
▶ | const char *k = HePV(he, kl); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *k = HePV(he, kl); |
0 |
2 |
2 |
|
| 141 |
2 |
| SV *key = sv_2mortal(newSVpvn(OTEL_METRIC_MARK, |
| 142 |
|
| OTEL_METRIC_MARK_LEN)); |
| 143 |
2 |
| sv_catpvn(key, k, kl); |
| 144 |
2 |
| (void)hv_store_ent(out, key, newSVsv(HeVAL(he)), 0); |
| 145 |
|
| } |
| 146 |
|
| } |
| 147 |
|
| } |
| 148 |
|
| } |
| 149 |
39 |
| return out; |
| 150 |
|
| } |
| 151 |
|
| |
| 152 |
|
| /* ---- which versions to apply, and in which direction --------------------- * |
| 153 |
|
| * |
| 154 |
|
| * THE RULE THAT MATTERS: they are applied ONE AT A TIME, in order. A single |
| 155 |
|
| * merged rename map computed in one pass gives the wrong answer whenever an |
| 156 |
|
| * attribute was renamed twice - a -> b in 1.1 and b -> c in 1.2 has to become |
| 157 |
|
| * a -> c, and a flattened map produces a -> b and b -> c as independent |
| 158 |
|
| * entries, so `a` arrives as `b` and stops there. |
| 159 |
|
| * |
| 160 |
|
| * Fills *dir with the direction and returns the steps (mortal AV). */ |
| 161 |
15 |
| static AV *otel_schema_walk(pTHX_ HV *self, SV *from, SV *to, int *dir) { |
| 162 |
15 |
| AV *out = (AV *)sv_2mortal((SV *)newAV()); |
| 163 |
15 |
| AV *order = otel_h_av(aTHX_ self, "order"); |
| 164 |
|
| SSize_t i, n; |
| 165 |
15 |
| int d = otel_schema_vcmp(aTHX_ to, from); |
| 166 |
15 |
| *dir = d; |
| 167 |
15 |
▶ | if (d == 0 || !order) return out; |
Branch: 2 branches
| Branch | True | False | Total |
| if (d == 0 || !order) return out; |
14 |
1 |
15 |
| if (d == 0 || !order) return out; |
0 |
14 |
14 |
|
| 168 |
14 |
| n = av_len(order) + 1; |
| 169 |
14 |
▶ | if (d > 0) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (d > 0) { |
10 |
4 |
14 |
|
| 170 |
|
| /* forward: apply every version ABOVE from, up to and including to */ |
| 171 |
88 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
78 |
10 |
88 |
|
| 172 |
78 |
| SV **e = av_fetch(order, i, 0); |
| 173 |
78 |
▶ | if (!(e && *e)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(e && *e)) continue; |
78 |
0 |
78 |
| if (!(e && *e)) continue; |
0 |
78 |
78 |
|
| 174 |
78 |
▶ | if (otel_schema_vcmp(aTHX_ *e, from) > 0 |
Branch: 1 branch
| Branch | True | False | Total |
| if (otel_schema_vcmp(aTHX_ *e, from) > 0 |
38 |
40 |
78 |
|
| 175 |
38 |
▶ | && otel_schema_vcmp(aTHX_ *e, to) <= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| && otel_schema_vcmp(aTHX_ *e, to) <= 0) |
30 |
8 |
38 |
|
| 176 |
30 |
| av_push(out, newSVsv(*e)); |
| 177 |
|
| } |
| 178 |
|
| } |
| 179 |
|
| else { |
| 180 |
|
| /* backward: undo every version above to, down to and including from, |
| 181 |
|
| * newest first */ |
| 182 |
39 |
▶ | for (i = n - 1; i >= 0; i--) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = n - 1; i >= 0; i--) { |
35 |
4 |
39 |
|
| 183 |
35 |
| SV **e = av_fetch(order, i, 0); |
| 184 |
35 |
▶ | if (!(e && *e)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(e && *e)) continue; |
35 |
0 |
35 |
| if (!(e && *e)) continue; |
0 |
35 |
35 |
|
| 185 |
35 |
▶ | if (otel_schema_vcmp(aTHX_ *e, to) > 0 |
Branch: 1 branch
| Branch | True | False | Total |
| if (otel_schema_vcmp(aTHX_ *e, to) > 0 |
14 |
21 |
35 |
|
| 186 |
14 |
▶ | && otel_schema_vcmp(aTHX_ *e, from) <= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| && otel_schema_vcmp(aTHX_ *e, from) <= 0) |
12 |
2 |
14 |
|
| 187 |
12 |
| av_push(out, newSVsv(*e)); |
| 188 |
|
| } |
| 189 |
|
| } |
| 190 |
14 |
| return out; |
| 191 |
|
| } |
| 192 |
|
| |
| 193 |
|
| /* ---- applying one step --------------------------------------------------- */ |
| 194 |
|
| |
| 195 |
|
| /* Rename the keys of one attribute hash, in place, for one version step. |
| 196 |
|
| * Collected first and applied after, because renaming while iterating a hash |
| 197 |
|
| * is undefined and a rename can land on a key not yet visited. */ |
| 198 |
64 |
| static void otel_schema_apply_map(pTHX_ SV *attrs_sv, HV *map, int forward) { |
| 199 |
64 |
| HV *attrs = otel_hv_of(aTHX_ attrs_sv); |
| 200 |
|
| HV *renamed; |
| 201 |
|
| HE *he; |
| 202 |
64 |
▶ | if (!attrs || !HvUSEDKEYS(attrs)) return; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!attrs || !HvUSEDKEYS(attrs)) return; |
64 |
0 |
64 |
| if (!attrs || !HvUSEDKEYS(attrs)) return; |
0 |
64 |
64 |
| if (!attrs || !HvUSEDKEYS(attrs)) return; |
0 |
64 |
64 |
|
| 203 |
64 |
| renamed = (HV *)sv_2mortal((SV *)newHV()); |
| 204 |
|
| |
| 205 |
64 |
| hv_iterinit(attrs); |
| 206 |
128 |
▶ | while ((he = hv_iternext(attrs))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(attrs))) { |
64 |
64 |
128 |
|
| 207 |
|
| STRLEN kl; |
| 208 |
64 |
▶ | const char *k = HePV(he, kl); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *k = HePV(he, kl); |
0 |
64 |
64 |
|
| 209 |
64 |
| SV *to = NULL; |
| 210 |
64 |
▶ | if (forward) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (forward) { |
47 |
17 |
64 |
|
| 211 |
47 |
| SV **t = hv_fetch(map, k, (I32)kl, 0); |
| 212 |
47 |
▶ | if (t && *t && SvOK(*t)) to = *t; |
Branch: 3 branches
| Branch | True | False | Total |
| if (t && *t && SvOK(*t)) to = *t; |
21 |
26 |
47 |
| if (t && *t && SvOK(*t)) to = *t; |
21 |
0 |
21 |
| if (t && *t && SvOK(*t)) to = *t; |
21 |
0 |
21 |
|
| 213 |
|
| } |
| 214 |
|
| else { |
| 215 |
|
| /* backward: the map is old -> new, so invert it */ |
| 216 |
|
| HE *m; |
| 217 |
17 |
| hv_iterinit(map); |
| 218 |
81 |
▶ | while ((m = hv_iternext(map))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((m = hv_iternext(map))) { |
73 |
8 |
81 |
|
| 219 |
|
| STRLEN ml; |
| 220 |
73 |
▶ | const char *mk = HePV(m, ml); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *mk = HePV(m, ml); |
0 |
73 |
73 |
|
| 221 |
73 |
| SV *mv = HeVAL(m); |
| 222 |
|
| STRLEN vl; |
| 223 |
|
| const char *vp; |
| 224 |
73 |
▶ | if (ml >= OTEL_METRIC_MARK_LEN |
Branch: 1 branch
| Branch | True | False | Total |
| if (ml >= OTEL_METRIC_MARK_LEN |
68 |
5 |
73 |
|
| 225 |
68 |
▶ | && memEQ(mk, OTEL_METRIC_MARK, OTEL_METRIC_MARK_LEN)) |
Branch: 1 branch
| Branch | True | False | Total |
| && memEQ(mk, OTEL_METRIC_MARK, OTEL_METRIC_MARK_LEN)) |
0 |
68 |
68 |
|
| 226 |
0 |
| continue; /* a metric rename, not ours */ |
| 227 |
73 |
▶ | if (!(mv && SvOK(mv))) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(mv && SvOK(mv))) continue; |
73 |
0 |
73 |
| if (!(mv && SvOK(mv))) continue; |
0 |
73 |
73 |
|
| 228 |
73 |
| vp = SvPV_const(mv, vl); |
| 229 |
73 |
▶ | if (vl == kl && memEQ(vp, k, kl)) { |
Branch: 2 branches
| Branch | True | False | Total |
| if (vl == kl && memEQ(vp, k, kl)) { |
15 |
58 |
73 |
| if (vl == kl && memEQ(vp, k, kl)) { |
9 |
6 |
15 |
|
| 230 |
9 |
| to = sv_2mortal(newSVpvn(mk, ml)); |
| 231 |
9 |
| break; |
| 232 |
|
| } |
| 233 |
|
| } |
| 234 |
|
| } |
| 235 |
64 |
▶ | if (!to || !SvOK(to)) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!to || !SvOK(to)) continue; |
30 |
34 |
64 |
| if (!to || !SvOK(to)) continue; |
0 |
30 |
30 |
|
| 236 |
|
| { |
| 237 |
|
| STRLEN tl; |
| 238 |
30 |
| const char *tp = SvPV_const(to, tl); |
| 239 |
30 |
▶ | if (tl == kl && memEQ(tp, k, kl)) continue; /* renamed to itself */ |
Branch: 2 branches
| Branch | True | False | Total |
| if (tl == kl && memEQ(tp, k, kl)) continue; /* renamed to itself */ |
14 |
16 |
30 |
| if (tl == kl && memEQ(tp, k, kl)) continue; /* renamed to itself */ |
0 |
14 |
14 |
|
| 240 |
30 |
| (void)hv_store(renamed, k, (I32)kl, newSVsv(to), 0); |
| 241 |
|
| } |
| 242 |
|
| } |
| 243 |
|
| |
| 244 |
64 |
| hv_iterinit(renamed); |
| 245 |
94 |
▶ | while ((he = hv_iternext(renamed))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(renamed))) { |
30 |
64 |
94 |
|
| 246 |
|
| STRLEN kl, nl; |
| 247 |
30 |
▶ | const char *k = HePV(he, kl); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *k = HePV(he, kl); |
0 |
30 |
30 |
|
| 248 |
30 |
| const char *n = SvPV_const(HeVAL(he), nl); |
| 249 |
30 |
| SV *val = hv_delete(attrs, k, (I32)kl, 0); /* mortal */ |
| 250 |
30 |
▶ | if (val) (void)hv_store(attrs, n, (I32)nl, newSVsv(val), 0); |
Branch: 1 branch
| Branch | True | False | Total |
| if (val) (void)hv_store(attrs, n, (I32)nl, newSVsv(val), 0); |
30 |
0 |
30 |
|
| 251 |
|
| } |
| 252 |
|
| } |
| 253 |
|
| |
| 254 |
|
| /* The new name for a metric, or the name unchanged. */ |
| 255 |
2 |
| static SV *otel_schema_metric_name(pTHX_ HV *map, SV *name, int forward) { |
| 256 |
|
| STRLEN nl; |
| 257 |
|
| const char *np; |
| 258 |
2 |
▶ | if (!name || !SvOK(name)) return NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!name || !SvOK(name)) return NULL; |
2 |
0 |
2 |
| if (!name || !SvOK(name)) return NULL; |
0 |
2 |
2 |
|
| 259 |
2 |
| np = SvPV_const(name, nl); |
| 260 |
2 |
▶ | if (forward) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (forward) { |
1 |
1 |
2 |
|
| 261 |
1 |
| SV *key = sv_2mortal(newSVpvn(OTEL_METRIC_MARK, OTEL_METRIC_MARK_LEN)); |
| 262 |
|
| HE *he; |
| 263 |
1 |
| sv_catpvn(key, np, nl); |
| 264 |
1 |
| he = hv_fetch_ent(map, key, 0, 0); |
| 265 |
1 |
▶ | return (he && HeVAL(he) && SvOK(HeVAL(he))) ? HeVAL(he) : NULL; |
Branch: 3 branches
| Branch | True | False | Total |
| return (he && HeVAL(he) && SvOK(HeVAL(he))) ? HeVAL(he) : NULL; |
1 |
0 |
1 |
| return (he && HeVAL(he) && SvOK(HeVAL(he))) ? HeVAL(he) : NULL; |
1 |
0 |
1 |
| return (he && HeVAL(he) && SvOK(HeVAL(he))) ? HeVAL(he) : NULL; |
1 |
0 |
1 |
|
| 266 |
|
| } |
| 267 |
|
| { |
| 268 |
|
| HE *he; |
| 269 |
1 |
| hv_iterinit(map); |
| 270 |
2 |
▶ | while ((he = hv_iternext(map))) { |
Branch: 1 branch
| Branch | True | False | Total |
| while ((he = hv_iternext(map))) { |
2 |
0 |
2 |
|
| 271 |
|
| STRLEN kl, vl; |
| 272 |
2 |
▶ | const char *k = HePV(he, kl); |
Branch: 1 branch
| Branch | True | False | Total |
| const char *k = HePV(he, kl); |
0 |
2 |
2 |
|
| 273 |
2 |
| SV *v = HeVAL(he); |
| 274 |
|
| const char *vp; |
| 275 |
2 |
▶ | if (kl <= OTEL_METRIC_MARK_LEN |
Branch: 1 branch
| Branch | True | False | Total |
| if (kl <= OTEL_METRIC_MARK_LEN |
1 |
1 |
2 |
|
| 276 |
2 |
▶ | || !memEQ(k, OTEL_METRIC_MARK, OTEL_METRIC_MARK_LEN)) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| || !memEQ(k, OTEL_METRIC_MARK, OTEL_METRIC_MARK_LEN)) continue; |
0 |
1 |
1 |
|
| 277 |
1 |
▶ | if (!(v && SvOK(v))) continue; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!(v && SvOK(v))) continue; |
1 |
0 |
1 |
| if (!(v && SvOK(v))) continue; |
0 |
1 |
1 |
|
| 278 |
1 |
| vp = SvPV_const(v, vl); |
| 279 |
1 |
▶ | if (vl == nl && memEQ(vp, np, nl)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (vl == nl && memEQ(vp, np, nl)) |
1 |
0 |
1 |
| if (vl == nl && memEQ(vp, np, nl)) |
1 |
0 |
1 |
|
| 280 |
1 |
| return sv_2mortal(newSVpvn(k + OTEL_METRIC_MARK_LEN, |
| 281 |
|
| kl - OTEL_METRIC_MARK_LEN)); |
| 282 |
|
| } |
| 283 |
|
| } |
| 284 |
0 |
| return NULL; |
| 285 |
|
| } |
| 286 |
|
| |
| 287 |
|
| /* ---- walking a payload --------------------------------------------------- * |
| 288 |
|
| * |
| 289 |
|
| * Every attribute hash in a payload: the resource, each scope, and each span / |
| 290 |
|
| * data point / log record, plus span events and links. */ |
| 291 |
32 |
| static void otel_schema_each_attrs(pTHX_ HV *payload, const char *signal, |
| 292 |
|
| STRLEN siglen, HV *map, int forward) { |
| 293 |
|
| const char *rkey, *skey, *ikey; |
| 294 |
|
| AV *rs; |
| 295 |
|
| SSize_t ri, rn; |
| 296 |
32 |
▶ | int is_metrics = (siglen == 7 && memEQ(signal, "metrics", 7)); |
Branch: 2 branches
| Branch | True | False | Total |
| int is_metrics = (siglen == 7 && memEQ(signal, "metrics", 7)); |
2 |
30 |
32 |
| int is_metrics = (siglen == 7 && memEQ(signal, "metrics", 7)); |
2 |
0 |
2 |
|
| 297 |
32 |
▶ | int is_logs = (siglen == 4 && memEQ(signal, "logs", 4)); |
Branch: 2 branches
| Branch | True | False | Total |
| int is_logs = (siglen == 4 && memEQ(signal, "logs", 4)); |
0 |
32 |
32 |
| int is_logs = (siglen == 4 && memEQ(signal, "logs", 4)); |
0 |
0 |
0 |
|
| 298 |
|
| |
| 299 |
32 |
▶ | rkey = is_metrics ? "resource_metrics" : is_logs ? "resource_logs" |
Branch: 2 branches
| Branch | True | False | Total |
| rkey = is_metrics ? "resource_metrics" : is_logs ? "resource_logs" |
30 |
2 |
32 |
| rkey = is_metrics ? "resource_metrics" : is_logs ? "resource_logs" |
0 |
30 |
30 |
|
| 300 |
|
| : "resource_spans"; |
| 301 |
32 |
▶ | skey = is_metrics ? "scope_metrics" : is_logs ? "scope_logs" |
Branch: 2 branches
| Branch | True | False | Total |
| skey = is_metrics ? "scope_metrics" : is_logs ? "scope_logs" |
30 |
2 |
32 |
| skey = is_metrics ? "scope_metrics" : is_logs ? "scope_logs" |
0 |
30 |
30 |
|
| 302 |
|
| : "scope_spans"; |
| 303 |
32 |
▶ | ikey = is_metrics ? "metrics" : is_logs ? "log_records" |
Branch: 2 branches
| Branch | True | False | Total |
| ikey = is_metrics ? "metrics" : is_logs ? "log_records" |
30 |
2 |
32 |
| ikey = is_metrics ? "metrics" : is_logs ? "log_records" |
0 |
30 |
30 |
|
| 304 |
|
| : "spans"; |
| 305 |
|
| |
| 306 |
32 |
| rs = otel_h_av(aTHX_ payload, rkey); |
| 307 |
32 |
▶ | if (!rs) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!rs) return; |
0 |
32 |
32 |
|
| 308 |
32 |
| rn = av_len(rs) + 1; |
| 309 |
64 |
▶ | for (ri = 0; ri < rn; ri++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ri = 0; ri < rn; ri++) { |
32 |
32 |
64 |
|
| 310 |
32 |
| SV **rp = av_fetch(rs, ri, 0); |
| 311 |
32 |
▶ | HV *r = (rp && *rp) ? otel_hv_of(aTHX_ *rp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *r = (rp && *rp) ? otel_hv_of(aTHX_ *rp) : NULL; |
32 |
0 |
32 |
| HV *r = (rp && *rp) ? otel_hv_of(aTHX_ *rp) : NULL; |
32 |
0 |
32 |
|
| 312 |
|
| HV *res; |
| 313 |
|
| AV *ss; |
| 314 |
|
| SSize_t si, sn; |
| 315 |
32 |
▶ | if (!r) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!r) continue; |
0 |
32 |
32 |
|
| 316 |
32 |
| res = otel_h_hv(aTHX_ r, "resource"); |
| 317 |
32 |
▶ | if (res) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (res) { |
30 |
2 |
32 |
|
| 318 |
30 |
| SV **a = hv_fetchs(res, "attributes", 0); |
| 319 |
30 |
▶ | if (a && *a) otel_schema_apply_map(aTHX_ *a, map, forward); |
Branch: 2 branches
| Branch | True | False | Total |
| if (a && *a) otel_schema_apply_map(aTHX_ *a, map, forward); |
30 |
0 |
30 |
| if (a && *a) otel_schema_apply_map(aTHX_ *a, map, forward); |
30 |
0 |
30 |
|
| 320 |
|
| } |
| 321 |
32 |
| ss = otel_h_av(aTHX_ r, skey); |
| 322 |
32 |
▶ | if (!ss) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ss) continue; |
0 |
32 |
32 |
|
| 323 |
32 |
| sn = av_len(ss) + 1; |
| 324 |
64 |
▶ | for (si = 0; si < sn; si++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (si = 0; si < sn; si++) { |
32 |
32 |
64 |
|
| 325 |
32 |
| SV **sp = av_fetch(ss, si, 0); |
| 326 |
32 |
▶ | HV *s = (sp && *sp) ? otel_hv_of(aTHX_ *sp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *s = (sp && *sp) ? otel_hv_of(aTHX_ *sp) : NULL; |
32 |
0 |
32 |
| HV *s = (sp && *sp) ? otel_hv_of(aTHX_ *sp) : NULL; |
32 |
0 |
32 |
|
| 327 |
|
| HV *scope; |
| 328 |
|
| AV *items; |
| 329 |
|
| SSize_t ii, in; |
| 330 |
32 |
▶ | if (!s) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) continue; |
0 |
32 |
32 |
|
| 331 |
32 |
| scope = otel_h_hv(aTHX_ s, "scope"); |
| 332 |
32 |
▶ | if (scope) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (scope) { |
30 |
2 |
32 |
|
| 333 |
30 |
| SV **a = hv_fetchs(scope, "attributes", 0); |
| 334 |
30 |
▶ | if (a && *a) otel_schema_apply_map(aTHX_ *a, map, forward); |
Branch: 2 branches
| Branch | True | False | Total |
| if (a && *a) otel_schema_apply_map(aTHX_ *a, map, forward); |
0 |
30 |
30 |
| if (a && *a) otel_schema_apply_map(aTHX_ *a, map, forward); |
0 |
0 |
0 |
|
| 335 |
|
| } |
| 336 |
32 |
| items = otel_h_av(aTHX_ s, ikey); |
| 337 |
32 |
▶ | if (!items) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!items) continue; |
0 |
32 |
32 |
|
| 338 |
32 |
| in = av_len(items) + 1; |
| 339 |
64 |
▶ | for (ii = 0; ii < in; ii++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ii = 0; ii < in; ii++) { |
32 |
32 |
64 |
|
| 340 |
32 |
| SV **ip = av_fetch(items, ii, 0); |
| 341 |
32 |
▶ | HV *item = (ip && *ip) ? otel_hv_of(aTHX_ *ip) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *item = (ip && *ip) ? otel_hv_of(aTHX_ *ip) : NULL; |
32 |
0 |
32 |
| HV *item = (ip && *ip) ? otel_hv_of(aTHX_ *ip) : NULL; |
32 |
0 |
32 |
|
| 342 |
|
| static const char *nested[3] = { "events", "links", |
| 343 |
|
| "data_points" }; |
| 344 |
|
| int ni; |
| 345 |
|
| SV **a; |
| 346 |
32 |
▶ | if (!item) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!item) continue; |
0 |
32 |
32 |
|
| 347 |
32 |
| a = hv_fetchs(item, "attributes", 0); |
| 348 |
32 |
▶ | if (a && *a) otel_schema_apply_map(aTHX_ *a, map, forward); |
Branch: 2 branches
| Branch | True | False | Total |
| if (a && *a) otel_schema_apply_map(aTHX_ *a, map, forward); |
30 |
2 |
32 |
| if (a && *a) otel_schema_apply_map(aTHX_ *a, map, forward); |
30 |
0 |
30 |
|
| 349 |
128 |
▶ | for (ni = 0; ni < 3; ni++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ni = 0; ni < 3; ni++) { |
96 |
32 |
128 |
|
| 350 |
96 |
| AV *sub = otel_h_av(aTHX_ item, nested[ni]); |
| 351 |
|
| SSize_t bi, bn; |
| 352 |
96 |
▶ | if (!sub) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!sub) continue; |
92 |
4 |
96 |
|
| 353 |
4 |
| bn = av_len(sub) + 1; |
| 354 |
8 |
▶ | for (bi = 0; bi < bn; bi++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (bi = 0; bi < bn; bi++) { |
4 |
4 |
8 |
|
| 355 |
4 |
| SV **bp = av_fetch(sub, bi, 0); |
| 356 |
4 |
▶ | HV *b = (bp && *bp) ? otel_hv_of(aTHX_ *bp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *b = (bp && *bp) ? otel_hv_of(aTHX_ *bp) : NULL; |
4 |
0 |
4 |
| HV *b = (bp && *bp) ? otel_hv_of(aTHX_ *bp) : NULL; |
4 |
0 |
4 |
|
| 357 |
|
| SV **ba; |
| 358 |
4 |
▶ | if (!b) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!b) continue; |
0 |
4 |
4 |
|
| 359 |
4 |
| ba = hv_fetchs(b, "attributes", 0); |
| 360 |
4 |
▶ | if (ba && *ba) |
Branch: 2 branches
| Branch | True | False | Total |
| if (ba && *ba) |
4 |
0 |
4 |
| if (ba && *ba) |
4 |
0 |
4 |
|
| 361 |
4 |
| otel_schema_apply_map(aTHX_ *ba, map, forward); |
| 362 |
|
| } |
| 363 |
|
| } |
| 364 |
|
| } |
| 365 |
|
| } |
| 366 |
|
| } |
| 367 |
|
| } |
| 368 |
|
| |
| 369 |
|
| /* Every metric in a payload, for the name rename. */ |
| 370 |
2 |
| static void otel_schema_each_metric(pTHX_ HV *payload, HV *map, int forward) { |
| 371 |
2 |
| AV *rs = otel_h_av(aTHX_ payload, "resource_metrics"); |
| 372 |
|
| SSize_t ri, rn; |
| 373 |
2 |
▶ | if (!rs) return; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!rs) return; |
0 |
2 |
2 |
|
| 374 |
2 |
| rn = av_len(rs) + 1; |
| 375 |
4 |
▶ | for (ri = 0; ri < rn; ri++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (ri = 0; ri < rn; ri++) { |
2 |
2 |
4 |
|
| 376 |
2 |
| SV **rp = av_fetch(rs, ri, 0); |
| 377 |
2 |
▶ | HV *r = (rp && *rp) ? otel_hv_of(aTHX_ *rp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *r = (rp && *rp) ? otel_hv_of(aTHX_ *rp) : NULL; |
2 |
0 |
2 |
| HV *r = (rp && *rp) ? otel_hv_of(aTHX_ *rp) : NULL; |
2 |
0 |
2 |
|
| 378 |
|
| AV *ss; |
| 379 |
|
| SSize_t si, sn; |
| 380 |
2 |
▶ | if (!r) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!r) continue; |
0 |
2 |
2 |
|
| 381 |
2 |
| ss = otel_h_av(aTHX_ r, "scope_metrics"); |
| 382 |
2 |
▶ | if (!ss) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ss) continue; |
0 |
2 |
2 |
|
| 383 |
2 |
| sn = av_len(ss) + 1; |
| 384 |
4 |
▶ | for (si = 0; si < sn; si++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (si = 0; si < sn; si++) { |
2 |
2 |
4 |
|
| 385 |
2 |
| SV **sp = av_fetch(ss, si, 0); |
| 386 |
2 |
▶ | HV *s = (sp && *sp) ? otel_hv_of(aTHX_ *sp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *s = (sp && *sp) ? otel_hv_of(aTHX_ *sp) : NULL; |
2 |
0 |
2 |
| HV *s = (sp && *sp) ? otel_hv_of(aTHX_ *sp) : NULL; |
2 |
0 |
2 |
|
| 387 |
|
| AV *ms; |
| 388 |
|
| SSize_t mi, mn; |
| 389 |
2 |
▶ | if (!s) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!s) continue; |
0 |
2 |
2 |
|
| 390 |
2 |
| ms = otel_h_av(aTHX_ s, "metrics"); |
| 391 |
2 |
▶ | if (!ms) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!ms) continue; |
0 |
2 |
2 |
|
| 392 |
2 |
| mn = av_len(ms) + 1; |
| 393 |
4 |
▶ | for (mi = 0; mi < mn; mi++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (mi = 0; mi < mn; mi++) { |
2 |
2 |
4 |
|
| 394 |
2 |
| SV **mp = av_fetch(ms, mi, 0); |
| 395 |
2 |
▶ | HV *m = (mp && *mp) ? otel_hv_of(aTHX_ *mp) : NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| HV *m = (mp && *mp) ? otel_hv_of(aTHX_ *mp) : NULL; |
2 |
0 |
2 |
| HV *m = (mp && *mp) ? otel_hv_of(aTHX_ *mp) : NULL; |
2 |
0 |
2 |
|
| 396 |
|
| SV *name, *to; |
| 397 |
2 |
▶ | if (!m) continue; |
Branch: 1 branch
| Branch | True | False | Total |
| if (!m) continue; |
0 |
2 |
2 |
|
| 398 |
2 |
| name = otel_h(aTHX_ m, "name"); |
| 399 |
2 |
| to = otel_schema_metric_name(aTHX_ map, name, forward); |
| 400 |
2 |
▶ | if (to) (void)hv_stores(m, "name", newSVsv(to)); |
Branch: 1 branch
| Branch | True | False | Total |
| if (to) (void)hv_stores(m, "name", newSVsv(to)); |
2 |
0 |
2 |
|
| 401 |
|
| } |
| 402 |
|
| } |
| 403 |
|
| } |
| 404 |
|
| } |
| 405 |
|
| |
| 406 |
|
| /* ---- the search path, and the file on it --------------------------------- * |
| 407 |
|
| * |
| 408 |
|
| * Shared by file_for, for_url and load, so all three answer the same question |
| 409 |
|
| * the same way: a caller's dir, then OTEL_SCHEMA_DIR, then the directory this |
| 410 |
|
| * module was loaded from. Mortal AV. */ |
| 411 |
7 |
| static AV *otel_schema_dirs(pTHX_ SV **args, int nargs) { |
| 412 |
7 |
| AV *out = (AV *)sv_2mortal((SV *)newAV()); |
| 413 |
|
| int a; |
| 414 |
9 |
▶ | for (a = 0; a + 1 < nargs; a += 2) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (a = 0; a + 1 < nargs; a += 2) { |
2 |
7 |
9 |
|
| 415 |
|
| STRLEN kl; |
| 416 |
2 |
| const char *k = SvPV_const(args[a], kl); |
| 417 |
2 |
▶ | if (kl == 3 && memEQ(k, "dir", 3) && SvOK(args[a + 1])) |
Branch: 3 branches
| Branch | True | False | Total |
| if (kl == 3 && memEQ(k, "dir", 3) && SvOK(args[a + 1])) |
1 |
1 |
2 |
| if (kl == 3 && memEQ(k, "dir", 3) && SvOK(args[a + 1])) |
1 |
0 |
1 |
| if (kl == 3 && memEQ(k, "dir", 3) && SvOK(args[a + 1])) |
1 |
0 |
1 |
|
| 418 |
1 |
| av_push(out, newSVsv(args[a + 1])); |
| 419 |
|
| } |
| 420 |
|
| { |
| 421 |
7 |
| SV **e = hv_fetchs(GvHV(PL_envgv), "OTEL_SCHEMA_DIR", 0); |
| 422 |
7 |
▶ | if (e && *e && SvOK(*e) && SvCUR(*e)) av_push(out, newSVsv(*e)); |
Branch: 4 branches
| Branch | True | False | Total |
| if (e && *e && SvOK(*e) && SvCUR(*e)) av_push(out, newSVsv(*e)); |
1 |
6 |
7 |
| if (e && *e && SvOK(*e) && SvCUR(*e)) av_push(out, newSVsv(*e)); |
1 |
0 |
1 |
| if (e && *e && SvOK(*e) && SvCUR(*e)) av_push(out, newSVsv(*e)); |
1 |
0 |
1 |
| if (e && *e && SvOK(*e) && SvCUR(*e)) av_push(out, newSVsv(*e)); |
1 |
0 |
1 |
|
| 423 |
|
| } |
| 424 |
|
| { /* through %INC rather than guessed, so it is right under blib, under |
| 425 |
|
| * a local::lib, and installed */ |
| 426 |
7 |
| HV *inc = GvHV(PL_incgv); |
| 427 |
7 |
▶ | SV **e = inc ? hv_fetchs(inc, "Punk/OpenTelemetry/Schema.pm", 0) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| SV **e = inc ? hv_fetchs(inc, "Punk/OpenTelemetry/Schema.pm", 0) : NULL; |
7 |
0 |
7 |
|
| 428 |
7 |
▶ | if (e && *e && SvOK(*e)) { |
Branch: 3 branches
| Branch | True | False | Total |
| if (e && *e && SvOK(*e)) { |
7 |
0 |
7 |
| if (e && *e && SvOK(*e)) { |
7 |
0 |
7 |
| if (e && *e && SvOK(*e)) { |
7 |
0 |
7 |
|
| 429 |
|
| STRLEN l; |
| 430 |
7 |
| const char *p = SvPV_const(*e, l); |
| 431 |
7 |
▶ | if (l > 3 && memEQ(p + l - 3, ".pm", 3)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (l > 3 && memEQ(p + l - 3, ".pm", 3)) |
7 |
0 |
7 |
| if (l > 3 && memEQ(p + l - 3, ".pm", 3)) |
7 |
0 |
7 |
|
| 432 |
7 |
| av_push(out, newSVpvn(p, l - 3)); |
| 433 |
|
| } |
| 434 |
|
| } |
| 435 |
7 |
| return out; |
| 436 |
|
| } |
| 437 |
|
| |
| 438 |
|
| /* The file for a version on that path, or NULL. Mortal SV. */ |
| 439 |
5 |
| static SV *otel_schema_file_for(pTHX_ SV *version, SV **args, int nargs) { |
| 440 |
|
| AV *dirs; |
| 441 |
|
| SSize_t i, n; |
| 442 |
|
| STRLEN vl, j; |
| 443 |
|
| const char *vp; |
| 444 |
5 |
▶ | if (!version || !SvOK(version)) return NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!version || !SvOK(version)) return NULL; |
5 |
0 |
5 |
| if (!version || !SvOK(version)) return NULL; |
0 |
5 |
5 |
|
| 445 |
5 |
| vp = SvPV_const(version, vl); |
| 446 |
5 |
▶ | if (!vl || !isDIGIT(vp[0])) return NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!vl || !isDIGIT(vp[0])) return NULL; |
5 |
0 |
5 |
| if (!vl || !isDIGIT(vp[0])) return NULL; |
0 |
5 |
5 |
|
| 447 |
32 |
▶ | for (j = 0; j < vl; j++) |
Branch: 1 branch
| Branch | True | False | Total |
| for (j = 0; j < vl; j++) |
27 |
5 |
32 |
|
| 448 |
27 |
▶ | if (!isDIGIT(vp[j]) && vp[j] != '.') return NULL; |
Branch: 2 branches
| Branch | True | False | Total |
| if (!isDIGIT(vp[j]) && vp[j] != '.') return NULL; |
10 |
17 |
27 |
| if (!isDIGIT(vp[j]) && vp[j] != '.') return NULL; |
0 |
10 |
10 |
|
| 449 |
5 |
| dirs = otel_schema_dirs(aTHX_ args, nargs); |
| 450 |
5 |
| n = av_len(dirs) + 1; |
| 451 |
6 |
▶ | for (i = 0; i < n; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for (i = 0; i < n; i++) { |
5 |
1 |
6 |
|
| 452 |
5 |
| SV **d = av_fetch(dirs, i, 0); |
| 453 |
|
| SV *path; |
| 454 |
|
| Stat_t st; |
| 455 |
5 |
▶ | if (!(d && *d && SvOK(*d))) continue; |
Branch: 3 branches
| Branch | True | False | Total |
| if (!(d && *d && SvOK(*d))) continue; |
5 |
0 |
5 |
| if (!(d && *d && SvOK(*d))) continue; |
5 |
0 |
5 |
| if (!(d && *d && SvOK(*d))) continue; |
0 |
5 |
5 |
|
| 456 |
5 |
| path = sv_2mortal(newSVsv(*d)); |
| 457 |
5 |
| sv_catpvs(path, "/"); |
| 458 |
5 |
| sv_catsv(path, version); |
| 459 |
5 |
| sv_catpvs(path, ".yaml"); |
| 460 |
5 |
▶ | if (PerlLIO_stat(SvPV_nolen(path), &st) == 0 && S_ISREG(st.st_mode)) |
Branch: 2 branches
| Branch | True | False | Total |
| if (PerlLIO_stat(SvPV_nolen(path), &st) == 0 && S_ISREG(st.st_mode)) |
4 |
1 |
5 |
| if (PerlLIO_stat(SvPV_nolen(path), &st) == 0 && S_ISREG(st.st_mode)) |
4 |
0 |
4 |
|
| 461 |
4 |
| return path; |
| 462 |
|
| } |
| 463 |
1 |
| return NULL; |
| 464 |
|
| } |
| 465 |
|
| |
| 466 |
|
| #endif /* OTEL_SCHEMA_H */ |