Skip to content

Commit

Permalink
Add metrics on segment merges
Browse files Browse the repository at this point in the history
  • Loading branch information
lalinsky committed Nov 30, 2024
1 parent 7fc9907 commit 5d8ea32
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions src/Index.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const TieredMergePolicy = @import("segment_merge_policy.zig").TieredMergePolicy;

const filefmt = @import("filefmt.zig");

const metrics = @import("metrics.zig");
const Self = @This();

const Options = struct {
Expand Down Expand Up @@ -273,6 +274,7 @@ fn maybeMergeFileSegments(self: *Self) !bool {

self.file_segments.commitUpdate(&upd);
// log.debug("committed file segments merge", .{});
metrics.fileSegmentMerge();

return true;
}
Expand Down Expand Up @@ -316,6 +318,7 @@ fn maybeMergeMemorySegments(self: *Self) !bool {

self.memory_segments.commitUpdate(&upd);
// log.debug("committed memory segments merge", .{});
metrics.memorySegmentMerge();

self.maybeScheduleCheckpoint();

Expand Down
20 changes: 16 additions & 4 deletions src/metrics.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ const m = @import("metrics");
var metrics = m.initializeNoop(Metrics);

const Metrics = struct {
searches: m.Counter(u32),
updates: m.Counter(u32),
searches: m.Counter(u64),
updates: m.Counter(u64),
memory_segment_merges: m.Counter(u64),
file_segment_merges: m.Counter(u64),
};

pub fn search() void {
Expand All @@ -15,10 +17,20 @@ pub fn update(count: usize) void {
metrics.updates.incrBy(@intCast(count));
}

pub fn memorySegmentMerge() void {
metrics.memory_segment_merges.incr();
}

pub fn fileSegmentMerge() void {
metrics.file_segment_merges.incr();
}

pub fn initializeMetrics(comptime opts: m.RegistryOpts) !void {
metrics = .{
.searches = m.Counter(u32).init("searches_total", .{}, opts),
.updates = m.Counter(u32).init("updates_total", .{}, opts),
.searches = m.Counter(u64).init("searches_total", .{}, opts),
.updates = m.Counter(u64).init("updates_total", .{}, opts),
.memory_segment_merges = m.Counter(u64).init("memory_segment_merges_total", .{}, opts),
.file_segment_merges = m.Counter(u64).init("file_segment_merges_total", .{}, opts),
};
}

Expand Down

0 comments on commit 5d8ea32

Please sign in to comment.