add per-user usage metrics #7

Merged
eslamnawara merged 8 commits from add-per-user-usage-metrics into master 2026-02-09 15:06:28 +00:00
Member

Added per-user usage metrics for TLSPassthrough and non TLSPassthrough

image

Added per-user usage metrics for `TLSPassthrough` and `non TLSPassthrough` - https://forge.ourworld.tf/geomind_code/webgateway/issues/4 ![image](/attachments/b63b9636-9754-4168-bc02-19420032e975)
Author
Member

updated usage metrics to report usage per user service not per user
image

updated usage metrics to report usage per user service not per user ![image](/attachments/70c8c089-0e03-4f6e-8fbf-b5a1190ad8fe)
230 KiB
@ -0,0 +16,4 @@
// HTTPHandler is an HTTP middleware handler that records per-service
// request/response byte metrics for Prometheus.
type HTTPHandler struct {
Owner

HTTPHandler is generic, rename to something related to metrics.

HTTPHandler is generic, rename to something related to metrics.
@ -0,0 +64,4 @@
// countingReader wraps an io.ReadCloser to count bytes read.
type countingReader struct {
r io.ReadCloser
bytesRead atomic.Uint64
Owner

do we need atomic variables for this? afaik it's not used concurrently and it's done as uint64 directly in l4 app:
github.com/mholt/caddy-l4@040d25cc88/layer4/connection.go (L78)

do we need atomic variables for this? afaik it's not used concurrently and it's done as uint64 directly in l4 app: https://github.com/mholt/caddy-l4/blob/040d25cc886ab41afe5a3e25a7cb33a2fcafa202/layer4/connection.go#L78
@ -0,0 +97,4 @@
return c.bytesWritten.Load()
}
func (c *countingResponseWriter) Unwrap() http.ResponseWriter {
Owner

is this needed?

is this needed?
@ -0,0 +15,4 @@
// L4Handler is a Layer4 handler that records bytes read and written
// per connection, labeled by service FQDN and user public key for Prometheus metrics.
type L4Handler struct {
Owner

same here, rename to anything related to metrics handling

same here, rename to anything related to metrics handling
@ -328,1 +328,4 @@
// Record per-user bytes transferred on this TLS passthrough connection
metricsHandlerConfig := map[string]interface{}{
"service": hostMatcher,
Owner

it should be the the id of the user service. we can also add the host in another label

it should be the the id of the user service. we can also add the host in another label
@ -446,1 +453,4 @@
// Build per-service HTTP metrics handler
httpMetricsConfig := map[string]interface{}{
"service": hostMatcher,
Owner

same here

same here
eslamnawara force-pushed add-per-user-usage-metrics from c2c474224b to 34931b3ca0 2026-02-09 14:04:38 +00:00 Compare
thabeta left a comment
Owner
>>>>>>>
thabeta approved these changes 2026-02-09 14:47:05 +00:00
@ -0,0 +37,4 @@
}
func (h *HTTPMetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {
countedBody := &countingReader{r: r.Body}
Owner

no need to wrap the request to get the body we can just use r.ContentLength

no need to wrap the request to get the body we can just use r.ContentLength
Author
Member

I left it just to match the response behavior, but we can drop it

I left it just to match the response behavior, but we can drop it
eslamnawara deleted branch add-per-user-usage-metrics 2026-02-09 15:06:36 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
geomind_code/webgateway!7
No description provided.