2017-07-18 02:03:15 +00:00
|
|
|
package batchconsumer
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
|
|
|
|
"fmt"
|
|
|
|
|
)
|
|
|
|
|
|
2017-07-19 00:21:31 +00:00
|
|
|
// ErrMessageIgnored should be returned by ProcessMessage when it encounters a message that will
|
|
|
|
|
// not be consumed
|
|
|
|
|
var ErrMessageIgnored = errors.New("Message intentionally skipped by sender")
|
2017-07-18 02:03:15 +00:00
|
|
|
|
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 {
|
2018-08-09 23:43:30 +00:00
|
|
|
// Initialize called once before ProcessMessage and SendBatch
|
|
|
|
|
Initialize(shardID string)
|
2017-07-19 00:21:31 +00:00
|
|
|
// ProcessMessage receives a raw message and is expected to return an appropriately formatted
|
|
|
|
|
// message 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 message will not be consumed, ProcessMessage should return a ErrMessageIgnored error.
|
|
|
|
|
ProcessMessage(rawmsg []byte) (msg []byte, tags []string, err error)
|
|
|
|
|
// SendBatch receives a batch of messages. All messages were given the specified tag by
|
|
|
|
|
// ProcessMessage
|
2017-07-18 02:03:15 +00:00
|
|
|
SendBatch(batch [][]byte, tag string) error
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-19 00:21:31 +00:00
|
|
|
// PartialSendBatchError should be returned by SendBatch implementations when some messages
|
2017-07-18 19:19:40 +00:00
|
|
|
// couldn't be sent to an output. It's expected that SendBatch implementations do a "best effort"
|
|
|
|
|
// before returning this error.
|
2017-07-19 00:21:31 +00:00
|
|
|
type PartialSendBatchError struct {
|
|
|
|
|
// ErrMessage is a description of error that occurred
|
|
|
|
|
ErrMessage string
|
|
|
|
|
// FailedMessages a list of messages that failed to be sent
|
|
|
|
|
FailedMessages [][]byte
|
2017-07-18 02:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 00:21:31 +00:00
|
|
|
func (c PartialSendBatchError) Error() string {
|
|
|
|
|
return fmt.Sprintf("%d failed logs. %s", len(c.FailedMessages), c.ErrMessage)
|
2017-07-18 02:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 00:21:31 +00:00
|
|
|
// CatastrophicSendBatchError should be returned by SendBatch implementations when the output is
|
2017-07-18 19:19:40 +00:00
|
|
|
// unreachable. Returning this error causes this container to exit without checkpointing.
|
2017-07-19 00:21:31 +00:00
|
|
|
type CatastrophicSendBatchError struct {
|
|
|
|
|
ErrMessage string
|
2017-07-18 02:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
2017-07-19 00:21:31 +00:00
|
|
|
func (c CatastrophicSendBatchError) Error() string {
|
|
|
|
|
return fmt.Sprintf("catastrophic SendBatch error: %s", c.ErrMessage)
|
2017-07-18 02:03:15 +00:00
|
|
|
}
|