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 missed blocks metric #1

Merged
merged 14 commits into from
Dec 21, 2023
Merged

Conversation

kayano
Copy link
Contributor

@kayano kayano commented Dec 19, 2023

PR adds:

  • first metric - cosmos_validator_missed_blocks
# HELP cosmos_validator_missed_blocks Returns missed blocks for a validator.
# TYPE cosmos_validator_missed_blocks gauge
cosmos_validator_missed_blocks{moniker="validator_1",valcons="archwayvalcons18le5pevj6sdynyksn77n9z9g8394l3xqk04s3z",valoper="archwayvaloper172zqrqtrwfplwhec44050dhuv66ekcmty4hnfv"} 0
cosmos_validator_missed_blocks{moniker="validator_2",valcons="archwayvalcons1z4q9zpe8l8puwv8aq4dqadkz4zm244pnu72qcd",valoper="archwayvaloper1370vgzkv5l3kylcylwekzjcdt2hjk2k8zrht6c"} 0
cosmos_validator_missed_blocks{moniker="validator_3",valcons="archwayvalcons1ep8hnygqw8gvsdfvyanhcfsmvlrvae4s9hljta",valoper="archwayvaloper1scxt3mgxmw3z2hpf8k4mlssz5qvljmtaplv6nz"} 2
  • CI pipelines

@kayano kayano marked this pull request as draft December 19, 2023 22:32
@kayano kayano marked this pull request as ready for review December 20, 2023 09:41
pkg/collector/collector.go Outdated Show resolved Hide resolved
pkg/grpc/grpc.go Outdated Show resolved Hide resolved
pkg/grpc/grpc.go Outdated
}

if slashRes == nil {
return nil, fmt.Errorf("got empty response from signing infos endpoint")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you should use static wrapped errors and not dynamic ones in pkg/libraries.
It makes the logging/debugging a lot easier, example:
https://github.com/archway-network/discord-alertmanager/blob/main/pkg/discordbot/discordbot.go#L122-L126

This applies to all the packages that are returning errors

pkg/grpc/grpc.go Outdated Show resolved Hide resolved
pkg/grpc/grpc.go Outdated Show resolved Hide resolved
pkg/logger/logger.go Show resolved Hide resolved
pkg/logger/logger.go Show resolved Hide resolved
)

func main() {
port := flag.Int("p", 8008, "Server port")
Copy link
Contributor

Choose a reason for hiding this comment

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

8008 should be const


addr := fmt.Sprintf(":%d", *port)
log.Info(fmt.Sprintf("Starting server on addr: %s", addr))
log.Fatal(http.ListenAndServe(addr, nil).Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

I would change this so that it's possible to have timeouts on the server end for security reasons:

server := &http.Server{
        Addr:              ":port",
        ReadHeaderTimeout: 10 * time.Second,
    }

    if err := server.ListenAndServe(); err != nil {
        log.Fatal(err)
    }

pkg/config/config.go Show resolved Hide resolved
pkg/grpc/grpc.go Outdated Show resolved Hide resolved
cmd/validator-exporter/main.go Outdated Show resolved Hide resolved
kayano and others added 7 commits December 20, 2023 16:11
Co-authored-by: Joonas Lehtimäki <joonas.lehtimaki@gmail.com>
Co-authored-by: Joonas Lehtimäki <joonas.lehtimaki@gmail.com>
Co-authored-by: Joonas Lehtimäki <joonas.lehtimaki@gmail.com>
Copy link
Contributor

@jlehtimaki jlehtimaki left a comment

Choose a reason for hiding this comment

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

Take a look at the grpc errors, I think they all should be wrapped

grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.NewProtoCodec(nil).GRPCCodec())),
)

return conn, err
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd go with wrapped errors here as well

pkg/grpc/grpc.go Outdated

conn, err := cfg.GRPCConn()
if err != nil {
return Client{}, err
Copy link
Contributor

Choose a reason for hiding this comment

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

wrapped error

pkg/grpc/grpc.go Outdated

const valConsStr = "valcons"

var errEndpoint = errors.New("grpc endpoint error")
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd name it based on the package, so just grpc error , the extra information then will be appended

pkg/grpc/grpc.go Outdated
client.conn = conn
client.connClose = func() {
if err := conn.Close(); err != nil {
log.Error(fmt.Sprintf("failed to close connection :%s", err))
Copy link
Contributor

Choose a reason for hiding this comment

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

wrapped error

pkg/grpc/grpc.go Outdated

slashRes, err := client.SigningInfos(ctx, request)
if err != nil {
return nil, err
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nil, err
return nil, endpointError(err.Error())

pkg/grpc/grpc.go Outdated
func SigningValidators(ctx context.Context, cfg config.Config) ([]types.Validator, error) {
sVals := []types.Validator{}

func SigningValidators(ctx context.Context, cfg config.Config) (sVals []types.Validator, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func SigningValidators(ctx context.Context, cfg config.Config) (sVals []types.Validator, err error) {
func SigningValidators(ctx context.Context, cfg config.Config) ([]types.Validator, error) {

pkg/grpc/grpc.go Outdated
Comment on lines 166 to 168
err = endpointError(fmt.Errorf("%w: %s", err, tempErr).Error())
} else {
err = endpointError(tempErr.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

Convert these to fmt.Errorf statements and in the line 30 call the endpointError(err) ?

pkg/grpc/grpc.go Outdated
@@ -205,27 +206,36 @@ func SigningValidators(ctx context.Context, cfg config.Config) ([]types.Validato
return sVals, nil
}

func LatestBlockHeight(ctx context.Context, cfg config.Config) (int64, error) {
func LatestBlockHeight(ctx context.Context, cfg config.Config) (height int64, err error) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
func LatestBlockHeight(ctx context.Context, cfg config.Config) (height int64, err error) {
func LatestBlockHeight(ctx context.Context, cfg config.Config) (int64, error) {

pkg/grpc/grpc.go Outdated
Comment on lines 223 to 227
if tempErr := client.conn.Close(); tempErr != nil {
if err != nil {
err = endpointError(fmt.Errorf("%w: %s", err, tempErr).Error())
} else {
err = endpointError(tempErr.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

See previous comment

@kayano kayano merged commit 3ca0ef4 into main Dec 21, 2023
3 checks passed
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