test: improve t_size

This commit is contained in:
Simon Cruanes 2025-10-30 22:15:21 -04:00
parent 6e8877f177
commit 4066cad663
No known key found for this signature in database
GPG key ID: EBFFF6F283F3A2B4
2 changed files with 160 additions and 4 deletions

View file

@ -1 +1,147 @@
metrics size: 492B
metrics size: 243B
res1: { resource =
Some(
{ attributes =
[{ key = "service.name";
value = Some(String_value("unknown_service"));
}
];
dropped_attributes_count = 0;
});
scope_metrics =
[{ scope =
Some(
{ name = "ocaml-otel";
version = "%%VERSION_NUM%%";
attributes = [];
dropped_attributes_count = 0;
});
metrics =
[{ name = "sum.foo";
description = "";
unit_ = "";
data =
Sum(
{ data_points =
[{ attributes = [];
start_time_unix_nano = 42;
time_unix_nano = 45;
value = As_int(10);
exemplars = [];
flags = 0;
};
{ attributes = [];
start_time_unix_nano = 52;
time_unix_nano = 55;
value = As_int(20);
exemplars = [];
flags = 0;
}
];
aggregation_temporality =
Aggregation_temporality_cumulative;
is_monotonic = false;
});
};
{ name = "gauge.bar";
description = "";
unit_ = "";
data =
Gauge(
{ data_points =
[{ attributes = [];
start_time_unix_nano = 42;
time_unix_nano = 45;
value = As_double(10.);
exemplars = [];
flags = 0;
};
{ attributes = [];
start_time_unix_nano = 52;
time_unix_nano = 55;
value = As_double(20.);
exemplars = [];
flags = 0;
}
];
});
}
];
schema_url = "";
}
];
schema_url = "";
}
res1: { resource =
Some(
{ attributes =
[{ key = "service.name";
value = Some(String_value("unknown_service"));
}
];
dropped_attributes_count = 0;
});
scope_metrics =
[{ scope =
Some(
{ name = "ocaml-otel";
version = "%%VERSION_NUM%%";
attributes = [];
dropped_attributes_count = 0;
});
metrics =
[{ name = "sum.foo";
description = "";
unit_ = "";
data =
Sum(
{ data_points =
[{ attributes = [];
start_time_unix_nano = 42;
time_unix_nano = 45;
value = As_int(10);
exemplars = [];
flags = 0;
};
{ attributes = [];
start_time_unix_nano = 52;
time_unix_nano = 55;
value = As_int(20);
exemplars = [];
flags = 0;
}
];
aggregation_temporality =
Aggregation_temporality_cumulative;
is_monotonic = false;
});
};
{ name = "gauge.bar";
description = "";
unit_ = "";
data =
Gauge(
{ data_points =
[{ attributes = [];
start_time_unix_nano = 42;
time_unix_nano = 45;
value = As_double(10.);
exemplars = [];
flags = 0;
};
{ attributes = [];
start_time_unix_nano = 52;
time_unix_nano = 55;
value = As_double(20.);
exemplars = [];
flags = 0;
}
];
});
}
];
schema_url = "";
}
];
schema_url = "";
}

View file

@ -2,7 +2,7 @@
open Opentelemetry
let m =
let res1 =
Metrics.make_resource_metrics
[
Metrics.sum ~name:"sum.foo"
@ -17,6 +17,16 @@ let m =
];
]
let str =
let enc = Pbrt.Encoder.create () in
Proto.Metrics.encode_pb_resource_metrics res1 enc;
Pbrt.Encoder.to_string enc
let () = Printf.printf "metrics size: %dB\n" (String.length str)
let () =
let str = Opentelemetry_client.Signal.Encode.metrics [ m; m ] in
Printf.printf "metrics size: %dB\n" (String.length str)
let dec = Pbrt.Decoder.of_string str in
let res2 = Proto.Metrics.decode_pb_resource_metrics dec in
Format.printf "res1: %a@." Proto.Metrics.pp_resource_metrics res1;
Format.printf "res1: %a@." Proto.Metrics.pp_resource_metrics res2;
()