|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance to LLM Agents when working with code in this repository. |
| 4 | + |
| 5 | +## Project |
| 6 | + |
| 7 | +PHP OpenTSDB HTTP API Client (`cybercog/opentsdb-client`) — a library for sending time-series metric data to OpenTSDB via its HTTP API. Also compatible with VictoriaMetrics. |
| 8 | + |
| 9 | +## Commands |
| 10 | + |
| 11 | +All commands must be run inside Docker containers via `docker compose run`. |
| 12 | + |
| 13 | +### Install dependencies |
| 14 | +```bash |
| 15 | +docker compose run php85 composer update --prefer-stable --prefer-dist --no-interaction |
| 16 | +``` |
| 17 | + |
| 18 | +### Run all tests |
| 19 | +```bash |
| 20 | +docker compose run php85 vendor/bin/phpunit |
| 21 | +``` |
| 22 | + |
| 23 | +### Run unit tests only |
| 24 | +```bash |
| 25 | +docker compose run php85 vendor/bin/phpunit --testsuite Unit |
| 26 | +``` |
| 27 | + |
| 28 | +### Run integration tests only (requires running OpenTSDB container) |
| 29 | +```bash |
| 30 | +docker compose run php85 vendor/bin/phpunit --testsuite Integration |
| 31 | +``` |
| 32 | + |
| 33 | +### Run a single test |
| 34 | +```bash |
| 35 | +docker compose run php85 vendor/bin/phpunit --filter testMethodName |
| 36 | +``` |
| 37 | + |
| 38 | +Available PHP services: `php80` through `php85`. The `opentsdb` service runs on port 4242. |
| 39 | + |
| 40 | +## Architecture |
| 41 | + |
| 42 | +The library has three core classes in `src/` under namespace `Cog\OpenTsdbClient`: |
| 43 | + |
| 44 | +- **`DataPoint`** — Immutable value object representing a single metric. Validates all inputs in the constructor (AssertionError on failure). Sanitizes metric/tag names by replacing unsupported characters with `-`. Implements `JsonSerializable`. |
| 45 | +- **`OpenTsdbClient`** — Main client. Takes a PSR-18 `ClientInterface` via constructor injection. Two send methods: `sendDataPointList()` (fire-and-forget) and `sendDataPointListWithDebug()` (returns response details). Maps 12 HTTP status codes to specific error messages. |
| 46 | +- **`SendDataPointListResponse`** — Immutable response object with httpStatusCode, success/failed counts, and errors. |
| 47 | + |
| 48 | +Exception hierarchy: `OpenTsdbExceptionInterface` marker implemented by `OpenTsdbException` (HTTP errors) and `OpenTsdbConnectionException` (network failures). |
| 49 | + |
| 50 | +## Code Conventions |
| 51 | + |
| 52 | +- `declare(strict_types=1)` in all files |
| 53 | +- All classes are `final` |
| 54 | +- PSR-4 autoloading, PSR-18 HTTP client, PSR-7 messages |
| 55 | +- 4-space indentation, LF line endings |
| 56 | +- Tests: `test/Unit/` and `test/Integration/` with separate PSR-4 namespaces |
| 57 | +- Integration tests are skipped in CI via `APP_ENV=ci` check |
0 commit comments