Documentation
¶
Overview ¶
Package extlogging contains general utilities for extension logging. We recommend that extensions leverage zerolog.
Index ¶
Constants ¶
const DefaultReminder = 15 * time.Minute
DefaultReminder is how often Transitions repeats the warning for an operation that keeps failing with the same error.
const RFC3339Micro = "2006-01-02T15:04:05.999Z07:00"
Variables ¶
This section is empty.
Functions ¶
func DefaultFingerprint ¶ added in v1.13.2
DefaultFingerprint decides whether two errors are the same: by the title and detail of an ExtensionError in the chain, else by the error text, in both cases with request ids, UUIDs, long hex ids, timestamps and the local port of a connection masked. Cloud SDK errors carry a request id that differs on every call; compared verbatim, every attempt would count as a different error and warn. The detail counts because extensions usually keep the title fixed ("Failed to discover EC2 instances") and put the cause, which may change, into the detail.
func ForgetTransition ¶ added in v1.13.2
func ForgetTransition(key string)
ForgetTransition stops tracking key in the shared Transitions, see Transitions.Forget.
func InitZeroLog ¶
func InitZeroLog()
InitZeroLog configures the zerolog logging output in a standardized way. More specifically, it configures the output to be sent to stderr, a human-readable output format, the time format and the global log level.
func ReportTransition ¶ added in v1.13.2
ReportTransition reports the outcome of a recurring operation to a shared Transitions with the DefaultReminder. The key names the operation and what it ran against, e.g. "discovery of AWS EC2 instances in account 123, eu-west-1", because it is the subject of every log line. Keys should come from a bounded set, see Transitions.
Types ¶
type Outcome ¶ added in v1.13.2
type Outcome struct {
Kind OutcomeKind
Since time.Time
Attempts int
}
Outcome is what Observe decided about one outcome. Since and Attempts describe the failure streak: for Recovered the one that just ended, for the failure kinds the current one including this attempt.
type OutcomeKind ¶ added in v1.13.2
type OutcomeKind int
OutcomeKind says what one outcome means for a recurring operation.
const ( // Succeeded follows a success: nothing to log. Succeeded OutcomeKind = iota // Recovered is the first success after one or more failures. Recovered // Failed is the first failure after a success, or the very first outcome. Failed // FailedDifferently is a failure with a different error than the previous one. FailedDifferently // StillFailing is a failure with the same error, and the reminder is due. StillFailing // FailedAgain is a failure with the same error, and the reminder is not due. FailedAgain )
type Transitions ¶ added in v1.13.2
type Transitions struct {
// Reminder is the interval of the repeated warning while an operation keeps failing; zero or less turns it off.
Reminder time.Duration
// Fingerprint reduces an error to what makes it "the same" error; nil means DefaultFingerprint.
Fingerprint func(error) string
// contains filtered or unexported fields
}
Transitions tracks the outcome of recurring operations, such as a discovery or a poll loop, by key, so a failure that repeats on every interval neither floods the log nor gets lost in it:
- the first failure, and a failure with a different error, at WARN;
- while it keeps failing with the same error, one reminder at WARN every Reminder, saying since when and how often;
- all other repeated failures at DEBUG;
- the first success after a failure at INFO, saying how long it failed.
Whether two errors are "the same" is decided by Fingerprint, see DefaultFingerprint. Successes that follow successes are not logged. Report logs a standard line; callers that log their own, richer line use Observe and log at the Level it returns. Both are safe for concurrent use.
Keys should come from a bounded set (a discovery, an account and region), because a key that stops reporting while it fails stays tracked; call Forget when such an operation ends. The zero value is usable, without reminders; prefer NewTransitions.
func NewTransitions ¶ added in v1.13.2
func NewTransitions(reminder time.Duration) *Transitions
NewTransitions returns Transitions that repeat the warning for a lasting failure every reminder.
func (*Transitions) Forget ¶ added in v1.13.2
func (t *Transitions) Forget(key string)
Forget stops tracking key, for an operation that ended (a poll loop of a finished execution, a removed account) and might otherwise stay tracked as failing for the life of the process. Nothing is logged.
func (*Transitions) Observe ¶ added in v1.13.2
func (t *Transitions) Observe(key string, err error) Outcome
Observe records one outcome of the operation named by key, err being nil on success, and returns what it means.
func (*Transitions) Report ¶ added in v1.13.2
func (t *Transitions) Report(key string, err error)
Report records one outcome of the operation named by key, err being nil on success, and logs it.