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 LeaseLister ¶
type LeaseLister interface {
ListAll(ctx context.Context) ([]dispatch.DAGRunLease, error)
}
LeaseLister lists the leases of runs on distributed workers.
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) DismissErrorsNotice ¶
func (m *Monitoring) DismissErrorsNotice(ctx context.Context) error
DismissErrorsNotice records that an administrator dismissed the notice offering to send error messages. Like DismissNotice, it does nothing when configuration fixes the level.
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, which also counts as offering error messages. It fails with ErrLevelConfigured when configuration fixes the level, and with ErrUnknownLevel for an unknown one.
type ProcLister ¶
ProcLister lists the runs in progress on the server's own processes, by queue.
type QueueStore ¶
type QueueStore interface {
queue.Summarizer
GetByItemID(ctx context.Context, name, itemID string) (queue.QueuedItemData, error)
}
QueueStore sums up the queues that hold queued runs and reads a queued run by its item ID.
type Queues ¶
type Queues struct {
// Store sums up the queues that hold queued runs, and reads a queue's
// next run in line.
Store QueueStore
// Procs lists the runs in progress on the server's own processes, by
// queue, and Leases those on distributed workers.
Procs ProcLister
Leases LeaseLister
// Runs opens a queued run's attempt, to read why it cannot start.
Runs RunFinder
// Capacity is how many runs of the queue may run at once; a queue runs
// at least one, as the scheduler does.
Capacity func(queue string) int
}
Queues is what reports read of the server's queues. A nil Store leaves queues out of reports; a nil Procs, Leases, or Runs leaves out what it tells. A report whose read of the queues or of the runs in progress fails leaves the queues out, rather than send counts that are short.
type RemoteAccess ¶
type RemoteAccess interface {
Status(ctx context.Context) (cloudaccess.Status, error)
}
RemoteAccess reads how far calls from Dagu Cloud may go on the server.
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, scheduler Scheduler, queues Queues, monitoring *Monitoring, remote RemoteAccess, refresh func(context.Context) error, ) *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, with the scheduler's last tick and pause from scheduler and, unless remote is nil, how far calls from Dagu Cloud may go, and also, at runs, the finished and in-progress DAG runs that events configures, the scheduled DAGs with what came of their latest slots, and the queues that queues reads. Schedules are sent by the process that reports the events. 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 Dagu Console answers that the server's license changed, refresh checks in for it, at most every five minutes.
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 RunFinder ¶
type RunFinder interface {
FindAttempt(ctx context.Context, ref ir.DAGRunRef) (dagrun.Attempt, error)
}
RunFinder finds a run's latest attempt.
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 Scheduler ¶
type Scheduler struct {
// State holds each DAG's next run and latest start slot, and the last
// tick.
State schedulerstate.Store
// Pause says whether the scheduler is paused.
Pause schedulerstate.PauseStore
}
Scheduler is what the scheduler keeps, for reports. A nil store leaves out what it holds.
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
// ErrorsOffered reports that an administrator was offered to send error
// messages: they chose a level, which they choose among choices that
// include them, or dismissed the notice that offers them.
ErrorsOffered 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.