Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 15 additions & 13 deletions protocol/metrics/cancelled_relay_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ import (
// MAG-2648. A relay-race loser must balance the in-flight gauge and land in its own
// counter, without polluting the error counter or the router request-group counters.

func cancelledTestLabels() map[string]string {
return map[string]string{"spec": "ETH1", "apiInterface": "jsonrpc", "endpoint_id": "ep1", "function": "eth_sendRawTransaction"}
// cancelledTestLabels is the series under test, in endpointFunctionLabels order
// (spec, apiInterface, endpoint_id, function).
func cancelledTestLabels() []string {
return []string{"ETH1", "jsonrpc", "ep1", "eth_sendRawTransaction"}
}

// The trap this fix had to route around: the in-flight gauge is incremented at relay
Expand All @@ -23,7 +25,7 @@ func TestCancelledRelay_InFlightGaugeReturnsToZero(t *testing.T) {
m.RecordDirectRelayStart("ETH1", "jsonrpc", "ep1", "eth_sendRawTransaction")
m.RecordDirectRelayEnd("ETH1", "jsonrpc", "ep1", "eth_sendRawTransaction", 5, RelayOutcomeCancelled, &RelayMetrics{IsWrite: true})
}
require.Equal(t, float64(0), testutil.ToFloat64(m.endpointInFlight.WithLabelValues(cancelledTestLabels())),
require.Equal(t, float64(0), testutil.ToFloat64(m.endpointInFlight.WithLabelValues(cancelledTestLabels()...)),
"every cancelled relay must still decrement the in-flight gauge")
}

Expand All @@ -33,7 +35,7 @@ func TestCancelledRelay_InFlightBalancesAcrossMixedOutcomes(t *testing.T) {
m.RecordDirectRelayStart("ETH1", "jsonrpc", "ep1", "eth_sendRawTransaction")
m.RecordDirectRelayEnd("ETH1", "jsonrpc", "ep1", "eth_sendRawTransaction", 5, outcome, &RelayMetrics{IsWrite: true})
}
require.Equal(t, float64(0), testutil.ToFloat64(m.endpointInFlight.WithLabelValues(cancelledTestLabels())))
require.Equal(t, float64(0), testutil.ToFloat64(m.endpointInFlight.WithLabelValues(cancelledTestLabels()...)))
}

// The customer-visible symptom: errored relays were almost all eth_sendRawTransaction.
Expand All @@ -45,9 +47,9 @@ func TestCancelledRelay_DoesNotCountAsErrored(t *testing.T) {
m.RecordDirectRelayEnd("ETH1", "jsonrpc", "ep1", "eth_sendRawTransaction", 5, RelayOutcomeCancelled, &RelayMetrics{IsWrite: true})
}

require.Equal(t, float64(0), testutil.ToFloat64(m.endpointTotalErrored.WithLabelValues(labels)))
require.Equal(t, float64(10), testutil.ToFloat64(m.endpointTotalCancelled.WithLabelValues(labels)))
require.Equal(t, float64(0), testutil.ToFloat64(m.endpointTotalRelaysServiced.WithLabelValues(labels)))
require.Equal(t, float64(0), testutil.ToFloat64(m.endpointTotalErrored.WithLabelValues(labels...)))
require.Equal(t, float64(10), testutil.ToFloat64(m.endpointTotalCancelled.WithLabelValues(labels...)))
require.Equal(t, float64(0), testutil.ToFloat64(m.endpointTotalRelaysServiced.WithLabelValues(labels...)))
}

// COLLATERAL GUARD: a real error must still be counted as errored. If this ever fails the
Expand All @@ -58,8 +60,8 @@ func TestErroredRelay_StillCountsAsErrored(t *testing.T) {

m.RecordDirectRelayEnd("ETH1", "jsonrpc", "ep1", "eth_sendRawTransaction", 5, RelayOutcomeError, &RelayMetrics{IsWrite: true})

require.Equal(t, float64(1), testutil.ToFloat64(m.endpointTotalErrored.WithLabelValues(labels)))
require.Equal(t, float64(0), testutil.ToFloat64(m.endpointTotalCancelled.WithLabelValues(labels)))
require.Equal(t, float64(1), testutil.ToFloat64(m.endpointTotalErrored.WithLabelValues(labels...)))
require.Equal(t, float64(0), testutil.ToFloat64(m.endpointTotalCancelled.WithLabelValues(labels...)))
}

