Skip to content

Commit fbcda4c

Browse files
Deprecate various APIs (ava-labs#2734)
1 parent f34eafa commit fbcda4c

21 files changed

+498
-118
lines changed

api/admin/service.go

Lines changed: 43 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -74,28 +74,40 @@ func NewService(config Config) (*common.HTTPHandler, error) {
7474

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

7982
return a.profiler.StartCPUProfiler()
8083
}
8184

8285
// StopCPUProfiler stops the cpu profile
8386
func (a *Admin) StopCPUProfiler(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
84-
a.Log.Debug("Admin: StopCPUProfiler called")
87+
a.Log.Debug("API called",
88+
zap.String("service", "admin"),
89+
zap.String("method", "stopCPUProfiler"),
90+
)
8591

8692
return a.profiler.StopCPUProfiler()
8793
}
8894

8995
// MemoryProfile runs a memory profile writing to the specified file
9096
func (a *Admin) MemoryProfile(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
91-
a.Log.Debug("Admin: MemoryProfile called")
97+
a.Log.Debug("API called",
98+
zap.String("service", "admin"),
99+
zap.String("method", "memoryProfile"),
100+
)
92101

93102
return a.profiler.MemoryProfile()
94103
}
95104

96105
// LockProfile runs a mutex profile writing to the specified file
97106
func (a *Admin) LockProfile(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
98-
a.Log.Debug("Admin: LockProfile called")
107+
a.Log.Debug("API called",
108+
zap.String("service", "admin"),
109+
zap.String("method", "lockProfile"),
110+
)
99111

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

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

129143
// AliasChain attempts to alias a chain to a new name
130144
func (a *Admin) AliasChain(_ *http.Request, args *AliasChainArgs, _ *api.EmptyReply) error {
131-
a.Log.Debug("Admin: AliasChain called",
145+
a.Log.Debug("API called",
146+
zap.String("service", "admin"),
147+
zap.String("method", "aliasChain"),
132148
logging.UserString("chain", args.Chain),
133149
logging.UserString("alias", args.Alias),
134150
)
@@ -162,7 +178,9 @@ type GetChainAliasesReply struct {
162178

163179
// GetChainAliases returns the aliases of the chain
164180
func (a *Admin) GetChainAliases(_ *http.Request, args *GetChainAliasesArgs, reply *GetChainAliasesReply) error {
165-
a.Log.Debug("Admin: GetChainAliases called",
181+
a.Log.Debug("API called",
182+
zap.String("service", "admin"),
183+
zap.String("method", "getChainAliases"),
166184
logging.UserString("chain", args.Chain),
167185
)
168186

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

178196
// Stacktrace returns the current global stacktrace
179197
func (a *Admin) Stacktrace(_ *http.Request, _ *struct{}, _ *api.EmptyReply) error {
180-
a.Log.Debug("Admin: Stacktrace called")
198+
a.Log.Debug("API called",
199+
zap.String("service", "admin"),
200+
zap.String("method", "stacktrace"),
201+
)
181202

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

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

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

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

301332
ctx := r.Context()
302333
loadedVMs, failedVMs, err := a.VMRegistry.ReloadWithReadLock(ctx)

api/admin/service_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func TestLoadVMsSuccess(t *testing.T) {
6666
id2: alias2[1:],
6767
}
6868

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

87-
resources.mockLog.EXPECT().Debug(gomock.Any()).Times(1)
87+
resources.mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).Times(1)
8888
// Reload fails
8989
resources.mockVMRegistry.EXPECT().ReloadWithReadLock(gomock.Any()).Times(1).Return(nil, nil, errTest)
9090

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

111-
resources.mockLog.EXPECT().Debug(gomock.Any()).Times(1)
111+
resources.mockLog.EXPECT().Debug(gomock.Any(), gomock.Any()).Times(1)
112112
resources.mockVMRegistry.EXPECT().ReloadWithReadLock(gomock.Any()).Times(1).Return(newVMs, failedVMs, nil)
113113
resources.mockVMManager.EXPECT().Aliases(id1).Times(1).Return(alias1, nil)
114114
resources.mockVMManager.EXPECT().Aliases(id2).Times(1).Return(nil, errTest)

api/auth/service.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package auth
66
import (
77
"net/http"
88

9+
"go.uber.org/zap"
10+
911
"github.com/ava-labs/avalanchego/api"
1012
)
1113

@@ -33,7 +35,10 @@ type Token struct {
3335
}
3436

3537
func (s *Service) NewToken(_ *http.Request, args *NewTokenArgs, reply *Token) error {
36-
s.auth.log.Debug("Auth: NewToken called")
38+
s.auth.log.Debug("API called",
39+
zap.String("service", "auth"),
40+
zap.String("method", "newToken"),
41+
)
3742

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

4853
func (s *Service) RevokeToken(_ *http.Request, args *RevokeTokenArgs, _ *api.EmptyReply) error {
49-
s.auth.log.Debug("Auth: RevokeToken called")
54+
s.auth.log.Debug("API called",
55+
zap.String("service", "auth"),
56+
zap.String("method", "revokeToken"),
57+
)
5058

5159
return s.auth.RevokeToken(args.Token.Token, args.Password.Password)
5260
}
@@ -57,7 +65,10 @@ type ChangePasswordArgs struct {
5765
}
5866

5967
func (s *Service) ChangePassword(_ *http.Request, args *ChangePasswordArgs, _ *api.EmptyReply) error {
60-
s.auth.log.Debug("Auth: ChangePassword called")
68+
s.auth.log.Debug("API called",
69+
zap.String("service", "auth"),
70+
zap.String("method", "changePassword"),
71+
)
6172

6273
return s.auth.ChangePassword(args.OldPassword, args.NewPassword)
6374
}

api/health/service.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ package health
66
import (
77
"net/http"
88

9+
"go.uber.org/zap"
10+
911
"github.com/ava-labs/avalanchego/utils/logging"
1012
)
1113

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

2325
// Readiness returns if the node has finished initialization
2426
func (s *Service) Readiness(_ *http.Request, _ *struct{}, reply *APIReply) error {
25-
s.log.Debug("Health.readiness called")
27+
s.log.Debug("API called",
28+
zap.String("service", "health"),
29+
zap.String("method", "readiness"),
30+
)
2631
reply.Checks, reply.Healthy = s.health.Readiness()
2732
return nil
2833
}
2934

3035
// Health returns a summation of the health of the node
3136
func (s *Service) Health(_ *http.Request, _ *struct{}, reply *APIReply) error {
32-
s.log.Debug("Health.health called")
37+
s.log.Debug("API called",
38+
zap.String("service", "health"),
39+
zap.String("method", "health"),
40+
)
3341
reply.Checks, reply.Healthy = s.health.Health()
3442
return nil
3543
}
3644

3745
// Liveness returns if the node is in need of a restart
3846
func (s *Service) Liveness(_ *http.Request, _ *struct{}, reply *APIReply) error {
39-
s.log.Debug("Health.liveness called")
47+
s.log.Debug("API called",
48+
zap.String("service", "health"),
49+
zap.String("method", "liveness"),
50+
)
4051
reply.Checks, reply.Healthy = s.health.Liveness()
4152
return nil
4253
}

api/info/service.go

Lines changed: 47 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010

1111
"github.com/gorilla/rpc/v2"
1212

13+
"go.uber.org/zap"
14+
1315
"github.com/ava-labs/avalanchego/chains"
1416
"github.com/ava-labs/avalanchego/ids"
1517
"github.com/ava-labs/avalanchego/network"
@@ -101,7 +103,10 @@ type GetNodeVersionReply struct {
101103

102104
// GetNodeVersion returns the version this node is running
103105
func (i *Info) GetNodeVersion(_ *http.Request, _ *struct{}, reply *GetNodeVersionReply) error {
104-
i.log.Debug("Info: GetNodeVersion called")
106+
i.log.Debug("API called",
107+
zap.String("service", "info"),
108+
zap.String("method", "getNodeVersion"),
109+
)
105110

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

125130
// GetNodeID returns the node ID of this node
126131
func (i *Info) GetNodeID(_ *http.Request, _ *struct{}, reply *GetNodeIDReply) error {
127-
i.log.Debug("Info: GetNodeID called")
132+
i.log.Debug("API called",
133+
zap.String("service", "info"),
134+
zap.String("method", "getNodeID"),
135+
)
128136

129137
reply.NodeID = i.NodeID
130138
reply.NodePOP = i.NodePOP
@@ -143,15 +151,21 @@ type GetNodeIPReply struct {
143151

144152
// GetNodeIP returns the IP of this node
145153
func (i *Info) GetNodeIP(_ *http.Request, _ *struct{}, reply *GetNodeIPReply) error {
146-
i.log.Debug("Info: GetNodeIP called")
154+
i.log.Debug("API called",
155+
zap.String("service", "info"),
156+
zap.String("method", "getNodeIP"),
157+
)
147158

148159
reply.IP = i.myIP.IPPort().String()
149160
return nil
150161
}
151162

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

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

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

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

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

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

211231
// Peers returns the list of current validators
212232
func (i *Info) Peers(_ *http.Request, args *PeersArgs, reply *PeersReply) error {
213-
i.log.Debug("Info: Peers called")
233+
i.log.Debug("API called",
234+
zap.String("service", "info"),
235+
zap.String("method", "peers"),
236+
)
214237

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

@@ -280,7 +305,11 @@ type UptimeRequest struct {
280305
}
281306

282307
func (i *Info) Uptime(_ *http.Request, args *UptimeRequest, reply *UptimeResponse) error {
283-
i.log.Debug("Info: Uptime called")
308+
i.log.Debug("API called",
309+
zap.String("service", "info"),
310+
zap.String("method", "uptime"),
311+
)
312+
284313
result, err := i.networking.NodeUptime(args.SubnetID)
285314
if err != nil {
286315
return fmt.Errorf("couldn't get node uptime: %w", err)
@@ -304,6 +333,11 @@ type GetTxFeeResponse struct {
304333

305334
// GetTxFee returns the transaction fee in nAVAX.
306335
func (i *Info) GetTxFee(_ *http.Request, _ *struct{}, reply *GetTxFeeResponse) error {
336+
i.log.Debug("API called",
337+
zap.String("service", "info"),
338+
zap.String("method", "getTxFee"),
339+
)
340+
307341
reply.TxFee = json.Uint64(i.TxFee)
308342
reply.CreateAssetTxFee = json.Uint64(i.CreateAssetTxFee)
309343
reply.CreateSubnetTxFee = json.Uint64(i.CreateSubnetTxFee)
@@ -323,7 +357,10 @@ type GetVMsReply struct {
323357

324358
// GetVMs lists the virtual machines installed on the node
325359
func (i *Info) GetVMs(_ *http.Request, _ *struct{}, reply *GetVMsReply) error {
326-
i.log.Debug("Info: GetVMs called")
360+
i.log.Debug("API called",
361+
zap.String("service", "info"),
362+
zap.String("method", "getVMs"),
363+
)
327364

328365
// Fetch the VMs registered on this node.
329366
vmIDs, err := i.VMManager.ListFactories()

0 commit comments

Comments
 (0)