From 5d7b0710a66cb62315c3a8f48a7a71764ca54388 Mon Sep 17 00:00:00 2001 From: mattverse Date: Tue, 28 Nov 2023 13:17:11 +0900 Subject: [PATCH 01/19] Add initial struct --- .../delivery/http/system_http_handler.go | 71 ++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index da5def14ad2..6ab013bb4c3 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -1,17 +1,86 @@ package http import ( + "fmt" "net/http" _ "net/http/pprof" + "os" + + "go.uber.org/zap" + + "github.com/go-redis/redis" + + "github.com/osmosis-labs/osmosis/v20/ingest/sqs/log" "github.com/labstack/echo" ) +type SystemHandler struct { + logger log.Logger + host string // Host for the GRPC gateway + grpcPort string // GRPC gateway port + redisHost string // Redis host + redisPort string // Redis port +} + // NewSystemHandler will initialize the /debug/ppof resources endpoint -func NewSystemHandler(e *echo.Echo) { +func NewSystemHandler(e *echo.Echo, logger log.Logger) { + // GRPC Gateway configuration + host := getEnvOrDefault("GRPC_GATEWAY_HOST", "localhost") + grpcPort := getEnvOrDefault("GRPC_GATEWAY_PORT", "1317") + + // Redis configuration + redisHost := getEnvOrDefault("REDIS_HOST", "localhost") + redisPort := getEnvOrDefault("REDIS_PORT", "6379") + + handler := &SystemHandler{ + logger: logger, + host: host, + grpcPort: grpcPort, + redisHost: redisHost, + redisPort: redisPort, + } e.GET("/debug/pprof/*", echo.WrapHandler(http.DefaultServeMux)) + e.GET("/health", handler.GetHealthStatus) // // Register pprof handlers on "/debug/pprof" // e.GET("/debug/pprof/*", echo.WrapHandler(http.HandlerFunc(pprof.Index))) } + +// GetHealthStatus handles health check requests for both GRPC gateway and Redis +func (h *SystemHandler) GetHealthStatus(c echo.Context) error { + // Check GRPC Gateway status + grpcStatus := "running" + url := fmt.Sprintf("http://%s:%s/status", h.host, h.grpcPort) + if _, err := http.Get(url); err != nil { + grpcStatus = "down" + h.logger.Error("Error checking GRPC gateway status", zap.Error(err)) + } + + // Check Redis status + redisStatus := "running" + rdb := redis.NewClient(&redis.Options{ + Addr: fmt.Sprintf("%s:%s", h.redisHost, h.redisPort), + }) + + if _, err := rdb.Ping().Result(); err != nil { + redisStatus = "down" + h.logger.Error("Error connecting to Redis", zap.Error(err)) + } + + // Return combined status + return c.JSON(http.StatusOK, map[string]string{ + "grpc_gateway_status": grpcStatus, + "redis_status": redisStatus, + }) +} + +// getEnvOrDefault gets an environment variable or returns a default value +func getEnvOrDefault(key, defaultValue string) string { + value := os.Getenv(key) + if value == "" { + return defaultValue + } + return value +} From af15c49a412f9450b881886d174382986236d544 Mon Sep 17 00:00:00 2001 From: mattverse Date: Tue, 28 Nov 2023 13:56:37 +0900 Subject: [PATCH 02/19] Add redis to go mod --- go.mod | 6 +----- go.sum | 18 ++---------------- 2 files changed, 3 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index 02f6fa38359..57f7495713a 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v4 v4.1.0 github.com/cosmos/ibc-apps/modules/async-icq/v4 v4.1.0 github.com/cosmos/ibc-go/v4 v4.5.1 + github.com/go-redis/redis v6.15.9+incompatible github.com/gogo/protobuf v1.3.3 github.com/golang/mock v1.6.0 github.com/golang/protobuf v1.5.3 @@ -22,8 +23,6 @@ require ( github.com/iancoleman/orderedmap v0.3.0 github.com/labstack/echo v3.3.10+incompatible github.com/mattn/go-sqlite3 v1.14.17 - github.com/onsi/ginkgo/v2 v2.11.0 - github.com/onsi/gomega v1.27.10 github.com/ory/dockertest/v3 v3.10.0 github.com/osmosis-labs/go-mutesting v0.0.0-20221208041716-b43bcd97b3b3 github.com/osmosis-labs/osmosis/osmomath v0.0.7-0.20231014001935-1946419d44eb @@ -75,12 +74,9 @@ require ( github.com/docker/distribution v2.8.2+incompatible // indirect github.com/felixge/httpsnoop v1.0.2 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect - github.com/go-logr/logr v1.2.4 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 // indirect github.com/gogo/gateway v1.1.0 // indirect github.com/google/btree v1.1.2 // indirect - github.com/google/pprof v0.0.0-20230228050547-1710fef4ab10 // indirect github.com/kkHAIKE/contextcheck v1.1.4 // indirect github.com/labstack/gommon v0.3.0 // indirect github.com/leodido/go-urn v1.2.4 // indirect diff --git a/go.sum b/go.sum index da6b458f1d1..a6e3dbc49a7 100644 --- a/go.sum +++ b/go.sum @@ -253,7 +253,6 @@ github.com/containerd/continuity v0.3.0/go.mod h1:wJEAIwKOm/pBZuBd0JmeTvnLquTB1A github.com/coreos/etcd v3.3.10+incompatible/go.mod h1:uF7uidLiAD3TWHmW31ZFd/JWoc32PjwdhPthX9715RE= github.com/coreos/go-etcd v2.0.0+incompatible/go.mod h1:Jez6KQU2B/sWsbdaef3ED8NzMklzPG4d5KIOhIy30Tk= github.com/coreos/go-semver v0.2.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= -github.com/coreos/go-semver v0.3.0/go.mod h1:nnelYz7RCh+5ahJtPPxZlU+153eP4D4r3EedlOD2RNk= github.com/coreos/go-systemd v0.0.0-20180511133405-39ca1b05acc7/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd/v22 v22.3.2/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/coreos/go-systemd/v22 v22.3.3-0.20220203105225-a9a7ef127534/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= @@ -280,7 +279,6 @@ github.com/cosmos/ibc-go/v4 v4.5.1/go.mod h1:2EOi40Bx/j6rJrtP1ui8k8yUAMpGybmL1Ej github.com/cosmos/interchain-accounts v0.2.6 h1:TV2M2g1/Rb9MCNw1YePdBKE0rcEczNj1RGHT+2iRYas= github.com/cosmos/ledger-cosmos-go v0.12.2 h1:/XYaBlE2BJxtvpkHiBm97gFGSGmYGKunKyF3nNqAXZA= github.com/cosmos/ledger-cosmos-go v0.12.2/go.mod h1:ZcqYgnfNJ6lAXe4HPtWgarNEY+B74i+2/8MhZw4ziiI= -github.com/cosmos/ledger-go v0.9.2/go.mod h1:oZJ2hHAZROdlHiwTg4t7kP+GKIIkBT+o6c9QWFanOyI= github.com/cpuguy83/go-md2man v1.0.10/go.mod h1:SmD6nW6nTyfqj6ABTjUi3V3JVMnlJmwcJI5acqYI6dE= github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU= github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= @@ -425,7 +423,6 @@ github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4= github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs= github.com/go-logr/logr v1.2.4 h1:g01GSCwiDw2xSZfjJ2/T9M+S6pFdcNtFYsp+Y43HYDQ= -github.com/go-logr/logr v1.2.4/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-ole/go-ole v1.2.1/go.mod h1:7FAglXiTm7HKlQRDeOQ6ZNUHidzCWXuZWq/1dTyBNF8= github.com/go-openapi/jsonpointer v0.19.5/go.mod h1:Pl9vOtqEWErmShwVjC8pYs9cog34VGT37dQOVbmoatg= github.com/go-openapi/swag v0.19.5/go.mod h1:POnQmlKehdgb5mhVOsnJFsivZCEZ/vjK9gh66Z9tfKk= @@ -437,6 +434,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.2.0/go.mod h1:uOYAAleCW8F/7oMFd6aG0GOhaH6EGOAJShg8Id5JGkI= github.com/go-playground/validator/v10 v10.14.0 h1:vgvQWe3XCz3gIeFDm/HnTIbj6UGmg/+t63MyGU2n5js= +github.com/go-redis/redis v6.15.9+incompatible h1:K0pv1D7EQUjfyoMql+r/jZqCLizCGKFlFgcHWWmHQjg= +github.com/go-redis/redis v6.15.9+incompatible/go.mod h1:NAIEuMOZ/fxfXJIrKDQDz8wamY7mA7PouImQ2Jvg6kA= github.com/go-sourcemap/sourcemap v2.1.3+incompatible/go.mod h1:F8jJfvm2KbVjc5NqelyYJmf/v5J0dwNLS2mL4sNA1Jg= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.4.1/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= @@ -444,7 +443,6 @@ github.com/go-sql-driver/mysql v1.7.0 h1:ueSltNNllEqE3qcWBTD0iQd3IpL/6U+mJxLkazJ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= -github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572/go.mod h1:9Pwr4B2jHnOSGXyyzV8ROjYa2ojvAY6HCGYYfMoC3Ls= github.com/go-toolsmith/astcast v1.1.0 h1:+JN9xZV1A+Re+95pgnMgDboWNVnIMMQXwfBwLRPgSC8= github.com/go-toolsmith/astcast v1.1.0/go.mod h1:qdcuFWeGGS2xX5bLM/c3U9lewg7+Zu4mr+xPwZIB4ZU= github.com/go-toolsmith/astcopy v1.1.0 h1:YGwBN0WM+ekI/6SS6+52zLDEf8Yvp3n2seZITCUBt5s= @@ -590,7 +588,6 @@ github.com/google/pprof v0.0.0-20201023163331-3e6fc7fc9c4c/go.mod h1:kpwsk12EmLe github.com/google/pprof v0.0.0-20201203190320-1bf35d6f28c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20201218002935-b9804c9f04c2/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE= github.com/google/pprof v0.0.0-20230228050547-1710fef4ab10 h1:CqYfpuYIjnlNxM3msdyPRKabhXZWbKjf3Q8BWROFBso= -github.com/google/pprof v0.0.0-20230228050547-1710fef4ab10/go.mod h1:79YE0hCXdHag9sBkw2o+N/YnZtTkXi0UT9Nnixa5eYk= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= @@ -652,7 +649,6 @@ github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brv github.com/hashicorp/go-bexpr v0.1.10/go.mod h1:oxlubA2vC/gFVfX1A6JGp7ls7uCDlfJn732ehYYg+g0= github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= github.com/hashicorp/go-cleanhttp v0.5.1/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80= -github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48= github.com/hashicorp/go-immutable-radix v1.0.0/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= github.com/hashicorp/go-immutable-radix v1.3.1 h1:DKHmCUm2hRBK510BaiZlwvpD40f8bJFeZnpfm2KLowc= github.com/hashicorp/go-immutable-radix v1.3.1/go.mod h1:0y9vanUI8NX6FsYoO3zeMjhV/C5i9g4Q3DwcSNZ4P60= @@ -662,7 +658,6 @@ github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+l github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= github.com/hashicorp/go-retryablehttp v0.5.3/go.mod h1:9B5zBasrRhHXnJnui7y6sL7es7NDiJgTc6Er0maI1Xs= github.com/hashicorp/go-rootcerts v1.0.0/go.mod h1:K6zTfqpRlCUIjkwsN4Z+hiSfzSTQa6eBIzfwKfwNnHU= -github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR319Vf4pU3K5EGc8= github.com/hashicorp/go-sockaddr v1.0.0/go.mod h1:7Xibr9yA9JjQq1JpNB2Vw7kxv8xerXegt+ozgdvDeDU= github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4= github.com/hashicorp/go-uuid v1.0.0/go.mod h1:6SBZvOh/SIDV7/2o3Jml5SYk/TvGqwFJ/bN7x4byOro= @@ -695,7 +690,6 @@ github.com/huin/goupnp v1.0.3-0.20220313090229-ca81a64b4204/go.mod h1:ZxNlw5WqJj github.com/huin/goutil v0.0.0-20170803182201-1ca381bf3150/go.mod h1:PpLOETDnJ0o3iZrZfqZzyLl6l7F3c6L1oWn7OICBi6o= github.com/iancoleman/orderedmap v0.3.0 h1:5cbR2grmZR/DiVt+VJopEhtVs9YGInGIxAoMJn+Ichc= github.com/iancoleman/orderedmap v0.3.0/go.mod h1:XuLcCUkdL5owUCQeF2Ue9uuw1EptkJDkXXS7VoV7XGE= -github.com/iancoleman/strcase v0.2.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= github.com/imdario/mergo v0.3.13 h1:lFzP57bqS/wsqKssCGmtLAb8A0wKjLGrve2q3PPVcBk= @@ -760,7 +754,6 @@ github.com/julz/importas v0.1.0/go.mod h1:oSFU2R4XK/P7kNBrnL/FEQlDGN1/6WoxXEjSSX github.com/jung-kurt/gofpdf v1.0.3-0.20190309125859-24315acbbda5/go.mod h1:7Id9E/uU8ce6rXgefFLlgrJj/GYY22cpxn+r32jIOes= github.com/jwilder/encoding v0.0.0-20170811194829-b4e1701a28ef/go.mod h1:Ct9fl0F6iIOGgxJ5npU/IUOhOhqlVrGjyIZc8/MagT0= github.com/karalabe/usb v0.0.2/go.mod h1:Od972xHfMJowv7NGVDiWVxk2zxnWgjLlJzE+F4F7AGU= -github.com/keybase/go-keychain v0.0.0-20190712205309-48d3d31d256d/go.mod h1:JJNrCn9otv/2QP4D7SMJBgaleKpOf66PnW6F5WGNRIc= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/errcheck v1.6.3 h1:dEKh+GLHcWm2oN34nMvDzn1sqI0i0WxPvrgiJA5JuM8= @@ -951,13 +944,11 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU= github.com/onsi/ginkgo/v2 v2.11.0 h1:WgqUCUt/lT6yXoQ8Wef0fsNn5cAuMK7+KT9UFRz2tcU= -github.com/onsi/ginkgo/v2 v2.11.0/go.mod h1:ZhrRA5XmEE3x3rhlzamx/JJvujdZoJ2uvgI7kR0iZvM= github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= github.com/onsi/gomega v1.27.10 h1:naR28SdDFlqrG6kScpT8VWpu1xWY5nJRCF3XaYyBjhI= -github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3evPbQ0M= github.com/op/go-logging v0.0.0-20160315200505-970db520ece7/go.mod h1:HzydrMdWErDVzsI23lYNej1Htcns9BCg93Dk0bBINWk= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM= @@ -1014,7 +1005,6 @@ github.com/peterh/liner v1.0.1-0.20180619022028-8c1271fcf47f/go.mod h1:xIteQHvHu github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 h1:q2e307iGHPdTGp0hoxKjt1H5pDo6utceo3dQVK3I5XQ= github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5/go.mod h1:jvVRKCrJTQWu0XVbaOlby/2lO20uSCHEMzzplHXte1o= -github.com/phayes/checkstyle v0.0.0-20170904204023-bfd46e6a821d/go.mod h1:3OzsM7FXDQlpCiw2j81fOmAwQLnZnLGXVKUzeKQXIAw= github.com/philhofer/fwd v1.0.0/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/philhofer/fwd v1.1.1/go.mod h1:gk3iGcWd9+svBvR0sR+KPcfE+RNWozjowpeBVG3ZVNU= github.com/pierrec/lz4 v1.0.2-0.20190131084431-473cd7ce01a1/go.mod h1:3/3N9NVKO0jef7pBehbT1qWhCMrIgbYNnFAZCqQ5LRc= @@ -1075,7 +1065,6 @@ github.com/prometheus/procfs v0.11.1/go.mod h1:eesXgaPo1q7lBpVMoMy0ZOFTth9hBn4W/ github.com/prometheus/tsdb v0.7.1/go.mod h1:qhTCs0VvXwvX/y3TZrWD7rabWM+ijKTux40TwIPHuXU= github.com/quasilyte/go-ruleguard v0.4.0 h1:DyM6r+TKL+xbKB4Nm7Afd1IQh9kEUKQs2pboWGKtvQo= github.com/quasilyte/go-ruleguard v0.4.0/go.mod h1:Eu76Z/R8IXtViWUIHkE3p8gdH3/PKk1eh3YGfaEof10= -github.com/quasilyte/go-ruleguard/rules v0.0.0-20211022131956-028d6511ab71/go.mod h1:4cgAphtvu7Ftv7vOT2ZOYhC6CvBxZixcasr8qIOTA50= github.com/quasilyte/gogrep v0.5.0 h1:eTKODPXbI8ffJMN+W2aE0+oL0z/nh8/5eNdiO34SOAo= github.com/quasilyte/gogrep v0.5.0/go.mod h1:Cm9lpz9NZjEoL1tgZ2OgeUKPIxL1meE7eo60Z6Sk+Ng= github.com/quasilyte/regex/syntax v0.0.0-20210819130434-b3f0c404a727 h1:TCg2WBOl980XxGFEZSS6KlBGIV0diGdySzxATTWoqaU= @@ -1180,7 +1169,6 @@ github.com/spf13/cobra v0.0.5/go.mod h1:3K3wKZymM7VvHMDS9+Akkh4K60UwM26emMESw8tL github.com/spf13/cobra v1.7.0 h1:hyqWnYt1ZQShIddO5kBpj3vu05/++x6tJ6dg8EC572I= github.com/spf13/cobra v1.7.0/go.mod h1:uLxZILRyS/50WlhOIKD7W6V5bgeIt+4sICxh6uRMrb0= github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo= -github.com/spf13/jwalterweatherman v1.1.0/go.mod h1:aNWZUN0dPAAO/Ljvb5BEdw96iTZ0EXowPYD95IqWIGo= github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4= github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= @@ -1223,7 +1211,6 @@ github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c h1:+aPplB github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c/go.mod h1:SbErYREK7xXdsRiigaQiQkI9McGRzYMvlKYaP3Nimdk= github.com/tdakkota/asciicheck v0.2.0 h1:o8jvnUANo0qXtnslk2d3nMKTFNlOnJjRrNcj0j9qkHM= github.com/tdakkota/asciicheck v0.2.0/go.mod h1:Qb7Y9EgjCLJGup51gDHFzbI08/gbGhL/UVhYIPWG2rg= -github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= github.com/tendermint/btcd v0.1.1 h1:0VcxPfflS2zZ3RiOAHkBiFUcPvbtRj5O7zHmcJWHV7s= github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U= github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 h1:hqAk8riJvK4RMWx1aInLzndwxKalgi5rTqgfXxOxbEI= @@ -1421,7 +1408,6 @@ golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRu golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/lint v0.0.0-20201208152925-83fdc39ff7b5/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= -golang.org/x/lint v0.0.0-20210508222113-6edffad5e616/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mobile v0.0.0-20190312151609-d3739f865fa6/go.mod h1:z+o9i4GpDbdi3rU15maQ/Ox0txvL9dWGYEHz965HBQE= golang.org/x/mobile v0.0.0-20190719004257-d2bd2a29d028/go.mod h1:E/iHnbuqvinMTCcRqshq8CkpyQDoeVncDDYHnLhea+o= golang.org/x/mod v0.0.0-20190513183733-4bf6d317e70e/go.mod h1:mXi4GBBbnImb6dmsKGUJ2LatrhH/nqhxcFungHvyanc= From c9a80112294b27f2b435c94b000cef8ae4e2a814 Mon Sep 17 00:00:00 2001 From: mattverse Date: Tue, 28 Nov 2023 13:57:32 +0900 Subject: [PATCH 03/19] Add logger to system handler --- ingest/sqs/sidecar_query_server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ingest/sqs/sidecar_query_server.go b/ingest/sqs/sidecar_query_server.go index ccc0e9aaf5a..0fee954a273 100644 --- a/ingest/sqs/sidecar_query_server.go +++ b/ingest/sqs/sidecar_query_server.go @@ -137,7 +137,7 @@ func NewSideCarQueryServer(appCodec codec.Codec, routerConfig domain.RouterConfi routerHttpDelivery.NewRouterHandler(e, routerUsecase, logger) // Initialize system handler - systemhttpdelivery.NewSystemHandler(e) + systemhttpdelivery.NewSystemHandler(e, logger) // Initialized tokens usecase tokensUseCase := tokensUseCase.NewTokensUsecase(timeoutContext) From d4e0e11961cb453651d119d462deba733aed346e Mon Sep 17 00:00:00 2001 From: mattverse Date: Tue, 28 Nov 2023 21:23:14 +0900 Subject: [PATCH 04/19] Finsih --- .../ingester/redis/chain_info_ingester.go | 52 +++++++++++++ .../redis/redis_chain_info_repository.go | 77 +++++++++++++++++++ .../chain_info/usecase/chain_info_usecase.go | 36 +++++++++ ingest/sqs/domain/mvc/chainInfo.go | 18 +++++ ingest/sqs/ingester.go | 17 ++-- ingest/sqs/sidecar_query_server.go | 33 +++++--- .../delivery/http/system_http_handler.go | 48 +++++++++++- 7 files changed, 263 insertions(+), 18 deletions(-) create mode 100644 ingest/sqs/chain_info/ingester/redis/chain_info_ingester.go create mode 100644 ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go create mode 100644 ingest/sqs/chain_info/usecase/chain_info_usecase.go create mode 100644 ingest/sqs/domain/mvc/chainInfo.go diff --git a/ingest/sqs/chain_info/ingester/redis/chain_info_ingester.go b/ingest/sqs/chain_info/ingester/redis/chain_info_ingester.go new file mode 100644 index 00000000000..cb5ce6de514 --- /dev/null +++ b/ingest/sqs/chain_info/ingester/redis/chain_info_ingester.go @@ -0,0 +1,52 @@ +package redis + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "go.uber.org/zap" + + "github.com/osmosis-labs/osmosis/v20/ingest" + "github.com/osmosis-labs/osmosis/v20/ingest/sqs/domain/mvc" + "github.com/osmosis-labs/osmosis/v20/ingest/sqs/log" +) + +// chainInfoIngester is an ingester for blockchain information. +// It implements ingest.Ingester. +// It reads the latest blockchain height and writes it to the chainInfo repository. +type chainInfoIngester struct { + chainInfoRepo mvc.ChainInfoRepository + repositoryManager mvc.TxManager + logger log.Logger +} + +// NewChainInfoIngester returns a new chain information ingester. +func NewChainInfoIngester(chainInfoRepo mvc.ChainInfoRepository, repositoryManager mvc.TxManager) ingest.AtomicIngester { + return &chainInfoIngester{ + chainInfoRepo: chainInfoRepo, + repositoryManager: repositoryManager, + } +} + +// ProcessBlock implements ingest.Ingester. +// It reads the latest blockchain height and stores it in Redis. +func (ci *chainInfoIngester) ProcessBlock(ctx sdk.Context, tx mvc.Tx) error { + height := ctx.BlockHeight() + + ci.logger.Info("ingesting latest blockchain height", zap.Int64("height", height)) + + err := ci.chainInfoRepo.StoreLatestHeight(context.Background(), uint64(height)) + if err != nil { + ci.logger.Error("failed to ingest latest blockchain height", zap.Error(err)) + return err + } + + return nil +} + +// SetLogger implements ingest.AtomicIngester. +func (ci *chainInfoIngester) SetLogger(logger log.Logger) { + ci.logger = logger +} + +var _ ingest.AtomicIngester = &chainInfoIngester{} diff --git a/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go b/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go new file mode 100644 index 00000000000..0350d52bfe5 --- /dev/null +++ b/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go @@ -0,0 +1,77 @@ +package redis + +import ( + "context" + "fmt" + "strconv" + + "github.com/osmosis-labs/osmosis/v20/ingest/sqs/domain/mvc" +) + +type chainInfoRepo struct { + repositoryManager mvc.TxManager +} + +const ( + latestHeightKey = "latestHeight" + latestHeightField = "height" +) + +// NewChainInfoRepo creates a new repository for chain information +func NewChainInfoRepo(repositoryManager mvc.TxManager) *chainInfoRepo { + return &chainInfoRepo{ + repositoryManager: repositoryManager, + } +} + +// StoreLatestHeight stores the latest blockchain height into Redis +func (r *chainInfoRepo) StoreLatestHeight(ctx context.Context, height uint64) error { + tx := r.repositoryManager.StartTx() + redisTx, err := tx.AsRedisTx() + if err != nil { + return err + } + + pipeliner, err := redisTx.GetPipeliner(ctx) + if err != nil { + return err + } + + heightStr := strconv.FormatUint(height, 10) + // Use HSet for storing the latest height + err = pipeliner.HSet(ctx, latestHeightKey, latestHeightField, heightStr).Err() + if err != nil { + return err + } + + return tx.Exec(ctx) +} + +// GetLatestHeight retrieves the latest blockchain height from Redis +func (r *chainInfoRepo) GetLatestHeight(ctx context.Context) (uint64, error) { + tx := r.repositoryManager.StartTx() + redisTx, err := tx.AsRedisTx() + if err != nil { + return 0, err + } + + pipeliner, err := redisTx.GetPipeliner(ctx) + if err != nil { + return 0, err + } + + // Use HGet for getting the latest height + heightCmd := pipeliner.HGet(ctx, latestHeightKey, latestHeightField) + + if err := tx.Exec(ctx); err != nil { + return 0, err + } + + heightStr := heightCmd.Val() + height, err := strconv.ParseUint(heightStr, 10, 64) + if err != nil { + return 0, fmt.Errorf("error parsing height from Redis: %v", err) + } + + return height, nil +} diff --git a/ingest/sqs/chain_info/usecase/chain_info_usecase.go b/ingest/sqs/chain_info/usecase/chain_info_usecase.go new file mode 100644 index 00000000000..5e28222f790 --- /dev/null +++ b/ingest/sqs/chain_info/usecase/chain_info_usecase.go @@ -0,0 +1,36 @@ +package usecase + +import ( + "context" + "time" + + "github.com/osmosis-labs/osmosis/v20/ingest/sqs/domain/mvc" +) + +type chainInfoUseCase struct { + contextTimeout time.Duration + chainInfoRepository mvc.ChainInfoRepository + redisRepositoryManager mvc.TxManager +} + +var _ mvc.ChainInfoUsecase = &chainInfoUseCase{} + +func NewChainInfoUsecase(timeout time.Duration, chainInfoRepository mvc.ChainInfoRepository, redisRepositoryManager mvc.TxManager) mvc.ChainInfoUsecase { + return &chainInfoUseCase{ + contextTimeout: timeout, + chainInfoRepository: chainInfoRepository, + redisRepositoryManager: redisRepositoryManager, + } +} + +func (p *chainInfoUseCase) GetLatestHeight(ctx context.Context) (uint64, error) { + ctx, cancel := context.WithTimeout(ctx, p.contextTimeout) + defer cancel() + + latestHeight, err := p.chainInfoRepository.GetLatestHeight(ctx) + if err != nil { + return 0, err + } + + return latestHeight, nil +} diff --git a/ingest/sqs/domain/mvc/chainInfo.go b/ingest/sqs/domain/mvc/chainInfo.go new file mode 100644 index 00000000000..0e27998fbbc --- /dev/null +++ b/ingest/sqs/domain/mvc/chainInfo.go @@ -0,0 +1,18 @@ +package mvc + +import ( + "context" +) + +// ChainInfoRepository represents the contract for a repository handling chain information +type ChainInfoRepository interface { + // StoreLatestHeight stores the latest blockchain height + StoreLatestHeight(ctx context.Context, height uint64) error + + // GetLatestHeight retrieves the latest blockchain height + GetLatestHeight(ctx context.Context) (uint64, error) +} + +type ChainInfoUsecase interface { + GetLatestHeight(ctx context.Context) (uint64, error) +} diff --git a/ingest/sqs/ingester.go b/ingest/sqs/ingester.go index 6f1dcada4d8..6df193293a5 100644 --- a/ingest/sqs/ingester.go +++ b/ingest/sqs/ingester.go @@ -12,17 +12,19 @@ var _ ingest.Ingester = &sqsIngester{} // sqsIngester is a sidecar query server (SQS) implementation of Ingester. // It encapsulates all individual SQS ingesters. type sqsIngester struct { - txManager mvc.TxManager - poolsIngester ingest.AtomicIngester + txManager mvc.TxManager + poolsIngester ingest.AtomicIngester + chainInfoIngester ingest.AtomicIngester } // NewSidecarQueryServerIngester creates a new sidecar query server ingester. // poolsRepository is the storage for pools. // gammKeeper is the keeper for Gamm pools. -func NewSidecarQueryServerIngester(poolsIngester ingest.AtomicIngester, txManager mvc.TxManager) ingest.Ingester { +func NewSidecarQueryServerIngester(poolsIngester, chainInfoIngester ingest.AtomicIngester, txManager mvc.TxManager) ingest.Ingester { return &sqsIngester{ - txManager: txManager, - poolsIngester: poolsIngester, + txManager: txManager, + chainInfoIngester: chainInfoIngester, + poolsIngester: poolsIngester, } } @@ -43,6 +45,11 @@ func (i *sqsIngester) ProcessBlock(ctx sdk.Context) error { return err } + // Process block by reading and writing data and ingesting data into sinks + if err := i.chainInfoIngester.ProcessBlock(ctx, tx); err != nil { + return err + } + // Flush all writes atomically return tx.Exec(goCtx) } diff --git a/ingest/sqs/sidecar_query_server.go b/ingest/sqs/sidecar_query_server.go index 0fee954a273..a46280313ab 100644 --- a/ingest/sqs/sidecar_query_server.go +++ b/ingest/sqs/sidecar_query_server.go @@ -14,6 +14,8 @@ import ( "github.com/redis/go-redis/v9" "go.uber.org/zap" + chainInfoRepository "github.com/osmosis-labs/osmosis/v20/ingest/sqs/chain_info/repository/redis" + chainInfoUseCase "github.com/osmosis-labs/osmosis/v20/ingest/sqs/chain_info/usecase" "github.com/osmosis-labs/osmosis/v20/ingest/sqs/domain" "github.com/osmosis-labs/osmosis/v20/ingest/sqs/domain/mvc" "github.com/osmosis-labs/osmosis/v20/ingest/sqs/log" @@ -37,17 +39,19 @@ import ( type SideCarQueryServer interface { GetTxManager() mvc.TxManager GetPoolsRepository() mvc.PoolsRepository + GetChainInfoRepository() mvc.ChainInfoRepository GetRouterRepository() mvc.RouterRepository GetTokensUseCase() domain.TokensUsecase GetLogger() log.Logger } type sideCarQueryServer struct { - txManager mvc.TxManager - poolsRepository mvc.PoolsRepository - routerRepository mvc.RouterRepository - tokensUseCase domain.TokensUsecase - logger log.Logger + txManager mvc.TxManager + poolsRepository mvc.PoolsRepository + chainInfoRepository mvc.ChainInfoRepository + routerRepository mvc.RouterRepository + tokensUseCase domain.TokensUsecase + logger log.Logger } // GetTokensUseCase implements SideCarQueryServer. @@ -60,6 +64,10 @@ func (sqs *sideCarQueryServer) GetPoolsRepository() mvc.PoolsRepository { return sqs.poolsRepository } +func (sqs *sideCarQueryServer) GetChainInfoRepository() mvc.ChainInfoRepository { + return sqs.chainInfoRepository +} + // GetRouterRepository implements SideCarQueryServer. func (sqs *sideCarQueryServer) GetRouterRepository() mvc.RouterRepository { return sqs.routerRepository @@ -137,7 +145,9 @@ func NewSideCarQueryServer(appCodec codec.Codec, routerConfig domain.RouterConfi routerHttpDelivery.NewRouterHandler(e, routerUsecase, logger) // Initialize system handler - systemhttpdelivery.NewSystemHandler(e, logger) + chainInfoRepository := chainInfoRepository.NewChainInfoRepo(redisTxManager) + chainInfoUseCase := chainInfoUseCase.NewChainInfoUsecase(timeoutContext, chainInfoRepository, redisTxManager) + systemhttpdelivery.NewSystemHandler(e, logger, chainInfoUseCase) // Initialized tokens usecase tokensUseCase := tokensUseCase.NewTokensUsecase(timeoutContext) @@ -160,10 +170,11 @@ func NewSideCarQueryServer(appCodec codec.Codec, routerConfig domain.RouterConfi }() return &sideCarQueryServer{ - txManager: redisTxManager, - poolsRepository: poolsRepository, - routerRepository: routerRepository, - tokensUseCase: tokensUseCase, - logger: logger, + txManager: redisTxManager, + poolsRepository: poolsRepository, + chainInfoRepository: chainInfoRepository, + routerRepository: routerRepository, + tokensUseCase: tokensUseCase, + logger: logger, }, nil } diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index 6ab013bb4c3..701c7775b67 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -1,7 +1,9 @@ package http import ( + "encoding/json" "fmt" + "io/ioutil" "net/http" _ "net/http/pprof" "os" @@ -10,6 +12,7 @@ import ( "github.com/go-redis/redis" + "github.com/osmosis-labs/osmosis/v20/ingest/sqs/domain/mvc" "github.com/osmosis-labs/osmosis/v20/ingest/sqs/log" "github.com/labstack/echo" @@ -21,10 +24,11 @@ type SystemHandler struct { grpcPort string // GRPC gateway port redisHost string // Redis host redisPort string // Redis port + CIUsecase mvc.ChainInfoUsecase } // NewSystemHandler will initialize the /debug/ppof resources endpoint -func NewSystemHandler(e *echo.Echo, logger log.Logger) { +func NewSystemHandler(e *echo.Echo, logger log.Logger, us mvc.ChainInfoUsecase) { // GRPC Gateway configuration host := getEnvOrDefault("GRPC_GATEWAY_HOST", "localhost") grpcPort := getEnvOrDefault("GRPC_GATEWAY_PORT", "1317") @@ -39,6 +43,7 @@ func NewSystemHandler(e *echo.Echo, logger log.Logger) { grpcPort: grpcPort, redisHost: redisHost, redisPort: redisPort, + CIUsecase: us, } e.GET("/debug/pprof/*", echo.WrapHandler(http.DefaultServeMux)) @@ -50,12 +55,17 @@ func NewSystemHandler(e *echo.Echo, logger log.Logger) { // GetHealthStatus handles health check requests for both GRPC gateway and Redis func (h *SystemHandler) GetHealthStatus(c echo.Context) error { + ctx := c.Request().Context() + // Check GRPC Gateway status grpcStatus := "running" url := fmt.Sprintf("http://%s:%s/status", h.host, h.grpcPort) - if _, err := http.Get(url); err != nil { + resp, err := http.Get(url) + if err != nil { grpcStatus = "down" h.logger.Error("Error checking GRPC gateway status", zap.Error(err)) + } else { + defer resp.Body.Close() } // Check Redis status @@ -69,10 +79,44 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { h.logger.Error("Error connecting to Redis", zap.Error(err)) } + // Check the latest height from chain info use case + latestHeight, err := h.CIUsecase.GetLatestHeight(ctx) + if err != nil { + return err + } + + // Parse the response from the GRPC Gateway status endpoint + var statusResponse struct { + Result struct { + SyncInfo struct { + LatestBlockHeight string `json:"latest_block_height"` + } `json:"sync_info"` + } `json:"result"` + } + + if resp != nil { + bodyBytes, err := ioutil.ReadAll(resp.Body) + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, "Failed to read response body") + } + + err = json.Unmarshal(bodyBytes, &statusResponse) + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, "Failed to parse JSON response") + } + } + + // Compare latestHeight with latest_block_height from the status endpoint + nodeStatus := "synced" + if statusResponse.Result.SyncInfo.LatestBlockHeight != fmt.Sprint(latestHeight) { + nodeStatus = "not_synced" + } + // Return combined status return c.JSON(http.StatusOK, map[string]string{ "grpc_gateway_status": grpcStatus, "redis_status": redisStatus, + "node_status": nodeStatus, }) } From e0f0738fe43ea071f5545d76c3e60d97ce8792fa Mon Sep 17 00:00:00 2001 From: mattverse Date: Tue, 28 Nov 2023 21:52:12 +0900 Subject: [PATCH 05/19] Finish wiring ingester --- app/app.go | 6 ++++- .../delivery/http/system_http_handler.go | 26 +++++++++---------- 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/app/app.go b/app/app.go index c08e76b7bf9..237ee269933 100644 --- a/app/app.go +++ b/app/app.go @@ -76,6 +76,7 @@ import ( "github.com/osmosis-labs/osmosis/v20/ingest" "github.com/osmosis-labs/osmosis/v20/ingest/sqs" + redischaininfoingester "github.com/osmosis-labs/osmosis/v20/ingest/sqs/chain_info/ingester/redis" redispoolsingester "github.com/osmosis-labs/osmosis/v20/ingest/sqs/pools/ingester/redis" ) @@ -313,8 +314,11 @@ func NewOsmosisApp( poolsIngester := redispoolsingester.NewPoolIngester(sidecarQueryServer.GetPoolsRepository(), sidecarQueryServer.GetRouterRepository(), sidecarQueryServer.GetTokensUseCase(), txManager, routerConfig, app.GAMMKeeper, app.ConcentratedLiquidityKeeper, app.CosmwasmPoolKeeper, app.BankKeeper, app.ProtoRevKeeper, app.PoolManagerKeeper) poolsIngester.SetLogger(sidecarQueryServer.GetLogger()) + chainInfoingester := redischaininfoingester.NewChainInfoIngester(sidecarQueryServer.GetChainInfoRepository(), txManager) + chainInfoingester.SetLogger(sidecarQueryServer.GetLogger()) + // Create sqs ingester that encapsulates all ingesters. - sqsIngester := sqs.NewSidecarQueryServerIngester(poolsIngester, txManager) + sqsIngester := sqs.NewSidecarQueryServerIngester(poolsIngester, chainInfoingester, txManager) // Set the sidecar query server ingester to the ingest manager. app.IngestManager.SetIngester(sqsIngester) diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index 701c7775b67..54b30f4bb1a 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -3,7 +3,7 @@ package http import ( "encoding/json" "fmt" - "io/ioutil" + "io" "net/http" _ "net/http/pprof" "os" @@ -68,17 +68,6 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { defer resp.Body.Close() } - // Check Redis status - redisStatus := "running" - rdb := redis.NewClient(&redis.Options{ - Addr: fmt.Sprintf("%s:%s", h.redisHost, h.redisPort), - }) - - if _, err := rdb.Ping().Result(); err != nil { - redisStatus = "down" - h.logger.Error("Error connecting to Redis", zap.Error(err)) - } - // Check the latest height from chain info use case latestHeight, err := h.CIUsecase.GetLatestHeight(ctx) if err != nil { @@ -95,7 +84,7 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { } if resp != nil { - bodyBytes, err := ioutil.ReadAll(resp.Body) + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to read response body") } @@ -112,6 +101,17 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { nodeStatus = "not_synced" } + // Check Redis status + redisStatus := "running" + rdb := redis.NewClient(&redis.Options{ + Addr: fmt.Sprintf("%s:%s", h.redisHost, h.redisPort), + }) + + if _, err := rdb.Ping().Result(); err != nil { + redisStatus = "down" + h.logger.Error("Error connecting to Redis", zap.Error(err)) + } + // Return combined status return c.JSON(http.StatusOK, map[string]string{ "grpc_gateway_status": grpcStatus, From 120895e6fcbc89ea99b583931300039802029526 Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 11:07:03 +0900 Subject: [PATCH 06/19] Roman's comments --- app/app.go | 4 +++- ingest/sqs/chain_info/ingester/redis/chain_info_ingester.go | 4 +--- .../repository/redis/redis_chain_info_repository.go | 3 +-- ingest/sqs/domain/mvc/chainInfo.go | 2 +- ingest/sqs/sidecar_query_server.go | 4 ++-- ingest/sqs/system/delivery/http/system_http_handler.go | 4 ++-- 6 files changed, 10 insertions(+), 11 deletions(-) diff --git a/app/app.go b/app/app.go index 237ee269933..8cd7b4f7811 100644 --- a/app/app.go +++ b/app/app.go @@ -93,6 +93,7 @@ const ( ENV_NAME_INGEST_SQS_LOGGER_FILENAME = "INGEST_SQS_LOGGER_FILENAME" ENV_NAME_INGEST_SQS_LOGGER_IS_PRODUCTION = "INGEST_SQS_LOGGER_IS_PRODUCTION" ENV_NAME_INGEST_SQS_LOGGER_LEVEL = "INGEST_SQS_LOGGER_LEVEL" + ENV_NAME_GRPC_GATEWAY_ENDPOINT = "ENV_NAME_GRPC_GATEWAY_ENDPOINT" ENV_VALUE_INGESTER_SQS = "sqs" ) @@ -271,6 +272,7 @@ func NewOsmosisApp( if isIngestManagerEnabled { dbHost := os.Getenv(ENV_NAME_INGEST_SQS_DBHOST) dbPort := os.Getenv(ENV_NAME_INGEST_SQS_DBPORT) + grpcAddress := os.Getenv(ENV_NAME_GRPC_GATEWAY_ENDPOINT) sidecarQueryServerAddress := os.Getenv(ENV_NAME_INGEST_SQS_SERVER_ADDRESS) sidecarQueryServerTimeoutDuration, err := strconv.Atoi(os.Getenv(ENV_NAME_INGEST_SQS_SERVER_TIMEOUT_DURATION_SECS)) if err != nil { @@ -303,7 +305,7 @@ func NewOsmosisApp( } // Create sidecar query server - sidecarQueryServer, err := sqs.NewSideCarQueryServer(appCodec, routerConfig, dbHost, dbPort, sidecarQueryServerAddress, sidecarQueryServerTimeoutDuration, logger) + sidecarQueryServer, err := sqs.NewSideCarQueryServer(appCodec, routerConfig, dbHost, dbPort, sidecarQueryServerAddress, grpcAddress, sidecarQueryServerTimeoutDuration, logger) if err != nil { panic(fmt.Sprintf("error while creating sidecar query server: %s", err)) } diff --git a/ingest/sqs/chain_info/ingester/redis/chain_info_ingester.go b/ingest/sqs/chain_info/ingester/redis/chain_info_ingester.go index cb5ce6de514..876a8eb3c68 100644 --- a/ingest/sqs/chain_info/ingester/redis/chain_info_ingester.go +++ b/ingest/sqs/chain_info/ingester/redis/chain_info_ingester.go @@ -1,8 +1,6 @@ package redis import ( - "context" - sdk "github.com/cosmos/cosmos-sdk/types" "go.uber.org/zap" @@ -35,7 +33,7 @@ func (ci *chainInfoIngester) ProcessBlock(ctx sdk.Context, tx mvc.Tx) error { ci.logger.Info("ingesting latest blockchain height", zap.Int64("height", height)) - err := ci.chainInfoRepo.StoreLatestHeight(context.Background(), uint64(height)) + err := ci.chainInfoRepo.StoreLatestHeight(sdk.WrapSDKContext(ctx), tx, uint64(height)) if err != nil { ci.logger.Error("failed to ingest latest blockchain height", zap.Error(err)) return err diff --git a/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go b/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go index 0350d52bfe5..71da17d6c5e 100644 --- a/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go +++ b/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go @@ -25,8 +25,7 @@ func NewChainInfoRepo(repositoryManager mvc.TxManager) *chainInfoRepo { } // StoreLatestHeight stores the latest blockchain height into Redis -func (r *chainInfoRepo) StoreLatestHeight(ctx context.Context, height uint64) error { - tx := r.repositoryManager.StartTx() +func (r *chainInfoRepo) StoreLatestHeight(ctx context.Context, tx mvc.Tx, height uint64) error { redisTx, err := tx.AsRedisTx() if err != nil { return err diff --git a/ingest/sqs/domain/mvc/chainInfo.go b/ingest/sqs/domain/mvc/chainInfo.go index 0e27998fbbc..b10f4e89ac5 100644 --- a/ingest/sqs/domain/mvc/chainInfo.go +++ b/ingest/sqs/domain/mvc/chainInfo.go @@ -7,7 +7,7 @@ import ( // ChainInfoRepository represents the contract for a repository handling chain information type ChainInfoRepository interface { // StoreLatestHeight stores the latest blockchain height - StoreLatestHeight(ctx context.Context, height uint64) error + StoreLatestHeight(ctx context.Context, tx Tx, height uint64) error // GetLatestHeight retrieves the latest blockchain height GetLatestHeight(ctx context.Context) (uint64, error) diff --git a/ingest/sqs/sidecar_query_server.go b/ingest/sqs/sidecar_query_server.go index a46280313ab..7fe1fe24bcc 100644 --- a/ingest/sqs/sidecar_query_server.go +++ b/ingest/sqs/sidecar_query_server.go @@ -84,7 +84,7 @@ func (sqs *sideCarQueryServer) GetLogger() log.Logger { } // NewSideCarQueryServer creates a new sidecar query server (SQS). -func NewSideCarQueryServer(appCodec codec.Codec, routerConfig domain.RouterConfig, dbHost, dbPort, sideCarQueryServerAddress string, useCaseTimeoutDuration int, logger log.Logger) (SideCarQueryServer, error) { +func NewSideCarQueryServer(appCodec codec.Codec, routerConfig domain.RouterConfig, dbHost, dbPort, sideCarQueryServerAddress, grpcAddress string, useCaseTimeoutDuration int, logger log.Logger) (SideCarQueryServer, error) { // Handle SIGINT and SIGTERM signals to initiate shutdown exitChan := make(chan os.Signal, 1) signal.Notify(exitChan, os.Interrupt, syscall.SIGTERM) @@ -147,7 +147,7 @@ func NewSideCarQueryServer(appCodec codec.Codec, routerConfig domain.RouterConfi // Initialize system handler chainInfoRepository := chainInfoRepository.NewChainInfoRepo(redisTxManager) chainInfoUseCase := chainInfoUseCase.NewChainInfoUsecase(timeoutContext, chainInfoRepository, redisTxManager) - systemhttpdelivery.NewSystemHandler(e, logger, chainInfoUseCase) + systemhttpdelivery.NewSystemHandler(e, redisAddress, grpcAddress, logger, chainInfoUseCase) // Initialized tokens usecase tokensUseCase := tokensUseCase.NewTokensUsecase(timeoutContext) diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index 54b30f4bb1a..e7cdacc0f70 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -28,7 +28,7 @@ type SystemHandler struct { } // NewSystemHandler will initialize the /debug/ppof resources endpoint -func NewSystemHandler(e *echo.Echo, logger log.Logger, us mvc.ChainInfoUsecase) { +func NewSystemHandler(e *echo.Echo, redisAddress, grpcAddress string, logger log.Logger, us mvc.ChainInfoUsecase) { // GRPC Gateway configuration host := getEnvOrDefault("GRPC_GATEWAY_HOST", "localhost") grpcPort := getEnvOrDefault("GRPC_GATEWAY_PORT", "1317") @@ -47,7 +47,7 @@ func NewSystemHandler(e *echo.Echo, logger log.Logger, us mvc.ChainInfoUsecase) } e.GET("/debug/pprof/*", echo.WrapHandler(http.DefaultServeMux)) - e.GET("/health", handler.GetHealthStatus) + e.GET("/healthcheck", handler.GetHealthStatus) // // Register pprof handlers on "/debug/pprof" // e.GET("/debug/pprof/*", echo.WrapHandler(http.HandlerFunc(pprof.Index))) From 9a226598eb01242c6a8dc2d1b1aab3192b2c0696 Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 11:34:23 +0900 Subject: [PATCH 07/19] Change to tendermint struct, add log --- .../system/delivery/http/system_http_handler.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index e7cdacc0f70..75cb75322f4 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -15,6 +15,8 @@ import ( "github.com/osmosis-labs/osmosis/v20/ingest/sqs/domain/mvc" "github.com/osmosis-labs/osmosis/v20/ingest/sqs/log" + coretypes "github.com/cometbft/cometbft/rpc/core/types" + "github.com/labstack/echo" ) @@ -75,13 +77,7 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { } // Parse the response from the GRPC Gateway status endpoint - var statusResponse struct { - Result struct { - SyncInfo struct { - LatestBlockHeight string `json:"latest_block_height"` - } `json:"sync_info"` - } `json:"result"` - } + var statusResponse coretypes.ResultStatus if resp != nil { bodyBytes, err := io.ReadAll(resp.Body) @@ -97,7 +93,9 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { // Compare latestHeight with latest_block_height from the status endpoint nodeStatus := "synced" - if statusResponse.Result.SyncInfo.LatestBlockHeight != fmt.Sprint(latestHeight) { + h.logger.Debug("status resp: ", zap.Int("height", int(statusResponse.SyncInfo.LatestBlockHeight))) + h.logger.Debug("latest height: ", zap.Int("latest_height", int(statusResponse.SyncInfo.LatestBlockHeight))) + if statusResponse.SyncInfo.LatestBlockHeight != int64(latestHeight) { nodeStatus = "not_synced" } From d9c79e8de1022eee6a30cf17b4073d969bcc6cfc Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 11:46:15 +0900 Subject: [PATCH 08/19] Run go mod tidy --- go.mod | 5 +++++ go.sum | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/go.mod b/go.mod index 57f7495713a..962a62ddb67 100644 --- a/go.mod +++ b/go.mod @@ -65,11 +65,14 @@ require ( github.com/butuzov/mirror v1.1.0 // indirect github.com/ccojocar/zxcvbn-go v1.0.1 // indirect github.com/chenzhuoyu/iasm v0.9.0 // indirect + github.com/cometbft/cometbft-db v0.7.0 // indirect github.com/cosmos/gogoproto v1.4.11 // indirect github.com/cosmos/iavl v0.19.7 // indirect github.com/creachadair/taskgroup v0.3.2 // indirect github.com/curioswitch/go-reassign v0.2.0 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1 // indirect + github.com/dgraph-io/badger/v2 v2.2007.4 // indirect + github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/docker/distribution v2.8.2+incompatible // indirect github.com/felixge/httpsnoop v1.0.2 // indirect @@ -82,6 +85,7 @@ require ( github.com/leodido/go-urn v1.2.4 // indirect github.com/maratori/testableexamples v1.0.0 // indirect github.com/nunnatsa/ginkgolinter v0.13.5 // indirect + github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae // indirect github.com/onsi/ginkgo v1.16.5 // indirect github.com/regen-network/cosmos-proto v0.3.1 // indirect github.com/sagikazarmark/locafero v0.3.0 // indirect @@ -91,6 +95,7 @@ require ( github.com/sivchari/nosnakecase v1.7.0 // indirect github.com/sourcegraph/conc v0.3.0 // indirect github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c // indirect + github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect github.com/timonwong/loggercheck v0.9.4 // indirect diff --git a/go.sum b/go.sum index a6e3dbc49a7..73fd6fe4de1 100644 --- a/go.sum +++ b/go.sum @@ -241,6 +241,8 @@ github.com/coinbase/rosetta-sdk-go v0.7.9 h1:lqllBjMnazTjIqYrOGv8h8jxjg9+hJazIGZ github.com/coinbase/rosetta-sdk-go v0.7.9/go.mod h1:0/knutI7XGVqXmmH4OQD8OckFrbQ8yMsUZTG7FXCR2M= github.com/cometbft/cometbft v0.38.0 h1:ogKnpiPX7gxCvqTEF4ly25/wAxUqf181t30P3vqdpdc= github.com/cometbft/cometbft v0.38.0/go.mod h1:5Jz0Z8YsHSf0ZaAqGvi/ifioSdVFPtEGrm8Y9T/993k= +github.com/cometbft/cometbft-db v0.7.0 h1:uBjbrBx4QzU0zOEnU8KxoDl18dMNgDh+zZRUE0ucsbo= +github.com/cometbft/cometbft-db v0.7.0/go.mod h1:yiKJIm2WKrt6x8Cyxtq9YTEcIMPcEe4XPxhgX59Fzf0= github.com/confio/ics23/go v0.9.1 h1:3MV46eeWwO3xCauKyAtuAdJYMyPnnchW4iLr2bTw6/U= github.com/confio/ics23/go v0.9.1/go.mod h1:4LPZ2NYqnYIVRklaozjNR1FScgDJ2s5Xrp+e/mYVRak= github.com/consensys/bavard v0.1.8-0.20210406032232-f3452dc9b572/go.mod h1:Bpd0/3mZuaj6Sj+PqrmIquiOKy397AKGThQPaGzNXAQ= @@ -313,6 +315,7 @@ github.com/denis-tingaikin/go-header v0.4.3 h1:tEaZKAlqql6SKCY++utLmkPLd6K8IBM20 github.com/denis-tingaikin/go-header v0.4.3/go.mod h1:0wOCWuN71D5qIgE2nz9KrKmuYBAC2Mra5RassOIQ2/c= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f h1:U5y3Y5UE0w7amNe7Z5G/twsBW0KEalRQXZzf8ufSh9I= github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f/go.mod h1:xH/i4TFMt8koVQZ6WFms69WAsDWr2XsYL3Hkl7jkoLE= +github.com/dgraph-io/badger/v2 v2.2007.4 h1:TRWBQg8UrlUhaFdco01nO2uXwzKS7zd+HVdwV/GHc4o= github.com/dgraph-io/badger/v2 v2.2007.4/go.mod h1:vSw/ax2qojzbN6eXHIx6KPKtCSHJN/Uz0X0VPruTIhk= github.com/dgraph-io/badger/v3 v3.2103.2 h1:dpyM5eCJAtQCBcMCZcT4UBZchuTJgCywerHHgmxfxM8= github.com/dgraph-io/badger/v3 v3.2103.2/go.mod h1:RHo4/GmYcKKh5Lxu63wLEMHJ70Pac2JqZRYGhlyAo2M= @@ -930,6 +933,8 @@ github.com/nunnatsa/ginkgolinter v0.13.5/go.mod h1:OBHy4536xtuX3102NM63XRtOyxqZO github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU= +github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae h1:FatpGJD2jmJfhZiFDElaC0QhZUDQnxUeAwTGkfAHN3I= +github.com/oasisprotocol/curve25519-voi v0.0.0-20220708102147-0a8a51822cae/go.mod h1:hVoHR2EVESiICEMbg137etN/Lx+lSrHPTD39Z/uE+2s= github.com/oklog/oklog v0.3.2/go.mod h1:FCV+B7mhrz4o+ueLpx+KqkyXRGMWOYEvfiXtdGtbWGs= github.com/oklog/run v1.0.0/go.mod h1:dlhp/R75TPv97u0XWUtDeV/lRKWPKSdTuV0TZvrmrQA= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= @@ -1211,6 +1216,8 @@ github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c h1:+aPplB github.com/t-yuki/gocover-cobertura v0.0.0-20180217150009-aaee18c8195c/go.mod h1:SbErYREK7xXdsRiigaQiQkI9McGRzYMvlKYaP3Nimdk= github.com/tdakkota/asciicheck v0.2.0 h1:o8jvnUANo0qXtnslk2d3nMKTFNlOnJjRrNcj0j9qkHM= github.com/tdakkota/asciicheck v0.2.0/go.mod h1:Qb7Y9EgjCLJGup51gDHFzbI08/gbGhL/UVhYIPWG2rg= +github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c h1:g+WoO5jjkqGAzHWCjJB1zZfXPIAaDpzXIEJ0eS6B5Ok= +github.com/tecbot/gorocksdb v0.0.0-20191217155057-f0fad39f321c/go.mod h1:ahpPrc7HpcfEWDQRZEmnXMzHY03mLDYMCxeDzy46i+8= github.com/tendermint/btcd v0.1.1 h1:0VcxPfflS2zZ3RiOAHkBiFUcPvbtRj5O7zHmcJWHV7s= github.com/tendermint/btcd v0.1.1/go.mod h1:DC6/m53jtQzr/NFmMNEu0rxf18/ktVoVtMrnDD5pN+U= github.com/tendermint/crypto v0.0.0-20191022145703-50d29ede1e15 h1:hqAk8riJvK4RMWx1aInLzndwxKalgi5rTqgfXxOxbEI= From f337c3be02de1badd444769122120712788786a7 Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 19:14:11 +0900 Subject: [PATCH 09/19] Add more logging --- ingest/sqs/system/delivery/http/system_http_handler.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index 75cb75322f4..f2a95911e63 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -57,6 +57,7 @@ func NewSystemHandler(e *echo.Echo, redisAddress, grpcAddress string, logger log // GetHealthStatus handles health check requests for both GRPC gateway and Redis func (h *SystemHandler) GetHealthStatus(c echo.Context) error { + h.logger.Info("START=======") ctx := c.Request().Context() // Check GRPC Gateway status @@ -93,8 +94,8 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { // Compare latestHeight with latest_block_height from the status endpoint nodeStatus := "synced" - h.logger.Debug("status resp: ", zap.Int("height", int(statusResponse.SyncInfo.LatestBlockHeight))) - h.logger.Debug("latest height: ", zap.Int("latest_height", int(statusResponse.SyncInfo.LatestBlockHeight))) + h.logger.Info("status resp: ", zap.Int("height", int(statusResponse.SyncInfo.LatestBlockHeight))) + h.logger.Info("latest height: ", zap.Int("latest_height", int(statusResponse.SyncInfo.LatestBlockHeight))) if statusResponse.SyncInfo.LatestBlockHeight != int64(latestHeight) { nodeStatus = "not_synced" } From 0537590452e02e850f818e84cb5411e3eb843680 Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 19:31:42 +0900 Subject: [PATCH 10/19] Allow 10 blocks --- ingest/sqs/system/delivery/http/system_http_handler.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index f2a95911e63..bd7eb1b1650 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -96,7 +96,9 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { nodeStatus := "synced" h.logger.Info("status resp: ", zap.Int("height", int(statusResponse.SyncInfo.LatestBlockHeight))) h.logger.Info("latest height: ", zap.Int("latest_height", int(statusResponse.SyncInfo.LatestBlockHeight))) - if statusResponse.SyncInfo.LatestBlockHeight != int64(latestHeight) { + + // allow 10 blocks of difference before claiming node is not synced + if int64(latestHeight)+10 < statusResponse.SyncInfo.LatestBlockHeight { nodeStatus = "not_synced" } From e313b7e49ae69ca5f2b4f7bbf0d3060ab8bf37e4 Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 19:36:44 +0900 Subject: [PATCH 11/19] Add more log --- ingest/sqs/system/delivery/http/system_http_handler.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index bd7eb1b1650..7863fe0024a 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -39,6 +39,7 @@ func NewSystemHandler(e *echo.Echo, redisAddress, grpcAddress string, logger log redisHost := getEnvOrDefault("REDIS_HOST", "localhost") redisPort := getEnvOrDefault("REDIS_PORT", "6379") + logger.Info("new sys handler") handler := &SystemHandler{ logger: logger, host: host, @@ -58,6 +59,7 @@ func NewSystemHandler(e *echo.Echo, redisAddress, grpcAddress string, logger log // GetHealthStatus handles health check requests for both GRPC gateway and Redis func (h *SystemHandler) GetHealthStatus(c echo.Context) error { h.logger.Info("START=======") + fmt.Println("=====Start") ctx := c.Request().Context() // Check GRPC Gateway status From 0d383827e8f4458bccba7d6159860caebd085d89 Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 20:14:33 +0900 Subject: [PATCH 12/19] Add more print --- .../repository/redis/redis_chain_info_repository.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go b/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go index 71da17d6c5e..a29b23adab8 100644 --- a/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go +++ b/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go @@ -26,6 +26,7 @@ func NewChainInfoRepo(repositoryManager mvc.TxManager) *chainInfoRepo { // StoreLatestHeight stores the latest blockchain height into Redis func (r *chainInfoRepo) StoreLatestHeight(ctx context.Context, tx mvc.Tx, height uint64) error { + fmt.Println("Starting store latest height") redisTx, err := tx.AsRedisTx() if err != nil { return err @@ -38,11 +39,13 @@ func (r *chainInfoRepo) StoreLatestHeight(ctx context.Context, tx mvc.Tx, height heightStr := strconv.FormatUint(height, 10) // Use HSet for storing the latest height - err = pipeliner.HSet(ctx, latestHeightKey, latestHeightField, heightStr).Err() - if err != nil { + cmd := pipeliner.HSet(ctx, latestHeightKey, latestHeightField, heightStr) + if err := cmd.Err(); err != nil { return err } + fmt.Println("Ending store latest height") + return tx.Exec(ctx) } From a9129f2123a115b20746271678ed2276a7fecaad Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 20:24:12 +0900 Subject: [PATCH 13/19] Add more log --- .../repository/redis/redis_chain_info_repository.go | 2 ++ ingest/sqs/system/delivery/http/system_http_handler.go | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go b/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go index a29b23adab8..8226808524a 100644 --- a/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go +++ b/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go @@ -27,6 +27,7 @@ func NewChainInfoRepo(repositoryManager mvc.TxManager) *chainInfoRepo { // StoreLatestHeight stores the latest blockchain height into Redis func (r *chainInfoRepo) StoreLatestHeight(ctx context.Context, tx mvc.Tx, height uint64) error { fmt.Println("Starting store latest height") + redisTx, err := tx.AsRedisTx() if err != nil { return err @@ -38,6 +39,7 @@ func (r *chainInfoRepo) StoreLatestHeight(ctx context.Context, tx mvc.Tx, height } heightStr := strconv.FormatUint(height, 10) + fmt.Println(heightStr) // Use HSet for storing the latest height cmd := pipeliner.HSet(ctx, latestHeightKey, latestHeightField, heightStr) if err := cmd.Err(); err != nil { diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index 7863fe0024a..89490269a1f 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -97,7 +97,14 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { // Compare latestHeight with latest_block_height from the status endpoint nodeStatus := "synced" h.logger.Info("status resp: ", zap.Int("height", int(statusResponse.SyncInfo.LatestBlockHeight))) - h.logger.Info("latest height: ", zap.Int("latest_height", int(statusResponse.SyncInfo.LatestBlockHeight))) + h.logger.Info("latest height: ", zap.Int("latest", int(latestHeight))) + + b, err := json.MarshalIndent(statusResponse, "", " ") + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, "Failed to parse JSON response") + } + + h.logger.Info(string(b)) // allow 10 blocks of difference before claiming node is not synced if int64(latestHeight)+10 < statusResponse.SyncInfo.LatestBlockHeight { From 0e26865a62e8a5e3fd986bc63cb1340e1e5aacda Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 20:43:22 +0900 Subject: [PATCH 14/19] Change json --- .../system/delivery/http/system_http_handler.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index 89490269a1f..aa5490659b6 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -58,7 +58,6 @@ func NewSystemHandler(e *echo.Echo, redisAddress, grpcAddress string, logger log // GetHealthStatus handles health check requests for both GRPC gateway and Redis func (h *SystemHandler) GetHealthStatus(c echo.Context) error { - h.logger.Info("START=======") fmt.Println("=====Start") ctx := c.Request().Context() @@ -80,7 +79,11 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { } // Parse the response from the GRPC Gateway status endpoint - var statusResponse coretypes.ResultStatus + type tempResponse struct { + Result coretypes.ResultStatus `json:"result"` + } + + var statusResponse tempResponse if resp != nil { bodyBytes, err := io.ReadAll(resp.Body) @@ -96,18 +99,17 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { // Compare latestHeight with latest_block_height from the status endpoint nodeStatus := "synced" - h.logger.Info("status resp: ", zap.Int("height", int(statusResponse.SyncInfo.LatestBlockHeight))) + h.logger.Info("status resp: ", zap.Int("height", int(statusResponse.Result.SyncInfo.LatestBlockHeight))) h.logger.Info("latest height: ", zap.Int("latest", int(latestHeight))) b, err := json.MarshalIndent(statusResponse, "", " ") if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to parse JSON response") } - - h.logger.Info(string(b)) + fmt.Println(b) // allow 10 blocks of difference before claiming node is not synced - if int64(latestHeight)+10 < statusResponse.SyncInfo.LatestBlockHeight { + if int64(latestHeight)+10 < statusResponse.Result.SyncInfo.LatestBlockHeight { nodeStatus = "not_synced" } From 66d4043b0b5892aec19704cb102611597b3295cf Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 21:12:18 +0900 Subject: [PATCH 15/19] use original struct --- .../delivery/http/system_http_handler.go | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index aa5490659b6..243a1722603 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -7,6 +7,7 @@ import ( "net/http" _ "net/http/pprof" "os" + "strconv" "go.uber.org/zap" @@ -15,8 +16,6 @@ import ( "github.com/osmosis-labs/osmosis/v20/ingest/sqs/domain/mvc" "github.com/osmosis-labs/osmosis/v20/ingest/sqs/log" - coretypes "github.com/cometbft/cometbft/rpc/core/types" - "github.com/labstack/echo" ) @@ -79,11 +78,15 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { } // Parse the response from the GRPC Gateway status endpoint - type tempResponse struct { - Result coretypes.ResultStatus `json:"result"` + type JsonResponse struct { + Result struct { + SyncInfo struct { + LatestBlockHeight string `json:"latest_block_height"` + } `json:"sync_info"` + } `json:"result"` } - var statusResponse tempResponse + var statusResponse JsonResponse if resp != nil { bodyBytes, err := io.ReadAll(resp.Body) @@ -99,7 +102,13 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { // Compare latestHeight with latest_block_height from the status endpoint nodeStatus := "synced" - h.logger.Info("status resp: ", zap.Int("height", int(statusResponse.Result.SyncInfo.LatestBlockHeight))) + + latestBlockHeight, err := strconv.Atoi(statusResponse.Result.SyncInfo.LatestBlockHeight) + if err != nil { + return echo.NewHTTPError(http.StatusInternalServerError, "Failed to parse JSON response") + } + + h.logger.Info("status resp: ", zap.Int("height", latestBlockHeight)) h.logger.Info("latest height: ", zap.Int("latest", int(latestHeight))) b, err := json.MarshalIndent(statusResponse, "", " ") @@ -109,7 +118,7 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { fmt.Println(b) // allow 10 blocks of difference before claiming node is not synced - if int64(latestHeight)+10 < statusResponse.Result.SyncInfo.LatestBlockHeight { + if fmt.Sprint(int64(latestHeight)+10) < statusResponse.Result.SyncInfo.LatestBlockHeight { nodeStatus = "not_synced" } From 15f6ae4b8112b561d5ba5257732d29a68fe919a4 Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 21:20:09 +0900 Subject: [PATCH 16/19] More logs --- ingest/sqs/system/delivery/http/system_http_handler.go | 1 + 1 file changed, 1 insertion(+) diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index 243a1722603..921838a733d 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -103,6 +103,7 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { // Compare latestHeight with latest_block_height from the status endpoint nodeStatus := "synced" + fmt.Println(statusResponse) latestBlockHeight, err := strconv.Atoi(statusResponse.Result.SyncInfo.LatestBlockHeight) if err != nil { return echo.NewHTTPError(http.StatusInternalServerError, "Failed to parse JSON response") From e9a2095726185a3995f21e65827f66bb19706607 Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 21:28:33 +0900 Subject: [PATCH 17/19] Try using diff endpoint --- .../delivery/http/system_http_handler.go | 3 ++- x/mint/keeper/hooks_test.go | 25 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index 921838a733d..a4f49be551b 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -62,7 +62,8 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { // Check GRPC Gateway status grpcStatus := "running" - url := fmt.Sprintf("http://%s:%s/status", h.host, h.grpcPort) + // url := fmt.Sprintf("http://%s:%s/status", h.host, h.grpcPort) + url := "https://rpc-cosmoshub.blockapsis.com/status" resp, err := http.Get(url) if err != nil { grpcStatus = "down" diff --git a/x/mint/keeper/hooks_test.go b/x/mint/keeper/hooks_test.go index 60eaac6f3c0..ce24d092240 100644 --- a/x/mint/keeper/hooks_test.go +++ b/x/mint/keeper/hooks_test.go @@ -1,6 +1,8 @@ package keeper_test import ( + "encoding/json" + "fmt" "testing" "github.com/stretchr/testify/suite" @@ -426,6 +428,29 @@ func (s *KeeperTestSuite) TestAfterEpochEnd() { } } +// TestAfterEpochEnd tests that the after epoch end hook correctly +// distributes the rewards depending on what epoch it is in. +func (s *KeeperTestSuite) TestA() { + // Parse the response from the GRPC Gateway status endpoint + + // Parse the response from the GRPC Gateway status endpoint + type JsonResponse struct { + Result struct { + SyncInfo struct { + LatestBlockHeight string `json:"latest_block_height"` + } `json:"sync_info"` + } `json:"result"` + } + var statusResponse JsonResponse + + jsonData := `{"jsonrpc":"2.0","id":-1,"result":{"node_info":{"protocol_version":{"p2p":"8","block":"11","app":"0"},"id":"5e14e87cf797b622a227d6b09bd393fd415c5a91","listen_addr":"159.89.3.35:31581","network":"cosmoshub-4","version":"0.34.29","channels":"40202122233038606100","moniker":"cosmoshub-ba-public-statefulset-0","other":{"tx_index":"on","rpc_address":"tcp://0.0.0.0:26657"}},"sync_info":{"latest_block_hash":"B40E32B83F0F68D17244BD5F705FED134C97891EC85451C6EE510801F7498B58","latest_app_hash":"AEA738C12FE3866AF40229DA9FF7989F0C0E782E35F5FA2B705B353A287090F4","latest_block_height":"18062301","latest_block_time":"2023-11-29T11:50:58.244063897Z","earliest_block_hash":"1C68BFD6035F4FF179BE4625B5C081C801C0F31A224BD6CE622FC4E12D04B0DD","earliest_app_hash":"C7D5E842154AADF210ABB22815E99671B9136BA15D6AB2247C980C1BF98A181D","earliest_block_height":"17847213","earliest_block_time":"2023-11-14T07:58:50.776009038Z","catching_up":false},"validator_info":{"address":"EC9732FAA6E9EE5EAFC0B1487DA4077805FBA8AF","pub_key":{"type":"tendermint/PubKeyEd25519","value":"GmHGUGFg6qDu1VWN8dT8FQkddQ4jWsyKAxZgEA4MJ78="},"voting_power":"0"}}}` + + err := json.Unmarshal([]byte(jsonData), &statusResponse) + s.Require().NoError(err) + + fmt.Println(statusResponse.Result.SyncInfo.LatestBlockHeight) +} + // TODO: Remove after rounding errors are addressed and resolved. // Make sure that more specific test specs are added to validate the expected // supply for correctness. From d8e71d85f7782e649be3443604859f7b3cbb03f1 Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 22:53:10 +0900 Subject: [PATCH 18/19] Use correct port --- app/app.go | 4 ++ .../delivery/http/system_http_handler.go | 42 +++++-------------- x/mint/keeper/hooks_test.go | 25 ----------- 3 files changed, 15 insertions(+), 56 deletions(-) diff --git a/app/app.go b/app/app.go index 8cd7b4f7811..4c2d9674582 100644 --- a/app/app.go +++ b/app/app.go @@ -273,6 +273,10 @@ func NewOsmosisApp( dbHost := os.Getenv(ENV_NAME_INGEST_SQS_DBHOST) dbPort := os.Getenv(ENV_NAME_INGEST_SQS_DBPORT) grpcAddress := os.Getenv(ENV_NAME_GRPC_GATEWAY_ENDPOINT) + if grpcAddress == "" { + grpcAddress = "http://localhost:26657" + } + sidecarQueryServerAddress := os.Getenv(ENV_NAME_INGEST_SQS_SERVER_ADDRESS) sidecarQueryServerTimeoutDuration, err := strconv.Atoi(os.Getenv(ENV_NAME_INGEST_SQS_SERVER_TIMEOUT_DURATION_SECS)) if err != nil { diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index a4f49be551b..de828018821 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -6,7 +6,6 @@ import ( "io" "net/http" _ "net/http/pprof" - "os" "strconv" "go.uber.org/zap" @@ -20,32 +19,22 @@ import ( ) type SystemHandler struct { - logger log.Logger - host string // Host for the GRPC gateway - grpcPort string // GRPC gateway port - redisHost string // Redis host - redisPort string // Redis port - CIUsecase mvc.ChainInfoUsecase + logger log.Logger + redisAddress string + grpcAddress string + CIUsecase mvc.ChainInfoUsecase } // NewSystemHandler will initialize the /debug/ppof resources endpoint func NewSystemHandler(e *echo.Echo, redisAddress, grpcAddress string, logger log.Logger, us mvc.ChainInfoUsecase) { // GRPC Gateway configuration - host := getEnvOrDefault("GRPC_GATEWAY_HOST", "localhost") - grpcPort := getEnvOrDefault("GRPC_GATEWAY_PORT", "1317") - - // Redis configuration - redisHost := getEnvOrDefault("REDIS_HOST", "localhost") - redisPort := getEnvOrDefault("REDIS_PORT", "6379") logger.Info("new sys handler") handler := &SystemHandler{ - logger: logger, - host: host, - grpcPort: grpcPort, - redisHost: redisHost, - redisPort: redisPort, - CIUsecase: us, + logger: logger, + redisAddress: redisAddress, + grpcAddress: grpcAddress, + CIUsecase: us, } e.GET("/debug/pprof/*", echo.WrapHandler(http.DefaultServeMux)) @@ -62,8 +51,8 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { // Check GRPC Gateway status grpcStatus := "running" - // url := fmt.Sprintf("http://%s:%s/status", h.host, h.grpcPort) - url := "https://rpc-cosmoshub.blockapsis.com/status" + url := h.grpcAddress + "/status" + fmt.Println(url) resp, err := http.Get(url) if err != nil { grpcStatus = "down" @@ -127,7 +116,7 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { // Check Redis status redisStatus := "running" rdb := redis.NewClient(&redis.Options{ - Addr: fmt.Sprintf("%s:%s", h.redisHost, h.redisPort), + Addr: h.redisAddress, }) if _, err := rdb.Ping().Result(); err != nil { @@ -142,12 +131,3 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { "node_status": nodeStatus, }) } - -// getEnvOrDefault gets an environment variable or returns a default value -func getEnvOrDefault(key, defaultValue string) string { - value := os.Getenv(key) - if value == "" { - return defaultValue - } - return value -} diff --git a/x/mint/keeper/hooks_test.go b/x/mint/keeper/hooks_test.go index ce24d092240..60eaac6f3c0 100644 --- a/x/mint/keeper/hooks_test.go +++ b/x/mint/keeper/hooks_test.go @@ -1,8 +1,6 @@ package keeper_test import ( - "encoding/json" - "fmt" "testing" "github.com/stretchr/testify/suite" @@ -428,29 +426,6 @@ func (s *KeeperTestSuite) TestAfterEpochEnd() { } } -// TestAfterEpochEnd tests that the after epoch end hook correctly -// distributes the rewards depending on what epoch it is in. -func (s *KeeperTestSuite) TestA() { - // Parse the response from the GRPC Gateway status endpoint - - // Parse the response from the GRPC Gateway status endpoint - type JsonResponse struct { - Result struct { - SyncInfo struct { - LatestBlockHeight string `json:"latest_block_height"` - } `json:"sync_info"` - } `json:"result"` - } - var statusResponse JsonResponse - - jsonData := `{"jsonrpc":"2.0","id":-1,"result":{"node_info":{"protocol_version":{"p2p":"8","block":"11","app":"0"},"id":"5e14e87cf797b622a227d6b09bd393fd415c5a91","listen_addr":"159.89.3.35:31581","network":"cosmoshub-4","version":"0.34.29","channels":"40202122233038606100","moniker":"cosmoshub-ba-public-statefulset-0","other":{"tx_index":"on","rpc_address":"tcp://0.0.0.0:26657"}},"sync_info":{"latest_block_hash":"B40E32B83F0F68D17244BD5F705FED134C97891EC85451C6EE510801F7498B58","latest_app_hash":"AEA738C12FE3866AF40229DA9FF7989F0C0E782E35F5FA2B705B353A287090F4","latest_block_height":"18062301","latest_block_time":"2023-11-29T11:50:58.244063897Z","earliest_block_hash":"1C68BFD6035F4FF179BE4625B5C081C801C0F31A224BD6CE622FC4E12D04B0DD","earliest_app_hash":"C7D5E842154AADF210ABB22815E99671B9136BA15D6AB2247C980C1BF98A181D","earliest_block_height":"17847213","earliest_block_time":"2023-11-14T07:58:50.776009038Z","catching_up":false},"validator_info":{"address":"EC9732FAA6E9EE5EAFC0B1487DA4077805FBA8AF","pub_key":{"type":"tendermint/PubKeyEd25519","value":"GmHGUGFg6qDu1VWN8dT8FQkddQ4jWsyKAxZgEA4MJ78="},"voting_power":"0"}}}` - - err := json.Unmarshal([]byte(jsonData), &statusResponse) - s.Require().NoError(err) - - fmt.Println(statusResponse.Result.SyncInfo.LatestBlockHeight) -} - // TODO: Remove after rounding errors are addressed and resolved. // Make sure that more specific test specs are added to validate the expected // supply for correctness. From a9167a938e2f13b75474c5c9b6c850f9b4703f85 Mon Sep 17 00:00:00 2001 From: mattverse Date: Wed, 29 Nov 2023 22:58:41 +0900 Subject: [PATCH 19/19] clean up --- .../redis/redis_chain_info_repository.go | 5 ----- .../delivery/http/system_http_handler.go | 21 ------------------- 2 files changed, 26 deletions(-) diff --git a/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go b/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go index 8226808524a..d0bd4dc815a 100644 --- a/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go +++ b/ingest/sqs/chain_info/repository/redis/redis_chain_info_repository.go @@ -26,8 +26,6 @@ func NewChainInfoRepo(repositoryManager mvc.TxManager) *chainInfoRepo { // StoreLatestHeight stores the latest blockchain height into Redis func (r *chainInfoRepo) StoreLatestHeight(ctx context.Context, tx mvc.Tx, height uint64) error { - fmt.Println("Starting store latest height") - redisTx, err := tx.AsRedisTx() if err != nil { return err @@ -39,15 +37,12 @@ func (r *chainInfoRepo) StoreLatestHeight(ctx context.Context, tx mvc.Tx, height } heightStr := strconv.FormatUint(height, 10) - fmt.Println(heightStr) // Use HSet for storing the latest height cmd := pipeliner.HSet(ctx, latestHeightKey, latestHeightField, heightStr) if err := cmd.Err(); err != nil { return err } - fmt.Println("Ending store latest height") - return tx.Exec(ctx) } diff --git a/ingest/sqs/system/delivery/http/system_http_handler.go b/ingest/sqs/system/delivery/http/system_http_handler.go index de828018821..f1c7ac453e8 100644 --- a/ingest/sqs/system/delivery/http/system_http_handler.go +++ b/ingest/sqs/system/delivery/http/system_http_handler.go @@ -6,7 +6,6 @@ import ( "io" "net/http" _ "net/http/pprof" - "strconv" "go.uber.org/zap" @@ -27,9 +26,6 @@ type SystemHandler struct { // NewSystemHandler will initialize the /debug/ppof resources endpoint func NewSystemHandler(e *echo.Echo, redisAddress, grpcAddress string, logger log.Logger, us mvc.ChainInfoUsecase) { - // GRPC Gateway configuration - - logger.Info("new sys handler") handler := &SystemHandler{ logger: logger, redisAddress: redisAddress, @@ -46,13 +42,11 @@ func NewSystemHandler(e *echo.Echo, redisAddress, grpcAddress string, logger log // GetHealthStatus handles health check requests for both GRPC gateway and Redis func (h *SystemHandler) GetHealthStatus(c echo.Context) error { - fmt.Println("=====Start") ctx := c.Request().Context() // Check GRPC Gateway status grpcStatus := "running" url := h.grpcAddress + "/status" - fmt.Println(url) resp, err := http.Get(url) if err != nil { grpcStatus = "down" @@ -93,21 +87,6 @@ func (h *SystemHandler) GetHealthStatus(c echo.Context) error { // Compare latestHeight with latest_block_height from the status endpoint nodeStatus := "synced" - fmt.Println(statusResponse) - latestBlockHeight, err := strconv.Atoi(statusResponse.Result.SyncInfo.LatestBlockHeight) - if err != nil { - return echo.NewHTTPError(http.StatusInternalServerError, "Failed to parse JSON response") - } - - h.logger.Info("status resp: ", zap.Int("height", latestBlockHeight)) - h.logger.Info("latest height: ", zap.Int("latest", int(latestHeight))) - - b, err := json.MarshalIndent(statusResponse, "", " ") - if err != nil { - return echo.NewHTTPError(http.StatusInternalServerError, "Failed to parse JSON response") - } - fmt.Println(b) - // allow 10 blocks of difference before claiming node is not synced if fmt.Sprint(int64(latestHeight)+10) < statusResponse.Result.SyncInfo.LatestBlockHeight { nodeStatus = "not_synced"