Skip to content

Commit

Permalink
Deprecate various APIs (ava-labs#2734)
Browse files Browse the repository at this point in the history
  • Loading branch information
StephenButtolph authored Mar 15, 2023
1 parent f34eafa commit fbcda4c
Show file tree
Hide file tree
Showing 21 changed files with 498 additions and 118 deletions.
55 changes: 43 additions & 12 deletions api/admin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,28 +74,40 @@ func NewService(config Config) (*common.HTTPHandler, error) {

// StartCPUProfiler starts a cpu profile writing to the specified file
func (a *Admin) StartCPUProfiler(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
a.Log.Debug("Admin: StartCPUProfiler called")
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "startCPUProfiler"),
)

return a.profiler.StartCPUProfiler()
}

// StopCPUProfiler stops the cpu profile
func (a *Admin) StopCPUProfiler(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
a.Log.Debug("Admin: StopCPUProfiler called")
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "stopCPUProfiler"),
)

return a.profiler.StopCPUProfiler()
}

// MemoryProfile runs a memory profile writing to the specified file
func (a *Admin) MemoryProfile(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
a.Log.Debug("Admin: MemoryProfile called")
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "memoryProfile"),
)

return a.profiler.MemoryProfile()
}

// LockProfile runs a mutex profile writing to the specified file
func (a *Admin) LockProfile(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
a.Log.Debug("Admin: LockProfile called")
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "lockProfile"),
)

