Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metrics debugging #687

Merged
merged 3 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .bazelci/basic-auth-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ echo 'topsecretusername:$apr1$Ke2kcK4W$EyueqiHyoqhwXcpiEGNyJ1' \
echo "Starting bazel-remote, allowing unauthenticated reads..."
./bazel-remote --dir "$tmpdir/cache" --max_size 1 --http_address "0.0.0.0:$HTTP_PORT" \
--htpasswd_file "$tmpdir/htpasswd" \
--enable_endpoint_metrics \
--allow_unauthenticated_reads > "$tmpdir/bazel-remote.log" 2>&1 &
server_pid=$!

Expand Down Expand Up @@ -57,6 +58,11 @@ then
exit 1
fi

# Check that metrics are working (requires authentication).
wget --inet4-only -d -O - \
--http-user "$USER" --http-password "$PASS" \
http://localhost:$HTTP_PORT/metrics

# Authenticated read.
wget --inet4-only -d -O - \
--http-user "$USER" --http-password "$PASS" \
Expand Down
8 changes: 8 additions & 0 deletions .bazelci/tls-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ echo "Starting bazel-remote, allowing unauthenticated reads..."
--tls_cert_file "$tmpdir/server.crt" \
--tls_key_file "$tmpdir/server.key" \
--tls_ca_file "$tmpdir/ca.crt" \
--enable_endpoint_metrics \
--allow_unauthenticated_reads > "$tmpdir/bazel-remote.log" 2>&1 &
server_pid=$!

Expand Down Expand Up @@ -114,6 +115,13 @@ then
exit 1
fi

# Check that metrics are working (requires authentication).
wget --inet4-only -d -O - --ca-certificate=$tmpdir/server.crt \
--certificate=$tmpdir/client.crt \
--private-key=$tmpdir/client.pem \
--timeout=2 \
"https://localhost:$HTTP_PORT/metrics"

# Authenticated read.
wget --inet4-only -d -O - --ca-certificate=$tmpdir/server.crt \
--certificate=$tmpdir/client.crt \
Expand Down
8 changes: 8 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ func startHttpServer(c *config.Config, httpServer **http.Server,
}

if c.EnableEndpointMetrics {
log.Println("Endpoint metrics: enabled")

metricsMdlw := middleware.New(middleware.Config{
Recorder: httpmetrics.NewRecorder(httpmetrics.Config{
DurationBuckets: c.MetricsDurationBuckets,
Expand All @@ -292,6 +294,12 @@ func startHttpServer(c *config.Config, httpServer **http.Server,
cacheHandler = func(w http.ResponseWriter, r *http.Request) {
middlewarestd.Handler(r.Method, metricsMdlw, http.HandlerFunc(ch)).ServeHTTP(w, r)
}
} else {
log.Println("Endpoint metrics: disabled")

mux.HandleFunc("/metrics", func(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Endpoint metrics are not enabled on this server.", http.StatusNotFound)
})
}

mux.HandleFunc("/status", statusHandler)
Expand Down
4 changes: 2 additions & 2 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func NewHTTPCache(cache disk.Cache, accessLogger cache.Logger, errorLogger cache
func parseRequestURL(url string, validateAC bool) (kind cache.EntryKind, hash string, instance string, err error) {
m := blobNameSHA256.FindStringSubmatch(url)
if m == nil {
err := fmt.Errorf("resource name must be a SHA256 hash in hex. "+
err := fmt.Errorf("resource name must be a SHA256 hash in hex, "+
"got '%s'", html.EscapeString(url))
return 0, "", "", err
}
Expand All @@ -100,7 +100,7 @@ func parseRequestURL(url string, validateAC bool) (kind cache.EntryKind, hash st

parts := m[2:]
if len(parts) != 2 {
err := fmt.Errorf("the path '%s' is invalid. expected (ac/|cas/)sha256",
err := fmt.Errorf("the path '%s' is invalid, expected (ac/|cas/)sha256",
html.EscapeString(url))
return 0, "", "", err
}
Expand Down
Loading