You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2020/12/15 02:54:36 UTC

[couchdb] branch pluggable-custodian-monitor updated (4f8742f -> 43e8882)

This is an automated email from the ASF dual-hosted git repository.

jaydoane pushed a change to branch pluggable-custodian-monitor
in repository https://gitbox.apache.org/repos/asf/couchdb.git.


 discard 4f8742f  Support pluggable custodian monitor
     add b98dc48  2906 couchjs sm version (#2911) (#3297)
     new 43e8882  Support pluggable custodian monitor

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (4f8742f)
            \
             N -- N -- N   refs/heads/pluggable-custodian-monitor (43e8882)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 src/couch/priv/couch_js/1.8.5/help.h | 2 +-
 src/couch/priv/couch_js/60/help.h    | 2 +-
 src/couch/priv/couch_js/68/help.h    | 2 +-
 src/couch/rebar.config.script        | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)


[couchdb] 01/01: Support pluggable custodian monitor

Posted by ja...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jaydoane pushed a commit to branch pluggable-custodian-monitor
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 43e8882e7a7a023b73789a1d7ec90e0ff7477857
Author: Jay Doane <ja...@apache.org>
AuthorDate: Mon Dec 14 18:54:02 2020 -0800

    Support pluggable custodian monitor
    
    Enable build time configurable monitor for custodian and remove custom
    sensu events.
---
 src/custodian/rebar.config.script                  | 35 ++++++++++++++++
 ...{custodian.app.src => custodian.app.src.script} | 37 ++++++++++++-----
 src/custodian/src/custodian_db_checker.erl         | 14 ++-----
 .../{custodian.app.src => custodian_monitor.erl}   | 30 ++++++--------
 ...ustodian.app.src => custodian_noop_monitor.erl} | 40 ++++++++++--------
 src/custodian/src/custodian_server.erl             | 47 +---------------------
 6 files changed, 103 insertions(+), 100 deletions(-)

diff --git a/src/custodian/rebar.config.script b/src/custodian/rebar.config.script
new file mode 100644
index 0000000..f32db97
--- /dev/null
+++ b/src/custodian/rebar.config.script
@@ -0,0 +1,35 @@
+% Licensed under the Apache License, Version 2.0 (the "License"); you may not
+% use this file except in compliance with the License. You may obtain a copy of
+% the License at
+%
+%   http://www.apache.org/licenses/LICENSE-2.0
+%
+% Unless required by applicable law or agreed to in writing, software
+% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+% License for the specific language governing permissions and limitations under
+% the License.
+
+
+CouchConfig = case filelib:is_file(os:getenv("COUCHDB_CONFIG")) of
+    true ->
+        {ok, Result} = file:consult(os:getenv("COUCHDB_CONFIG")),
+        Result;
+    false ->
+        []
+end,
+
+CustodianMonitor = case lists:keyfind(custodian_monitor, 1, CouchConfig) of
+    {custodian_monitor, Module} when Module /= "" ->
+        list_to_atom(Module);
+    _ ->
+        custodian_noop_monitor
+end,
+
+CurrentOpts = case lists:keyfind(erl_opts, 1, CONFIG) of
+    {erl_opts, Opts} -> Opts;
+    false -> []
+end,
+
+CustodianOpts = {d, 'CUSTODIAN_MONITOR', CustodianMonitor},
+lists:keystore(erl_opts, 1, CONFIG, {erl_opts, [CustodianOpts | CurrentOpts]}).
diff --git a/src/custodian/src/custodian.app.src b/src/custodian/src/custodian.app.src.script
similarity index 54%
copy from src/custodian/src/custodian.app.src
copy to src/custodian/src/custodian.app.src.script
index b93b21e..551b9c2 100644
--- a/src/custodian/src/custodian.app.src
+++ b/src/custodian/src/custodian.app.src.script
@@ -10,20 +10,39 @@
 % License for the specific language governing permissions and limitations under
 % the License.
 
+CouchConfig = case filelib:is_file(os:getenv("COUCHDB_CONFIG")) of
+    true ->
+        {ok, Result} = file:consult(os:getenv("COUCHDB_CONFIG")),
+        Result;
+    false ->
+        []
+end.
+
+CustodianMonitorApp = case lists:keyfind(custodian_monitor_app, 1, CouchConfig) of
+    {custodian_monitor_app, AppName} when AppName /= "" ->
+        [list_to_atom(AppName)];
+    _ ->
+        []
+end.
+
+BaseApplications = [
+    kernel,
+    stdlib,
+    couch_log,
+    config,
+    couch_event,
+    couch,
+    mem3
+].
+
+Applications = CustodianMonitorApp ++ BaseApplications.
+
 {application, custodian,
  [
   {description, "in your cluster, looking after your stuff"},
   {vsn, git},
   {registered, []},
-  {applications, [
-                  kernel,
-                  stdlib,
-                  couch_log,
-                  config,
-                  couch_event,
-                  couch,
-                  mem3
-                 ]},
+  {applications, Applications},
   {mod, { custodian_app, []}},
   {env, []}
  ]}.
diff --git a/src/custodian/src/custodian_db_checker.erl b/src/custodian/src/custodian_db_checker.erl
index 8308c8e..10502dd 100644
--- a/src/custodian/src/custodian_db_checker.erl
+++ b/src/custodian/src/custodian_db_checker.erl
@@ -149,17 +149,9 @@ get_stats_db() ->
 
 send_missing_db_alert(DbName) ->
     couch_log:notice("Missing system database ~s", [DbName]),
-    Command = [
-        "send-sensu-event --standalone --critical",
-        " --output=\"Missing system database ",
-        binary_to_list(DbName),
-        "\" --handler=default custodian-missing-db-check"],
-    os:cmd(lists:concat(Command)).
+    ?CUSTODIAN_MONITOR:send_missing_db_alert(DbName).
+
 
 clear_missing_dbs_alert() ->
     couch_log:notice("All system databases exist.", []),
-    Command = [
-        "send-sensu-event --standalone --ok",
-        " --output=\"All system databases exist\"",
-        " --handler=default custodian-missing-db-check"],
-    os:cmd(lists:concat(Command)).
+    ?CUSTODIAN_MONITOR:clear_missing_dbs_alert().
diff --git a/src/custodian/src/custodian.app.src b/src/custodian/src/custodian_monitor.erl
similarity index 57%
copy from src/custodian/src/custodian.app.src
copy to src/custodian/src/custodian_monitor.erl
index b93b21e..700e092 100644
--- a/src/custodian/src/custodian.app.src
+++ b/src/custodian/src/custodian_monitor.erl
@@ -10,20 +10,16 @@
 % License for the specific language governing permissions and limitations under
 % the License.
 
-{application, custodian,
- [
-  {description, "in your cluster, looking after your stuff"},
-  {vsn, git},
-  {registered, []},
-  {applications, [
-                  kernel,
-                  stdlib,
-                  couch_log,
-                  config,
-                  couch_event,
-                  couch,
-                  mem3
-                 ]},
-  {mod, { custodian_app, []}},
-  {env, []}
- ]}.
+-module(custodian_monitor).
+
+
+-callback send_missing_db_alert(DbName :: binary()) ->
+    Output :: string().
+
+
+-callback clear_missing_dbs_alert() ->
+    Output :: string().
+
+
+-callback send_event({Type :: atom(), Count :: non_neg_integer()}) ->
+    Output :: string().
diff --git a/src/custodian/src/custodian.app.src b/src/custodian/src/custodian_noop_monitor.erl
similarity index 57%
rename from src/custodian/src/custodian.app.src
rename to src/custodian/src/custodian_noop_monitor.erl
index b93b21e..ed4711b 100644
--- a/src/custodian/src/custodian.app.src
+++ b/src/custodian/src/custodian_noop_monitor.erl
@@ -10,20 +10,26 @@
 % License for the specific language governing permissions and limitations under
 % the License.
 
-{application, custodian,
- [
-  {description, "in your cluster, looking after your stuff"},
-  {vsn, git},
-  {registered, []},
-  {applications, [
-                  kernel,
-                  stdlib,
-                  couch_log,
-                  config,
-                  couch_event,
-                  couch,
-                  mem3
-                 ]},
-  {mod, { custodian_app, []}},
-  {env, []}
- ]}.
+-module(custodian_noop_monitor).
+
+
+-behaviour(custodian_monitor).
+
+
+-export([
+    send_missing_db_alert/1,
+    clear_missing_dbs_alert/0,
+    send_event/1
+]).
+
+
+send_missing_db_alert(_DbName) ->
+    "no-op".
+
+
+clear_missing_dbs_alert() ->
+    "no-op".
+
+
+send_event(_Item) ->
+    "no-op".
diff --git a/src/custodian/src/custodian_server.erl b/src/custodian/src/custodian_server.erl
index 322cc32..8ce02b7 100644
--- a/src/custodian/src/custodian_server.erl
+++ b/src/custodian/src/custodian_server.erl
@@ -143,52 +143,7 @@ handle_db_event(_DbName, _Event, _St) ->
     {ok, nil}.
 
 check_shards() ->
-    [send_sensu_event(Item) || Item <- custodian:summary()].
-
-send_sensu_event({_, Count} = Item) ->
-    Level = case Count of
-        0 ->
-            "--ok";
-        1 ->
-            couch_log:critical("~s", [describe(Item)]),
-            "--critical";
-        _ ->
-            couch_log:warning("~s", [describe(Item)]),
-            "--warning"
-    end,
-    Cmd = lists:concat([
-        "send-sensu-event --standalone ",
-        Level,
-        " --output=\"",
-        describe(Item),
-        "\" ",
-        check_name(Item)
-    ]),
-    os:cmd(Cmd).
-
-describe({{safe, N}, Count}) ->
-    lists:concat([Count, " ", shards(Count), " in cluster with only ", N,
-                  " ", copies(N), " on nodes that are currently up"]);
-describe({{live, N}, Count}) ->
-    lists:concat([Count, " ", shards(Count), " in cluster with only ",
-                  N, " ", copies(N), " on nodes not in maintenance mode"]);
-describe({conflicted, Count}) ->
-    lists:concat([Count, " conflicted ", shards(Count), " in cluster"]).
-
-check_name({{Type, N}, _}) ->
-    lists:concat(["custodian-", N, "-", Type, "-shards-check"]);
-check_name({Type, _}) ->
-    lists:concat(["custodian-", Type, "-shards-check"]).
-
-shards(1) ->
-    "shard";
-shards(_) ->
-    "shards".
-
-copies(1) ->
-    "copy";
-copies(_) ->
-    "copies".
+    [?CUSTODIAN_MONITOR:send_event(Item) || Item <- custodian:summary()].
 
 
 -ifdef(TEST).