Skip to content

fix(arangodb): register metrics and return not-connected errors when Connect fails - #4373

Merged
aryanmehrotra merged 2 commits into
gofr-dev:developmentfrom
NitinKumar004:fix/arangodb-failed-connect
Oct 13, 2026
Merged

aryanmehrotra merged 2 commits into
gofr-dev:developmentfrom
NitinKumar004:fix/arangodb-failed-connect

Conversation

@NitinKumar004

Copy link
Copy Markdown
Contributor

Connect registered the app_arango_stats histogram only after the first Version call succeeded. If ArangoDB was down at startup, the histogram was never created. Connect is not retried, so every later operation logged a metrics error and the latency metric stayed missing for the whole process, even after the server came back.

The histogram is now registered at the start of Connect, as the SurrealDB datasource already does.

When config validation or auth setup failed, Connect returned with a nil driver client, so HealthCheck and every DB, collection, document, graph and user method panicked with a nil pointer dereference. They now go through a single arangoClient()/database()/user() accessor that returns errNotConnected. There are 6 nil guards in total: arangoClient, HealthCheck, CreateDB, DropDB, createUser and dropUser.

HealthCheck reports DOWN with details.error in both failure cases, so the payload has the same shape either way:

  • not connected;
  • Version failing, which now includes the underlying error text.

The server-down path deliberately keeps its lazily-connecting client, so the datasource recovers once the server becomes reachable.

No public API, interface or mock changes. I checked that it also builds and passes against go-driver v2.4.1, the version #4351 bumps to.

Tests

  • TestClient_Connect is now table-driven, with rows for invalid config, server unreachable (httptest 503) and success. It replaces Test_NewArangoClient_Error, which depended on nothing listening on localhost:8529.
  • TestClient_NotConnected has one row per method that touches the driver.
  • New TestClient_HealthCheck_NotConnected.
  • TestClient_HealthCheck_Error now asserts details.error.

Docs: the ArangoDB page now describes the failure behaviour.

Possible follow-up (not in this PR): mongo.Connect registers its histogram after the ping in the same way.

Fixes #4369

…Connect fails

Connect registered the app_arango_stats histogram only after the first
Version call succeeded, so if ArangoDB was down at startup the metric
was missing for the whole process. Register it at the start of Connect.

When config validation failed, Connect left a nil driver client and
HealthCheck plus every DB/collection/document/graph/user method
panicked. Route driver access through accessors that return
errNotConnected, and report DOWN with details.error in both HealthCheck
failure branches.

Fixes gofr-dev#4369

@aryanmehrotra aryanmehrotra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two fixes are correct. I reviewed commit 7de5957, which is cb49156 merged with development.

Connect()                   BEFORE                           AFTER (this PR)
---------                   ------                           ---------------
register histogram          last step, only on success       first step, always

config invalid              client = nil                     client = nil
  -> DB call                panic (nil pointer)              returns errNotConnected
  -> HealthCheck            panic                            DOWN + details.error

server down at start        client kept, no histogram        client kept, histogram exists
  -> DB call                metrics error on every call      metric records
  -> server comes back      works, metric still missing      works, metric works

What I ran

  • go build, go vet and go test -race pass in the arangodb module on this tree, at go-driver v2.4.1.
  • I removed each fix in turn. The new tests fail each time: TestClient_NotConnected, 2 rows of TestClient_Connect, and TestClient_HealthCheck_NotConnected.
  • I changed one httptest server from 503 to 200. HealthCheck reported DOWN, then UP, with no second Connect call.
  • I did not use a real ArangoDB server. I did not run lint locally.

Items

  1. The docs promise recovery after the server becomes reachable. No test covers this. Please add a test that changes one httptest server from 503 to 200, and then asserts that HealthCheck reports UP.
  2. Nit: the row "server unreachable still registers metrics" uses a server that answers 503. Please rename the row, or use a closed port.
  3. Question, not a request: a not-connected call still goes through instrumentOp. It records a sample in app_arango_stats with endpoint="". Do we want these samples? I read this from the code. I did not measure it.
  4. Nit: the new sentence in docs/datasources/arangodb/page.md is more than 40 words long. Please split it into 2 or 3 sentences.

Item 1 is a strong request. Items 2 to 4 are optional.

@aryanmehrotra
aryanmehrotra merged commit 56cea5b into gofr-dev:development Oct 13, 2026
18 checks passed
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.

ArangoDB: if the server is down at startup the metrics histogram is never registered, and a config error leaves a nil client that panics

2 participants