This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
This is the OpenSearch Rust SDK - an early-stage implementation of OpenSearch Extensions in Rust. The project provides a foundation for building OpenSearch extensions using Rust, with a working "Hello World" implementation that demonstrates the transport protocol communication with OpenSearch.
# Build (includes formatting)
just build
# or directly: cargo build
# Run tests
just test
# or directly: cargo test
# Run linter
just clippy
# or directly: cargo clippy --all --all-targets --all-features
# Format code
just fmt
# or directly: cargo fmt --all
# Run the extension server (listens on port 1234)
just run
# or directly: cargo run# Complete setup (starts cluster + builds + registers extension)
just setup
# Start development cycle (builds and runs extension)
just dev
# OpenSearch cluster management
just start-cluster # Start OpenSearch with extensions enabled
just stop-cluster # Stop cluster
just restart-cluster # Restart cluster
# Extension management
just register-extension # Register extension with OpenSearch
just test-extension # Test the hello endpoint
just check-extension-health # Check if extension is running
# Monitoring
just cluster-health # Check cluster health
just extensions-list # List registered extensions
just cluster-logs # View cluster logs# Run a specific test
cargo test test_name
# Run tests in a specific module
cargo test module_name::
# Run with output
cargo test -- --nocaptureThe SDK implements OpenSearch's binary transport protocol:
- TCP Server (
src/main.rs): Listens on port 1234 for OpenSearch connections - Transport Layer (
src/transport.rs):- Parses
TcpHeaderto identify request/response and request IDs - Routes requests based on transport action names
- Handles serialization/deserialization of messages
- Parses
- Protocol Buffers: Messages defined in
src/*.protofiles, compiled at build time
- TcpHeader: Contains request ID, version, and request/response flag
- Transport Actions: Handle specific OpenSearch requests (e.g., "internal:transport/handshake")
- Extension Identity: Registered via
examples/hello/hello.json
- OpenSearch connects to extension on port 1234
- Extension parses TCP header from incoming bytes
- Based on action name, appropriate handler processes the request
- Response is serialized and sent back with matching request ID
The extension must be registered with OpenSearch using the configuration in examples/hello/hello.json. This file defines:
- Extension name, unique ID, and version
- Port (1234) and host (127.0.0.1)
- OpenSearch version compatibility (3.0.0+)
The project uses Docker Compose for OpenSearch:
- Configuration:
resources/compose/docker-compose-prod.yml - 2-node cluster with extensions enabled
- Admin credentials:
admin:$PASS(where $PASS is from environment) - Extensions feature flag:
-Dopensearch.experimental.feature.extensions.enabled=true
- Development uses HTTPS with self-signed certificates
- Curl commands use
-kuflags for insecure connections - Production deployments should use proper certificates
The transport uses nom parser combinators to parse the binary protocol. Key structures:
- Fixed header: 6 bytes (TY, ES, status, version, request ID)
- Variable header: Contains features and action names
- Message content: Protocol buffer encoded
- Basic hello world implementation only
- Limited to transport protocol (no REST actions yet)
- No cluster state or settings management
- Development/testing focused (not production-ready)
When adding new features:
- Add unit tests in the same file using
#[cfg(test)]modules - Test protocol parsing with known byte sequences
- Use
cargo test -- --nocaptureto see debug output - Integration testing requires running OpenSearch cluster
- Define the protobuf message in
src/ - Add to
build.rsfor compilation - Implement handler in transport layer
- Add action name mapping in the request router
- Enable debug logging to see raw bytes
- Use Wireshark or similar to capture TCP traffic
- Check OpenSearch logs for extension-related messages
- Verify request IDs match between request and response