agentleFS
ElasticKnown publisherelastic/elastic-transport-go/AGENTS.md

elastic-transport-go

AGENTS.md14 starsChanged 7 months agoApache-2.0View on GitHub

CLAUDE.md is a symlink to this file. elastic-transport-go is the shared HTTP transport layer for Elastic Go clients (e.g. go-elasticsearch). It provides connection pooling, node discovery, retry logic, request compression, OpenTelemetry instrumentation, interceptors, and logging. All code lives in a single package: elastictransport. Everything is in the elastictransport package. There is no cmd/, internal/, or multi-package structure. Client (elastictransport.go) — The Client struct implements Interface (the Perform(*http.Request) method). It owns the retry loop, request decoration (auth, headers, compression), and delegates…

We split this AGENTS.md into the rules it gives an agent

2 rules. About 0 are common, 1 is distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Test files use the naming convention *_internal_test.go (package elastictransport), *_test.go (external), *_benchmark_test.go, …

    line 62
  2. Distinctive:

    Always include tests covering changes or new features.

    line 73

≈ “Common” is an estimate: at least 1 in 5 of the 36,368 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

AGENTS.md

This file provides guidance to AI coding agents (Claude Code, Cursor, Copilot, etc.) when working with code in this repository. CLAUDE.md is a symlink to this file.

What This Is

elastic-transport-go is the shared HTTP transport layer for Elastic Go clients (e.g. go-elasticsearch). It provides connection pooling, node discovery, retry logic, request compression, OpenTelemetry instrumentation, interceptors, and logging. All code lives in a single package: elastictransport.

Commands

# Unit tests (with race detector)
go test -v -race ./...

# Benchmarks
go test -bench=. ./...

# Integration tests (requires running Elasticsearch)
go test -v -race --tags=integration ./...

# Multi-node integration tests
go test -v --tags=integration,multinode ./...

# Lint
golangci-lint run

# Single test
go test -v -run TestFunctionName ./elastictransport/

Architecture

Everything is in the elastictransport package. There is no cmd/, internal/, or multi-package structure.

Client (elastictransport.go) — The Client struct implements Interface (the Perform(*http.Request) method). It owns the retry loop, request decoration (auth, headers, compression), and delegates to a ConnectionPool for node selection.

Two construction APIs:

  • NewClient(opts ...Option) — preferred, functional options pattern
  • New(Config{...}) — deprecated struct-based config, still fully functional. NewClient converts options to a Config and calls New.

Options (option.go, options.go) — Option is a self-describing value type with Name(), String() (secrets redacted), and Describe(showSensitive). Options (slice type) supports Validate(), Visit(), and Describe(). With* constructors build options. Sensitive options (passwords, API keys, certs) use newSensitiveOption to separate masked/unmasked descriptions.

Connection pools (connection.go) — Multiple pool implementations: singleConnectionPool, statusConnectionPool (dead/live tracking with resurrection), synchronizedPool, synchronizedUpdatablePool. Pools implement ConnectionPool; discovery-aware pools implement UpdatableConnectionPool; closeable ones implement CloseableConnectionPool. The synchronizedPool wrapper makes non-concurrent-safe pools safe. Custom pools via ConnectionPoolFunc config. Connection pools are pluggable — users can implement their own pool strategy via ConnectionPoolFunc, so new built-in pool strategies are generally not needed.

Discovery (discovery.go) — Discoverable interface. Calls /_nodes/http to refresh the connection pool. Supports periodic scheduling via WithDiscoverNodesInterval. During discovery, pools implementing UpdatableConnectionPool get in-place Update() calls; others get replaced entirely.

Interceptors (interceptor.go) — InterceptorFunc wraps the RoundTripFunc chain. Multiple interceptors are merged into one at construction time via mergeInterceptors.

Gzip (gzip.go) — Two compressor strategies: simpleGzipCompressor (allocates per-request) and pooledGzipCompressor (reuses via sync.Pool). Controlled by PoolCompressor config / WithPooledCompression option.

Instrumentation (instrumentation.go) — OpenTelemetry integration via the Instrumentation interface. Called in the request path (AfterResponse).

Hot Path

Client.Perform is the hot path — every Elasticsearch API call flows through it. Changes to the retry loop, connection selection, request decoration, or compression in elastictransport.go require careful benchmarking and review. Performance regressions here affect every user of go-elasticsearch. Always run go test -bench=. ./... and compare before/after when touching this code.

Conventions

  • All .go files must have the Apache 2.0 license header (17 lines, see .github/license-header.txt). CI checks this.
  • Test files use the naming convention *_internal_test.go (package elastictransport), *_test.go (external), *_benchmark_test.go, *_integration_test.go.
  • Integration tests use build tags: //go:build integration or //go:build integration && multinode.
  • The Config struct is deprecated but kept until the next major version. New features must add both a With* option constructor and the corresponding Config field.
  • Version is in elastictransport/version/version.go, managed by release-please.
  • The v8 module path is not tied to Elasticsearch 8 specifically — it supports Elasticsearch 8+ and is also used by go-elasticsearch v9.
  • When a feature interacts with pluggable interfaces (connection pools, selectors, interceptors), document edge cases and limitations for custom implementations at the user-facing API surface: the With* option godoc, the corresponding Config field comment, and doc.go. Internal code comments alone are not enough, as users read godoc and option constructors, not internal types.

Contributing

  • PRs require 1 maintainer review.
  • A CLA check runs automatically.
  • Always include tests covering changes or new features. CI runs unit tests; integration tests do not need to pass locally.
  • Contributions should focus on capabilities users cannot achieve externally. Since connection pools are pluggable, new pool strategies belong in user code, not here.
  • Branch naming: prefer feat/, fix/, chore/, etc. prefixes.

Commit Messages

This repo uses conventional commits for changelog generation via release-please.

PrefixWhen to use
feat:New user-facing functionality
fix:Bug fix
perf:Performance improvement (no functional change)
refactor:Code restructuring (no functional change)
test:Adding or updating tests only
docs:Documentation changes only
chore:Maintenance (CI, dependencies, tooling)
ci:CI pipeline changes

Downstream Impact

This library is used across several public Elastic Go repositories:

  • go-elasticsearch — the primary consumer (direct dependency); released versions here must be manually updated via PR and backported to relevant version branches
  • terraform-provider-elasticstack (direct dependency)
  • beats, apm-server, fleet-server, go-docappender, opentelemetry-collector-components (indirect, via go-elasticsearch)

Download now (ZIP)

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 28,693 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repositoryOne other file it gives its agents.

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.