Merge PR #4837: Cleanup node_info Endpoint
This commit is contained in:
parent
c4e3578087
commit
451535bd79
|
@ -0,0 +1,2 @@
|
||||||
|
[\#4837](https://github.com/cosmos/cosmos-sdk/pull/4837) Remove /version and /node_version
|
||||||
|
endpoints in favor of refactoring /node_info to also include application version info.
|
6
Makefile
6
Makefile
|
@ -25,11 +25,11 @@ build: go.sum
|
||||||
|
|
||||||
update-swagger-docs: statik
|
update-swagger-docs: statik
|
||||||
$(BINDIR)/statik -src=client/lcd/swagger-ui -dest=client/lcd -f -m
|
$(BINDIR)/statik -src=client/lcd/swagger-ui -dest=client/lcd -f -m
|
||||||
if [ -n "$(git status --porcelain)" ]; then \
|
@if [ -n "$(git status --porcelain)" ]; then \
|
||||||
echo "swagger docs out of sync";\
|
echo "\033[91mSwagger docs are out of sync!!!\033[0m";\
|
||||||
exit 1;\
|
exit 1;\
|
||||||
else \
|
else \
|
||||||
echo "swagger docs are in sync";\
|
echo "\033[92mSwagger docs are in sync\033[0m";\
|
||||||
fi
|
fi
|
||||||
.PHONY: update-swagger-docs
|
.PHONY: update-swagger-docs
|
||||||
|
|
||||||
|
|
|
@ -94,8 +94,6 @@ var (
|
||||||
BlockRequestHandlerFn = rpc.BlockRequestHandlerFn
|
BlockRequestHandlerFn = rpc.BlockRequestHandlerFn
|
||||||
LatestBlockRequestHandlerFn = rpc.LatestBlockRequestHandlerFn
|
LatestBlockRequestHandlerFn = rpc.LatestBlockRequestHandlerFn
|
||||||
RegisterRPCRoutes = rpc.RegisterRPCRoutes
|
RegisterRPCRoutes = rpc.RegisterRPCRoutes
|
||||||
CLIVersionRequestHandler = rpc.CLIVersionRequestHandler
|
|
||||||
NodeVersionRequestHandler = rpc.NodeVersionRequestHandler
|
|
||||||
StatusCommand = rpc.StatusCommand
|
StatusCommand = rpc.StatusCommand
|
||||||
NodeInfoRequestHandlerFn = rpc.NodeInfoRequestHandlerFn
|
NodeInfoRequestHandlerFn = rpc.NodeInfoRequestHandlerFn
|
||||||
NodeSyncingRequestHandlerFn = rpc.NodeSyncingRequestHandlerFn
|
NodeSyncingRequestHandlerFn = rpc.NodeSyncingRequestHandlerFn
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -35,15 +35,6 @@ securityDefinitions:
|
||||||
kms:
|
kms:
|
||||||
type: basic
|
type: basic
|
||||||
paths:
|
paths:
|
||||||
/version:
|
|
||||||
get:
|
|
||||||
summary: Version of Gaia-lite
|
|
||||||
tags:
|
|
||||||
- Misc
|
|
||||||
description: Get the version of gaia-lite running locally to compare against expected
|
|
||||||
responses:
|
|
||||||
200:
|
|
||||||
description: Plaintext version i.e. "v0.25.0"
|
|
||||||
/node_info:
|
/node_info:
|
||||||
get:
|
get:
|
||||||
description: Information about the connected node
|
description: Information about the connected node
|
||||||
|
@ -58,44 +49,62 @@ paths:
|
||||||
schema:
|
schema:
|
||||||
type: object
|
type: object
|
||||||
properties:
|
properties:
|
||||||
id:
|
application_version:
|
||||||
type: string
|
|
||||||
moniker:
|
|
||||||
type: string
|
|
||||||
example: validator-name
|
|
||||||
protocol_version:
|
|
||||||
properties:
|
properties:
|
||||||
p2p:
|
build_tags:
|
||||||
type: string
|
type: string
|
||||||
example: 7
|
client_name:
|
||||||
block:
|
|
||||||
type: string
|
type: string
|
||||||
example: 10
|
commit:
|
||||||
app:
|
|
||||||
type: string
|
type: string
|
||||||
example: 0
|
go:
|
||||||
network:
|
type: string
|
||||||
type: string
|
name:
|
||||||
example: gaia-2
|
type: string
|
||||||
channels:
|
server_name:
|
||||||
type: string
|
type: string
|
||||||
listen_addr:
|
version:
|
||||||
type: string
|
type: string
|
||||||
example: 192.168.56.1:26656
|
node_info:
|
||||||
version:
|
|
||||||
description: Tendermint version
|
|
||||||
type: string
|
|
||||||
example: 0.15.0
|
|
||||||
other:
|
|
||||||
description: more information on versions
|
|
||||||
type: object
|
|
||||||
properties:
|
properties:
|
||||||
tx_index:
|
id:
|
||||||
type: string
|
type: string
|
||||||
example: on
|
moniker:
|
||||||
rpc_address:
|
|
||||||
type: string
|
type: string
|
||||||
example: tcp://0.0.0.0:26657
|
example: validator-name
|
||||||
|
protocol_version:
|
||||||
|
properties:
|
||||||
|
p2p:
|
||||||
|
type: string
|
||||||
|
example: 7
|
||||||
|
block:
|
||||||
|
type: string
|
||||||
|
example: 10
|
||||||
|
app:
|
||||||
|
type: string
|
||||||
|
example: 0
|
||||||
|
network:
|
||||||
|
type: string
|
||||||
|
example: gaia-2
|
||||||
|
channels:
|
||||||
|
type: string
|
||||||
|
listen_addr:
|
||||||
|
type: string
|
||||||
|
example: 192.168.56.1:26656
|
||||||
|
version:
|
||||||
|
description: Tendermint version
|
||||||
|
type: string
|
||||||
|
example: 0.15.0
|
||||||
|
other:
|
||||||
|
description: more information on versions
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
tx_index:
|
||||||
|
type: string
|
||||||
|
example: on
|
||||||
|
rpc_address:
|
||||||
|
type: string
|
||||||
|
example: tcp://0.0.0.0:26657
|
||||||
500:
|
500:
|
||||||
description: Failed to query node status
|
description: Failed to query node status
|
||||||
/syncing:
|
/syncing:
|
||||||
|
@ -104,9 +113,16 @@ paths:
|
||||||
tags:
|
tags:
|
||||||
- Tendermint RPC
|
- Tendermint RPC
|
||||||
description: Get if the node is currently syning with other nodes
|
description: Get if the node is currently syning with other nodes
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
200:
|
200:
|
||||||
description: '"true" or "false"'
|
description: Node syncing status
|
||||||
|
schema:
|
||||||
|
type: object
|
||||||
|
properties:
|
||||||
|
syncing:
|
||||||
|
type: boolean
|
||||||
500:
|
500:
|
||||||
description: Server internal error
|
description: Server internal error
|
||||||
/blocks/latest:
|
/blocks/latest:
|
||||||
|
@ -2481,4 +2497,4 @@ definitions:
|
||||||
total:
|
total:
|
||||||
type: array
|
type: array
|
||||||
items:
|
items:
|
||||||
$ref: "#/definitions/Coin"
|
$ref: "#/definitions/Coin"
|
||||||
|
|
|
@ -1,21 +1,13 @@
|
||||||
package rpc
|
package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"log"
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
|
||||||
"github.com/cosmos/cosmos-sdk/client/context"
|
"github.com/cosmos/cosmos-sdk/client/context"
|
||||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
|
||||||
"github.com/cosmos/cosmos-sdk/version"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Register REST endpoints
|
// Register REST endpoints
|
||||||
func RegisterRPCRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
func RegisterRPCRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
||||||
r.HandleFunc("/version", CLIVersionRequestHandler).Methods("GET")
|
|
||||||
r.HandleFunc("/node_version", NodeVersionRequestHandler(cliCtx)).Methods("GET")
|
|
||||||
r.HandleFunc("/node_info", NodeInfoRequestHandlerFn(cliCtx)).Methods("GET")
|
r.HandleFunc("/node_info", NodeInfoRequestHandlerFn(cliCtx)).Methods("GET")
|
||||||
r.HandleFunc("/syncing", NodeSyncingRequestHandlerFn(cliCtx)).Methods("GET")
|
r.HandleFunc("/syncing", NodeSyncingRequestHandlerFn(cliCtx)).Methods("GET")
|
||||||
r.HandleFunc("/blocks/latest", LatestBlockRequestHandlerFn(cliCtx)).Methods("GET")
|
r.HandleFunc("/blocks/latest", LatestBlockRequestHandlerFn(cliCtx)).Methods("GET")
|
||||||
|
@ -23,27 +15,3 @@ func RegisterRPCRoutes(cliCtx context.CLIContext, r *mux.Router) {
|
||||||
r.HandleFunc("/validatorsets/latest", LatestValidatorSetRequestHandlerFn(cliCtx)).Methods("GET")
|
r.HandleFunc("/validatorsets/latest", LatestValidatorSetRequestHandlerFn(cliCtx)).Methods("GET")
|
||||||
r.HandleFunc("/validatorsets/{height}", ValidatorSetRequestHandlerFn(cliCtx)).Methods("GET")
|
r.HandleFunc("/validatorsets/{height}", ValidatorSetRequestHandlerFn(cliCtx)).Methods("GET")
|
||||||
}
|
}
|
||||||
|
|
||||||
// cli version REST handler endpoint
|
|
||||||
func CLIVersionRequestHandler(w http.ResponseWriter, r *http.Request) {
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
if _, err := w.Write([]byte(fmt.Sprintf("{\"version\": \"%s\"}", version.Version))); err != nil {
|
|
||||||
log.Printf("could not write response: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// connected node version REST handler endpoint
|
|
||||||
func NodeVersionRequestHandler(cliCtx context.CLIContext) http.HandlerFunc {
|
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
|
||||||
res, _, err := cliCtx.Query("/app/version")
|
|
||||||
if err != nil {
|
|
||||||
rest.WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json")
|
|
||||||
if _, err := w.Write(res); err != nil {
|
|
||||||
log.Printf("could not write response: %v", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -2,9 +2,7 @@ package rpc
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
@ -15,9 +13,12 @@ import (
|
||||||
"github.com/cosmos/cosmos-sdk/client/flags"
|
"github.com/cosmos/cosmos-sdk/client/flags"
|
||||||
"github.com/cosmos/cosmos-sdk/codec"
|
"github.com/cosmos/cosmos-sdk/codec"
|
||||||
"github.com/cosmos/cosmos-sdk/types/rest"
|
"github.com/cosmos/cosmos-sdk/types/rest"
|
||||||
|
"github.com/cosmos/cosmos-sdk/version"
|
||||||
|
|
||||||
|
"github.com/tendermint/tendermint/p2p"
|
||||||
)
|
)
|
||||||
|
|
||||||
// StatusCommand returns the status of the network
|
// StatusCommand returns the command to return the status of the network.
|
||||||
func StatusCommand() *cobra.Command {
|
func StatusCommand() *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "status",
|
Use: "status",
|
||||||
|
@ -32,7 +33,6 @@ func StatusCommand() *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) {
|
func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) {
|
||||||
// get the node
|
|
||||||
node, err := cliCtx.GetNode()
|
node, err := cliCtx.GetNode()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return &ctypes.ResultStatus{}, err
|
return &ctypes.ResultStatus{}, err
|
||||||
|
@ -41,9 +41,7 @@ func getNodeStatus(cliCtx context.CLIContext) (*ctypes.ResultStatus, error) {
|
||||||
return node.Status()
|
return node.Status()
|
||||||
}
|
}
|
||||||
|
|
||||||
// CMD
|
func printNodeStatus(_ *cobra.Command, _ []string) error {
|
||||||
|
|
||||||
func printNodeStatus(cmd *cobra.Command, args []string) error {
|
|
||||||
// No need to verify proof in getting node status
|
// No need to verify proof in getting node status
|
||||||
viper.Set(flags.FlagTrustNode, true)
|
viper.Set(flags.FlagTrustNode, true)
|
||||||
cliCtx := context.NewCLIContext()
|
cliCtx := context.NewCLIContext()
|
||||||
|
@ -66,7 +64,11 @@ func printNodeStatus(cmd *cobra.Command, args []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// REST
|
type nodeInfoResponse struct {
|
||||||
|
p2p.DefaultNodeInfo `json:"node_info"`
|
||||||
|
|
||||||
|
ApplicationVersion version.Info `json:"application_version"`
|
||||||
|
}
|
||||||
|
|
||||||
// REST handler for node info
|
// REST handler for node info
|
||||||
func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
|
@ -77,11 +79,18 @@ func NodeInfoRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
nodeInfo := status.NodeInfo
|
resp := nodeInfoResponse{
|
||||||
rest.PostProcessResponse(w, cliCtx, nodeInfo)
|
DefaultNodeInfo: status.NodeInfo,
|
||||||
|
ApplicationVersion: version.NewInfo(),
|
||||||
|
}
|
||||||
|
rest.PostProcessResponseBare(w, cliCtx, resp)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type syncingResponse struct {
|
||||||
|
Syncing bool `json:"syncing"`
|
||||||
|
}
|
||||||
|
|
||||||
// REST handler for node syncing
|
// REST handler for node syncing
|
||||||
func NodeSyncingRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
func NodeSyncingRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
@ -91,9 +100,6 @@ func NodeSyncingRequestHandlerFn(cliCtx context.CLIContext) http.HandlerFunc {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
syncing := status.SyncInfo.CatchingUp
|
rest.PostProcessResponseBare(w, cliCtx, syncingResponse{Syncing: status.SyncInfo.CatchingUp})
|
||||||
if _, err := w.Write([]byte(strconv.FormatBool(syncing))); err != nil {
|
|
||||||
log.Printf("could not write response: %v", err)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,6 +237,35 @@ func ParseQueryHeightOrReturnBadRequest(w http.ResponseWriter, cliCtx context.CL
|
||||||
return cliCtx, true
|
return cliCtx, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PostProcessResponseBare post processes a body similar to PostProcessResponse
|
||||||
|
// except it does not wrap the body and inject the height.
|
||||||
|
func PostProcessResponseBare(w http.ResponseWriter, cliCtx context.CLIContext, body interface{}) {
|
||||||
|
var (
|
||||||
|
resp []byte
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
switch body.(type) {
|
||||||
|
case []byte:
|
||||||
|
resp = body.([]byte)
|
||||||
|
|
||||||
|
default:
|
||||||
|
if cliCtx.Indent {
|
||||||
|
resp, err = cliCtx.Codec.MarshalJSONIndent(body, "", " ")
|
||||||
|
} else {
|
||||||
|
resp, err = cliCtx.Codec.MarshalJSON(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
WriteErrorResponse(w, http.StatusInternalServerError, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
_, _ = w.Write(resp)
|
||||||
|
}
|
||||||
|
|
||||||
// PostProcessResponse performs post processing for a REST response. The result
|
// PostProcessResponse performs post processing for a REST response. The result
|
||||||
// returned to clients will contain two fields, the height at which the resource
|
// returned to clients will contain two fields, the height at which the resource
|
||||||
// was queried at and the original result.
|
// was queried at and the original result.
|
||||||
|
|
|
@ -22,7 +22,7 @@ var Cmd = &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Print the app version",
|
Short: "Print the app version",
|
||||||
RunE: func(_ *cobra.Command, _ []string) error {
|
RunE: func(_ *cobra.Command, _ []string) error {
|
||||||
verInfo := newVersionInfo()
|
verInfo := NewInfo()
|
||||||
|
|
||||||
if !viper.GetBool(flagLong) {
|
if !viper.GetBool(flagLong) {
|
||||||
fmt.Println(verInfo.Version)
|
fmt.Println(verInfo.Version)
|
||||||
|
|
|
@ -33,33 +33,23 @@ var (
|
||||||
Version = ""
|
Version = ""
|
||||||
// commit
|
// commit
|
||||||
Commit = ""
|
Commit = ""
|
||||||
// hash of the go.sum file
|
|
||||||
GoSumHash = ""
|
|
||||||
// build tags
|
// build tags
|
||||||
BuildTags = ""
|
BuildTags = ""
|
||||||
)
|
)
|
||||||
|
|
||||||
type versionInfo struct {
|
// Info defines the application version information.
|
||||||
Name string `json:"name"`
|
type Info struct {
|
||||||
ServerName string `json:"server_name"`
|
Name string `json:"name" yaml:"name"`
|
||||||
ClientName string `json:"client_name"`
|
ServerName string `json:"server_name" yaml:"server_name"`
|
||||||
Version string `json:"version"`
|
ClientName string `json:"client_name" yaml:"client_name"`
|
||||||
GitCommit string `json:"commit"`
|
Version string `json:"version" yaml:"version"`
|
||||||
BuildTags string `json:"build_tags"`
|
GitCommit string `json:"commit" yaml:"commit"`
|
||||||
GoVersion string `json:"go"`
|
BuildTags string `json:"build_tags" yaml:"build_tags"`
|
||||||
|
GoVersion string `json:"go" yaml:"go"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v versionInfo) String() string {
|
func NewInfo() Info {
|
||||||
return fmt.Sprintf(`%s: %s
|
return Info{
|
||||||
git commit: %s
|
|
||||||
build tags: %s
|
|
||||||
%s`,
|
|
||||||
v.Name, v.Version, v.GitCommit, v.BuildTags, v.GoVersion,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
func newVersionInfo() versionInfo {
|
|
||||||
return versionInfo{
|
|
||||||
Name: Name,
|
Name: Name,
|
||||||
ServerName: ServerName,
|
ServerName: ServerName,
|
||||||
ClientName: ClientName,
|
ClientName: ClientName,
|
||||||
|
@ -69,3 +59,12 @@ func newVersionInfo() versionInfo {
|
||||||
GoVersion: fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
|
GoVersion: fmt.Sprintf("go version %s %s/%s", runtime.Version(), runtime.GOOS, runtime.GOARCH),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (vi Info) String() string {
|
||||||
|
return fmt.Sprintf(`%s: %s
|
||||||
|
git commit: %s
|
||||||
|
build tags: %s
|
||||||
|
%s`,
|
||||||
|
vi.Name, vi.Version, vi.GitCommit, vi.BuildTags, vi.GoVersion,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue