Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simple alert system; FD limit alerts #7108

Merged
merged 10 commits into from
Aug 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions api/api_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

apitypes "github.com/filecoin-project/lotus/api/types"
"github.com/filecoin-project/lotus/journal/alerting"

"github.com/google/uuid"

Expand Down Expand Up @@ -33,6 +34,10 @@ type Common interface {
LogList(context.Context) ([]string, error) //perm:write
LogSetLevel(context.Context, string, string) error //perm:write

// LogAlerts returns list of all, active and inactive alerts tracked by the
// node
LogAlerts(ctx context.Context) ([]alerting.Alert, error) //perm:admin

// MethodGroup: Common

// Version provides information about API provider
Expand Down
16 changes: 16 additions & 0 deletions api/mocks/mock_full.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions api/proxy_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions api/v0api/v0mocks/mock_full.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions build/limits.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package build

var (
DefaultFDLimit uint64 = 16 << 10
MinerFDLimit uint64 = 100_000
)
Binary file modified build/openrpc/full.json.gz
Binary file not shown.
Binary file modified build/openrpc/miner.json.gz
Binary file not shown.
Binary file modified build/openrpc/worker.json.gz
Binary file not shown.
51 changes: 51 additions & 0 deletions cli/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package cli

import (
"fmt"
"time"

"github.com/fatih/color"
"github.com/urfave/cli/v2"
"golang.org/x/xerrors"
)
Expand All @@ -13,6 +15,7 @@ var LogCmd = &cli.Command{
Subcommands: []*cli.Command{
LogList,
LogSetLevel,
LogAlerts,
},
}

Expand Down Expand Up @@ -100,3 +103,51 @@ var LogSetLevel = &cli.Command{
return nil
},
}

var LogAlerts = &cli.Command{
Name: "alerts",
Usage: "Get alert states",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "all",
Usage: "get all (active and inactive) alerts",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that it defaults to active?

},
},
Action: func(cctx *cli.Context) error {
api, closer, err := GetAPI(cctx)
if err != nil {
return err
}
defer closer()

ctx := ReqContext(cctx)

alerts, err := api.LogAlerts(ctx)
if err != nil {
return xerrors.Errorf("getting alerts: %w", err)
}

all := cctx.Bool("all")

for _, alert := range alerts {
if !all && !alert.Active {
continue
}

active := color.RedString("active ")
if !alert.Active {
active = color.GreenString("inactive")
}

fmt.Printf("%s %s:%s\n", active, alert.Type.System, alert.Type.Subsystem)
if alert.LastResolved != nil {
fmt.Printf(" last resolved at %s; reason: %s\n", alert.LastResolved.Time.Truncate(time.Millisecond), alert.LastResolved.Message)
}
if alert.LastActive != nil {
fmt.Printf(" %s %s; reason: %s\n", color.YellowString("last raised at"), alert.LastActive.Time.Truncate(time.Millisecond), alert.LastActive.Message)
}
}

return nil
},
}
16 changes: 16 additions & 0 deletions cmd/lotus-miner/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
"github.com/filecoin-project/lotus/chain/actors/builtin/miner"
"github.com/filecoin-project/lotus/chain/types"
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/journal/alerting"
)

var infoCmd = &cli.Command{
Expand Down Expand Up @@ -116,6 +117,21 @@ func infoCmdAct(cctx *cli.Context) error {

fmt.Println()

alerts, err := minerApi.LogAlerts(ctx)
if err != nil {
return xerrors.Errorf("getting alerts: %w", err)
}

activeAlerts := make([]alerting.Alert, 0)
for _, alert := range alerts {
if alert.Active {
activeAlerts = append(activeAlerts, alert)
}
}
if len(activeAlerts) > 0 {
fmt.Printf("%s (check %s)\n", color.RedString("⚠ %d Active alerts", len(activeAlerts)), color.YellowString("lotus-miner log alerts"))
}

err = handleMiningInfo(ctx, cctx, fullapi, minerApi)
if err != nil {
return err
Expand Down
3 changes: 2 additions & 1 deletion cmd/lotus-miner/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
sealing "github.com/filecoin-project/lotus/extern/storage-sealing"
"github.com/filecoin-project/lotus/genesis"
"github.com/filecoin-project/lotus/journal"
"github.com/filecoin-project/lotus/journal/fsjournal"
storageminer "github.com/filecoin-project/lotus/miner"
"github.com/filecoin-project/lotus/node/modules"
"github.com/filecoin-project/lotus/node/modules/dtypes"
Expand Down Expand Up @@ -479,7 +480,7 @@ func storageMinerInit(ctx context.Context, cctx *cli.Context, api v1api.FullNode
return err
}

j, err := journal.OpenFSJournal(lr, journal.EnvDisabledEvents())
j, err := fsjournal.OpenFSJournal(lr, journal.EnvDisabledEvents())
if err != nil {
return fmt.Errorf("failed to open filesystem journal: %w", err)
}
Expand Down
3 changes: 2 additions & 1 deletion cmd/lotus/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import (
lcli "github.com/filecoin-project/lotus/cli"
"github.com/filecoin-project/lotus/extern/sector-storage/ffiwrapper"
"github.com/filecoin-project/lotus/journal"
"github.com/filecoin-project/lotus/journal/fsjournal"
"github.com/filecoin-project/lotus/lib/peermgr"
"github.com/filecoin-project/lotus/lib/ulimit"
"github.com/filecoin-project/lotus/metrics"
Expand Down Expand Up @@ -476,7 +477,7 @@ func ImportChain(ctx context.Context, r repo.Repo, fname string, snapshot bool)
return err
}

j, err := journal.OpenFSJournal(lr, journal.EnvDisabledEvents())
j, err := fsjournal.OpenFSJournal(lr, journal.EnvDisabledEvents())
if err != nil {
return xerrors.Errorf("failed to open journal: %w", err)
}
Expand Down
10 changes: 10 additions & 0 deletions documentation/en/api-v0-methods-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
* [I](#I)
* [ID](#ID)
* [Log](#Log)
* [LogAlerts](#LogAlerts)
* [LogList](#LogList)
* [LogSetLevel](#LogSetLevel)
* [Market](#Market)
Expand Down Expand Up @@ -664,6 +665,15 @@ Response: `"12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf"`
## Log


### LogAlerts


Perms: admin

Inputs: `null`

Response: `null`

### LogList


Expand Down
10 changes: 10 additions & 0 deletions documentation/en/api-v0-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
* [I](#I)
* [ID](#ID)
* [Log](#Log)
* [LogAlerts](#LogAlerts)
* [LogList](#LogList)
* [LogSetLevel](#LogSetLevel)
* [Market](#Market)
Expand Down Expand Up @@ -1816,6 +1817,15 @@ Response: `"12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf"`
## Log


### LogAlerts


Perms: admin

Inputs: `null`

Response: `null`

### LogList


Expand Down
10 changes: 10 additions & 0 deletions documentation/en/api-v1-unstable-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
* [I](#I)
* [ID](#ID)
* [Log](#Log)
* [LogAlerts](#LogAlerts)
* [LogList](#LogList)
* [LogSetLevel](#LogSetLevel)
* [Market](#Market)
Expand Down Expand Up @@ -1880,6 +1881,15 @@ Response: `"12D3KooWGzxzKZYveHXtpG6AsrUJBcWxHBFS2HsEoGTxrMLvKXtf"`
## Log


### LogAlerts


Perms: admin

Inputs: `null`

Response: `null`

### LogList


Expand Down
15 changes: 15 additions & 0 deletions documentation/en/cli-lotus-miner.md
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ USAGE:
COMMANDS:
list List log systems
set-level Set log level
alerts Get alert states
help, h Shows a list of commands or help for one command

OPTIONS:
Expand Down Expand Up @@ -561,6 +562,20 @@ OPTIONS:

```

### lotus-miner log alerts
```
NAME:
lotus-miner log alerts - Get alert states

USAGE:
lotus-miner log alerts [command options] [arguments...]

OPTIONS:
--all get all (active and inactive) alerts (default: false)
--help, -h show help (default: false)

```

## lotus-miner wait-api
```
NAME:
Expand Down
15 changes: 15 additions & 0 deletions documentation/en/cli-lotus.md
Original file line number Diff line number Diff line change
Expand Up @@ -2366,6 +2366,7 @@ USAGE:
COMMANDS:
list List log systems
set-level Set log level
alerts Get alert states
help, h Shows a list of commands or help for one command

OPTIONS:
Expand Down Expand Up @@ -2421,6 +2422,20 @@ OPTIONS:

```

### lotus log alerts
```
NAME:
lotus log alerts - Get alert states

USAGE:
lotus log alerts [command options] [arguments...]

OPTIONS:
--all get all (active and inactive) alerts (default: false)
--help, -h show help (default: false)

```

## lotus wait-api
```
NAME:
Expand Down
Loading