Skip to content

Commit

Permalink
Fix metrics to not tie them to loglevel (#149)
Browse files Browse the repository at this point in the history
* Remove /health and /metrics req logging; closes #127

* Move metrics to metrics package

* Prometheus for index and car lookups; closes #126

* Cleanup metrics; closes #128

* Report latency histograms regardless of log level

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 41089cf commit ab34b14
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 ab34b14

Please sign in to comment.