Skip to content

Commit 8a6643e

Browse files
committed
model: Log topic_id as base64
Signed-off-by: Ben Pope <[email protected]>
1 parent 7128be1 commit 8a6643e

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/v/model/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ redpanda_cc_library(
7171
"//src/v/serde:vector",
7272
"//src/v/ssx:sformat",
7373
"//src/v/strings:string_switch",
74+
"//src/v/utils:base64",
7475
"//src/v/utils:move_canary",
7576
"//src/v/utils:named_type",
7677
"//src/v/utils:to_string",

src/v/model/fundamental.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ std::ostream& operator<<(std::ostream& os, const fips_mode_flag& f);
536536
std::istream& operator>>(std::istream& is, fips_mode_flag& f);
537537

538538
using topic_id = named_type<uuid_t, struct topic_id_type>;
539+
std::ostream& operator<<(std::ostream&, const topic_id&);
539540

540541
inline topic_id create_topic_id() { return topic_id{uuid_t::create()}; }
541542

@@ -629,3 +630,10 @@ struct hash<model::ntp> {
629630
};
630631

631632
} // namespace std
633+
634+
template<>
635+
struct fmt::formatter<model::topic_id> final
636+
: fmt::formatter<std::string_view> {
637+
auto format(const model::topic_id& s, fmt::format_context& ctx) const
638+
-> decltype(ctx.out());
639+
};

src/v/model/model.cc

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "absl/container/flat_hash_map.h"
1111
#include "absl/strings/numbers.h"
1212
#include "absl/strings/str_split.h"
13+
#include "bytes/bytes.h"
1314
#include "bytes/iobuf.h"
1415
#include "bytes/iobuf_parser.h"
1516
#include "model/compression.h"
@@ -24,6 +25,7 @@
2425
#include "serde/rw/sstring.h"
2526
#include "serde/serde_exception.h"
2627
#include "strings/string_switch.h"
28+
#include "utils/base64.h"
2729
#include "utils/to_string.h"
2830

2931
#include <seastar/core/print.hh>
@@ -783,6 +785,11 @@ std::istream& operator>>(std::istream& is, fips_mode_flag& f) {
783785
return is;
784786
}
785787

788+
std::ostream& operator<<(std::ostream& os, const topic_id& id) {
789+
fmt::print(os, "{}", id);
790+
return os;
791+
}
792+
786793
topic_id_partition topic_id_partition::from(std::string_view s) {
787794
std::vector<ss::sstring> ss = absl::StrSplit(s, "/");
788795
if (ss.size() != 2) {
@@ -836,3 +843,10 @@ std::istream& operator>>(std::istream& i, kafka_batch_validation_mode& mode) {
836843
}
837844

838845
} // namespace model
846+
847+
auto fmt::formatter<model::topic_id>::format(
848+
const model::topic_id& s, fmt::format_context& ctx) const
849+
-> decltype(ctx.out()) {
850+
bytes_view bv(s().uuid().begin(), s().uuid().size());
851+
return fmt::format_to(ctx.out(), "{}", bytes_to_base64(bv));
852+
}

0 commit comments

Comments
 (0)