diff --git a/http-range.go b/http-range.go index 8eebcf2b..4033455e 100644 --- a/http-range.go +++ b/http-range.go @@ -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 { @@ -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) } }()