// COLLATERAL GUARD: success accounting is untouched by the signature change.
Expand All @@ -70,8 +72,8 @@ func TestSuccessRelay_StillCountsAsServiced(t *testing.T) {

m.RecordDirectRelayEnd("ETH1", "jsonrpc", "ep1", "eth_sendRawTransaction", 5, RelayOutcomeSuccess, &RelayMetrics{IsWrite: true})

require.Equal(t, float64(1), testutil.ToFloat64(m.endpointTotalRelaysServiced.WithLabelValues(labels)))
require.Equal(t, float64(0), testutil.ToFloat64(m.endpointTotalErrored.WithLabelValues(labels)))
require.Equal(t, float64(1), testutil.ToFloat64(m.endpointTotalRelaysServiced.WithLabelValues(labels...)))
require.Equal(t, float64(0), testutil.ToFloat64(m.endpointTotalErrored.WithLabelValues(labels...)))
require.Equal(t, float64(1), testutil.ToFloat64(m.routerRequestsTotal.WithLabelValues(reqLabels...)))
require.Equal(t, float64(1), testutil.ToFloat64(m.routerRequestsSuccess.WithLabelValues(reqLabels...)))
require.Equal(t, float64(1), testutil.ToFloat64(m.routerRequestsWrite.WithLabelValues(reqLabels...)))
Expand Down Expand Up @@ -126,7 +128,7 @@ func TestCancelledRelay_StillNormalisesBatchLabel(t *testing.T) {
raw := "eth_call&eth_call&eth_getBalance"
m.RecordDirectRelayEnd("ETH1", "jsonrpc", "ep1", raw, 5, RelayOutcomeCancelled, &RelayMetrics{IsBatch: true})

collapsed := map[string]string{"spec": "ETH1", "apiInterface": "jsonrpc", "endpoint_id": "ep1", "function": "batch:eth_call+eth_getBalance"}
require.Equal(t, float64(1), testutil.ToFloat64(m.endpointTotalCancelled.WithLabelValues(collapsed)),
collapsed := []string{"ETH1", "jsonrpc", "ep1", "batch:eth_call+eth_getBalance"}
require.Equal(t, float64(1), testutil.ToFloat64(m.endpointTotalCancelled.WithLabelValues(collapsed...)),
"the cancelled path must collapse batch labels like every other recorder")
}
24 changes: 12 additions & 12 deletions protocol/metrics/endpoint_url_latest_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ func TestURLLatestBlock_OneSeriesPerURL(t *testing.T) {
m.SetEndpointURLLatestBlock("TON", "rest", tonV2URL, 1000, DefaultURLAnswerTimeout) // frozen, still answering
m.SetEndpointURLLatestBlock("TON", "rest", tonV3URL, v3, DefaultURLAnswerTimeout)
require.Equal(t, map[string]float64{"/v2": 1000, "/v3": float64(v3)},
byPath(t, urlPoints(t, m.endpointURLLatestBlock.GaugeVec, "TON", "chainstack")))
byPath(t, urlPoints(t, m.endpointURLLatestBlock, "TON", "chainstack")))
}
points := urlPoints(t, m.endpointURLLatestBlock.GaugeVec, "TON", "chainstack")
points := urlPoints(t, m.endpointURLLatestBlock, "TON", "chainstack")
require.NotEqual(t, points[0].url, points[1].url, "/v2 and /v3 share a host; the url label still tells them apart")
for _, p := range points {
require.Equal(t, map[string]string{"/v2": URLFingerprint(tonV2URL), "/v3": URLFingerprint(tonV3URL)}[p.internalPath], p.url)
}
require.Empty(t, urlPoints(t, m.endpointLatestBlock.GaugeVec, "TON", "chainstack"), "the provider series is written elsewhere")
require.Empty(t, urlPoints(t, m.endpointLatestBlock, "TON", "chainstack"), "the provider series is written elsewhere")
}

// Every write moves the url's answered-until time to now plus the answer timeout its caller
Expand All @@ -108,10 +108,10 @@ func TestURLLatestBlock_AnsweredUntilIsTheLastAnswerPlusTheTimeout(t *testing.T)
require.GreaterOrEqual(t, got, float64(before.Add(timeout).Unix()))
require.LessOrEqual(t, got, float64(after.Add(timeout).Unix()))
}
ton := byPath(t, urlPoints(t, m.endpointURLAnsweredUntil.GaugeVec, "TON", "chainstack"))
ton := byPath(t, urlPoints(t, m.endpointURLAnsweredUntil, "TON", "chainstack"))
within(ton["/v2"], 10*time.Minute)
within(ton["/v3"], 20*time.Minute)
within(byPath(t, urlPoints(t, m.endpointURLAnsweredUntil.GaugeVec, "ETH1", "solo"))[""], DefaultURLAnswerTimeout)
within(byPath(t, urlPoints(t, m.endpointURLAnsweredUntil, "ETH1", "solo"))[""], DefaultURLAnswerTimeout)
}

