Skip to content

Commit

Permalink
Add ability to define a link on a node
Browse files Browse the repository at this point in the history
  • Loading branch information
valeriansaliou committed Jan 6, 2025
1 parent 314e469 commit 00ed130
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand Down
29 changes: 29 additions & 0 deletions config.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
'''
]
15 changes: 14 additions & 1 deletion res/assets/stylesheets/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
Expand Down
10 changes: 10 additions & 0 deletions res/assets/templates/index.tera
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@
</span>
</span>
{% endfor %}

{% if node.link_url %}
<a href="{{ node.link_url | escape }}" class="link font-sans-semibold">
{% if node.link_label %}
{{ node.link_label }}
{% else %}
{{ node.link_url }}
{% endif %}
</a>
{% endif %}
</div>
</li>
{% endfor %}
Expand Down
3 changes: 3 additions & 0 deletions src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SerdeUrl>,
pub link_label: Option<String>,

pub rabbitmq_queue: Option<String>,
pub rabbitmq_queue_nack_healthy_below: Option<u32>,
pub rabbitmq_queue_nack_dead_above: Option<u32>,
Expand Down
2 changes: 2 additions & 0 deletions src/prober/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 2 additions & 0 deletions src/prober/states.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ pub struct ServiceStatesProbeNode {
pub http_body: Option<String>,
pub http_body_healthy_match: Option<Regex>,
pub reveal_replica_name: bool,
pub link_url: Option<String>,
pub link_label: Option<String>,
pub rabbitmq: Option<ServiceStatesProbeNodeRabbitMQ>,
}

Expand Down

0 comments on commit 00ed130

Please sign in to comment.