Skip to content
This repository was archived by the owner on Sep 23, 2024. It is now read-only.

Commit

Permalink
Add health endpoint (#99)
Browse files Browse the repository at this point in the history
* Use cdk-rpc
* Health endpoint
  • Loading branch information
vcastellm authored Mar 7, 2024
1 parent 75ab7ef commit e943599
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 16 deletions.
23 changes: 22 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"os/signal"
"time"

jRPC "github.com/0xPolygon/cdk-data-availability/rpc"
jRPC "github.com/0xPolygon/cdk-rpc/rpc"
dbConf "github.com/0xPolygonHermez/zkevm-node/db"
"github.com/0xPolygonHermez/zkevm-node/ethtxmanager"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
Expand Down Expand Up @@ -161,6 +161,7 @@ func start(cliCtx *cli.Context) error {
Service: rpc.NewInteropEndpoints(log.WithFields("module", "rpc"), executor, storage, c),
},
},
jRPC.WithHealthHandler(http.HandlerFunc(healthHandler(storage))),
)

// Run RPC
Expand Down Expand Up @@ -302,3 +303,23 @@ func useLocalAuth(c *config.Config) (*bind.TransactOpts, common.Address, error)

return auth, addr, nil
}

// healthHandler returns a handler that checks the health of the application
func healthHandler(storage *db.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
txctx := context.Background()
dbtx, err := storage.BeginStateTransaction(txctx)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}

if err = dbtx.Rollback(txctx); err != nil {
w.WriteHeader(http.StatusInternalServerError)
return
}

_, _ = w.Write([]byte("Healthy"))
w.WriteHeader(http.StatusOK)
}
}
2 changes: 1 addition & 1 deletion config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"strings"

"github.com/0xPolygon/agglayer/log"
jRPC "github.com/0xPolygon/cdk-data-availability/rpc"
jRPC "github.com/0xPolygon/cdk-rpc/rpc"
"github.com/0xPolygonHermez/zkevm-node/config/types"
"github.com/0xPolygonHermez/zkevm-node/db"
"github.com/0xPolygonHermez/zkevm-node/ethtxmanager"
Expand Down
2 changes: 1 addition & 1 deletion docker/data/agglayer/agglayer.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
{Path = "/pk/agglayer.keystore", Password = "testonly"},
]
GasOffset = 100000
KMSKeyName = "gcp/resource/id"
KMSKeyName = ""
KMSConnectionTimeout = "30s"

[L1]
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ services:
agglayer-db:
condition: service_healthy
ports:
- '8444:8444'
- '4444:4444'
- '2223:2223'
volumes:
- ./data/agglayer/agglayer.keystore:/pk/agglayer.keystore
Expand Down
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
module github.com/0xPolygon/agglayer

go 1.21
go 1.21.3

require (
cloud.google.com/go/kms v1.15.7
github.com/0xPolygon/cdk-data-availability v0.0.5
github.com/0xPolygon/cdk-rpc v0.0.0-20240305171901-8dbb68fe396a
github.com/0xPolygonHermez/zkevm-node v0.0.0-20240222104536-0204affc7436
github.com/ethereum/go-ethereum v1.13.11
github.com/hermeznetwork/tracerr v0.3.2
Expand Down Expand Up @@ -108,7 +108,6 @@ require (
github.com/markbates/oncer v1.0.0 // indirect
github.com/markbates/safe v1.0.1 // indirect
github.com/mattn/go-runewidth v0.0.13 // indirect
github.com/miguelmota/go-solidity-sha3 v0.1.1 // indirect
github.com/mmcloughlin/addchain v0.4.0 // indirect
github.com/olekukonko/tablewriter v0.0.5 // indirect
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
Expand Down
8 changes: 2 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX
cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0=
collectd.org v0.3.0/go.mod h1:A/8DzQBkF6abtvrT2j/AU/4tiBgJWYyh0y/oB/4MlWE=
dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU=
github.com/0xPolygon/cdk-data-availability v0.0.5 h1://vg1oR/5tw2XfEIorpP+wIxLfNUmoKrdmX8YZvBKX4=
github.com/0xPolygon/cdk-data-availability v0.0.5/go.mod h1:aGwqHiJhL+mJbdepl3s58wsY18EuViDa9vZCpPuIYGw=
github.com/0xPolygon/cdk-rpc v0.0.0-20240305171901-8dbb68fe396a h1:bu2Dh0q7vNkj8I2FhOdxVTp6HL1TmUKjARizKK5ZS6k=
github.com/0xPolygon/cdk-rpc v0.0.0-20240305171901-8dbb68fe396a/go.mod h1:2scWqMMufrQXu7TikDgQ3BsyaKoX8qP26D6E262vSOg=
github.com/0xPolygonHermez/zkevm-data-streamer v0.1.19 h1:wRFA6uF0sqihWKaxKsk+hEkxcQeOU1eKhVzZy90otZ8=
github.com/0xPolygonHermez/zkevm-data-streamer v0.1.19/go.mod h1:0QkAXcFa92mFJrCbN3UPUJGJYes851yEgYHLONnaosE=
github.com/0xPolygonHermez/zkevm-node v0.0.0-20240222104536-0204affc7436 h1:7VzMlnx+SHXkkoKUIIMuJ2pcby4ngVF8vmEtlSuAZRk=
Expand All @@ -85,8 +85,6 @@ github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym
github.com/CloudyKit/fastprinter v0.0.0-20200109182630-33d98a066a53/go.mod h1:+3IMCy2vIlbG1XG/0ggNQv0SvxCAIpPM5b1nCz56Xno=
github.com/CloudyKit/jet/v3 v3.0.0/go.mod h1:HKQPgSJmdK8hdoAbKUUWajkHyHo4RaU5rMdUywE7VMo=
github.com/DATA-DOG/go-sqlmock v1.3.3/go.mod h1:f/Ixk793poVmq4qj/V1dPUg2JEAKC73Q5eFN3EC/SaM=
github.com/DATA-DOG/go-sqlmock v1.5.1 h1:FK6RCIUSfmbnI/imIICmboyQBkOckutaa6R5YYlLZyo=
github.com/DATA-DOG/go-sqlmock v1.5.1/go.mod h1:88MAG/4G7SMwSE3CeA0ZKzrT5CiOU3OJ+JlNzwDqpNU=
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
Expand Down Expand Up @@ -729,8 +727,6 @@ github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5
github.com/mediocregopher/radix/v3 v3.4.2/go.mod h1:8FL3F6UQRXHXIBSPUs5h0RybMF8i4n7wVopoX3x7Bv8=
github.com/microcosm-cc/bluemonday v1.0.2/go.mod h1:iVP4YcDBq+n/5fb23BhYFvIMq/leAFZyRl6bYmGDlGc=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
github.com/miguelmota/go-solidity-sha3 v0.1.1 h1:3Y08sKZDtudtE5kbTBPC9RYJznoSYyWI9VD6mghU0CA=
github.com/miguelmota/go-solidity-sha3 v0.1.1/go.mod h1:sax1FvQF+f71j8W1uUHMZn8NxKyl5rYLks2nqj8RFEw=
github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
Expand Down
2 changes: 1 addition & 1 deletion interop/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"go.uber.org/zap"

"github.com/0xPolygon/agglayer/log"
jRPC "github.com/0xPolygon/cdk-data-availability/rpc"
jRPC "github.com/0xPolygon/cdk-rpc/rpc"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/client"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
Expand Down
2 changes: 1 addition & 1 deletion interop/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"testing"

"github.com/0xPolygon/agglayer/log"
jRPC "github.com/0xPolygon/cdk-data-availability/rpc"
jRPC "github.com/0xPolygon/cdk-rpc/rpc"
"github.com/0xPolygonHermez/zkevm-node/ethtxmanager"
rpctypes "github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
"github.com/ethereum/go-ethereum/common"
Expand Down
2 changes: 1 addition & 1 deletion rpc/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"fmt"

"github.com/0xPolygon/agglayer/log"
jRPC "github.com/0xPolygon/cdk-data-availability/rpc"
jRPC "github.com/0xPolygon/cdk-rpc/rpc"
"github.com/ethereum/go-ethereum/common"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
Expand Down

0 comments on commit e943599

Please sign in to comment.