// A shared url is one series per provider configured with it; the relay harvest moves only the
Expand All @@ -122,8 +122,8 @@ func TestURLLatestBlock_SharedURLIsASeriesPerProvider(t *testing.T) {
m.SetEndpointURLLatestBlock("TON", "rest", tonV2URL, 1000, DefaultURLAnswerTimeout)
m.SetProviderURLLatestBlock("TON", "rest", "chainstack", tonV2URL, 1001, DefaultURLAnswerTimeout)

require.Equal(t, map[string]float64{"/v2": 1001}, byPath(t, urlPoints(t, m.endpointURLLatestBlock.GaugeVec, "TON", "chainstack")))
require.Equal(t, map[string]float64{"/v2": 1000}, byPath(t, urlPoints(t, m.endpointURLLatestBlock.GaugeVec, "TON", "chainstack-backup")))
require.Equal(t, map[string]float64{"/v2": 1001}, byPath(t, urlPoints(t, m.endpointURLLatestBlock, "TON", "chainstack")))
require.Equal(t, map[string]float64{"/v2": 1000}, byPath(t, urlPoints(t, m.endpointURLLatestBlock, "TON", "chainstack-backup")))
}

// An unregistered url would name itself as its provider, and no part of a url is safe to export.
Expand All @@ -133,7 +133,7 @@ func TestURLLatestBlock_UnregisteredURLGetsNoSeries(t *testing.T) {
m.SetEndpointURLLatestBlock("ETH1", "jsonrpc", url, 10, DefaultURLAnswerTimeout)
m.SetProviderURLLatestBlock("ETH1", "jsonrpc", "p", url, 10, DefaultURLAnswerTimeout)
m.AddEndpointURLRelayServiced("ETH1", "jsonrpc", "p", url)
for _, c := range []prometheus.Collector{m.endpointURLLatestBlock.GaugeVec, m.endpointURLAnsweredUntil.GaugeVec, m.endpointURLRelaysServiced.CounterVec} {
for _, c := range []prometheus.Collector{m.endpointURLLatestBlock, m.endpointURLAnsweredUntil, m.endpointURLRelaysServiced} {
ch := make(chan prometheus.Metric, 4)
c.Collect(ch)
close(ch)
Expand All @@ -148,7 +148,7 @@ func TestURLRelaysServiced_CountsPerURL(t *testing.T) {
m.AddEndpointURLRelayServiced("TON", "rest", "chainstack", tonV2URL)
}
m.AddEndpointURLRelayServiced("TON", "rest", "chainstack", tonV3URL)
require.Equal(t, map[string]float64{"/v2": 3, "/v3": 1}, byPath(t, urlPoints(t, m.endpointURLRelaysServiced.CounterVec, "TON", "chainstack")))
require.Equal(t, map[string]float64{"/v2": 3, "/v3": 1}, byPath(t, urlPoints(t, m.endpointURLRelaysServiced, "TON", "chainstack")))
}

// A removed url loses every per-url series, and nothing else: a series left behind stands still
Expand All @@ -161,9 +161,9 @@ func TestURLLatestBlock_ForgetDeletesTheURLsSeries(t *testing.T) {
m.AddEndpointURLRelayServiced("TON", "rest", "chainstack", tonV3URL)

m.ForgetEndpointURLLatestBlock("TON", "rest", tonV2URL)
require.Equal(t, map[string]float64{"/v3": 1200}, byPath(t, urlPoints(t, m.endpointURLLatestBlock.GaugeVec, "TON", "chainstack")))
require.Len(t, urlPoints(t, m.endpointURLAnsweredUntil.GaugeVec, "TON", "chainstack"), 1)
require.Equal(t, map[string]float64{"/v3": 1}, byPath(t, urlPoints(t, m.endpointURLRelaysServiced.CounterVec, "TON", "chainstack")))
require.Equal(t, map[string]float64{"/v3": 1200}, byPath(t, urlPoints(t, m.endpointURLLatestBlock, "TON", "chainstack")))
require.Len(t, urlPoints(t, m.endpointURLAnsweredUntil, "TON", "chainstack"), 1)
require.Equal(t, map[string]float64{"/v3": 1}, byPath(t, urlPoints(t, m.endpointURLRelaysServiced, "TON", "chainstack")))

m.ForgetEndpointURLLatestBlock("TON", "rest", "https://never.registered.example")
var nilManager *SmartRouterMetricsManager
Expand Down
47 changes: 0 additions & 47 deletions protocol/metrics/mapped_labels_counter_vec.go

This file was deleted.

47 changes: 0 additions & 47 deletions protocol/metrics/mapped_labels_gauge_vec.go

This file was deleted.

22 changes: 0 additions & 22 deletions protocol/metrics/mapped_labels_metric_common.go

This file was deleted.

97 changes: 0 additions & 97 deletions protocol/metrics/mapped_labels_registerer_test.go

This file was deleted.

Loading