-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
pkg/grpc/grpc.go
Outdated
} | ||
|
||
if slashRes == nil { | ||
return nil, fmt.Errorf("got empty response from signing infos endpoint") |
There was a problem hiding this comment.
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
cmd/validator-exporter/main.go
Outdated
) | ||
|
||
func main() { | ||
port := flag.Int("p", 8008, "Server port") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
8008
should be const
cmd/validator-exporter/main.go
Outdated
|
||
addr := fmt.Sprintf(":%d", *port) | ||
log.Info(fmt.Sprintf("Starting server on addr: %s", addr)) | ||
log.Fatal(http.ListenAndServe(addr, nil).Error()) |
There was a problem hiding this comment.
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)
}
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>
There was a problem hiding this 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
pkg/config/config.go
Outdated
grpc.WithDefaultCallOptions(grpc.ForceCodec(codec.NewProtoCodec(nil).GRPCCodec())), | ||
) | ||
|
||
return conn, err |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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)) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
err = endpointError(fmt.Errorf("%w: %s", err, tempErr).Error()) | ||
} else { | ||
err = endpointError(tempErr.Error()) |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
if tempErr := client.conn.Close(); tempErr != nil { | ||
if err != nil { | ||
err = endpointError(fmt.Errorf("%w: %s", err, tempErr).Error()) | ||
} else { | ||
err = endpointError(tempErr.Error()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See previous comment
PR adds:
cosmos_validator_missed_blocks