Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add babylon-related metrics #158

Merged
merged 7 commits into from
Mar 2, 2023
Merged

feat: Add babylon-related metrics #158

merged 7 commits into from
Mar 2, 2023

Conversation

gitferry
Copy link
Collaborator

This PR adds Babylon-related metrics for monitoring purposes. The metrics and alarming rules are described as follows. cc @philmln.

  • reporter
    • "vigilante_reporter_reported_headers", "The total number of reported BTC headers to Babylon"
    • "vigilante_reporter_reported_checkpoints", "The total number of reported BTC checkpoints to Babylon"
    • "vigilante_reporter_failed_headers", "The total number of failed BTC headers to Babylon", should alarm when this metric > 0
    • "vigilante_reporter_failed_checkpoints", "The total number of failed BTC checkpoints to Babylon", should alarm when this metric > 0
    • "vigilante_reporter_since_last_header_seconds", "Seconds since the last successful reported BTC checkpoint to Babylon", should alarm when this metric > X
    • "vigilante_reporter_since_last_submission_seconds", "Seconds since the last successful reported BTC checkpoint to Babylon", should alarm when this metric > X
  • submitter
    • "vigilante_submitter_submitted_checkpoints", "The total number of submitted checkpoints to BTC"
    • "vigilante_submitter_failed_checkpoints", "The total number of failed checkpoints to BTC", should alarm when this metric > 0
    • "vigilante_submitter_since_last_checkpoint_seconds", "Seconds since the last successfully submitted checkpoint", should alarm when this metric > X
  • monitor
    • "vigilante_monitor_valid_epochs", "The total number of verified epochs"
    • "vigilante_monitor_invalid_epochs", "The total number of invalid epochs", should alarm when this metric > 0
    • "vigilante_monitor_valid_btc_headers", "The total number of valid BTC headers"
    • "vigilante_monitor_invalid_epochs", "The total number of invalid BTC headers", should alarm when this metric > 0
    • "vigilante_monitor_liveness_attacks", "The total number of detected liveness attacks", should alarm when this metric > 0

Copy link
Member

@vitsalis vitsalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Those are all very useful metrics.

Note that we should not alarm when the number of failed checkpoints submitted to Babylon surpasses 0. One can insert a bad checkpoint on purpose.

Copy link
Member

@SebastianElvis SebastianElvis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a great improvement! Just some minor comments

Registry: registry,
ValidEpochsCounter: registerer.NewCounter(prometheus.CounterOpts{
Name: "vigilante_monitor_valid_epochs",
Help: "The total number of verified epochs",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Help: "The total number of verified epochs",
Help: "The total number of valid epochs",

Name: "vigilante_monitor_invalid_epochs",
Help: "The total number of invalid BTC headers",
}),
LivenessAttacksCounter: registerer.NewCounter(prometheus.CounterOpts{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the monitor will just panick upon a liveness attack, do we need this metrics?

Copy link
Collaborator Author

@gitferry gitferry Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't want to panic the monitor or the validator but send an alert instead and let the operator decide how to deal with this.

Comment on lines +10 to +14
ValidEpochsCounter prometheus.Counter
InvalidEpochsCounter prometheus.Counter
ValidBTCHeadersCounter prometheus.Counter
InvalidBTCHeadersCounter prometheus.Counter
LivenessAttacksCounter prometheus.Counter
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be pointers or objects?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are interfaces, so it depends on whether the actual values are pointers or objects.

Comment on lines +12 to +17
SuccessfulHeadersCounter prometheus.Counter
SuccessfulCheckpointsCounter prometheus.Counter
FailedHeadersCounter prometheus.Counter
FailedCheckpointsCounter prometheus.Counter
SecondsSinceLastHeaderGauge prometheus.Gauge
SecondsSinceLastCheckpointGauge prometheus.Gauge
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question here

Comment on lines +12 to +14
SuccessfulCheckpointsCounter prometheus.Counter
FailedCheckpointsCounter prometheus.Counter
SecondsSinceLastCheckpointGauge prometheus.Gauge
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same ques here

func (sm *ReporterMetrics) RecordMetrics() {
go func() {
for {
time.Sleep(1 * time.Second)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use ticker here

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how to use ticker here. Btw, why can't we use sleep here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It basically achieves the same functionality as sleeping here, but a more formal way.
Something like below

	ticker := time.NewTicker(1 * time.Second)
	for range ticker.C {
    	// do our stuff
   	}

You can find multiple usages of this in vigilante repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see. It's good to know. Thanks a lot!

Comment on lines +59 to +60
sm.SecondsSinceLastHeaderGauge.Inc()
sm.SecondsSinceLastCheckpointGauge.Inc()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that the two gauges will never decrease, maybe they can be counters?

Copy link
Collaborator Author

@gitferry gitferry Mar 1, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They will be reset when the last header/checkpoint is successfully sent. For example, see this

@gitferry gitferry merged commit 8b2b0df into dev Mar 2, 2023
@gitferry gitferry deleted the add-babylon-metrics branch March 2, 2023 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants