Skip to content

Commit

Permalink
Cleanup metrics (#165)
Browse files Browse the repository at this point in the history
* Cleanup metrics

* Fix latency buckets

* Limit rusts tests for when rust is changed

* Fix?

* Split between test go and test rust

* Fix
  • Loading branch information
gagliardetto authored Oct 4, 2024
1 parent dd83ea1 commit d51f038
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 51 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/tests-go.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

on:
pull_request:
workflow_dispatch:

env:
CARGO_TERM_COLOR: always

name: tests_go
jobs:
test:
strategy:
matrix:
go-version: [1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Test
run: go test ./...
37 changes: 19 additions & 18 deletions .github/workflows/tests.yml → .github/workflows/tests-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,30 +4,31 @@ concurrency:

on:
pull_request:
paths:
- 'Cargo.toml'
- 'Cargo.lock'
- 'rust-toolchain.toml'
- '.github/workflows/tests-rust.yml'
- 'txstatus/**'
- 'old-faithful-proto/**'
- 'geyser-plugin-runner/**'
- 'tests/rust/**'
workflow_dispatch:
paths:
- 'Cargo.toml'
- 'Cargo.lock'
- 'rust-toolchain.toml'
- '.github/workflows/tests-rust.yml'
- 'txstatus/**'
- 'old-faithful-proto/**'
- 'geyser-plugin-runner/**'
- 'tests/rust/**'

env:
CARGO_TERM_COLOR: always

name: tests
name: tests_rust
jobs:
test:
strategy:
matrix:
go-version: [1.21.x]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
steps:
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Test
run: go test ./...
test_rust:
strategy:
matrix:
Expand Down
48 changes: 27 additions & 21 deletions http-range.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,36 @@ 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") {
isIndex = true
}
// if has suffix .car, then it's a car file
if strings.HasSuffix(r.name, ".car") || r.isSplitCar {
isCar = true
}

if isCar {
carName := filepath.Base(r.name)
metrics.CarLookupHistogram.WithLabelValues(
carName,
boolToString(r.isRemote),
boolToString(r.isSplitCar),
).Observe(float64(took.Seconds()))
}
if isIndex {
// 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()))
metrics.IndexLookupHistogram.WithLabelValues(
indexName,
boolToString(r.isRemote),
).Observe(float64(took.Seconds()))
}

if klog.V(5).Enabled() {
// Very verbose logging:
var icon string
if r.isRemote {
// add internet icon
Expand All @@ -69,15 +80,6 @@ func (r *readCloserWrapper) ReadAt(p []byte, off int64) (n int, err error) {
prefix := icon + "[READ-UNKNOWN]"
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 isCar {
Expand All @@ -86,9 +88,6 @@ 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 All @@ -111,3 +110,10 @@ func azureBG(s string) string {
func (r *readCloserWrapper) Close() error {
return r.rac.Close()
}

func boolToString(b bool) string {
if b {
return "true"
}
return "false"
}
35 changes: 23 additions & 12 deletions metrics/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,29 +62,40 @@ var Version = promauto.NewGaugeVec(
[]string{"started_at", "tag", "commit", "compiler", "goarch", "goos", "goamd64", "vcs", "vcs_revision", "vcs_time", "vcs_modified"},
)

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

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

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

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"},
)
var latencyBuckets = []float64{
// fractional seconds from 0 to 1, with increments of 0.05 (= 50 ms)
0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45,
0.5, 0.55, 0.6, 0.65, 0.7, 0.75, 0.8, 0.85, 0.9, 0.95,
1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5,
// then 5-10 with increments of 1
6, 7, 8, 9, 10,
// then 10-60 with increments of 5
15, 20, 25, 30, 35, 40, 45, 50, 55, 60,
}

0 comments on commit d51f038

Please sign in to comment.