Skip to content

Commit

Permalink
Report latency histograms regardless of log level
Browse files Browse the repository at this point in the history
Previously the latency histograms were tied to verbosity level which meant
that they were not published unless using v=5. This makes the metrics always visible.
  • Loading branch information
linuskendall authored Aug 15, 2024
1 parent cfcc97f commit 4a3526f
Showing 1 changed file with 29 additions and 17 deletions.
46 changes: 29 additions & 17 deletions http-range.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ func (r *readCloserWrapper) ReadAt(p []byte, off int64) (n int, err error) {
startedAt := time.Now()
defer func() {
took := time.Since(startedAt)
var isIndex, isCar bool

// Metrics want to always report
// if has suffix .index, then it's an index file
if strings.HasSuffix(r.name, ".index") {
isIndex = true
// get the index name, which is the part before the .index suffix, after the last .
indexName := strings.TrimSuffix(r.name, ".index")
// split the index name by . and get the last part
byDot := strings.Split(indexName, ".")
if len(byDot) > 0 {
indexName = byDot[len(byDot)-1]
}
// TODO: distinguish between remote and local index reads
metrics.IndexLookupHistogram.WithLabelValues(indexName).Observe(float64(took.Seconds()))
}
// if has suffix .car, then it's a car file
if strings.HasSuffix(r.name, ".car") || r.isSplitCar {
isCar = true
carName := filepath.Base(r.name)
// TODO: distinguish between remote and local index reads
metrics.CarLookupHistogram.WithLabelValues(carName).Observe(float64(took.Seconds()))
}

if klog.V(5).Enabled() {
var icon string
if r.isRemote {
Expand All @@ -41,31 +65,19 @@ func (r *readCloserWrapper) ReadAt(p []byte, off int64) (n int, err error) {
// add disk icon
icon = "💾 "
}

prefix := icon + "[READ-UNKNOWN]"
// if has suffix .index, then it's an index file
if strings.HasSuffix(r.name, ".index") {
if isIndex {
prefix = icon + azureBG("[READ-INDEX]")
// get the index name, which is the part before the .index suffix, after the last .
indexName := strings.TrimSuffix(r.name, ".index")
// split the index name by . and get the last part
byDot := strings.Split(indexName, ".")
if len(byDot) > 0 {
indexName = byDot[len(byDot)-1]
}
// TODO: distinguish between remote and local index reads
metrics.IndexLookupHistogram.WithLabelValues(indexName).Observe(float64(took.Seconds()))
}
// if has suffix .car, then it's a car file
if strings.HasSuffix(r.name, ".car") || r.isSplitCar {
} else if isCar {

if r.isSplitCar {
prefix = icon + azureBG("[READ-SPLIT-CAR]")
} else {
prefix = icon + purpleBG("[READ-CAR]")
}
carName := filepath.Base(r.name)
// TODO: distinguish between remote and local index reads
metrics.CarLookupHistogram.WithLabelValues(carName).Observe(float64(took.Seconds()))
}

klog.V(5).Infof(prefix+" %s:%d+%d (%s)\n", (r.name), off, len(p), took)
}
}()
Expand Down

0 comments on commit 4a3526f

Please sign in to comment.