Documentation
¶
Overview ¶
Package cloudreport reports the health and DAG runs of a server with an online license to Dagu Console.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( // ErrLevelConfigured is returned when configuration fixes the level. ErrLevelConfigured = errors.New("cloud.report is set in configuration") // ErrUnknownLevel is returned for a level other than off, health, or runs. ErrUnknownLevel = errors.New("unknown report level") )
Functions ¶
This section is empty.
Types ¶
type Events ¶
type Events struct {
// Reader is the event store. A nil Reader leaves runs out of reports.
Reader eventstore.DAGRunReader
// RetentionDays is how many days the event store keeps events; 0 keeps
// them forever.
RetentionDays int
// State persists which events Dagu Console has acknowledged.
State StateStore
// Stale persists, without the lease, that the position in State predates
// a period below runs, so that the next process to take the lease
// discards it. It must be set when Reader is.
Stale StateStore
// Lease lets one process at a time report the events of a shared data
// directory.
Lease Lease
// Statuses lists the runs in progress when they are not known from the
// events: when the reporter starts without a saved list of them, and
// after events were lost. It must be set when Reader is.
Statuses RunStatuses
}
Events configures the DAG runs that reports carry: the runs that finish, read from the event store, and the runs in progress.
type Lease ¶
Lease is a lock shared by processes. TryLock fails with dirlock.ErrLockConflict while another process holds it, and Heartbeat fails once the lease is lost.
type Monitoring ¶
type Monitoring struct {
// contains filtered or unexported fields
}
Monitoring is how much a server reports to Dagu Console, and what it sent last. Configuration can fix the level; otherwise an administrator chooses it and the choice persists. A server whose level is neither configured nor chosen reports nothing. One reporter at a time follows a Monitoring.
func NewMonitoring ¶
func NewMonitoring(configured config.ReportLevel, store StateStore) *Monitoring
NewMonitoring returns the reporting state of a server. A configured level other than empty fixes the level; otherwise store persists the choice. Either way, store persists the level of the last report sent.
func (*Monitoring) DismissNotice ¶
func (m *Monitoring) DismissNotice(ctx context.Context) error
DismissNotice records that an administrator dismissed the notice asking them to choose a level. It does nothing when configuration fixes the level, since the notice is never shown then.
func (*Monitoring) SetLevel ¶
func (m *Monitoring) SetLevel(ctx context.Context, level config.ReportLevel) error
SetLevel chooses the level. It fails with ErrLevelConfigured when configuration fixes the level, and with ErrUnknownLevel for an unknown one.
type Reporter ¶
type Reporter struct {
// contains filtered or unexported fields
}
Reporter sends reports to Dagu Console until stopped.
func Start ¶
func Start( ctx context.Context, credentials func() (license.CloudCredentials, bool), registry serviceregistry.ServiceRegistry, events Events, monitoring *Monitoring, ) *Reporter
Start reports in the background until Stop is called or ctx is done. Reports authenticate with what credentials returns and are skipped while it returns false. Services are counted in registry; a nil registry leaves them out of reports. Each report sends what the level in monitoring allows at the time: health at health, and also the finished and in-progress DAG runs that events configures at runs. Choosing off stops a report in flight. Finished runs are sent even while Dagu Console pauses storing them; monitoring shows until when.
Runs that finish below runs are never sent, even when runs is chosen again after a restart.
When the level is off, while running or at a later start, and the last report sent was at a level that reports, one report tells Dagu Console that the server no longer reports. It is retried until Dagu Console answers other than with 429 or 5xx, and nothing is sent after it. A level that cannot be read sends nothing. When configuration fixes off, reporting ends once no such report is due.
type RunStatuses ¶
type RunStatuses interface {
ListStatuses(ctx context.Context, options persis.DAGRunListOptions) ([]*ir.DAGRunStatus, error)
}
RunStatuses lists the statuses of top-level DAG runs.
type StateStore ¶
type StateStore interface {
Load(ctx context.Context) (data []byte, found bool, err error)
Save(ctx context.Context, data []byte) error
}
StateStore persists encoded reporter state.
type Status ¶
type Status struct {
// Level is the level in effect.
Level config.ReportLevel
// Configured reports that configuration fixes Level.
Configured bool
// Chosen reports that an administrator chose Level.
Chosen bool
// NoticeDismissed reports that an administrator dismissed the notice
// asking them to choose a level.
NoticeDismissed bool
// LastReportAt is when Dagu Console accepted the last report this
// process sent, or zero before the first.
LastReportAt time.Time
// LastReport is the JSON body of that report, with the heartbeat secret
// redacted.
LastReport []byte
// RunsPausedUntil is when Dagu Console stores this server's finished runs
// again, as the last accepted report was told, or zero when it was not
// paused.
RunsPausedUntil time.Time
}
Status describes what a server reports to Dagu Console.