Browse Source

Add `\health` rpc endpoint (#1306)

* Init `\health` rpc endpoint

* remove additional info from `\health` rpc endpoint

* Cleanup imports

* Added time threshold for health check

* Update rpc doc

* Remove unnecessary checks for blocktime creation lag

* Clean up of unnecessary config usage
pull/1335/head
Constantine 7 years ago
committed by Anton Kaliaev
parent
commit
152290db7e
8 changed files with 41 additions and 3 deletions
  1. +3
    -0
      .gitignore
  2. +1
    -0
      docs/specification/rpc.rst
  3. +1
    -0
      rpc/core/doc.go
  4. +30
    -0
      rpc/core/health.go
  5. +2
    -2
      rpc/core/pipe.go
  6. +1
    -0
      rpc/core/routes.go
  7. +2
    -0
      rpc/core/types/responses.go
  8. +1
    -1
      types/heartbeat.go

+ 3
- 0
.gitignore View File

@ -21,3 +21,6 @@ docs/tools
scripts/wal2json/wal2json scripts/wal2json/wal2json
scripts/cutWALUntil/cutWALUntil scripts/cutWALUntil/cutWALUntil
.idea/
*.iml

+ 1
- 0
docs/specification/rpc.rst View File

@ -97,6 +97,7 @@ An HTTP Get request to the root RPC endpoint (e.g.
http://localhost:46657/genesis http://localhost:46657/genesis
http://localhost:46657/net_info http://localhost:46657/net_info
http://localhost:46657/num_unconfirmed_txs http://localhost:46657/num_unconfirmed_txs
http://localhost:46657/health
http://localhost:46657/status http://localhost:46657/status
http://localhost:46657/unconfirmed_txs http://localhost:46657/unconfirmed_txs
http://localhost:46657/unsafe_flush_mempool http://localhost:46657/unsafe_flush_mempool


+ 1
- 0
rpc/core/doc.go View File

@ -81,6 +81,7 @@ Available endpoints:
/net_info /net_info
/num_unconfirmed_txs /num_unconfirmed_txs
/status /status
/health
/unconfirmed_txs /unconfirmed_txs
/unsafe_flush_mempool /unsafe_flush_mempool
/unsafe_stop_cpu_profiler /unsafe_stop_cpu_profiler


+ 30
- 0
rpc/core/health.go View File

@ -0,0 +1,30 @@
package core
import (
ctypes "github.com/tendermint/tendermint/rpc/core/types"
)
// Get node health. Checks whether new blocks are created.
//
// ```shell
// curl 'localhost:46657/health'
// ```
//
// ```go
// client := client.NewHTTP("tcp://0.0.0.0:46657", "/websocket")
// result, err := client.Health()
// ```
//
// > The above command returns JSON structured like this:
//
// ```json
// {
// "error": "",
// "result": {},
// "id": "",
// "jsonrpc": "2.0"
// }
// ```
func Health() (*ctypes.ResultHealth, error) {
return &ctypes.ResultHealth{}, nil
}

+ 2
- 2
rpc/core/pipe.go View File

@ -3,10 +3,10 @@ package core
import ( import (
"time" "time"
crypto "github.com/tendermint/go-crypto"
"github.com/tendermint/go-crypto"
"github.com/tendermint/tendermint/consensus" "github.com/tendermint/tendermint/consensus"
cstypes "github.com/tendermint/tendermint/consensus/types" cstypes "github.com/tendermint/tendermint/consensus/types"
p2p "github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/p2p"
"github.com/tendermint/tendermint/proxy" "github.com/tendermint/tendermint/proxy"
sm "github.com/tendermint/tendermint/state" sm "github.com/tendermint/tendermint/state"
"github.com/tendermint/tendermint/state/txindex" "github.com/tendermint/tendermint/state/txindex"


+ 1
- 0
rpc/core/routes.go View File

@ -12,6 +12,7 @@ var Routes = map[string]*rpc.RPCFunc{
"unsubscribe_all": rpc.NewWSRPCFunc(UnsubscribeAll, ""), "unsubscribe_all": rpc.NewWSRPCFunc(UnsubscribeAll, ""),
// info API // info API
"health": rpc.NewRPCFunc(Health, ""),
"status": rpc.NewRPCFunc(Status, ""), "status": rpc.NewRPCFunc(Status, ""),
"net_info": rpc.NewRPCFunc(NetInfo, ""), "net_info": rpc.NewRPCFunc(NetInfo, ""),
"blockchain": rpc.NewRPCFunc(BlockchainInfo, "minHeight,maxHeight"), "blockchain": rpc.NewRPCFunc(BlockchainInfo, "minHeight,maxHeight"),


+ 2
- 0
rpc/core/types/responses.go View File

@ -155,3 +155,5 @@ type ResultEvent struct {
Query string `json:"query"` Query string `json:"query"`
Data types.TMEventData `json:"data"` Data types.TMEventData `json:"data"`
} }
type ResultHealth struct{}

+ 1
- 1
types/heartbeat.go View File

@ -14,7 +14,7 @@ import (
// json field tags because we always want the JSON // json field tags because we always want the JSON
// representation to be in its canonical form. // representation to be in its canonical form.
type Heartbeat struct { type Heartbeat struct {
ValidatorAddress Address `json:"validator_address"`
ValidatorAddress Address `json:"validator_address"`
ValidatorIndex int `json:"validator_index"` ValidatorIndex int `json:"validator_index"`
Height int64 `json:"height"` Height int64 `json:"height"`
Round int `json:"round"` Round int `json:"round"`


Loading…
Cancel
Save