add per-user usage metrics #7
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "add-per-user-usage-metrics"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Added per-user usage metrics for
TLSPassthroughandnon TLSPassthroughupdated usage metrics to report usage per user service not per user

@ -0,0 +16,4 @@// HTTPHandler is an HTTP middleware handler that records per-service// request/response byte metrics for Prometheus.type HTTPHandler struct {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.ReadCloserbytesRead atomic.Uint64do 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)@ -0,0 +97,4 @@return c.bytesWritten.Load()}func (c *countingResponseWriter) Unwrap() http.ResponseWriter {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 {same here, rename to anything related to metrics handling
@ -328,1 +328,4 @@// Record per-user bytes transferred on this TLS passthrough connectionmetricsHandlerConfig := map[string]interface{}{"service": hostMatcher,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 handlerhttpMetricsConfig := map[string]interface{}{"service": hostMatcher,same here
c2c474224bto34931b3ca0@ -0,0 +37,4 @@}func (h *HTTPMetricsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {countedBody := &countingReader{r: r.Body}no need to wrap the request to get the body we can just use r.ContentLength
I left it just to match the response behavior, but we can drop it