[k2] add metrics builder and k2_write_metric API#1639
Open
denisichh wants to merge 6 commits into
Open
Conversation
apolyakov
requested changes
Jun 22, 2026
| * <COUNT_MASK><f64> - count value | ||
| * <INC_MASK> - counter increment (no payload) | ||
| */ | ||
| enum MetricValueMask : uint32_t { VALUE_MASK = 0, VALUES_ARRAY_MASK = 1, COUNT_MASK = 2, INC_MASK = 3 }; |
Contributor
There was a problem hiding this comment.
- What does
0mean here? - Maybe rename to
MetricKind?
|
|
||
| /* | ||
| * Serialized metric format: | ||
| * <timestamp_u32><value_format><msg_size><metric_name_len><metric_name><tag1_name_len><tag1_name><tag1_value_len><tag1_value>... |
Contributor
There was a problem hiding this comment.
What is msg_size? Let's add a more detailed description
| * @param `buf_len` The length of the serialized metric data in bytes. | ||
| * @param `ms` The target monitoring system. | ||
| */ | ||
| void k2_write_metric(const uint8_t* buf, size_t buf_len, enum MonitoringSystem ms); |
Contributor
There was a problem hiding this comment.
- The interface looks like an error is possible, but you never return it
- Do we need
bufto beuint8_t*? Why isvoid*not enough?
| return {}; | ||
| } | ||
|
|
||
| inline void write_metric(const kphp::stl::vector<uint8_t, kphp::memory::script_allocator>& serialized_metric, k2::MonitoringSystem ms) noexcept { |
Contributor
There was a problem hiding this comment.
I think we don't need vector here. std::span is enough
apolyakov
reviewed
Jun 22, 2026
|
|
||
| struct MetricBuilder final : vk::movable_only { | ||
| private: | ||
| using bytes_vector = kphp::stl::vector<uint8_t, kphp::memory::script_allocator>; |
Contributor
There was a problem hiding this comment.
std::byte instead of uint8_t?
| #include "runtime-common/core/std/containers.h" | ||
| #include "runtime-light/k2-platform/k2-api.h" | ||
|
|
||
| struct MetricBuilder final : vk::movable_only { |
Contributor
There was a problem hiding this comment.
Let's put it in kphp::diagnostics namespace as kphp::diagnostics::metric_builder
|
|
||
| struct MetricBuilder final : vk::movable_only { | ||
| private: | ||
| using bytes_vector = kphp::stl::vector<uint8_t, kphp::memory::script_allocator>; |
Contributor
There was a problem hiding this comment.
It looks a bit weird that you use private type in public API of MetricBuilder
| private: | ||
| using bytes_vector = kphp::stl::vector<uint8_t, kphp::memory::script_allocator>; | ||
|
|
||
| std::string metric_name; |
Contributor
There was a problem hiding this comment.
We can't use std::string as it uses malloc internally. Let's replace with kphp::stl::string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.