Skip to content

Commit

Permalink
Update metrics (#147)
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
  • Loading branch information
linuskendall authored Aug 14, 2024
1 parent bcfb24a commit 41089cf
Show file tree
Hide file tree
Showing 5 changed files with 184 additions and 163 deletions.
11 changes: 6 additions & 5 deletions cmd-rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/allegro/bigcache/v3"
"github.com/fsnotify/fsnotify"
hugecache "github.com/rpcpool/yellowstone-faithful/huge-cache"
"github.com/rpcpool/yellowstone-faithful/metrics"
splitcarfetcher "github.com/rpcpool/yellowstone-faithful/split-car-fetcher"
"github.com/ryanuber/go-glob"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -202,13 +203,13 @@ func newCmd_rpc() *cli.Command {
return nil
}()
if err != nil {
metrics_epochsAvailable.WithLabelValues(fmt.Sprintf("%d", epochNum)).Set(0)
metrics.EpochsAvailable.WithLabelValues(fmt.Sprintf("%d", epochNum)).Set(0)
klog.Error(err)
numFailed.Add(1)
// NOTE: DO NOT return the error here, as we want to continue loading other epochs
return nil
}
metrics_epochsAvailable.WithLabelValues(fmt.Sprintf("%d", epochNum)).Set(1)
metrics.EpochsAvailable.WithLabelValues(fmt.Sprintf("%d", epochNum)).Set(1)
numSucceeded.Add(1)
return nil
})
Expand Down Expand Up @@ -275,7 +276,7 @@ func newCmd_rpc() *cli.Command {
return
}
klog.V(2).Infof("Epoch %d added/replaced in %s", epoch.Epoch(), time.Since(startedAt))
metrics_epochsAvailable.WithLabelValues(fmt.Sprintf("%d", epoch.Epoch())).Set(1)
metrics.EpochsAvailable.WithLabelValues(fmt.Sprintf("%d", epoch.Epoch())).Set(1)
}
case fsnotify.Create:
{
Expand All @@ -298,7 +299,7 @@ func newCmd_rpc() *cli.Command {
return
}
klog.V(2).Infof("Epoch %d added in %s", epoch.Epoch(), time.Since(startedAt))
metrics_epochsAvailable.WithLabelValues(fmt.Sprintf("%d", epoch.Epoch())).Set(1)
metrics.EpochsAvailable.WithLabelValues(fmt.Sprintf("%d", epoch.Epoch())).Set(1)
}
case fsnotify.Remove:
{
Expand All @@ -310,7 +311,7 @@ func newCmd_rpc() *cli.Command {
klog.Errorf("error removing epoch for config file %q: %s", event.Name, err.Error())
}
klog.V(2).Infof("Epoch %d removed in %s", epNumber, time.Since(startedAt))
metrics_epochsAvailable.WithLabelValues(fmt.Sprintf("%d", epNumber)).Set(0)
metrics.EpochsAvailable.WithLabelValues(fmt.Sprintf("%d", epNumber)).Set(0)
}
case fsnotify.Rename:
klog.V(3).Infof("File %q was renamed; do nothing", event.Name)
Expand Down
14 changes: 14 additions & 0 deletions http-range.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package main

import (
"io"
"path/filepath"
"strings"
"time"

"github.com/rpcpool/yellowstone-faithful/metrics"
"k8s.io/klog/v2"
)

Expand Down Expand Up @@ -43,6 +45,15 @@ func (r *readCloserWrapper) ReadAt(p []byte, off int64) (n int, err error) {
// if has suffix .index, then it's an index file
if strings.HasSuffix(r.name, ".index") {
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 {
Expand All @@ -51,6 +62,9 @@ func (r *readCloserWrapper) ReadAt(p []byte, off int64) (n int, err error) {
} 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
147 changes: 0 additions & 147 deletions metrics.go

This file was deleted.

90 changes: 90 additions & 0 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
package metrics

import (
"github.com/prometheus/client_golang/prometheus"
"github.com/prometheus/client_golang/prometheus/promauto"
)

var RpcRequestByMethod = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "rpc_requests_by_method",
Help: "RPC requests by method",
},
[]string{"method"},
)

var EpochsAvailable = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "epoch_available",
Help: "Epochs available",
},
[]string{"epoch"},
)

var StatusCode = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "status_code",
Help: "Status code",
},
[]string{"code"},
)

var MethodToCode = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "method_to_code",
Help: "Method to code",
},
[]string{"method", "code"},
)

var MethodToSuccessOrFailure = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "method_to_success_or_failure",
Help: "Method to success or failure",
},
[]string{"method", "status"},
)

var MethodToNumProxied = promauto.NewCounterVec(
prometheus.CounterOpts{
Name: "method_to_num_proxied",
Help: "Method to num proxied",
},
[]string{"method"},
)

// - Version information of this binary
var Version = promauto.NewGaugeVec(
prometheus.GaugeOpts{
Name: "version",
Help: "Version information of this binary",
},
[]string{"started_at", "tag", "commit", "compiler", "goarch", "goos", "goamd64", "vcs", "vcs_revision", "vcs_time", "vcs_modified"},
)

var IndexLookupHistogram = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "index_lookup_latency_histogram",
Help: "Index lookup latency",
Buckets: prometheus.ExponentialBuckets(0.000001, 10, 10),
},
[]string{"index_type"},
)

var CarLookupHistogram = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "car_lookup_latency_histogram",
Help: "Car lookup latency",
Buckets: prometheus.ExponentialBuckets(0.000001, 10, 10),
},
[]string{"car"},
)

var RpcResponseLatencyHistogram = promauto.NewHistogramVec(
prometheus.HistogramOpts{
Name: "rpc_response_latency_histogram",
Help: "RPC response latency histogram",
Buckets: prometheus.ExponentialBuckets(0.000001, 10, 10),
},
[]string{"rpc_method"},
)
Loading

0 comments on commit 41089cf

Please sign in to comment.