api for getting alert states
This commit is contained in:
parent
81b1dd12f8
commit
5366821144
@ -5,6 +5,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
apitypes "github.com/filecoin-project/lotus/api/types"
|
apitypes "github.com/filecoin-project/lotus/api/types"
|
||||||
|
"github.com/filecoin-project/lotus/journal/alerting"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
|
|
||||||
@ -33,6 +34,10 @@ type Common interface {
|
|||||||
LogList(context.Context) ([]string, error) //perm:write
|
LogList(context.Context) ([]string, error) //perm:write
|
||||||
LogSetLevel(context.Context, string, 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)
|
||||||
|
|
||||||
// MethodGroup: Common
|
// MethodGroup: Common
|
||||||
|
|
||||||
// Version provides information about API provider
|
// Version provides information about API provider
|
||||||
|
@ -27,6 +27,7 @@ import (
|
|||||||
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
"github.com/filecoin-project/lotus/extern/sector-storage/stores"
|
||||||
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
"github.com/filecoin-project/lotus/extern/sector-storage/storiface"
|
||||||
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
"github.com/filecoin-project/lotus/extern/storage-sealing/sealiface"
|
||||||
|
"github.com/filecoin-project/lotus/journal/alerting"
|
||||||
marketevents "github.com/filecoin-project/lotus/markets/loggers"
|
marketevents "github.com/filecoin-project/lotus/markets/loggers"
|
||||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
"github.com/filecoin-project/lotus/node/repo/imports"
|
"github.com/filecoin-project/lotus/node/repo/imports"
|
||||||
@ -63,6 +64,8 @@ type CommonStruct struct {
|
|||||||
|
|
||||||
Discover func(p0 context.Context) (apitypes.OpenRPCDocument, error) `perm:"read"`
|
Discover func(p0 context.Context) (apitypes.OpenRPCDocument, error) `perm:"read"`
|
||||||
|
|
||||||
|
LogAlerts func(p0 context.Context) ([]alerting.Alert, error) ``
|
||||||
|
|
||||||
LogList func(p0 context.Context) ([]string, error) `perm:"write"`
|
LogList func(p0 context.Context) ([]string, error) `perm:"write"`
|
||||||
|
|
||||||
LogSetLevel func(p0 context.Context, p1 string, p2 string) error `perm:"write"`
|
LogSetLevel func(p0 context.Context, p1 string, p2 string) error `perm:"write"`
|
||||||
@ -946,6 +949,17 @@ func (s *CommonStub) Discover(p0 context.Context) (apitypes.OpenRPCDocument, err
|
|||||||
return *new(apitypes.OpenRPCDocument), ErrNotSupported
|
return *new(apitypes.OpenRPCDocument), ErrNotSupported
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *CommonStruct) LogAlerts(p0 context.Context) ([]alerting.Alert, error) {
|
||||||
|
if s.Internal.LogAlerts == nil {
|
||||||
|
return *new([]alerting.Alert), ErrNotSupported
|
||||||
|
}
|
||||||
|
return s.Internal.LogAlerts(p0)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *CommonStub) LogAlerts(p0 context.Context) ([]alerting.Alert, error) {
|
||||||
|
return *new([]alerting.Alert), ErrNotSupported
|
||||||
|
}
|
||||||
|
|
||||||
func (s *CommonStruct) LogList(p0 context.Context) ([]string, error) {
|
func (s *CommonStruct) LogList(p0 context.Context) ([]string, error) {
|
||||||
if s.Internal.LogList == nil {
|
if s.Internal.LogList == nil {
|
||||||
return *new([]string), ErrNotSupported
|
return *new([]string), ErrNotSupported
|
||||||
|
@ -2,6 +2,7 @@ package alerting
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"sort"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -127,3 +128,22 @@ func (a *Alerting) Resolve(at AlertType, message interface{}) {
|
|||||||
return alert
|
return alert
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *Alerting) GetAlerts() []Alert {
|
||||||
|
a.lk.Lock()
|
||||||
|
defer a.lk.Unlock()
|
||||||
|
|
||||||
|
out := make([]Alert, 0, len(a.alerts))
|
||||||
|
for _, alert := range a.alerts {
|
||||||
|
out = append(out, alert)
|
||||||
|
}
|
||||||
|
sort.Slice(out, func(i, j int) bool {
|
||||||
|
if out[i].Type.System != out[j].Type.System {
|
||||||
|
return out[i].Type.System < out[j].Type.System
|
||||||
|
}
|
||||||
|
|
||||||
|
return out[i].Type.Subsystem < out[j].Type.Subsystem
|
||||||
|
})
|
||||||
|
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
@ -10,9 +10,11 @@ import (
|
|||||||
"golang.org/x/xerrors"
|
"golang.org/x/xerrors"
|
||||||
|
|
||||||
"github.com/filecoin-project/go-jsonrpc/auth"
|
"github.com/filecoin-project/go-jsonrpc/auth"
|
||||||
|
|
||||||
"github.com/filecoin-project/lotus/api"
|
"github.com/filecoin-project/lotus/api"
|
||||||
apitypes "github.com/filecoin-project/lotus/api/types"
|
apitypes "github.com/filecoin-project/lotus/api/types"
|
||||||
"github.com/filecoin-project/lotus/build"
|
"github.com/filecoin-project/lotus/build"
|
||||||
|
"github.com/filecoin-project/lotus/journal/alerting"
|
||||||
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
"github.com/filecoin-project/lotus/node/modules/dtypes"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -21,6 +23,7 @@ var session = uuid.New()
|
|||||||
type CommonAPI struct {
|
type CommonAPI struct {
|
||||||
fx.In
|
fx.In
|
||||||
|
|
||||||
|
Alerting *alerting.Alerting
|
||||||
APISecret *dtypes.APIAlg
|
APISecret *dtypes.APIAlg
|
||||||
ShutdownChan dtypes.ShutdownChan
|
ShutdownChan dtypes.ShutdownChan
|
||||||
}
|
}
|
||||||
@ -72,6 +75,10 @@ func (a *CommonAPI) LogSetLevel(ctx context.Context, subsystem, level string) er
|
|||||||
return logging.SetLogLevel(subsystem, level)
|
return logging.SetLogLevel(subsystem, level)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *CommonAPI) LogAlerts(ctx context.Context) ([]alerting.Alert, error) {
|
||||||
|
return a.Alerting.GetAlerts(), nil
|
||||||
|
}
|
||||||
|
|
||||||
func (a *CommonAPI) Shutdown(ctx context.Context) error {
|
func (a *CommonAPI) Shutdown(ctx context.Context) error {
|
||||||
a.ShutdownChan <- struct{}{}
|
a.ShutdownChan <- struct{}{}
|
||||||
return nil
|
return nil
|
||||||
|
Loading…
Reference in New Issue
Block a user