Skip to content

Prometheus metrics - #110

Open
rlahfa-dinum wants to merge 1 commit into
mainfrom
metrics
Open

Prometheus metrics#110
rlahfa-dinum wants to merge 1 commit into
mainfrom
metrics

Conversation

@rlahfa-dinum

@rlahfa-dinum rlahfa-dinum commented Jun 15, 2026

Copy link
Copy Markdown
Collaborator

This adds a set of simple yet interesting time series via the Prometheus metrics standard over a UNIX domain socket (which many collectors know how to deal with) TCP socket because Prometheus cannot deal with UDS.

TODO:

  • update nixos module
  • focus on a first set of metrics
  • tests

Fixes #11.

@rlahfa-dinum
rlahfa-dinum force-pushed the metrics branch 4 times, most recently from 1cb4aca to e4ce4bb Compare June 19, 2026 18:01
@rlahfa-dinum
rlahfa-dinum marked this pull request as ready for review June 19, 2026 18:01
@rlahfa-dinum rlahfa-dinum changed the title WIP: Prometheus metrics Prometheus metrics Jun 19, 2026
This introduces a first batch of simple metrics about Portail (client or
server) with a TCP unprotected endpoint on port 10992 by default which
respects the Prometheus protocol.

How to test?

```console
$ curl localhost:10992/metrics
```

UDS was attempted first but
prometheus/prometheus#12024 is a thing.
Comment thread src/proxy/mod.rs

ACTIVE_CONNECTIONS
.with_label_values(&["ingress", proto.as_label()])
.dec();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't that double decrement with the _guard?

Comment thread src/proxy/mod.rs
/// finished yet.
static ref ACTIVE_CONNECTIONS: IntGaugeVec = register_int_gauge_vec!(
"portail_active_connections",
"Number of active connections",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That might be slightly misleading for people that will use portail as a blackbox, since it also include a good part of the setup of the connection: TLS handshake, ACL eval, try backend,...

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you have a TLS handshake with me, you have an active connection. It consumes resources.
I see your point but I think granular tracking could happen in second step.

Would you have a suggestion for a wording change on the meaning of active?

Comment thread src/proxy/socks5.rs
}
};

ACL_EVALUATION_TIMES

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 code paths that lead to this metric:

  1. a start began before the route evaluation. This seems a bit wider than just ACL evaluation, since it also include some parsing, various checks, potentially some locking.
  2. a start just before looping through the backends, which will not include route evaluation.

Maybe we should split into 2 histograms even if we lose correlation?

Comment thread src/proxy/mod.rs
static ref ACL_EVALUATION_TIMES: HistogramVec = register_histogram_vec!(
"portail_acl_evaluation_seconds",
"Duration in seconds of ACL evaluations",
&["decision"]

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This histogram receives durations in micros, I think the default buckets are not adapted https://docs.rs/prometheus/latest/src/prometheus/histogram.rs.html#25-27

Since we have a wide range from 1us to potentially 1s (or maybe more in extreme cases), maybe we should add buckets for micros on top of the default ones, like

Suggested change
&["decision"]
&["decision"],
vec![
0.000_001,
0.000_005,
0.000_01,
0.000_05,
0.000_1,
0.000_5,
0.001,
0.005,
0.01,
0.025,
0.05,
0.1,
0.25,
0.5,
1.0,
2.5,
5.0,
10.0,
],

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support Prometheus metrics

2 participants