2017-07-18 02:03:15 +00:00
|
|
|
package batchconsumer
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
2017-07-18 19:19:40 +00:00
|
|
|
// ErrLogIgnored should be returned by EncodeLog when it encounters a log line that will not be
|
|
|
|
|
// consumed
|
2017-07-18 02:03:15 +00:00
|
|
|
var ErrLogIgnored = errors.New("Log intentionally skipped by sender")
|
|
|
|
|
|
2017-07-18 19:19:40 +00:00
|
|
|
// Sender an interface needed for batch consumer implementations
|
2017-07-18 02:03:15 +00:00
|
|
|
type Sender interface {
|
2017-07-18 19:19:40 +00:00
|
|
|
// EncodeLog receives a raw log line. It's expected to return an appropriately formated log
|
|
|
|
|
// as well as a list of tags for that log line. A tag corresponds to a batch that it'll be
|
|
|
|
|
// put into. Typically tags are series names.
|
|
|
|
|
// If a log line will not be consumed, EncodeLog should return a ErrLogIgnored error.
|
2017-07-18 02:03:15 +00:00
|
|
|
EncodeLog(rawlog []byte) (log []byte, tags []string, err error)
|
2017-07-18 19:19:40 +00:00
|
|
|
// SendBatch receives a batch of log lines. All log lines were given the specified tag by
|
|
|
|
|
// EncodeLog
|
2017-07-18 02:03:15 +00:00
|
|
|
SendBatch(batch [][]byte, tag string) error
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-18 19:19:40 +00:00
|
|
|
// PartialOutputError should be returned by SendBatch implementations when a handful of log lines
|
|
|
|
|
// couldn't be sent to an output. It's expected that SendBatch implementations do a "best effort"
|
|
|
|
|
// before returning this error.
|
2017-07-18 02:03:15 +00:00
|
|
|
type PartialOutputError struct {
|
2017-07-18 19:19:40 +00:00
|
|
|
// Message is a description of error that occurred
|
2017-07-18 02:03:15 +00:00
|
|
|
Message string
|
2017-07-18 19:19:40 +00:00
|
|
|
// Logs a list of logs that failed to be sent
|
|
|
|
|
Logs [][]byte
|
2017-07-18 02:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c PartialOutputError) Error() string {
|
|
|
|
|
return fmt.Sprintf("%d failed logs. %s", len(c.Logs), c.Message)
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-18 19:19:40 +00:00
|
|
|
// CatastrophicOutputError should be returned by SendBatch implementations when the output is
|
|
|
|
|
// unreachable. Returning this error causes this container to exit without checkpointing.
|
2017-07-18 02:03:15 +00:00
|
|
|
type CatastrophicOutputError struct {
|
|
|
|
|
Message string
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (c CatastrophicOutputError) Error() string {
|
|
|
|
|
return c.Message
|
|
|
|
|
}
|