Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
d3506a0
failure store: update bulk indexer to support fs stats
1pkg Jan 25, 2025
2cdab68
Merge branch 'main' into response_failure_store_support
1pkg Jan 29, 2025
94581be
test: fix racy test
1pkg Jan 29, 2025
38095d1
failure store: appender stats update
1pkg Jan 29, 2025
bc81099
failure store: update stats too
1pkg Jan 29, 2025
6e8684c
failure store: add to response filter
1pkg Jan 30, 2025
8b691cc
failure store: ignore implicit not_applicable_or_unknown status
1pkg Jan 30, 2025
2f4f9f3
failure store: add relevant tests
1pkg Jan 31, 2025
f2332ac
failure store: add status const
1pkg Jan 31, 2025
323b9ba
failure store: fix typo
1pkg Jan 31, 2025
ee7973c
failure store: fix metric label test
1pkg Jan 31, 2025
442690a
failure store: use main branch from go-elasticsearch
1pkg Jan 31, 2025
18c7530
failure store: track "not_enabled" status
1pkg Jan 31, 2025
0250223
failure store: fix formatting
1pkg Jan 31, 2025
9423aa3
failure store: use latest elasticsearch client release
1pkg Feb 12, 2025
c0d492c
Merge branch 'main' into response_failure_store_support
1pkg Feb 12, 2025
1f7e409
Merge branch 'main' into response_failure_store_support
1pkg Feb 12, 2025
22f8a12
Merge branch 'main' into response_failure_store_support
1pkg Feb 13, 2025
48f9d85
failure store: do not export legacy metrics
1pkg Feb 13, 2025
19d6d05
Merge branch 'response_failure_store_support' of github.com:1pkg/go-d…
1pkg Feb 13, 2025
d2fbedf
Merge branch 'main' into response_failure_store_support
1pkg Feb 14, 2025
80a3199
failure store: use consistent docs naming for the stats
1pkg Feb 19, 2025
2f8eaad
Merge branch 'main' into response_failure_store_support
1pkg Feb 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 24 additions & 3 deletions appender.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,13 +409,13 @@ func (a *Appender) flush(ctx context.Context, bulkIndexer *BulkIndexer) error {
}
return err
}
var (
docsFailed, docsIndexed,
var docsFailed, docsIndexed,
// breakdown of failed docs:
tooManyRequests, // failed after document retries (if it applies) and final status is 429
clientFailed, // failed after document retries (if it applies) and final status is 400s excluding 429
serverFailed int64 // failed after document retries (if it applies) and final status is 500s
)

failureStore := resp.FailureStore
docsIndexed = resp.Indexed
var failedCount map[BulkIndexerResponseItem]int
if len(resp.FailedDocs) > 0 {
Expand Down Expand Up @@ -483,11 +483,32 @@ func (a *Appender) flush(ctx context.Context, bulkIndexer *BulkIndexer) error {
metric.WithAttributes(attribute.String("status", "FailedServer")),
)
}
if failureStore.Used > 0 {
a.addCount(failureStore.Used, nil,
a.metrics.docsIndexed,
metric.WithAttributes(attribute.String("failure_store", "used")),
)
}
if failureStore.Failed > 0 {
a.addCount(failureStore.Failed, nil,
a.metrics.docsIndexed,
metric.WithAttributes(attribute.String("failure_store", "failed")),
)
}
if failureStore.Unknown > 0 {
a.addCount(failureStore.Unknown, nil,
a.metrics.docsIndexed,
metric.WithAttributes(attribute.String("failure_store", "unknown")),
)
}
logger.Debug(
"bulk request completed",
zap.Int64("docs_indexed", docsIndexed),
zap.Int64("docs_failed", docsFailed),
zap.Int64("docs_rate_limited", tooManyRequests),
zap.Int64("docs_failure_store_used", failureStore.Used),
zap.Int64("docs_failure_store_failed", failureStore.Failed),
zap.Int64("docs_failure_store_unknown", failureStore.Unknown),
)
if a.otelTracingEnabled() && span.IsRecording() {
span.SetStatus(codes.Ok, "")
Expand Down
6 changes: 3 additions & 3 deletions appender_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,6 @@ func TestAppenderFlushRequestError(t *testing.T) {
}
})
assert.Equal(t, int64(1), asserted.Load())

}
t.Run("400", func(t *testing.T) {
test(t, http.StatusBadRequest, "flush failed (400): {\"error\":{\"type\":\"x_content_parse_exception\",\"caused_by\":{\"type\":\"json_parse_exception\"}}}")
Expand Down Expand Up @@ -806,7 +805,7 @@ func TestAppenderIndexFailedLogging(t *testing.T) {

core, observed := observer.New(zap.NewAtomicLevelAt(zapcore.DebugLevel))
indexer, err := docappender.New(client, docappender.Config{
FlushBytes: 500,
FlushBytes: 5000,
Logger: zap.New(core),
})
require.NoError(t, err)
Expand Down Expand Up @@ -1372,7 +1371,8 @@ func TestAppenderCloseBusyIndexer(t *testing.T) {
BytesTotal: bytesTotal,
BytesUncompressedTotal: bytesUncompressedTotal,
AvailableBulkRequests: 10,
IndexersActive: 0}, indexer.Stats())
IndexersActive: 0,
}, indexer.Stats())
}

func TestAppenderPipeline(t *testing.T) {
Expand Down
21 changes: 21 additions & 0 deletions bulk_indexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,12 @@ type BulkIndexerResponseStat struct {
Indexed int64
// RetriedDocs contains the total number of retried documents.
RetriedDocs int64
// FailureStore contains the stats for the documents indexed to failure store.
FailureStore struct {
Used int64
Failed int64
Unknown int64
}
// GreatestRetry contains the greatest observed retry count in the entire
// bulk request.
GreatestRetry int
Expand Down Expand Up @@ -140,6 +146,21 @@ func init() {
item.Index = i.ReadString()
case "status":
item.Status = i.ReadInt()
case "failure_store":
// For the stats the only actionable failure store statuses:
// "used" which represents that this document was stored in the failure store successfully.
// "failed" which represents that this document was rejected from the failure store.
// "not_applicable_or_unknown"represents that there is no information about this response or that the failure store is not applicable.
// Ignored non actionable statuses:
// "not_enabled" which represents that this document was rejected, but it could have ended up in the failure store if it was enabled.
switch fs := i.ReadString(); fs {
case "used":
(*((*BulkIndexerResponseStat)(ptr))).FailureStore.Used++
case "failed":
(*((*BulkIndexerResponseStat)(ptr))).FailureStore.Failed++
case "not_applicable_or_unknown":
(*((*BulkIndexerResponseStat)(ptr))).FailureStore.Unknown++
}
case "error":
i.ReadObjectCB(func(i *jsoniter.Iterator, s string) bool {
switch s {
Expand Down