Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit fe72c5b
Author: Stephen Buttolph <[email protected]>
Date:   Fri Nov 17 01:23:21 2023 -0500

    Remove `common.Config` functions (#2328)

commit 585424e
Author: Stephen Buttolph <[email protected]>
Date:   Fri Nov 17 00:39:46 2023 -0500

    Unexport avalanche constant from common package (#2327)

commit 8520112
Author: Dhruba Basu <[email protected]>
Date:   Thu Nov 16 20:53:10 2023 -0800

    Move `network` implementation to separate package (#2296)

    Signed-off-by: Stephen Buttolph <[email protected]>
    Co-authored-by: Stephen Buttolph <[email protected]>

commit 5236d72
Author: Stephen Buttolph <[email protected]>
Date:   Thu Nov 16 20:08:57 2023 -0500

    Remove useless anon functions (#2326)

commit e7ca38b
Author: Dan Laine <[email protected]>
Date:   Thu Nov 16 16:03:17 2023 -0500

    Update zap dependency to v1.26.0 (#2325)

commit 6900e72
Author: Dan Laine <[email protected]>
Date:   Thu Nov 16 15:20:19 2023 -0500

    nit: loop --> variadic (#2316)

commit 35fbb3a
Author: Alberto Benegiamo <[email protected]>
Date:   Thu Nov 16 10:33:18 2023 -0700

    Pchain - Cleanup NodeID generation in UTs (#2291)

    Co-authored-by: Dan Laine <[email protected]>
    Co-authored-by: Stephen Buttolph <[email protected]>

commit 043644f
Author: Stephen Buttolph <[email protected]>
Date:   Thu Nov 16 12:13:09 2023 -0500

    Refactor bootstrapper implementation into consensus (#2300)

    Co-authored-by: Dan Laine <[email protected]>

commit f1ec30c
Author: Joshua Kim <[email protected]>
Date:   Thu Nov 16 12:03:00 2023 -0500

    Update `error_code` to be int32 instead of uint32. (#2322)

    Signed-off-by: Joshua Kim <[email protected]>
    Co-authored-by: Stephen Buttolph <[email protected]>

commit 348f842
Author: Dhruba Basu <[email protected]>
Date:   Thu Nov 16 08:39:03 2023 -0800

    Remove `Network` interface from `Builder` (#2312)

commit 6484de4
Author: Joshua Kim <[email protected]>
Date:   Thu Nov 16 04:31:34 2023 -0500

    Rename AppRequestFailed to AppError (#2321)

    Signed-off-by: Joshua Kim <[email protected]>

commit 3d0611c
Author: Joshua Kim <[email protected]>
Date:   Wed Nov 15 19:24:10 2023 -0500

    Remove error from SDK AppGossip handler (#2252)

    Signed-off-by: Joshua Kim <[email protected]>
    Co-authored-by: Stephen Buttolph <[email protected]>

commit 01a1bbe
Author: Dhruba Basu <[email protected]>
Date:   Wed Nov 15 16:01:29 2023 -0800

    Remove `AddUnverifiedTx` from `Builder` (#2311)

commit e8ef4ad
Author: Dhruba Basu <[email protected]>
Date:   Wed Nov 15 14:15:17 2023 -0800

    Move `AddUnverifiedTx` logic to `network.IssueTx` (#2310)

commit dcc6ea8
Author: Stephen Buttolph <[email protected]>
Date:   Wed Nov 15 17:13:19 2023 -0500

    Use zap.Stringer rather than zap.Any (#2320)

commit 44f3aba
Author: Stephen Buttolph <[email protected]>
Date:   Wed Nov 15 17:12:57 2023 -0500

    Replace unique slices with sets in the engine interface (#2317)

commit d00b67f
Author: Stephen Buttolph <[email protected]>
Date:   Wed Nov 15 11:43:17 2023 -0500

    Simplify avalanche bootstrapping (#2286)

commit 5dff153
Author: Dhruba Basu <[email protected]>
Date:   Tue Nov 14 12:47:06 2023 -0800

    Add `VerifyTx` to `executor.Manager` (#2293)

commit 29f86e9
Author: marun <[email protected]>
Date:   Tue Nov 14 21:25:25 2023 +0100

    e2e: More fixture refinement in support of coreth integration testing  (#2275)

commit 72d2fae
Author: Dhruba Basu <[email protected]>
Date:   Tue Nov 14 10:26:39 2023 -0800

    Add `recentTxsLock` to platform `network` struct (#2294)

commit eb21b42
Author: Dhruba Basu <[email protected]>
Date:   Tue Nov 14 10:24:01 2023 -0800

    Move management of platformvm preferred block to `executor.Manager` (#2292)

commit 7f70fcf
Author: Stephen Buttolph <[email protected]>
Date:   Mon Nov 13 15:18:34 2023 -0500

    Simplify get server creation (#2285)

    Co-authored-by: Dan Laine <[email protected]>

commit baf0ef7
Author: Dan Laine <[email protected]>
Date:   Mon Nov 13 10:33:31 2023 -0500

    `merkledb` -- Add `Clearer` interface  (#2277)

commit b8746de
Author: Dhruba Basu <[email protected]>
Date:   Thu Nov 9 16:21:04 2023 -0800

    Embed `noop` handler for all unhandled messages (#2288)

commit 86201ae
Author: David Boehm <[email protected]>
Date:   Thu Nov 9 14:08:10 2023 -0500

    Remove sentinel node from MerkleDB proofs (#2106)

    Signed-off-by: David Boehm <[email protected]>
    Co-authored-by: Stephen Buttolph <[email protected]>
    Co-authored-by: Dan Laine <[email protected]>

commit 094ce50
Author: Joshua Kim <[email protected]>
Date:   Thu Nov 9 13:58:28 2023 -0500

    Remove Lazy Initialize on Node (#1384)

    Signed-off-by: Joshua Kim <[email protected]>
    Co-authored-by: Dan Laine <[email protected]>

commit e3f1212
Author: Alberto Benegiamo <[email protected]>
Date:   Thu Nov 9 10:08:59 2023 -0700

    Genesis validators cleanup (#2282)

commit 151621f
Author: Alberto Benegiamo <[email protected]>
Date:   Thu Nov 9 09:33:42 2023 -0700

    Cleanup `ids.NodeID` usage (#2280)

commit ebaf9d4
Author: Dhruba Basu <[email protected]>
Date:   Wed Nov 8 18:08:23 2023 -0500

    Move `DropExpiredStakerTxs` to platformvm mempool (#2279)

commit c94ff4e
Author: David Boehm <[email protected]>
Date:   Wed Nov 8 17:55:02 2023 -0500

    MerkleDB:Naming and comments cleanup (#2274)

    Co-authored-by: Dan Laine <[email protected]>

commit bcd4a94
Author: Dhruba Basu <[email protected]>
Date:   Wed Nov 8 17:28:33 2023 -0500

    Cleanup platformvm mempool errs (#2278)

commit aba404e
Author: marun <[email protected]>
Date:   Wed Nov 8 22:54:42 2023 +0100

    e2e: Refactor suite setup and helpers to tests/fixture/e2e for reuse by coreth (#2265)

commit fc95834
Author: Dhruba Basu <[email protected]>
Date:   Wed Nov 8 16:41:39 2023 -0500

    `mempool.NewMempool` -> `mempool.New` (#2276)

commit 93d88c0
Author: Dhruba Basu <[email protected]>
Date:   Wed Nov 8 15:02:10 2023 -0500

    Return if element was deleted from `Hashmap` (#2271)

    Co-authored-by: Dan Laine <[email protected]>

commit 1329a59
Author: Dan Laine <[email protected]>
Date:   Wed Nov 8 12:56:27 2023 -0500

    Add fuzz test for `NewIteratorWithStartAndPrefix` (#1992)

    Co-authored-by: Alberto Benegiamo <[email protected]>

commit 22f3c89
Author: Dan Laine <[email protected]>
Date:   Tue Nov 7 19:12:17 2023 -0500

    `merkledb` -- remove unneeded var declarations (#2269)

commit 683fcfa
Author: Dan Laine <[email protected]>
Date:   Tue Nov 7 17:36:20 2023 -0500

    Add read-only database flag (`--db-read-only`)  (#2266)

commit 52f93c8
Author: Dan Laine <[email protected]>
Date:   Tue Nov 7 17:34:19 2023 -0500

    `merkledb` -- fix nil check in test (#2268)

commit 1faec38
Author: Dan Laine <[email protected]>
Date:   Tue Nov 7 17:34:09 2023 -0500

    `merkledb` -- rename nit (#2267)

commit cdcfb5b
Author: felipemadero <[email protected]>
Date:   Tue Nov 7 17:06:59 2023 -0300

    Use extended public key to derive ledger addresses (#2246)

    Signed-off-by: felipemadero <[email protected]>
    Co-authored-by: Dan Laine <[email protected]>
    Co-authored-by: Stephen Buttolph <[email protected]>

commit 7490a92
Author: Joshua Kim <[email protected]>
Date:   Mon Nov 6 15:39:23 2023 -0500

    Document p2p package (#2254)

    Signed-off-by: Joshua Kim <[email protected]>
    Co-authored-by: Stephen Buttolph <[email protected]>

commit 10bd428
Author: Dhruba Basu <[email protected]>
Date:   Mon Nov 6 14:49:45 2023 -0500

    Remove unused `UnsortedEquals` function (#2264)

commit e710899
Author: David Boehm <[email protected]>
Date:   Mon Nov 6 13:36:34 2023 -0500

    Remove Token constants information from keys (#2197)

    Signed-off-by: David Boehm <[email protected]>
    Signed-off-by: Dan Laine <[email protected]>
    Co-authored-by: Darioush Jalali <[email protected]>
    Co-authored-by: Dan Laine <[email protected]>

commit 558d8fb
Author: vuittont60 <[email protected]>
Date:   Mon Nov 6 22:26:43 2023 +0800

    Fix typos in docs (#2261)

    Signed-off-by: vuittont60 <[email protected]>

commit a8db08e
Author: marun <[email protected]>
Date:   Mon Nov 6 15:26:27 2023 +0100

    e2e: Make NewWallet and NewEthclient regular functions (#2262)

commit aaed8f3
Author: Stephen Buttolph <[email protected]>
Date:   Sat Nov 4 17:29:12 2023 -0400

    Track all subnet validator sets in the validator manager (#2253)

commit cec1cd1
Author: Stephen Buttolph <[email protected]>
Date:   Fri Nov 3 19:19:26 2023 -0400

    Require poll metrics to be registered (#2260)

commit e4cb2cd
Author: Dan Laine <[email protected]>
Date:   Fri Nov 3 17:33:44 2023 -0400

    Cleanup `ipcs` `Socket` test (#2257)

commit 437ade8
Author: marun <[email protected]>
Date:   Fri Nov 3 21:45:12 2023 +0100

    Switch to using require.TestingT interface in SenderTest struct (#2258)

commit 11f1b55
Author: DoTheBestToGetTheBest <[email protected]>
Date:   Thu Nov 2 15:41:47 2023 -0700

    feat(api) : Peers function to return the PrimaryAlias of the chainID (#2251)

    Signed-off-by: DoTheBestToGetTheBest <[email protected]>
    Co-authored-by: Stephen Buttolph <[email protected]>

commit c174c62
Author: Stephen Buttolph <[email protected]>
Date:   Thu Nov 2 16:20:03 2023 -0400

    Return log levels from admin.SetLoggerLevel (#2250)

commit 20f3580
Author: Stephen Buttolph <[email protected]>
Date:   Wed Nov 1 22:11:47 2023 -0400

    Update versions for v1.10.15 (#2245)

commit 36d1630
Author: Cesar <[email protected]>
Date:   Wed Nov 1 22:44:14 2023 -0300

    Add nullable option to codec (#2171)

    Signed-off-by: Cesar <[email protected]>
    Co-authored-by: Stephen Buttolph <[email protected]>
    Co-authored-by: Dan Laine <[email protected]>

commit 4957ccb
Author: Dan Laine <[email protected]>
Date:   Tue Oct 31 18:38:57 2023 -0400

    Add `pebble` as valid value for `--db-type`. (#2244)

    Signed-off-by: Dan Laine <[email protected]>
    Co-authored-by: Dhruba Basu <[email protected]>
    Co-authored-by: Stephen Buttolph <[email protected]>

commit 047d493
Author: Dhruba Basu <[email protected]>
Date:   Tue Oct 31 18:14:14 2023 -0400

    Add `BaseTx` support to platformvm (#2232)

    Signed-off-by: Dhruba Basu <[email protected]>

commit 1f9df8f
Author: Dan Laine <[email protected]>
Date:   Tue Oct 31 17:10:05 2023 -0400

    Remove `database.Manager` (#2239)

    Signed-off-by: Dan Laine <[email protected]>

commit 8d15c22
Author: Stephen Buttolph <[email protected]>
Date:   Tue Oct 31 13:28:49 2023 -0400

    Document host and port behavior in help text (#2236)

commit 76d756f
Author: Joshua Kim <[email protected]>
Date:   Tue Oct 31 11:43:13 2023 -0400

    Remove error from Router AppGossip (#2238)

    Signed-off-by: Joshua Kim <[email protected]>

commit 5b96789
Author: Joshua Kim <[email protected]>
Date:   Mon Oct 30 16:41:51 2023 -0400

    P2P AppRequestFailed protobuf definition (#2111)

    Signed-off-by: Joshua Kim <[email protected]>
    Co-authored-by: Stephen Buttolph <[email protected]>

commit 826f941
Author: Dhruba Basu <[email protected]>
Date:   Fri Oct 27 19:41:19 2023 -0400

    Fix test typos (#2233)

    Signed-off-by: marun <[email protected]>
    Co-authored-by: marun <[email protected]>

commit 66375f5
Author: Dhruba Basu <[email protected]>
Date:   Fri Oct 27 18:44:34 2023 -0400

    Trim down size of secp256k1 `Factory` struct (#2223)

    Signed-off-by: Dhruba Basu <[email protected]>

commit 42d4e3e
Author: Dhruba Basu <[email protected]>
Date:   Fri Oct 27 17:44:38 2023 -0400

    Enable `perfsprint` linter (#2229)

commit b83af9b
Author: Dhruba Basu <[email protected]>
Date:   Fri Oct 27 17:42:03 2023 -0400

    Add `utils.Err` helper (#2212)

    Signed-off-by: Dhruba Basu <[email protected]>

Signed-off-by: Joshua Kim <[email protected]>
  • Loading branch information
joshua-kim committed Nov 17, 2023
1 parent 40a4ed5 commit 4535a50
Show file tree
Hide file tree
Showing 319 changed files with 7,770 additions and 6,601 deletions.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ linters:
- nakedret
- noctx
- nolintlint
- perfsprint
- prealloc
- revive
- staticcheck
Expand Down
38 changes: 37 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
# Release Notes

## [v1.10.15](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.15)

This version is backwards compatible to [v1.10.0](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0). It is optional, but encouraged.

The plugin version is updated to `30` all plugins must update to be compatible.

### Configs

- Added `pebble` as an allowed option to `--db-type`

### Fixes

- Fixed C-chain tracer API panic

### What's Changed

- Reduce allocations on insert and remove by @dboehm-avalabs in https://github.com/ava-labs/avalanchego/pull/2201
- `merkledb` -- shift nit by @danlaine in https://github.com/ava-labs/avalanchego/pull/2218
- Update `golangci-lint` to `v1.55.1` by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2228
- Add json marshal tests to existing serialization tests in `platformvm/txs` pkg by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2227
- Move all blst function usage to `bls` pkg by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2222
- `merkledb` -- don't pass `BranchFactor` to `encodeDBNode` by @danlaine in https://github.com/ava-labs/avalanchego/pull/2217
- Add `utils.Err` helper by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2212
- Enable `perfsprint` linter by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2229
- Trim down size of secp256k1 `Factory` struct by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2223
- Fix test typos by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2233
- P2P AppRequestFailed protobuf definition by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2111
- Remove error from Router AppGossip by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/2238
- Document host and port behavior in help text by @StephenButtolph in https://github.com/ava-labs/avalanchego/pull/2236
- Remove `database.Manager` by @danlaine in https://github.com/ava-labs/avalanchego/pull/2239
- Add `BaseTx` support to platformvm by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/2232
- Add `pebble` as valid value for `--db-type`. by @danlaine in https://github.com/ava-labs/avalanchego/pull/2244
- Add nullable option to codec by @nytzuga in https://github.com/ava-labs/avalanchego/pull/2171

**Full Changelog**: https://github.com/ava-labs/avalanchego/compare/v1.10.14...v1.10.15

## [v1.10.14](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.14)

This version is backwards compatible to [v1.10.0](https://github.com/ava-labs/avalanchego/releases/tag/v1.10.0). It is optional, but encouraged.
Expand Down Expand Up @@ -687,7 +723,7 @@ This version is backwards compatible to [v1.10.0](https://github.com/ava-labs/av
- Add workflow to mark stale issues and PRs by @joshua-kim in https://github.com/ava-labs/avalanchego/pull/1443
- Enforce inlining functions with a single error return in `require.NoError` by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/1500
- `x/sync` / `x/merkledb` -- add `SyncableDB` interface by @danlaine in https://github.com/ava-labs/avalanchego/pull/1555
- Rename beacon to boostrapper, define bootstrappers in JSON file for cross-language compatiblity by @gyuho in https://github.com/ava-labs/avalanchego/pull/1439
- Rename beacon to boostrapper, define bootstrappers in JSON file for cross-language compatibility by @gyuho in https://github.com/ava-labs/avalanchego/pull/1439
- add P-chain height indexing by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/1447
- Add P-chain `GetBlockByHeight` API method by @dhrubabasu in https://github.com/ava-labs/avalanchego/pull/1448
- `x/sync` -- use for sending Range Proofs by @danlaine in https://github.com/ava-labs/avalanchego/pull/1537
Expand Down
16 changes: 9 additions & 7 deletions api/admin/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ type Client interface {
GetChainAliases(ctx context.Context, chainID string, options ...rpc.Option) ([]string, error)
Stacktrace(context.Context, ...rpc.Option) error
LoadVMs(context.Context, ...rpc.Option) (map[ids.ID][]string, map[ids.ID]string, error)
SetLoggerLevel(ctx context.Context, loggerName, logLevel, displayLevel string, options ...rpc.Option) error
SetLoggerLevel(ctx context.Context, loggerName, logLevel, displayLevel string, options ...rpc.Option) (map[string]LogAndDisplayLevels, error)
GetLoggerLevel(ctx context.Context, loggerName string, options ...rpc.Option) (map[string]LogAndDisplayLevels, error)
GetConfig(ctx context.Context, options ...rpc.Option) (interface{}, error)
}
Expand Down Expand Up @@ -96,7 +96,7 @@ func (c *client) SetLoggerLevel(
logLevel,
displayLevel string,
options ...rpc.Option,
) error {
) (map[string]LogAndDisplayLevels, error) {
var (
logLevelArg logging.Level
displayLevelArg logging.Level
Expand All @@ -105,28 +105,30 @@ func (c *client) SetLoggerLevel(
if len(logLevel) > 0 {
logLevelArg, err = logging.ToLevel(logLevel)
if err != nil {
return err
return nil, err
}
}
if len(displayLevel) > 0 {
displayLevelArg, err = logging.ToLevel(displayLevel)
if err != nil {
return err
return nil, err
}
}
return c.requester.SendRequest(ctx, "admin.setLoggerLevel", &SetLoggerLevelArgs{
res := &LoggerLevelReply{}
err = c.requester.SendRequest(ctx, "admin.setLoggerLevel", &SetLoggerLevelArgs{
LoggerName: loggerName,
LogLevel: &logLevelArg,
DisplayLevel: &displayLevelArg,
}, &api.EmptyReply{}, options...)
}, res, options...)
return res.LoggerLevels, err
}

func (c *client) GetLoggerLevel(
ctx context.Context,
loggerName string,
options ...rpc.Option,
) (map[string]LogAndDisplayLevels, error) {
res := &GetLoggerLevelReply{}
res := &LoggerLevelReply{}
err := c.requester.SendRequest(ctx, "admin.getLoggerLevel", &GetLoggerLevelArgs{
LoggerName: loggerName,
}, res, options...)
Expand Down
74 changes: 46 additions & 28 deletions api/admin/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ func (mc *mockClient) SendRequest(_ context.Context, _ string, _ interface{}, re
case *LoadVMsReply:
response := mc.response.(*LoadVMsReply)
*p = *response
case *GetLoggerLevelReply:
response := mc.response.(*GetLoggerLevelReply)
case *LoggerLevelReply:
response := mc.response.(*LoggerLevelReply)
*p = *response
case *interface{}:
response := mc.response.(*interface{})
Expand Down Expand Up @@ -212,54 +212,72 @@ func TestReloadInstalledVMs(t *testing.T) {

func TestSetLoggerLevel(t *testing.T) {
type test struct {
name string
logLevel string
displayLevel string
serviceErr error
clientErr error
name string
logLevel string
displayLevel string
serviceResponse map[string]LogAndDisplayLevels
serviceErr error
clientErr error
}
tests := []test{
{
name: "Happy path",
logLevel: "INFO",
displayLevel: "INFO",
serviceErr: nil,
clientErr: nil,
serviceResponse: map[string]LogAndDisplayLevels{
"Happy path": {LogLevel: logging.Info, DisplayLevel: logging.Info},
},
serviceErr: nil,
clientErr: nil,
},
{
name: "Service errors",
logLevel: "INFO",
displayLevel: "INFO",
serviceErr: errTest,
clientErr: errTest,
name: "Service errors",
logLevel: "INFO",
displayLevel: "INFO",
serviceResponse: nil,
serviceErr: errTest,
clientErr: errTest,
},
{
name: "Invalid log level",
logLevel: "invalid",
displayLevel: "INFO",
serviceErr: nil,
clientErr: logging.ErrUnknownLevel,
name: "Invalid log level",
logLevel: "invalid",
displayLevel: "INFO",
serviceResponse: nil,
serviceErr: nil,
clientErr: logging.ErrUnknownLevel,
},
{
name: "Invalid display level",
logLevel: "INFO",
displayLevel: "invalid",
serviceErr: nil,
clientErr: logging.ErrUnknownLevel,
name: "Invalid display level",
logLevel: "INFO",
displayLevel: "invalid",
serviceResponse: nil,
serviceErr: nil,
clientErr: logging.ErrUnknownLevel,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
require := require.New(t)

c := client{
requester: NewMockClient(&api.EmptyReply{}, tt.serviceErr),
requester: NewMockClient(
&LoggerLevelReply{
LoggerLevels: tt.serviceResponse,
},
tt.serviceErr,
),
}
err := c.SetLoggerLevel(
res, err := c.SetLoggerLevel(
context.Background(),
"",
tt.logLevel,
tt.displayLevel,
)
require.ErrorIs(t, err, tt.clientErr)
require.ErrorIs(err, tt.clientErr)
if tt.clientErr != nil {
return
}
require.Equal(tt.serviceResponse, res)
})
}
}
Expand Down Expand Up @@ -296,7 +314,7 @@ func TestGetLoggerLevel(t *testing.T) {

c := client{
requester: NewMockClient(
&GetLoggerLevelReply{
&LoggerLevelReply{
LoggerLevels: tt.serviceResponse,
},
tt.serviceErr,
Expand Down
91 changes: 46 additions & 45 deletions api/admin/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,21 @@ func (a *Admin) Stacktrace(_ *http.Request, _ *struct{}, _ *api.EmptyReply) erro
return perms.WriteFile(stacktraceFile, stacktrace, perms.ReadWrite)
}

// See SetLoggerLevel
type SetLoggerLevelArgs struct {
LoggerName string `json:"loggerName"`
LogLevel *logging.Level `json:"logLevel"`
DisplayLevel *logging.Level `json:"displayLevel"`
}

type LogAndDisplayLevels struct {
LogLevel logging.Level `json:"logLevel"`
DisplayLevel logging.Level `json:"displayLevel"`
}

type LoggerLevelReply struct {
LoggerLevels map[string]LogAndDisplayLevels `json:"loggerLevels"`
}

// SetLoggerLevel sets the log level and/or display level for loggers.
// If len([args.LoggerName]) == 0, sets the log/display level of all loggers.
// Otherwise, sets the log/display level of the loggers named in that argument.
Expand All @@ -240,7 +248,7 @@ type SetLoggerLevelArgs struct {
// Sets the display level of these loggers to args.LogLevel.
// 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 {
func (a *Admin) SetLoggerLevel(_ *http.Request, args *SetLoggerLevelArgs, reply *LoggerLevelReply) error {
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "setLoggerLevel"),
Expand All @@ -256,14 +264,7 @@ func (a *Admin) SetLoggerLevel(_ *http.Request, args *SetLoggerLevelArgs, _ *api
a.lock.Lock()
defer a.lock.Unlock()

var loggerNames []string
if len(args.LoggerName) > 0 {
loggerNames = []string{args.LoggerName}
} else {
// Empty name means all loggers
loggerNames = a.LogFactory.GetLoggerNames()
}

loggerNames := a.getLoggerNames(args.LoggerName)
for _, name := range loggerNames {
if args.LogLevel != nil {
if err := a.LogFactory.SetLogLevel(name, *args.LogLevel); err != nil {
Expand All @@ -276,26 +277,18 @@ func (a *Admin) SetLoggerLevel(_ *http.Request, args *SetLoggerLevelArgs, _ *api
}
}
}
return nil
}

type LogAndDisplayLevels struct {
LogLevel logging.Level `json:"logLevel"`
DisplayLevel logging.Level `json:"displayLevel"`
var err error
reply.LoggerLevels, err = a.getLogLevels(loggerNames)
return err
}

// See GetLoggerLevel
type GetLoggerLevelArgs struct {
LoggerName string `json:"loggerName"`
}

// See GetLoggerLevel
type GetLoggerLevelReply struct {
LoggerLevels map[string]LogAndDisplayLevels `json:"loggerLevels"`
}

// GetLogLevel returns the log level and display level of all loggers.
func (a *Admin) GetLoggerLevel(_ *http.Request, args *GetLoggerLevelArgs, reply *GetLoggerLevelReply) error {
func (a *Admin) GetLoggerLevel(_ *http.Request, args *GetLoggerLevelArgs, reply *LoggerLevelReply) error {
a.Log.Debug("API called",
zap.String("service", "admin"),
zap.String("method", "getLoggerLevels"),
Expand All @@ -305,30 +298,11 @@ func (a *Admin) GetLoggerLevel(_ *http.Request, args *GetLoggerLevelArgs, reply
a.lock.RLock()
defer a.lock.RUnlock()

reply.LoggerLevels = make(map[string]LogAndDisplayLevels)
var loggerNames []string
// Empty name means all loggers
if len(args.LoggerName) > 0 {
loggerNames = []string{args.LoggerName}
} else {
loggerNames = a.LogFactory.GetLoggerNames()
}
loggerNames := a.getLoggerNames(args.LoggerName)

for _, name := range loggerNames {
logLevel, err := a.LogFactory.GetLogLevel(name)
if err != nil {
return err
}
displayLevel, err := a.LogFactory.GetDisplayLevel(name)
if err != nil {
return err
}
reply.LoggerLevels[name] = LogAndDisplayLevels{
LogLevel: logLevel,
DisplayLevel: displayLevel,
}
}
return nil
var err error
reply.LoggerLevels, err = a.getLogLevels(loggerNames)
return err
}

// GetConfig returns the config that the node was started with.
Expand Down Expand Up @@ -375,3 +349,30 @@ func (a *Admin) LoadVMs(r *http.Request, _ *struct{}, reply *LoadVMsReply) error
reply.NewVMs, err = ids.GetRelevantAliases(a.VMManager, loadedVMs)
return err
}

func (a *Admin) getLoggerNames(loggerName string) []string {
if len(loggerName) == 0 {
// Empty name means all loggers
return a.LogFactory.GetLoggerNames()
}
return []string{loggerName}
}

func (a *Admin) getLogLevels(loggerNames []string) (map[string]LogAndDisplayLevels, error) {
loggerLevels := make(map[string]LogAndDisplayLevels)
for _, name := range loggerNames {
logLevel, err := a.LogFactory.GetLogLevel(name)
if err != nil {
return nil, err
}
displayLevel, err := a.LogFactory.GetDisplayLevel(name)
if err != nil {
return nil, err
}
loggerLevels[name] = LogAndDisplayLevels{
LogLevel: logLevel,
DisplayLevel: displayLevel,
}
}
return loggerLevels, nil
}
Loading

0 comments on commit 4535a50

Please sign in to comment.