|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +This file provides guidance to AI coding agents when working |
| 4 | +with code in this repository. |
| 5 | + |
| 6 | +## Build Commands |
| 7 | + |
| 8 | +This project uses Maven with mise for task automation. |
| 9 | +The Maven wrapper (`./mvnw`) is used for all builds. |
| 10 | + |
| 11 | +```bash |
| 12 | +# Full CI build (clean + install + all checks) |
| 13 | +mise run ci |
| 14 | + |
| 15 | +# Quick compile without tests or checks (fastest) |
| 16 | +mise run compile |
| 17 | + |
| 18 | +# Run unit tests only (skips formatting/coverage/checkstyle) |
| 19 | +mise run test |
| 20 | + |
| 21 | +# Run all tests including integration tests |
| 22 | +mise run test-all |
| 23 | + |
| 24 | +# Format code with Google Java Format |
| 25 | +mise run format |
| 26 | +# or directly: ./mvnw spotless:apply |
| 27 | + |
| 28 | +# Run a single test class |
| 29 | +./mvnw test -Dtest=CounterTest \ |
| 30 | + -Dspotless.check.skip=true \ |
| 31 | + -Dcoverage.skip=true -Dcheckstyle.skip=true |
| 32 | + |
| 33 | +# Run a single test method |
| 34 | +./mvnw test -Dtest=CounterTest#testIncrement \ |
| 35 | + -Dspotless.check.skip=true \ |
| 36 | + -Dcoverage.skip=true -Dcheckstyle.skip=true |
| 37 | + |
| 38 | +# Run tests in a specific module |
| 39 | +./mvnw test -pl prometheus-metrics-core \ |
| 40 | + -Dspotless.check.skip=true \ |
| 41 | + -Dcoverage.skip=true -Dcheckstyle.skip=true |
| 42 | + |
| 43 | +# Regenerate protobuf classes (after protobuf dep update) |
| 44 | +mise run generate |
| 45 | +``` |
| 46 | + |
| 47 | +## Architecture |
| 48 | + |
| 49 | +The library follows a layered architecture where metrics |
| 50 | +flow from core types through a registry to exporters: |
| 51 | + |
| 52 | +```text |
| 53 | +prometheus-metrics-core (user-facing API) |
| 54 | + │ |
| 55 | + ▼ collect() |
| 56 | +prometheus-metrics-model (immutable snapshots) |
| 57 | + │ |
| 58 | + ▼ |
| 59 | +prometheus-metrics-exposition-formats |
| 60 | + │ |
| 61 | + ▼ |
| 62 | +Exporters (httpserver, servlet, pushgateway, otel) |
| 63 | +``` |
| 64 | + |
| 65 | +### Key Modules |
| 66 | + |
| 67 | +- **prometheus-metrics-core**: User-facing metric types |
| 68 | + (Counter, Gauge, Histogram, Summary, Info, StateSet). |
| 69 | + All metrics implement `Collector` with `collect()`. |
| 70 | +- **prometheus-metrics-model**: Internal read-only immutable |
| 71 | + snapshot types returned by `collect()`. |
| 72 | + Contains `PrometheusRegistry` for metric registration. |
| 73 | +- **prometheus-metrics-config**: Runtime configuration via |
| 74 | + properties files or system properties. |
| 75 | +- **prometheus-metrics-exposition-formats**: Converts |
| 76 | + snapshots to Prometheus exposition formats. |
| 77 | +- **prometheus-metrics-tracer**: Exemplar support with |
| 78 | + OpenTelemetry tracing integration. |
| 79 | +- **prometheus-metrics-simpleclient-bridge**: Allows legacy |
| 80 | + simpleclient 0.16.0 metrics to work with the new registry. |
| 81 | + |
| 82 | +### Instrumentation Modules |
| 83 | + |
| 84 | +Pre-built instrumentations: |
| 85 | +`prometheus-metrics-instrumentation-jvm`, `-caffeine`, |
| 86 | +`-guava`, `-dropwizard`, `-dropwizard5`. |
| 87 | + |
| 88 | +## Code Style |
| 89 | + |
| 90 | +- **Formatter**: Google Java Format (enforced via Spotless) |
| 91 | +- **Line length**: 100 characters |
| 92 | + (enforced for ALL files including Markdown, Java, YAML) |
| 93 | +- **Indentation**: 2 spaces |
| 94 | +- **Static analysis**: `Error Prone` with NullAway |
| 95 | + (`io.prometheus.metrics` package) |
| 96 | +- **Logger naming**: Logger fields must be named `logger` |
| 97 | + (not `log`, `LOG`, or `LOGGER`) |
| 98 | +- **Assertions in tests**: Use static imports from AssertJ |
| 99 | + (`import static ...Assertions.assertThat`) |
| 100 | +- **Empty catch blocks**: Use `ignored` as the variable name |
| 101 | +- **Markdown code blocks**: Always specify language |
| 102 | + (e.g., ` ```java`, ` ```bash`, ` ```text`) |
| 103 | + |
| 104 | +## Linting and Validation |
| 105 | + |
| 106 | +**CRITICAL**: These checks MUST be run before creating any |
| 107 | +commits. CI will fail if these checks fail. |
| 108 | + |
| 109 | +### Java Files |
| 110 | + |
| 111 | +- **ALWAYS** run `mise run build` after modifying Java files |
| 112 | + to ensure: |
| 113 | + - Code formatting (Spotless with Google Java Format) |
| 114 | + - Static analysis (`Error Prone` with NullAway) |
| 115 | + - Checkstyle validation |
| 116 | + - Build succeeds (tests are skipped; |
| 117 | + run `mise run test` or `mise run test-all` for tests) |
| 118 | + |
| 119 | +### Non-Java Files (Markdown, YAML, JSON, shell scripts) |
| 120 | + |
| 121 | +- **ALWAYS** run `mise run lint` after modifying non-Java |
| 122 | + files (runs super-linter + link checking + BOM check) |
| 123 | +- `mise run fix` autofixes linting issues |
| 124 | +- Super-linter will **autofix** many issues |
| 125 | + (formatting, trailing whitespace, etc.) |
| 126 | +- It only reports ERROR-level issues |
| 127 | + (configured via `LOG_LEVEL=ERROR` in |
| 128 | + `.github/super-linter.env`) |
| 129 | +- Common issues caught: |
| 130 | + - Lines exceeding 100 characters in Markdown files |
| 131 | + - Missing language tags in fenced code blocks |
| 132 | + - Table formatting issues |
| 133 | + - YAML/JSON syntax errors |
| 134 | + |
| 135 | +### Running Linters |
| 136 | + |
| 137 | +```bash |
| 138 | +# After modifying Java files (run BEFORE committing) |
| 139 | +mise run build |
| 140 | + |
| 141 | +# After modifying non-Java files (run BEFORE committing) |
| 142 | +mise run lint |
| 143 | +# or to autofix: mise run fix |
| 144 | +``` |
| 145 | + |
| 146 | +## Testing |
| 147 | + |
| 148 | +- JUnit 5 (Jupiter) with `@Test` annotations |
| 149 | +- AssertJ for fluent assertions |
| 150 | +- Mockito for mocking |
| 151 | +- **Test visibility**: Test classes and test methods must be |
| 152 | + package-protected (no `public` modifier) |
| 153 | +- Integration tests are in `integration-tests/` and run |
| 154 | + during `verify` phase |
| 155 | +- Acceptance tests use OATs framework: |
| 156 | + `mise run acceptance-test` |
| 157 | + |
| 158 | +## Documentation |
| 159 | + |
| 160 | +- Docs live under `docs/content/` and use `$version` as a |
| 161 | + placeholder for the library version |
| 162 | +- When publishing GitHub Pages, |
| 163 | + `mise run set-release-version-github-pages` replaces |
| 164 | + `$version` with the latest Git tag across all |
| 165 | + `docs/content/**/*.md` files |
| 166 | + (the published site is not versioned) |
| 167 | +- Use `$version` for the Prometheus client version and |
| 168 | + `$otelVersion-alpha` for the OTel instrumentation |
| 169 | + version — never hardcode them |
| 170 | + |
| 171 | +## Java Version |
| 172 | + |
| 173 | +Source compatibility: Java 8. Tests run on Java 25 |
| 174 | +(configured in `mise.toml`). |
0 commit comments