update http output pugin - #957
Conversation
| // can't save even one log | ||
| if right-i == 1 { | ||
| statusCode = sc | ||
| err = r | ||
| } |
There was a problem hiding this comment.
The switch / right-i == 1 handling here is unnecessary. Since each POST is a single event, right-i == 1 is only true on the last iteration, so a http.StatusRequestEntityTooLarge on any earlier event is dropped silently while a http.StatusRequestEntityTooLarge on the last one is returned.
But the whole error branch is redundant: if we just return (statusCode, err) on the first failing request, out() already increments the metric, logs it, and decides retry vs. drop by status code. And continuing the loop after a failure is pointless - on a retryable error the whole batch is resent anyway, and on http.StatusRequestEntityTooLarge out() drops the batch. So SendItemize can be represented like this:
func (p *Plugin) sendItemize(left int, right int, begin []int, data []byte) (int, error) {
for i := left; i < right; i++ {
if statusCode, err := p.send(data[begin[i]:begin[i+1]]); err != nil {
return statusCode, err
}
}
return http.StatusOK, nil
}| // > @3@4@5@6 | ||
| // > | ||
| // > Enable split big batches | ||
| SplitBatch bool `json:"split_batch" default:"false"` // * | ||
|
|
||
| // > @3@4@5@6 | ||
| // > | ||
| // > Enable partial shipment big batches | ||
| // > Only one flag out of two (SplitBatch or ItemizeBatch) can be initialized | ||
| ItemizeBatch bool `json:"itemize_batch" default:"false"` // * | ||
|
|
There was a problem hiding this comment.
I think making an enum is better than keeping two bool flags. We already validate string enums via options:"..." (e.g. gzip_compression_level).
Description
Когда не было http output плагина, мне пришлось реализовать свой. Я взял за основу output плагин elasticsearch.
Http плагин был необходим для передачи логов Куба (kube api) в CS (container security) по http. Т.e. мне надо было через file.d имитировать работу kube api audit-log webhooks.
Базовая настройка kube-api через webhook предполагает такую работу:
kube-api может разово передавать пачку событий формата
где: |Batch| = webhookMaxBatchSize, |event i| = maxEventSize.
А filed (да и все другие агенты) отправляет пачку событий формата:
Таким образом, массив не упакован в { }, а это не валидный json и функция json.Unmarshal в плагине CS валится с ошибкой.
Поэтому filed был настроен так, чтобы отправлять одним постом один event: |Batch| = |event|.
Настройка заключается в том, что я в свой http output добавил (помимо сплитования) флаг поэлементной отправки данных массива логов (событий).
Чтобы перейти на ваш плагин, нам нужен параметр itemize_batch. В текущем PR добавлен флаг itemize_batch и функция обработки массива логов.
Fixes # (issue)