Finish metrics design, I think

This commit is contained in:
2025-08-29 11:51:40 -04:00
parent e3a2ddbbfb
commit fac0d20ae1
2 changed files with 5 additions and 9 deletions

View File

@@ -76,15 +76,7 @@ struct LabelsKey {
namespace std { namespace std {
template <> struct hash<metric::LabelsKey> { template <> struct hash<metric::LabelsKey> {
std::size_t operator()(const metric::LabelsKey &k) const { std::size_t operator()(const metric::LabelsKey &k) const {
thread_local std::vector<size_t> parts; return std::hash<decltype(k.labels)>{}(k.labels);
parts.clear();
for (const auto &p : k.labels) {
parts.push_back(std::hash<std::string>{}(p.first));
parts.push_back(std::hash<std::string>{}(p.second));
}
return std::hash<std::string>{}(
std::string{reinterpret_cast<const char *>(parts.data()),
parts.size() * sizeof(size_t)});
} }
}; };
} // namespace std } // namespace std

View File

@@ -142,6 +142,10 @@ Family<Histogram> create_histogram(std::string name, std::string help,
std::initializer_list<double> buckets); std::initializer_list<double> buckets);
// Render all metrics in Prometheus text format // Render all metrics in Prometheus text format
// Returns chunks of Prometheus exposition format (includes # HELP and # TYPE
// lines) Each string_view may contain multiple lines separated by '\n' String
// views are NOT null-terminated - use .size() for length All string data
// allocated in provided arena for zero-copy efficiency
// TODO: Implement Prometheus text exposition format // TODO: Implement Prometheus text exposition format
// THREAD SAFETY: Serialized by global mutex - callbacks need not be thread-safe // THREAD SAFETY: Serialized by global mutex - callbacks need not be thread-safe
std::span<std::string_view> render(ArenaAllocator &arena); std::span<std::string_view> render(ArenaAllocator &arena);