Skip to content

Commit

Permalink
Merge pull request #116 from ipfs-force-community/feat/add_status_api
Browse files Browse the repository at this point in the history
feat: add status api to detect api ready
  • Loading branch information
simlecode authored Feb 21, 2023
2 parents 9dc368b + be069e2 commit 340d9af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/ipfs-force-community/venus-gateway
go 1.18

require (
github.com/etherlabsio/healthcheck/v2 v2.0.0
github.com/filecoin-project/go-address v1.1.0
github.com/filecoin-project/go-jsonrpc v0.1.5
github.com/filecoin-project/go-state-types v0.10.0-rc3
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ github.com/envoyproxy/go-control-plane v0.9.9-0.20210512163311-63b5d3c536b0/go.m
github.com/envoyproxy/go-control-plane v0.9.10-0.20210907150352-cf90f659a021/go.mod h1:AFq3mo9L8Lqqiid3OhADV3RfLJnjiw63cSpi+fDTRC0=
github.com/envoyproxy/go-control-plane v0.10.2-0.20220325020618-49ff273808a1/go.mod h1:KJwIaB5Mv44NWtYuAOFCVOjcI94vtpEz2JU/D2v6IjE=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/etherlabsio/healthcheck/v2 v2.0.0 h1:oKq8cbpwM/yNGPXf2Sff6MIjVUjx/pGYFydWzeK2MpA=
github.com/etherlabsio/healthcheck/v2 v2.0.0/go.mod h1:huNVOjKzu6FI1eaO1CGD3ZjhrmPWf5Obu/pzpI6/wog=
github.com/facebookgo/atomicfile v0.0.0-20151019160806-2de1f203e7d5/go.mod h1:JpoxHjuQauoxiFMl1ie8Xc/7TfLuMZ5eOCONd1sUBHg=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.8.0/go.mod h1:3l45GVGkyrnYNl9HoIjnp2NnNWvh6hLAqD8yTfGjnw8=
Expand Down
28 changes: 18 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (
"syscall"
"time"

"github.com/etherlabsio/healthcheck/v2"

"github.com/gorilla/mux"
logging "github.com/ipfs/go-log/v2"
"github.com/mitchellh/go-homedir"
Expand Down Expand Up @@ -204,6 +206,7 @@ func RunMain(ctx context.Context, repoPath string, cfg *config.Config) error {
}

mux := mux.NewRouter()

// v2api(newest api)
rpcServerV2 := jsonrpc.NewServer()
rpcServerV2.Register("Gateway", gatewayAPI)
Expand All @@ -226,22 +229,27 @@ func RunMain(ctx context.Context, repoPath string, cfg *config.Config) error {
return fmt.Errorf("failed to save local token to token file: %w", err)
}

handler := (http.Handler)(jwtclient.NewAuthMux(localJwtCli, jwtclient.WarpIJwtAuthClient(remoteJwtCli), mux))
authMux := jwtclient.NewAuthMux(localJwtCli, jwtclient.WarpIJwtAuthClient(remoteJwtCli), mux)
authMux.TrustHandle("/debug/pprof/", http.DefaultServeMux)
authMux.TrustHandle("/healthcheck", healthcheck.Handler())

if err := metrics2.SetupMetrics(ctx, cfg.Metrics, gatewayAPIImpl); err != nil {
return err
}
handler := (http.Handler)(authMux)
if cfg.Trace.JaegerTracingEnabled {
log.Infof("trace config %+v", cfg.Trace)
reporter, err := metrics.RegisterJaeger(cfg.Trace.ServerName, cfg.Trace)
if err != nil {
return fmt.Errorf("register jaeger exporter failed %v", cfg.Trace)
}

log.Infof("trace config %+v", cfg.Trace)
repoter, err := metrics.RegisterJaeger(cfg.Trace.ServerName, cfg.Trace)
if err != nil {
return fmt.Errorf("register jaeger exporter failed %v", cfg.Trace)
}
if repoter != nil {
log.Info("register jaeger exporter success!")
if reporter != nil {
log.Info("register jaeger exporter success!")

defer metrics.UnregisterJaeger(repoter)
handler = &ochttp.Handler{Handler: handler}
defer metrics.UnregisterJaeger(reporter)
handler = &ochttp.Handler{Handler: handler}
}
}

httptest.NewServer(handler)
Expand Down

0 comments on commit 340d9af

Please sign in to comment.