Skip to content

fix(elasticsearch-logger): retry transient version probe failures with backoff - #14273

Open
diaosj wants to merge 1 commit into
apache:masterfrom
diaosj:fix/es-logger-version-probe-recovery
Open

diaosj wants to merge 1 commit into
apache:masterfrom
diaosj:fix/es-logger-version-probe-recovery

Conversation

@diaosj

@diaosj diaosj commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Description

In elasticsearch-logger, fetch_and_update_es_version caches conf._es_version = false after any failed GET / version probe so that clusters denying GET / (missing the monitor privilege) do not get probed on every batch. However, if the very first probe fails due to a transient error (network timeout, connection refusal, 408, 429, or 5xx), Elasticsearch 5/6 clusters get permanently stuck with conf._es_version = false and never add _type = "_doc" to bulk action lines until the worker restarts or the route config changes.

This PR distinguishes permanent probe failures from transient ones and adds rate-bounded retry recovery:

  • get_es_major_version returns a third retryable boolean: true for HTTP client creation failures, network/timeout errors, and 408 / 429 / 5xx responses; false for other non-200 responses (e.g. 401/403) and malformed JSON/version payloads.
  • Permanent failures keep the existing behavior: set conf._es_version = false immediately and do not re-probe.
  • Transient failures store a bounded retry state (conf._es_version_probe via plugin.set_runtime_state) with in_flight guard and capped exponential backoff (1s -> 2s -> ... -> 60s, using resty.core.time.monotonic_time with ngx.now fallback). Once a later probe succeeds, conf._es_version is cached and _es_version_probe is cleared.
  • If a bulk write succeeds (HTTP 200 and resp_body.errors ~= true) without _type while transient probe retries are pending, conf._es_version is marked false and _es_version_probe is cleared so Elasticsearch 7/8+ clusters that block GET / with 5xx stop retrying probes.
  • Adds tests in t/plugin/elasticsearch-logger2.t (TEST 27-30) covering:
    • Elasticsearch 6 recovering after a transient 503 on the initial version probe, verifying no re-probe occurs inside the backoff window and _type: "_doc" is emitted after recovery.
    • Elasticsearch 8 stopping retries after a successful bulk write when GET / always returns 503.

Follow-up to #14192 and #14238.

Which issue(s) this PR fixes:

Follow-up to #14192.

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

…h backoff

Signed-off-by: Shoujun (Adrian) Diao <shoujun.diao@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant