Skip to content

Commit

Permalink
Merge branch 'main' into use-seshat-from-bcr
Browse files Browse the repository at this point in the history
  • Loading branch information
HoloRin authored Sep 13, 2023
2 parents 209bad2 + ed46179 commit ae2a716
Show file tree
Hide file tree
Showing 21 changed files with 529 additions and 133 deletions.
3 changes: 3 additions & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
build --enable_bzlmod

build --registry=https://bcr.bazel.build/
build --registry=https://raw.githubusercontent.com/rabbitmq/bazel-central-registry/erlang-packages/

build --incompatible_strict_action_env
build --local_test_jobs=1

Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/publish-rabbitmq-bcr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Add to rabbitmq/bazel-central-registry@erlang-packages
on:
release:
types: [published]
workflow_dispatch:
jobs:
add-module:
runs-on: ubuntu-latest
steps:
- name: CHECKOUT
uses: actions/checkout@v3
with:
path: ra
- name: CHECKOUT rabbitmq/bazel-central-registry@erlang-packages
uses: actions/checkout@v3
with:
repository: rabbitmq/bazel-central-registry
path: bazel-central-registry
ref: erlang-packages
- name: PUBLISH TO rabbitmq/bazel-central-registry@erlang-packages
working-directory: bazel-central-registry
env:
MODULE_NAME: rabbitmq_ra
REPO_NAME: ra
run: |
VERSION="${{ github.ref_name }}"
VERSION="${VERSION#v}"
MAJOR="${VERSION:0:1}"
echo "VERSION: ${VERSION}"
echo "MAJOR: ${MAJOR}"
cat << EOF > ${MODULE_NAME}.json
{
"build_file": null,
"build_targets": [
"@${MODULE_NAME}//:${MODULE_NAME}",
"@${MODULE_NAME}//:erlang_app"
],
"compatibility_level": "$((${MAJOR} - 1))",
"deps": [],
"module_dot_bazel": "${{ github.workspace }}/${REPO_NAME}/MODULE.bazel",
"name": "${MODULE_NAME}",
"patch_strip": 0,
"patches": [],
"presubmit_yml": "${{ github.workspace }}/${REPO_NAME}/.bcr/presubmit.yml",
"strip_prefix": "${REPO_NAME}-${VERSION}",
"test_module_build_targets": [],
"test_module_path": null,
"test_module_test_targets": [],
"url": "https://github.com/${{ github.repository }}/releases/download/v${VERSION}/${REPO_NAME}-${VERSION}.tar.gz",
"version": "${VERSION}"
}
EOF
jq '.' ${MODULE_NAME}.json
bazel run //tools:add_module -- \
--input=${MODULE_NAME}.json
git diff
- name: CREATE PULL REQUEST
uses: peter-evans/[email protected]
with:
token: ${{ secrets.REPO_SCOPED_TOKEN }}
path: bazel-central-registry
title: Add ${{ github.repository }}@${{ github.ref_name }}
body: >
Automated changes created by
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
using the [create-pull-request](https://github.com/peter-evans/create-pull-request)
GitHub action in the ${{ github.workflow }} workflow.
commit-message: |
Add ${{ github.repository }}@${{ github.ref_name }}
branch: add-${{ github.repository }}@${{ github.ref_name }}
delete-branch: true
9 changes: 3 additions & 6 deletions .github/workflows/rabbitmq-oci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,15 @@ jobs:
- name: Configure the ra override for this ra
working-directory: rabbitmq-server
run: |
sudo npm install --global --silent @bazel/buildozer
rules_erlang_version="$(cat MODULE.bazel | buildozer 'print version' -:rules_erlang)"
ra_repo="rules_erlang~$rules_erlang_version~erlang_package~ra"
cat << EOF >> user.bazelrc
build --override_repository $ra_repo=${{ github.workspace }}/ra
build --override_module rabbitmq_ra=${{ github.workspace }}/ra
EOF
- name: Configure otp for the OCI image
working-directory: rabbitmq-server
run: |
sudo npm install --global --silent @bazel/buildozer
buildozer 'set tars ["@otp_src_${{ matrix.otp_version_id }}//file"]' \
//packaging/docker-image:otp_source
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ jobs:
uses: actions/checkout@v3
with:
path: ra
- name: CONFIGURE OTP & ELIXIR
uses: erlef/[email protected]
with:
otp-version: 26
- name: ASSERT VERSIONS
id: versions
working-directory: ra
Expand Down Expand Up @@ -43,7 +47,6 @@ jobs:
uses: ncipollo/[email protected]
with:
allowUpdates: true
draft: true
artifactErrorsFailBuild: true
updateOnlyUnreleased: true
generateReleaseNotes: true
Expand Down
2 changes: 1 addition & 1 deletion MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module(
name = "rabbitmq_ra",
version = "2.6.3",
version = "2.7.0-pre.2",
)

bazel_dep(
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ ESCRIPT_EMU_ARGS = -noinput -setcookie ra_fifo_cli

dep_gen_batch_server = hex 0.8.8
dep_aten = hex 0.5.8
dep_seshat = hex 0.4.0
dep_seshat = hex 0.6.0
DEPS = aten gen_batch_server seshat

TEST_DEPS = proper meck eunit_formatters inet_tcp_proxy
Expand Down
2 changes: 1 addition & 1 deletion rebar.config
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{deps, [
{gen_batch_server, "0.8.8"},
{aten, "0.5.8"},
{seshat, "0.4.0"}
{seshat, "0.6.0"}

]}.

Expand Down
6 changes: 3 additions & 3 deletions rebar.lock
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{"1.2.0",
[{<<"aten">>,{pkg,<<"aten">>,<<"0.5.8">>},0},
{<<"gen_batch_server">>,{pkg,<<"gen_batch_server">>,<<"0.8.8">>},0},
{<<"seshat">>,{pkg,<<"seshat">>,<<"0.4.0">>},0}]}.
{<<"seshat">>,{pkg,<<"seshat">>,<<"0.6.0">>},0}]}.
[
{pkg_hash,[
{<<"aten">>, <<"B5C97F48517C4F37F26A519AA57A00A31FF1B8EA4324EC1CAE27F818ED5C0DB2">>},
{<<"gen_batch_server">>, <<"7840A1FA63EE1EFFC83E8A91D22664847A2BA1192D30EAFFFD914ACB51578068">>},
{<<"seshat">>, <<"1D5DC4294E36B8745245AB2649E24E39D7B6B1209D7A6484F2B8D706C35C9814">>}]},
{<<"seshat">>, <<"3172EB1D7A2A4F66108CD6933A4E465AFF80F84AA90ED83F047B92F636123CCD">>}]},
{pkg_hash_ext,[
{<<"aten">>, <<"64D40A8CF0DDFEA4E13AF00B7327F0925147F83612D0627D9506CBFFE90C13EF">>},
{<<"gen_batch_server">>, <<"C3E6A1A2A0FB62AEE631A98CFA0FD8903E9562422CBF72043953E2FB1D203017">>},
{<<"seshat">>, <<"2C3DEEC7FF86E0D0C05EDEBD3455C8363123C227BE292FFFFC1A05EEC08BFF63">>}]}
{<<"seshat">>, <<"7CEF700F92831DD7CAE6A6DD223CCC55AC88ECCE0631EE9AB0F2B5FB70E79B90">>}]}
].
2 changes: 1 addition & 1 deletion src/ra.app.src
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{application,ra,
[{description,"Raft library"},
{vsn,"2.6.3"},
{vsn,"2.7.0-pre.2"},
{licenses,["Apache-2.0","MPL-2.0"]},
{links,[{"github","https://github.com/rabbitmq/ra"}]},
{modules,[]},
Expand Down
40 changes: 39 additions & 1 deletion src/ra.erl
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
cast_aux_command/2,
register_external_log_reader/1,
member_overview/1,
member_overview/2
member_overview/2,
key_metrics/1
]).

%% xref should pick these up
Expand Down Expand Up @@ -1107,6 +1108,43 @@ member_overview(ServerId) ->
member_overview(ServerId, Timeout) ->
ra_server_proc:local_state_query(ServerId, overview, Timeout).

%% @doc Returns a map of key metrics about a Ra member
%%
%% The keys and values may vary depending on what state
%% the member is in. This function will never call into the
%% Ra process itself so is likely to return swiftly even
%% when the Ra process is busy (such as when it is recovering)
%%
%% @param ServerId the Ra server to obtain key metrics for
%% @end
key_metrics({Name, N} = ServerId) when N == node() ->
Fields = [last_applied,
commit_index,
snapshot_index,
last_written_index,
last_index,
commit_latency,
term],
Counters = case ra_counters:counters(ServerId, Fields) of
undefined ->
#{};
C -> C
end,
case whereis(Name) of
undefined ->
Counters#{state => noproc};
_ ->
case ets:lookup(ra_state, Name) of
[] ->
Counters#{state => unknown};
[{_, State}] ->
Counters#{state => State}
end
end;
key_metrics({_, N} = ServerId) ->
erpc:call(N, ?MODULE, ?FUNCTION_NAME, [ServerId]).


%% internal

-spec usr(UserCommand, ReplyMode) -> Command when
Expand Down
36 changes: 34 additions & 2 deletions src/ra.hrl
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@
-define(C_RA_SRV_TERM_AND_VOTED_FOR_UPDATES, ?C_RA_LOG_RESERVED + 18).
-define(C_RA_SRV_LOCAL_QUERIES, ?C_RA_LOG_RESERVED + 19).
-define(C_RA_SRV_INVALID_REPLY_MODE_COMMANDS, ?C_RA_LOG_RESERVED + 20).
-define(C_RA_SRV_RESERVED, ?C_RA_LOG_RESERVED + 21).


-define(RA_SRV_COUNTER_FIELDS,
Expand Down Expand Up @@ -312,7 +313,38 @@
{local_queries, ?C_RA_SRV_LOCAL_QUERIES, counter,
"Total number of local queries"},
{invalid_reply_mode_commands, ?C_RA_SRV_INVALID_REPLY_MODE_COMMANDS, counter,
"Total number of commands received with an invalid reply-mode"}
"Total number of commands received with an invalid reply-mode"},
{reserved_2, ?C_RA_SRV_RESERVED, counter, "Reserved counter"}
]).

-define(RA_COUNTER_FIELDS, ?RA_LOG_COUNTER_FIELDS ++ ?RA_SRV_COUNTER_FIELDS).
-define(C_RA_SVR_METRIC_LAST_APPLIED, ?C_RA_SRV_RESERVED + 1).
-define(C_RA_SVR_METRIC_COMMIT_INDEX, ?C_RA_SRV_RESERVED + 2).
-define(C_RA_SVR_METRIC_SNAPSHOT_INDEX, ?C_RA_SRV_RESERVED + 3).
-define(C_RA_SVR_METRIC_LAST_INDEX, ?C_RA_SRV_RESERVED + 4).
-define(C_RA_SVR_METRIC_LAST_WRITTEN_INDEX, ?C_RA_SRV_RESERVED + 5).
-define(C_RA_SVR_METRIC_COMMIT_LATENCY, ?C_RA_SRV_RESERVED + 6).
-define(C_RA_SVR_METRIC_TERM, ?C_RA_SRV_RESERVED + 7).

-define(RA_SRV_METRICS_COUNTER_FIELDS,
[
{last_applied, ?C_RA_SVR_METRIC_LAST_APPLIED, gauge,
"The last applied index. Can go backwards if a ra server is restarted."},
{commit_index, ?C_RA_SVR_METRIC_COMMIT_INDEX, counter,
"The current commit index."},
{snapshot_index, ?C_RA_SVR_METRIC_SNAPSHOT_INDEX, counter,
"The current snapshot index."},
{last_index, ?C_RA_SVR_METRIC_LAST_INDEX, counter,
"The last index of the log."},
{last_written_index, ?C_RA_SVR_METRIC_LAST_WRITTEN_INDEX, counter,
"The last fully written and fsynced index of the log."},
{commit_latency, ?C_RA_SVR_METRIC_COMMIT_LATENCY, gauge,
"Approximate time taken from an entry being written to the log until it is committed."},
{term, ?C_RA_SVR_METRIC_TERM, counter, "The current term."}
]).

-define(RA_COUNTER_FIELDS,
?RA_LOG_COUNTER_FIELDS ++
?RA_SRV_COUNTER_FIELDS ++
?RA_SRV_METRICS_COUNTER_FIELDS).

-define(FIELDSPEC_KEY, ra_seshat_fields_spec).
19 changes: 12 additions & 7 deletions src/ra_counters.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@
%% Copyright (c) 2017-2022 VMware, Inc. or its affiliates. All rights reserved.
%%
-module(ra_counters).
-include("ra.hrl").

-export([
init/0,
new/2,
fetch/1,
overview/0,
overview/1,
counters/2,
delete/1
]).

-type name() :: term().
-type seshat_field_spec() ::
{Name :: atom(), Position :: pos_integer(),
Type :: counter | gauge, Description :: string()}.


-spec init() -> ok.
init() ->
_ = application:ensure_all_started(seshat),
_ = seshat:new_group(ra),
persistent_term:put(?FIELDSPEC_KEY, ?RA_COUNTER_FIELDS),
ok.

-spec new(name(), [seshat_field_spec()]) ->
-spec new(name(), seshat:fields_spec()) ->
counters:counters_ref().
new(Name, Fields)
when is_list(Fields) ->
seshat:new(ra, Name, Fields).
new(Name, FieldsSpec) ->
seshat:new(ra, Name, FieldsSpec).

-spec fetch(name()) -> undefined | counters:counters_ref().
fetch(Name) ->
Expand All @@ -47,3 +47,8 @@ overview() ->
-spec overview(name()) -> #{atom() => non_neg_integer()}.
overview(Name) ->
seshat:overview(ra, Name).

-spec counters(name(), [atom()]) ->
#{atom() => non_neg_integer()} | undefined.
counters(Name, Fields) ->
seshat:counters(ra, Name, Fields).
6 changes: 3 additions & 3 deletions src/ra_directory.erl
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ init(System) when is_atom(System) ->
init(Dir, #{directory := Name,
directory_rev := NameRev}) ->
_ = ets:new(Name, [named_table,
public,
{read_concurrency, true}
]),
public,
{read_concurrency, true}
]),
ok = ra_lib:make_dir(Dir),
Dets = filename:join(Dir, "names.dets"),
{ok, NameRev} = dets:open_file(NameRev,
Expand Down
Loading

0 comments on commit ae2a716

Please sign in to comment.