Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix MonotonicCounterUint send bug #107

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions spectator/monotonic_counter_uint_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ TEST(MonotonicCounterUint, Set) {

c.Set(42);
c2.Set(2);
c.Set(43);
std::vector<std::string> expected = {"U:ctr:42", "U:ctr2,key=val:2", "U:ctr:43"};
c.Set(-1);
std::vector<std::string> expected = {"U:ctr:42", "U:ctr2,key=val:2", "U:ctr:18446744073709551615"};
EXPECT_EQ(publisher.SentMessages(), expected);
}
} // namespace
10 changes: 9 additions & 1 deletion spectator/stateless_meters.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@ class StatelessMeter {
publisher_->send(msg);
}

void send_uint(uint64_t value) {
if (value_prefix_.empty()) {
value_prefix_ = detail::create_prefix(*id_, Type());
}
auto msg = absl::StrFormat("%s%u", value_prefix_, value);
publisher_->send(msg);
}

private:
IdPtr id_;
Pub* publisher_;
Expand Down Expand Up @@ -134,7 +142,7 @@ class MonotonicCounterUint : public StatelessMeter<Pub> {
public:
MonotonicCounterUint(IdPtr id, Pub* publisher)
: StatelessMeter<Pub>(std::move(id), publisher) {}
void Set(uint64_t amount) noexcept { this->send(amount); }
void Set(uint64_t amount) noexcept { this->send_uint(amount); }

protected:
std::string_view Type() override { return "U"; }
Expand Down