return a.profiler.LockProfile()
}
Expand All @@ -108,7 +120,9 @@ type AliasArgs struct {

// Alias attempts to alias an HTTP endpoint to a new name
func (a *Admin) Alias(_ *http.Request, args *AliasArgs, _ *api.EmptyReply) error {
a.Log.Debug("Admin: Alias called",
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "alias"),
logging.UserString("endpoint", args.Endpoint),
logging.UserString("alias", args.Alias),
)
Expand All @@ -128,7 +142,9 @@ type AliasChainArgs struct {

// AliasChain attempts to alias a chain to a new name
func (a *Admin) AliasChain(_ *http.Request, args *AliasChainArgs, _ *api.EmptyReply) error {
a.Log.Debug("Admin: AliasChain called",
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "aliasChain"),
logging.UserString("chain", args.Chain),
logging.UserString("alias", args.Alias),
)
Expand Down Expand Up @@ -162,7 +178,9 @@ type GetChainAliasesReply struct {

// GetChainAliases returns the aliases of the chain
func (a *Admin) GetChainAliases(_ *http.Request, args *GetChainAliasesArgs, reply *GetChainAliasesReply) error {
a.Log.Debug("Admin: GetChainAliases called",
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "getChainAliases"),
logging.UserString("chain", args.Chain),
)

Expand All @@ -177,7 +195,10 @@ func (a *Admin) GetChainAliases(_ *http.Request, args *GetChainAliasesArgs, repl

// Stacktrace returns the current global stacktrace
func (a *Admin) Stacktrace(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
a.Log.Debug("Admin: Stacktrace called")
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "stacktrace"),
)

stacktrace := []byte(utils.GetStacktrace(true))
return perms.WriteFile(stacktraceFile, stacktrace, perms.ReadWrite)
Expand All @@ -200,7 +221,9 @@ type SetLoggerLevelArgs struct {
// If args.DisplayLevel == nil, doesn't set the display level of these loggers.
// If args.DisplayLevel != nil, must be a valid string representation of a log level.
func (a *Admin) SetLoggerLevel(_ *http.Request, args *SetLoggerLevelArgs, _ *api.EmptyReply) error {
a.Log.Debug("Admin: SetLoggerLevel called",
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "setLoggerLevel"),
logging.UserString("loggerName", args.LoggerName),
zap.Stringer("logLevel", args.LogLevel),
zap.Stringer("displayLevel", args.DisplayLevel),
Expand Down Expand Up @@ -250,7 +273,9 @@ type GetLoggerLevelReply struct {

// GetLogLevel returns the log level and display level of all loggers.
func (a *Admin) GetLoggerLevel(_ *http.Request, args *GetLoggerLevelArgs, reply *GetLoggerLevelReply) error {
a.Log.Debug("Admin: GetLoggerLevels called",
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "getLoggerLevels"),
logging.UserString("loggerName", args.LoggerName),
)
reply.LoggerLevels = make(map[string]LogAndDisplayLevels)
Expand Down Expand Up @@ -281,7 +306,10 @@ func (a *Admin) GetLoggerLevel(_ *http.Request, args *GetLoggerLevelArgs, reply

// GetConfig returns the config that the node was started with.
func (a *Admin) GetConfig(_ *http.Request, _ *struct{}, reply *interface{}) error {
a.Log.Debug("Admin: GetConfig called")
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "getConfig"),
)
*reply = a.NodeConfig
return nil
}
Expand All @@ -296,7 +324,10 @@ type LoadVMsReply struct {

// LoadVMs loads any new VMs available to the node and returns the added VMs.
func (a *Admin) LoadVMs(r *http.Request, _ *struct{}, reply *LoadVMsReply) error {
a.Log.Debug("Admin: LoadVMs called")
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "loadVMs"),
)

ctx := r.Context()
loadedVMs, failedVMs, err := a.VMRegistry.ReloadWithReadLock(ctx)
Expand Down
6 changes: 3 additions & 3 deletions api/admin/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ func TestLoadVMsSuccess(t *testing.T) {
id2: alias2[1:],
}

resources.mockLog.EXPECT().Debug(gomock.Any()).Times(1)
resources.mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).Times(1)
resources.mockVMRegistry.EXPECT().ReloadWithReadLock(gomock.Any()).Times(1).Return(newVMs, failedVMs, nil)
resources.mockVMManager.EXPECT().Aliases(id1).Times(1).Return(alias1, nil)
resources.mockVMManager.EXPECT().Aliases(id2).Times(1).Return(alias2, nil)
Expand All @@ -84,7 +84,7 @@ func TestLoadVMsReloadFails(t *testing.T) {
resources := initLoadVMsTest(t)
defer resources.ctrl.Finish()

resources.mockLog.EXPECT().Debug(gomock.Any()).Times(1)
resources.mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).Times(1)
// Reload fails
resources.mockVMRegistry.EXPECT().ReloadWithReadLock(gomock.Any()).Times(1).Return(nil, nil, errTest)

Expand All @@ -108,7 +108,7 @@ func TestLoadVMsGetAliasesFails(t *testing.T) {
// every vm is at least aliased to itself.
alias1 := []string{id1.String(), "vm1-alias-1", "vm1-alias-2"}

resources.mockLog.EXPECT().Debug(gomock.Any()).Times(1)
resources.mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).Times(1)
resources.mockVMRegistry.EXPECT().ReloadWithReadLock(gomock.Any()).Times(1).Return(newVMs, failedVMs, nil)
resources.mockVMManager.EXPECT().Aliases(id1).Times(1).Return(alias1, nil)
resources.mockVMManager.EXPECT().Aliases(id2).Times(1).Return(nil, errTest)
Expand Down
17 changes: 14 additions & 3 deletions api/auth/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package auth
import (
"net/http"

"go.uber.org/zap"

"github.com/ava-labs/avalanchego/api"
)

Expand Down Expand Up @@ -33,7 +35,10 @@ type Token struct {
}

func (s *Service) NewToken(_ *http.Request, args *NewTokenArgs, reply *Token) error {
s.auth.log.Debug("Auth: NewToken called")
s.auth.log.Debug("API called",
zap.String("service", "auth"),
zap.String("method", "newToken"),
)

var err error
reply.Token, err = s.auth.NewToken(args.Password.Password, defaultTokenLifespan, args.Endpoints)
Expand All @@ -46,7 +51,10 @@ type RevokeTokenArgs struct {
}

func (s *Service) RevokeToken(_ *http.Request, args *RevokeTokenArgs, _ *api.EmptyReply) error {
s.auth.log.Debug("Auth: RevokeToken called")
s.auth.log.Debug("API called",
zap.String("service", "auth"),
zap.String("method", "revokeToken"),
)

return s.auth.RevokeToken(args.Token.Token, args.Password.Password)
}
Expand All @@ -57,7 +65,10 @@ type ChangePasswordArgs struct {
}

func (s *Service) ChangePassword(_ *http.Request, args *ChangePasswordArgs, _ *api.EmptyReply) error {
s.auth.log.Debug("Auth: ChangePassword called")
s.auth.log.Debug("API called",
zap.String("service", "auth"),
zap.String("method", "changePassword"),
)

return s.auth.ChangePassword(args.OldPassword, args.NewPassword)
}
17 changes: 14 additions & 3 deletions api/health/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ package health
import (
"net/http"

"go.uber.org/zap"

"github.com/ava-labs/avalanchego/utils/logging"
)

Expand All @@ -22,21 +24,30 @@ type APIReply struct {

// Readiness returns if the node has finished initialization
func (s *Service) Readiness(_ *http.Request, _ *struct{}, reply *APIReply) error {
s.log.Debug("Health.readiness called")
s.log.Debug("API called",
zap.String("service", "health"),
zap.String("method", "readiness"),
)
reply.Checks, reply.Healthy = s.health.Readiness()
return nil
}

// Health returns a summation of the health of the node
func (s *Service) Health(_ *http.Request, _ *struct{}, reply *APIReply) error {
s.log.Debug("Health.health called")
s.log.Debug("API called",
zap.String("service", "health"),
zap.String("method", "health"),
)
reply.Checks, reply.Healthy = s.health.Health()
return nil
}

// Liveness returns if the node is in need of a restart
func (s *Service) Liveness(_ *http.Request, _ *struct{}, reply *APIReply) error {
s.log.Debug("Health.liveness called")
s.log.Debug("API called",
zap.String("service", "health"),
zap.String("method", "liveness"),
)
reply.Checks, reply.Healthy = s.health.Liveness()
return nil
}
57 changes: 47 additions & 10 deletions api/info/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import (

"github.com/gorilla/rpc/v2"

"go.uber.org/zap"

"github.com/ava-labs/avalanchego/chains"
"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/network"
Expand Down Expand Up @@ -101,7 +103,10 @@ type GetNodeVersionReply struct {

// GetNodeVersion returns the version this node is running
func (i *Info) GetNodeVersion(_ *http.Request, _ *struct{}, reply *GetNodeVersionReply) error {
i.log.Debug("Info: GetNodeVersion called")
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "getNodeVersion"),
)

vmVersions, err := i.vmManager.Versions()
if err != nil {
Expand All @@ -124,7 +129,10 @@ type GetNodeIDReply struct {

// GetNodeID returns the node ID of this node
func (i *Info) GetNodeID(_ *http.Request, _ *struct{}, reply *GetNodeIDReply) error {
i.log.Debug("Info: GetNodeID called")
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "getNodeID"),
)

reply.NodeID = i.NodeID
reply.NodePOP = i.NodePOP
Expand All @@ -143,15 +151,21 @@ type GetNodeIPReply struct {

// GetNodeIP returns the IP of this node
func (i *Info) GetNodeIP(_ *http.Request, _ *struct{}, reply *GetNodeIPReply) error {
i.log.Debug("Info: GetNodeIP called")
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "getNodeIP"),
)

reply.IP = i.myIP.IPPort().String()
return nil
}

// GetNetworkID returns the network ID this node is running on
func (i *Info) GetNetworkID(_ *http.Request, _ *struct{}, reply *GetNetworkIDReply) error {
i.log.Debug("Info: GetNetworkID called")
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "getNetworkID"),
)

reply.NetworkID = json.Uint32(i.NetworkID)
return nil
Expand All @@ -164,7 +178,10 @@ type GetNetworkNameReply struct {

// GetNetworkName returns the network name this node is running on
func (i *Info) GetNetworkName(_ *http.Request, _ *struct{}, reply *GetNetworkNameReply) error {
i.log.Debug("Info: GetNetworkName called")
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "getNetworkName"),
)

reply.NetworkName = constants.NetworkName(i.NetworkID)
return nil
Expand All @@ -182,7 +199,10 @@ type GetBlockchainIDReply struct {

// GetBlockchainID returns the blockchain ID that resolves the alias that was supplied
func (i *Info) GetBlockchainID(_ *http.Request, args *GetBlockchainIDArgs, reply *GetBlockchainIDReply) error {
i.log.Debug("Info: GetBlockchainID called")
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "getBlockchainID"),
)

bID, err := i.chainManager.Lookup(args.Alias)
reply.BlockchainID = bID
Expand Down Expand Up @@ -210,7 +230,10 @@ type PeersReply struct {

// Peers returns the list of current validators
func (i *Info) Peers(_ *http.Request, args *PeersArgs, reply *PeersReply) error {
i.log.Debug("Info: Peers called")
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "peers"),
)

peers := i.networking.PeerInfo(args.NodeIDs)
peerInfo := make([]Peer, len(peers))
Expand Down Expand Up @@ -242,7 +265,9 @@ type IsBootstrappedResponse struct {
// IsBootstrapped returns nil and sets [reply.IsBootstrapped] == true iff [args.Chain] exists and is done bootstrapping
// Returns an error if the chain doesn't exist
func (i *Info) IsBootstrapped(_ *http.Request, args *IsBootstrappedArgs, reply *IsBootstrappedResponse) error {
i.log.Debug("Info: IsBootstrapped called",
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "isBootstrapped"),
logging.UserString("chain", args.Chain),
)

Expand Down Expand Up @@ -280,7 +305,11 @@ type UptimeRequest struct {
}

func (i *Info) Uptime(_ *http.Request, args *UptimeRequest, reply *UptimeResponse) error {
i.log.Debug("Info: Uptime called")
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "uptime"),
)

result, err := i.networking.NodeUptime(args.SubnetID)
if err != nil {
return fmt.Errorf("couldn't get node uptime: %w", err)
Expand All @@ -304,6 +333,11 @@ type GetTxFeeResponse struct {

// GetTxFee returns the transaction fee in nAVAX.
func (i *Info) GetTxFee(_ *http.Request, _ *struct{}, reply *GetTxFeeResponse) error {
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "getTxFee"),
)

reply.TxFee = json.Uint64(i.TxFee)
reply.CreateAssetTxFee = json.Uint64(i.CreateAssetTxFee)
reply.CreateSubnetTxFee = json.Uint64(i.CreateSubnetTxFee)
Expand All @@ -323,7 +357,10 @@ type GetVMsReply struct {

// GetVMs lists the virtual machines installed on the node
func (i *Info) GetVMs(_ *http.Request, _ *struct{}, reply *GetVMsReply) error {
i.log.Debug("Info: GetVMs called")
i.log.Debug("API called",
zap.String("service", "info"),
zap.String("method", "getVMs"),
)

// Fetch the VMs registered on this node.
vmIDs, err := i.VMManager.ListFactories()
Expand Down
Loading

0 comments on commit fbcda4c

Please sign in to comment.