Skip to content

Commit

Permalink
Request TTFB metric for GetObject API
Browse files Browse the repository at this point in the history
  • Loading branch information
nopcoder committed Jan 27, 2025
1 parent 9d179c7 commit dde1d8f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pkg/api/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -4480,6 +4480,7 @@ func (c *Controller) GetObject(w http.ResponseWriter, r *http.Request, repositor
}
ctx := r.Context()
c.LogAction(ctx, "get_object", r, repository, ref, "")
requestStart := time.Now()

repo, err := c.Catalog.GetRepository(ctx, repository)
if c.handleAPIError(ctx, w, r, err) {
Expand Down Expand Up @@ -4564,6 +4565,11 @@ func (c *Controller) GetObject(w http.ResponseWriter, r *http.Request, repositor
w.Header().Set("Content-Length", fmt.Sprint(entry.Size))
}

// time to first byte - include out part of the processing without the actual data transfer
requestTTFBHistograms.
WithLabelValues("GetObject").
Observe(time.Since(requestStart).Seconds())

// copy the content
_, err = io.Copy(w, reader)
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions pkg/api/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,11 @@ var requestHistograms = promauto.NewHistogramVec(
Buckets: []float64{0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, 60},
},
[]string{"operation", "code"})

var requestTTFBHistograms = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "api_request_ttfb_duration_seconds",
Help: "request time-to-first-byte durations for lakeFS API",
Buckets: []float64{0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 30, 60},
},
[]string{"operation"})

0 comments on commit dde1d8f

Please sign in to comment.