Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
6096d317
Unverified
Commit
6096d317
authored
Mar 06, 2024
by
refcell
Committed by
GitHub
Mar 06, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat(op-dispute-mon): output fetch time metric (#9744)
parent
5928a728
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
11 deletions
+47
-11
metrics.go
op-dispute-mon/metrics/metrics.go
+13
-0
noop.go
op-dispute-mon/metrics/noop.go
+2
-0
service.go
op-dispute-mon/mon/service.go
+1
-1
validator.go
op-dispute-mon/mon/validator.go
+11
-3
validator_test.go
op-dispute-mon/mon/validator_test.go
+20
-7
No files found.
op-dispute-mon/metrics/metrics.go
View file @
6096d317
...
...
@@ -38,6 +38,8 @@ type Metricer interface {
RecordClaimResolutionDelayMax
(
delay
float64
)
RecordOutputFetchTime
(
timestamp
float64
)
RecordGamesStatus
(
inProgress
,
defenderWon
,
challengerWon
int
)
RecordGameAgreement
(
status
GameAgreementStatus
,
count
int
)
...
...
@@ -57,6 +59,8 @@ type Metrics struct {
info
prometheus
.
GaugeVec
up
prometheus
.
Gauge
lastOutputFetch
prometheus
.
Gauge
claimResolutionDelayMax
prometheus
.
Gauge
trackedGames
prometheus
.
GaugeVec
...
...
@@ -92,6 +96,11 @@ func NewMetrics() *Metrics {
Name
:
"up"
,
Help
:
"1 if the op-challenger has finished starting up"
,
}),
lastOutputFetch
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
Namespace
,
Name
:
"last_output_fetch"
,
Help
:
"Timestamp of the last output fetch"
,
}),
claimResolutionDelayMax
:
factory
.
NewGauge
(
prometheus
.
GaugeOpts
{
Namespace
:
Namespace
,
Name
:
"claim_resolution_delay_max"
,
...
...
@@ -155,6 +164,10 @@ func (m *Metrics) RecordGamesStatus(inProgress, defenderWon, challengerWon int)
m
.
trackedGames
.
WithLabelValues
(
"challenger_won"
)
.
Set
(
float64
(
challengerWon
))
}
func
(
m
*
Metrics
)
RecordOutputFetchTime
(
timestamp
float64
)
{
m
.
lastOutputFetch
.
Set
(
timestamp
)
}
func
(
m
*
Metrics
)
RecordGameAgreement
(
status
GameAgreementStatus
,
count
int
)
{
m
.
gamesAgreement
.
WithLabelValues
(
labelValuesFor
(
status
)
...
)
.
Set
(
float64
(
count
))
}
...
...
op-dispute-mon/metrics/noop.go
View file @
6096d317
...
...
@@ -12,5 +12,7 @@ func (*NoopMetricsImpl) CacheGet(_ string, _ bool) {}
func
(
*
NoopMetricsImpl
)
RecordClaimResolutionDelayMax
(
delay
float64
)
{}
func
(
*
NoopMetricsImpl
)
RecordOutputFetchTime
(
timestamp
float64
)
{}
func
(
*
NoopMetricsImpl
)
RecordGamesStatus
(
inProgress
,
defenderWon
,
challengerWon
int
)
{}
func
(
*
NoopMetricsImpl
)
RecordGameAgreement
(
status
GameAgreementStatus
,
count
int
)
{}
op-dispute-mon/mon/service.go
View file @
6096d317
...
...
@@ -100,7 +100,7 @@ func (s *Service) initFromConfig(ctx context.Context, cfg *config.Config) error
}
func
(
s
*
Service
)
initOutputValidator
()
{
s
.
validator
=
newOutputValidator
(
s
.
rollupClient
)
s
.
validator
=
newOutputValidator
(
s
.
metrics
,
s
.
rollupClient
)
}
func
(
s
*
Service
)
initGameCallerCreator
()
{
...
...
op-dispute-mon/mon/validator.go
View file @
6096d317
...
...
@@ -4,6 +4,7 @@ import (
"context"
"fmt"
"strings"
"time"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -14,13 +15,19 @@ type OutputRollupClient interface {
OutputAtBlock
(
ctx
context
.
Context
,
blockNum
uint64
)
(
*
eth
.
OutputResponse
,
error
)
}
type
OutputMetrics
interface
{
RecordOutputFetchTime
(
float64
)
}
type
outputValidator
struct
{
client
OutputRollupClient
metrics
OutputMetrics
client
OutputRollupClient
}
func
newOutputValidator
(
client
OutputRollupClient
)
*
outputValidator
{
func
newOutputValidator
(
metrics
OutputMetrics
,
client
OutputRollupClient
)
*
outputValidator
{
return
&
outputValidator
{
client
:
client
,
metrics
:
metrics
,
client
:
client
,
}
}
...
...
@@ -35,6 +42,7 @@ func (o *outputValidator) CheckRootAgreement(ctx context.Context, blockNum uint6
}
return
false
,
common
.
Hash
{},
fmt
.
Errorf
(
"failed to get output at block: %w"
,
err
)
}
o
.
metrics
.
RecordOutputFetchTime
(
float64
(
time
.
Now
()
.
Unix
()))
expected
:=
common
.
Hash
(
output
.
OutputRoot
)
return
rootClaim
==
expected
,
expected
,
nil
}
op-dispute-mon/mon/validator_test.go
View file @
6096d317
...
...
@@ -18,45 +18,58 @@ func TestDetector_CheckRootAgreement(t *testing.T) {
t
.
Parallel
()
t
.
Run
(
"OutputFetchFails"
,
func
(
t
*
testing
.
T
)
{
validator
,
rollup
:=
setupOutputValidatorTest
(
t
)
validator
,
rollup
,
metrics
:=
setupOutputValidatorTest
(
t
)
rollup
.
err
=
errors
.
New
(
"boom"
)
agree
,
fetched
,
err
:=
validator
.
CheckRootAgreement
(
context
.
Background
(),
0
,
mockRootClaim
)
require
.
ErrorIs
(
t
,
err
,
rollup
.
err
)
require
.
Equal
(
t
,
common
.
Hash
{},
fetched
)
require
.
False
(
t
,
agree
)
require
.
Zero
(
t
,
metrics
.
fetchTime
)
})
t
.
Run
(
"OutputMismatch"
,
func
(
t
*
testing
.
T
)
{
validator
,
_
:=
setupOutputValidatorTest
(
t
)
validator
,
_
,
metrics
:=
setupOutputValidatorTest
(
t
)
agree
,
fetched
,
err
:=
validator
.
CheckRootAgreement
(
context
.
Background
(),
0
,
common
.
Hash
{})
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
mockRootClaim
,
fetched
)
require
.
False
(
t
,
agree
)
require
.
NotZero
(
t
,
metrics
.
fetchTime
)
})
t
.
Run
(
"OutputMatches"
,
func
(
t
*
testing
.
T
)
{
validator
,
_
:=
setupOutputValidatorTest
(
t
)
validator
,
_
,
metrics
:=
setupOutputValidatorTest
(
t
)
agree
,
fetched
,
err
:=
validator
.
CheckRootAgreement
(
context
.
Background
(),
0
,
mockRootClaim
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
mockRootClaim
,
fetched
)
require
.
True
(
t
,
agree
)
require
.
NotZero
(
t
,
metrics
.
fetchTime
)
})
t
.
Run
(
"OutputNotFound"
,
func
(
t
*
testing
.
T
)
{
validator
,
rollup
:=
setupOutputValidatorTest
(
t
)
validator
,
rollup
,
metrics
:=
setupOutputValidatorTest
(
t
)
// This crazy error is what we actually get back from the API
rollup
.
err
=
errors
.
New
(
"failed to get L2 block ref with sync status: failed to determine L2BlockRef of height 42984924, could not get payload: not found"
)
agree
,
fetched
,
err
:=
validator
.
CheckRootAgreement
(
context
.
Background
(),
42984924
,
mockRootClaim
)
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
common
.
Hash
{},
fetched
)
require
.
False
(
t
,
agree
)
require
.
Zero
(
t
,
metrics
.
fetchTime
)
})
}
func
setupOutputValidatorTest
(
t
*
testing
.
T
)
(
*
outputValidator
,
*
stubRollupClient
)
{
func
setupOutputValidatorTest
(
t
*
testing
.
T
)
(
*
outputValidator
,
*
stubRollupClient
,
*
stubOutputMetrics
)
{
client
:=
&
stubRollupClient
{}
validator
:=
newOutputValidator
(
client
)
return
validator
,
client
metrics
:=
&
stubOutputMetrics
{}
validator
:=
newOutputValidator
(
metrics
,
client
)
return
validator
,
client
,
metrics
}
type
stubOutputMetrics
struct
{
fetchTime
float64
}
func
(
s
*
stubOutputMetrics
)
RecordOutputFetchTime
(
fetchTime
float64
)
{
s
.
fetchTime
=
fetchTime
}
type
stubRollupClient
struct
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment