Skip to content

Replace metrics by seshat counters #30

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

Merged
merged 4 commits into from
Jul 28, 2021
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
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ endef

LOCAL_DEPS = sasl crypto
dep_gen_batch_server = hex 0.8.6
DEPS = gen_batch_server
dep_seshat = git https://github.com/rabbitmq/seshat.git main
DEPS = gen_batch_server seshat

# TEST_DEPS=eunit_formatters looking_glass
TEST_DEPS=eunit_formatters
Expand Down
40 changes: 9 additions & 31 deletions src/osiris_counters.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,47 +26,25 @@

-spec init() -> ok.
init() ->
_ = ets:new(?MODULE, [set, named_table, public]),
ok.
seshat_counters:new_group(osiris).

-spec new(name(), [atom()]) -> counters:counters_ref().
new(Name, Fields) when is_list(Fields) ->
Size = length(Fields),
CRef = counters:new(Size, []),
ok = register_counter(Name, CRef, Fields),
CRef.
-spec new(name(), [{Name :: atom(), Position :: non_neg_integer(),
Type :: atom(), Description :: term()}]) ->
counters:counters_ref().
new(Name, Fields) ->
seshat_counters:new(osiris, Name, Fields).

-spec fetch(name()) -> undefined | counters:counters_ref().
fetch(Name) ->
case ets:lookup(?MODULE, Name) of
[{Name, Ref, _}] ->
Ref;
_ ->
undefined
end.
seshat_counters:fetch(osiris, Name).

-spec delete(term()) -> ok.
delete(Name) ->
true = ets:delete(?MODULE, Name),
ok.
seshat_counters:delete(osiris, Name).

-spec overview() -> #{name() => #{atom() => non_neg_integer()}}.
overview() ->
ets:foldl(fun({Name, Ref, Fields}, Acc) ->
Size = length(Fields),
Values = [counters:get(Ref, I) || I <- lists:seq(1, Size)],
Counters =
maps:from_list(
lists:zip(Fields, Values)),
Acc#{Name => Counters}
end,
#{}, ?MODULE).

%% internal

register_counter(Name, Ref, Size) ->
true = ets:insert(?MODULE, {Name, Ref, Size}),
ok.
seshat_counters:overview(osiris).

-ifdef(TEST).

Expand Down
21 changes: 9 additions & 12 deletions src/osiris_log.erl
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,19 @@
% maximum number of chunks per segment
-define(DEFAULT_MAX_SEGMENT_SIZE_C, 256_000).
-define(INDEX_RECORD_SIZE_B, 29).
-define(COUNTER_FIELDS,
[
%% the last offset (not chunk id) in the log (writers)
%% the last offset read (readers)
offset,
%% not updated for readers
first_offset,
%% number of chunks read or written
%% incremented even if a reader only reads the header
chunks,
%% number of segments
segments]).
-define(C_OFFSET, 1).
-define(C_FIRST_OFFSET, 2).
-define(C_CHUNKS, 3).
-define(C_SEGMENTS, 4).
-define(COUNTER_FIELDS,
[
{offset, ?C_OFFSET, counter, "The last offset (not chunk id) in the log for writers. The last offset read for readers"
},
{first_offset, ?C_FIRST_OFFSET, counter, "First offset, not updated for readers"},
{chunks, ?C_CHUNKS, counter, "Number of chunks read or written, incremented even if a reader only reads the header"},
{segments, ?C_SEGMENTS, counter, "Number of segments"}
]
).

%% Specification of the Log format.
%%
Expand Down
7 changes: 6 additions & 1 deletion src/osiris_replica.erl
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,16 @@

-export_type([state/0]).

-define(ADD_COUNTER_FIELDS, [committed_offset, forced_gcs, packets, readers]).
-define(C_COMMITTED_OFFSET, ?C_NUM_LOG_FIELDS + 1).
-define(C_FORCED_GCS, ?C_NUM_LOG_FIELDS + 2).
-define(C_PACKETS, ?C_NUM_LOG_FIELDS + 3).
-define(C_READERS, ?C_NUM_LOG_FIELDS + 4).
-define(ADD_COUNTER_FIELDS,
[{committed_offset, ?C_COMMITTED_OFFSET, counter, "Last committed offset"},
{forced_gcs, ?C_FORCED_GCS, counter, "Number of garbage collection runs"},
{packets, ?C_PACKETS, counter, "Number of packets"},
{readers, ?C_READERS, counter, "Number of readers"}]).

-define(DEFAULT_ONE_TIME_TOKEN_TIMEOUT, 30000).
-define(TOKEN_SIZE, 32).
-define(DEF_REC_BUF, 408300 * 5).
Expand Down
6 changes: 5 additions & 1 deletion src/osiris_replica_reader.erl
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,12 @@
committed_offset = -1 :: -1 | osiris:offset(),
offset_listener :: undefined | osiris:offset()}).

-define(COUNTER_FIELDS, [offset_listeners]).
-define(C_OFFSET_LISTENERS, ?C_NUM_LOG_FIELDS + 1).
-define(COUNTER_FIELDS,
[
{offset_listeners, ?C_OFFSET_LISTENERS, counter, "Number of offset listeners"}
]
).

-spec maybe_connect(list(), integer(), list()) ->
{ok, term(), term()} | {error, term()}.
Expand Down
7 changes: 6 additions & 1 deletion src/osiris_writer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@
stop/1,
delete/1]).

-define(ADD_COUNTER_FIELDS, [committed_offset, readers]).
-define(C_COMMITTED_OFFSET, ?C_NUM_LOG_FIELDS + 1).
-define(C_READERS, ?C_NUM_LOG_FIELDS + 2).
-define(ADD_COUNTER_FIELDS,
[
{committed_offset, ?C_COMMITTED_OFFSET, counter, "Last committed offset"},
{readers, ?C_READERS, counter, "Number of readers"}
]
).

%% primary osiris process
%% batch writes incoming data
Expand Down