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

Unify client metrics with other metrics approach #245

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

Bez625
Copy link
Collaborator

@Bez625 Bez625 commented Aug 28, 2024

No description provided.

@Bez625 Bez625 marked this pull request as ready for review August 28, 2024 15:57
@Bez625 Bez625 requested a review from mcdee September 1, 2024 10:23
@mcdee
Copy link
Contributor

mcdee commented Sep 22, 2024

Not sure about this one. This change hardcodes the prometheus metrics instance through the import

clientprometheus "github.com/attestantio/vouch/services/metrics/prometheus"

So we lose the flexibility of having other styles of metrics in the future. I'll have a bit more of a think about it, but I'm inclined to keep the client monitor interface and instantiate as we do at the moment.

@Bez625
Copy link
Collaborator Author

Bez625 commented Sep 23, 2024

Not sure about this one. This change hardcodes the prometheus metrics instance through the import

clientprometheus "github.com/attestantio/vouch/services/metrics/prometheus"

So we lose the flexibility of having other styles of metrics in the future. I'll have a bit more of a think about it, but I'm inclined to keep the client monitor interface and instantiate as we do at the moment.

I understand the point about flexibility, but we have moved to the prometheus client being hardcoded for all of the other metrics following the pattern in https://github.com/attestantio/vouch/blob/master/services/beaconblockproposer/standard/metrics.go.

It feels inconsistent to have the two different ways of working with metrics - is there a reason we would want the flexibility on client/strategy metrics alone and have the others follow the hard coded approach?

i had a think and the only way I can see for us to get flexibility without having a massive interface, or a collection of small interfaces all implemented by one struct, is to have a small generic interface like:

type Metrics interface {
    Observe(ctx context.Context, metricName string, startTime float64)
    SetGauge(ctx context.Context, metricName string, value float64)
    Inc(ctx context.Context, metricName string, labels ...string)
}

And this could be used in a similar way to now:

// monitorBeaconBlockProposalCompleted is called when a block proposal process has completed.
func (s *Service) monitorBeaconBlockProposalCompleted(ctx context.Context, started time.Time, slot phase0.Slot, startOfSlot time.Time, result string) {
    // Only log times for successful completions.
    if result == "succeeded" {
        s.Metrics.Observe(ctx, "vouch_beaconblockproposal_process_duration_seconds", time.Since(started).Seconds())
        secsSinceStartOfSlot := time.Since(startOfSlot).Seconds()
        s.Metrics.Observe(ctx, "vouch_beaconblockproposal_mark_seconds", secsSinceStartOfSlot)
        s.Metrics.SetGauge(ctx, "vouch_beaconblockproposal_process_latest_slot", float64(slot))
    }
    s.Metrics.Inc(ctx, "vouch_beaconblockproposal_process_requests_total", result)
}

Obviously we would need to perform some kind of metrics lookup in the implementation of the interface, which could introduce a risk of runtime failures to find the metrics. There is also the risk that the interface may not have appropriate params for a future metrics client, but it might give us a way to keep flexibility without having large interfaces.

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.

2 participants