From 00ed1305af86cf12638ef9627c33a37505990579 Mon Sep 17 00:00:00 2001 From: Valerian Saliou Date: Mon, 6 Jan 2025 13:14:19 -0300 Subject: [PATCH] Add ability to define a link on a node --- README.md | 2 ++ config.cfg | 29 +++++++++++++++++++++++++++++ res/assets/stylesheets/index.css | 15 ++++++++++++++- res/assets/templates/index.tera | 10 ++++++++++ src/config/config.rs | 3 +++ src/prober/manager.rs | 2 ++ src/prober/states.rs | 2 ++ 7 files changed, 62 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1244485..5b7cc8d 100644 --- a/README.md +++ b/README.md @@ -345,6 +345,8 @@ You can also use environment variables with string interpolation in your configu * `http_body` (type _string_, allowed: any string, no default) — Body to send in the HTTP request when polling an endpoint (this only works if `http_method` is set to `POST`, `PUT` or `PATCH`) * `http_body_healthy_match` (type: _string_, allowed: regular expressions, no default) — HTTP response body for which to report node replica as `healthy` (if the body does not match, the replica will be reported as `dead`, even if the status code check passes; the check uses a `GET` rather than the usual `HEAD` if this option is set) * `reveal_replica_name` (type: _boolean_, allowed: `true`, `false`, default: `false`) — Whether to reveal replica name on public status page or not (this can be a security risk if a replica URL is to be kept secret) +* `link_url` (type: _string_, allowed: URL, no default) — Link URL to show next to the node health (this can be used to direct the user to another page to see more details) +* `link_label` (type: _string_, allowed: any string, no default) — Link label to use for the URL link (if any link is set) * `rabbitmq_queue` (type: _string_, allowed: RabbitMQ queue names, no default) — RabbitMQ queue associated to node, which to check against for pending payloads via RabbitMQ API (this helps monitor unacked payloads accumulating in the queue) * `rabbitmq_queue_nack_healthy_below` (type: _integer_, allowed: any number, no default) — Maximum number of payloads in RabbitMQ queue associated to node, with status `nack` to consider node `healthy` (this overrides the global `plugins.rabbitmq.queue_nack_healthy_below`) * `rabbitmq_queue_nack_dead_above` (type: _integer_, allowed: any number, no default) — Threshold on the number of payloads in RabbitMQ queue associated to node, with status `nack` above which node should be considered `dead` (stalled queue, this overrides the global `plugins.rabbitmq.queue_nack_dead_above`) diff --git a/config.cfg b/config.cfg index e2091d0..4745efb 100644 --- a/config.cfg +++ b/config.cfg @@ -233,3 +233,32 @@ mode = "local" id = "capacity" label = "Network capacity" mode = "local" + +[[probe.service]] + +id = "plugin" +label = "Plugin nodes" + +[[probe.service.node]] + +id = "plugin-health" +label = "Plugins health" +mode = "script" +link_url = "https://status.plugins.crisp.chat/" +link_label = "See status details" + +scripts = [ + ''' + status=$(curl --silent --connect-timeout 3 https://status.plugins.crisp.chat/status/text) + + if [ -z "$status" ]; then + exit 2 + fi + + if [ "$status" = "healthy" ]; then + exit 0 + fi + + exit 1 + ''' +] diff --git a/res/assets/stylesheets/index.css b/res/assets/stylesheets/index.css index 853fa77..781bf8c 100644 --- a/res/assets/stylesheets/index.css +++ b/res/assets/stylesheets/index.css @@ -328,7 +328,7 @@ main section.probe ul li label { main section.probe ul li .node { background-color: #F7F8FA; - padding: 9px 20px 8px 24px; + padding: 9px 14px 8px 24px; flex: 0.65; } @@ -344,6 +344,19 @@ main section.probe ul li .node .replica { border-radius: 2px; } +main section.probe ul li .node .replica:last-of-type { + margin-right: 8px; +} + +main section.probe ul li .node .link { + color: #000000; + font-size: 12px; + line-height: 16px; + text-decoration: underline; + margin-top: 7px; + display: inline-block; +} + footer { text-align: center; letter-spacing: -0.05px; diff --git a/res/assets/templates/index.tera b/res/assets/templates/index.tera index a5079e3..ac5ec6c 100644 --- a/res/assets/templates/index.tera +++ b/res/assets/templates/index.tera @@ -212,6 +212,16 @@ {% endfor %} + + {% if node.link_url %} + + {% if node.link_label %} + {{ node.link_label }} + {% else %} + {{ node.link_url }} + {% endif %} + + {% endif %} {% endfor %} diff --git a/src/config/config.rs b/src/config/config.rs index f8c3a60..1c333d3 100644 --- a/src/config/config.rs +++ b/src/config/config.rs @@ -309,6 +309,9 @@ pub struct ConfigProbeServiceNode { #[serde(default = "defaults::probe_service_node_reveal_replica_name")] pub reveal_replica_name: bool, + pub link_url: Option, + pub link_label: Option, + pub rabbitmq_queue: Option, pub rabbitmq_queue_nack_healthy_below: Option, pub rabbitmq_queue_nack_dead_above: Option, diff --git a/src/prober/manager.rs b/src/prober/manager.rs index 97dd2b9..36d05ab 100644 --- a/src/prober/manager.rs +++ b/src/prober/manager.rs @@ -874,6 +874,8 @@ pub fn initialize_store() { http_body: node.http_body.to_owned(), http_body_healthy_match: node.http_body_healthy_match.to_owned(), reveal_replica_name: node.reveal_replica_name, + link_url: node.link_url.as_ref().map(|url| url.to_string()), + link_label: node.link_label.to_owned(), rabbitmq: node.rabbitmq_queue.as_ref().map(|queue| { ServiceStatesProbeNodeRabbitMQ { queue: queue.to_owned(), diff --git a/src/prober/states.rs b/src/prober/states.rs index d123c8d..21e8f09 100644 --- a/src/prober/states.rs +++ b/src/prober/states.rs @@ -42,6 +42,8 @@ pub struct ServiceStatesProbeNode { pub http_body: Option, pub http_body_healthy_match: Option, pub reveal_replica_name: bool, + pub link_url: Option, + pub link_label: Option, pub rabbitmq: Option, }