Skip to content

Commit 9b05a91

Browse files
committed
docs: unify configuration docs and precedence
Merge README "Environment variables" and "Programmatic configuration" into a single "Configuration" section covering: - Settings reference table mapping env vars to typed programmatic options - How to configure without env vars (WithSettings) - Full Settings struct example - Precedence order: programmatic > env vars > defaults - WithLogger interaction (disables log level/format settings) - Default env-backed behaviour for backward compatibility
1 parent 4693a3d commit 9b05a91

File tree

3 files changed

+59
-38
lines changed

3 files changed

+59
-38
lines changed

README.md

Lines changed: 56 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -88,60 +88,81 @@ It provides the following information:
8888
- `(20/s)` (attempted) rate,
8989
- `avg: 72ns, min: 125ns, max: 27.590042ms` average, min and max iteration times.
9090

91-
### Environment variables
91+
### Configuration
9292

93-
| Name | Format | Default | Description |
93+
f1 can be configured via environment variables, programmatic options, or both. By default, environment variables are read at construction time. Programmatic options override env vars for the fields they set.
94+
95+
#### Settings reference
96+
97+
| Setting | Environment variable | Programmatic option | Default |
9498
| --- | --- | --- | --- |
95-
| `PROMETHEUS_PUSH_GATEWAY` | string - `host:port` or `ip:port` | `""` | Configures the address of a [Prometheus Push Gateway](https://prometheus.io/docs/instrumenting/pushing/) for exposing metrics. The prometheus job name configured will be `f1-{scenario_name}`. Disabled by default.|
96-
| `PROMETHEUS_NAMESPACE` | string | `""` | Sets the metric label `namespace` to the specified value. Label is omitted if the value provided is empty.|
97-
| `PROMETHEUS_LABEL_ID` | string | `""` | Sets the metric label `id` to the specified value. Label is omitted if the value provided is empty.|
98-
| `LOG_FILE_PATH` | string | `""`| Specify the log file path used if `--verbose` is disabled. The logfile path will be an automatically generated temp file if not specified. |
99-
| `F1_LOG_LEVEL` | string | `"info"`| Specify the log level of the default logger, one of: `debug`, `warn`, `error` |
100-
| `F1_LOG_FORMAT` | string | `""`| Specify the log format of the default logger, defaults to `text` formatter, allows `json` |
99+
| Prometheus push gateway | `PROMETHEUS_PUSH_GATEWAY` | `f1.WithPrometheusPushGateway(url)` | disabled |
100+
| Prometheus namespace label | `PROMETHEUS_NAMESPACE` | `f1.WithPrometheusNamespace(ns)` | `""` |
101+
| Prometheus ID label | `PROMETHEUS_LABEL_ID` | `f1.WithPrometheusLabelID(id)` | `""` |
102+
| Log file path | `LOG_FILE_PATH` | `f1.WithLogFilePath(path)` | auto temp file |
103+
| Log level | `F1_LOG_LEVEL` | `f1.WithLogLevel(slog.LevelDebug)` | `slog.LevelInfo` |
104+
| Log format | `F1_LOG_FORMAT` | `f1.WithLogFormat(f1.LogFormatJSON)` | `f1.LogFormatText` |
105+
106+
Log level and format options use Go's standard `slog.Level` and f1's `LogFormat` type for compile-time safety. Use `f1.ParseLogLevel(string)` and `f1.ParseLogFormat(string)` to convert from strings (e.g. from config files).
101107

102-
### Programmatic configuration
108+
#### Configuring without environment variables
103109

104-
Every environment variable above has a programmatic equivalent that can be passed as an option to `f1.New()`:
110+
Use `f1.WithSettings(f1.Settings{})` to start from zero values, ignoring all environment variables. Fine-grained options (`WithLogLevel`, `WithPrometheusPushGateway`, etc.) still apply after the baseline:
111+
112+
```golang
113+
f1.New(
114+
f1.WithSettings(f1.Settings{}),
115+
f1.WithLogLevel(slog.LevelWarn),
116+
f1.WithLogFormat(f1.LogFormatJSON),
117+
).AddScenario("myScenario", mySetup).Execute()
118+
```
105119

106-
| Environment variable | Programmatic option | Accepted values |
107-
| --- | --- | --- |
108-
| `PROMETHEUS_PUSH_GATEWAY` | `f1.WithPrometheusPushGateway(url)` | `host:port` or full URL |
109-
| `PROMETHEUS_NAMESPACE` | `f1.WithPrometheusNamespace(ns)` | any string |
110-
| `PROMETHEUS_LABEL_ID` | `f1.WithPrometheusLabelID(id)` | any string |
111-
| `LOG_FILE_PATH` | `f1.WithLogFilePath(path)` | file path |
112-
| `F1_LOG_LEVEL` | `f1.WithLogLevel(level)` | `debug`, `info`, `warn`, `error` (case-insensitive) |
113-
| `F1_LOG_FORMAT` | `f1.WithLogFormat(format)` | `text`, `json` (case-insensitive) |
120+
For full control, pass a complete `f1.Settings` struct:
114121

115-
Additionally, `f1.WithoutEnvSettings()` can be used to ignore all environment variables and start from default values.
122+
```golang
123+
f1.New(
124+
f1.WithSettings(f1.Settings{
125+
Prometheus: f1.PrometheusSettings{
126+
PushGateway: "http://pushgateway:9091",
127+
Namespace: "my-namespace",
128+
},
129+
Logging: f1.LoggingSettings{
130+
Level: slog.LevelDebug,
131+
Format: f1.LogFormatJSON,
132+
},
133+
}),
134+
).AddScenario("myScenario", mySetup).Execute()
135+
```
116136

117137
#### Precedence
118138

119139
Settings are resolved in this order (highest priority first):
120140

121-
1. **Programmatic options** — values passed to `f1.New()`
122-
2. **Environment variables** — read at construction time
123-
3. **Defaults**info level, text format, no Prometheus push
141+
1. **Programmatic options** — values passed to `f1.New()` (applied in order)
142+
2. **Environment variables** — read at construction time (baseline when no `WithSettings` is used)
143+
3. **Defaults**`slog.LevelInfo`, `LogFormatText`, no Prometheus push
124144

125-
When `f1.WithLogger(logger)` is used, the caller owns the logger entirely. In this case `WithLogLevel`, `WithLogFormat`, `F1_LOG_LEVEL` and `F1_LOG_FORMAT` have no effect.
145+
When `f1.WithLogger(logger)` is used, the caller owns the logger entirely. `WithLogLevel`, `WithLogFormat`, and the corresponding env vars have no effect:
126146

127147
```golang
128-
// Example: override push gateway and log level programmatically
148+
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
129149
f1.New(
130-
f1.WithPrometheusPushGateway("http://pushgateway:9091"),
131-
f1.WithLogLevel("debug"),
150+
f1.WithLogger(logger),
132151
).AddScenario("myScenario", mySetup).Execute()
152+
```
133153

134-
// Example: ignore all env vars, configure everything in code
135-
f1.New(
136-
f1.WithoutEnvSettings(),
137-
f1.WithLogLevel("warn"),
138-
f1.WithLogFormat("json"),
139-
).AddScenario("myScenario", mySetup).Execute()
154+
#### Default env-backed behaviour
140155

141-
// Example: use a custom logger (log level/format options are ignored)
142-
logger := slog.New(slog.NewJSONHandler(os.Stdout, &slog.HandlerOptions{Level: slog.LevelDebug}))
156+
When no `WithSettings` is provided, environment variables are used as the baseline (backward-compatible with previous releases):
157+
158+
```golang
159+
// Env vars like PROMETHEUS_PUSH_GATEWAY are read automatically
160+
f1.New().AddScenario("myScenario", mySetup).Execute()
161+
162+
// Fine-grained options override individual env var values
143163
f1.New(
144-
f1.WithLogger(logger),
164+
f1.WithPrometheusPushGateway("http://pushgateway:9091"),
165+
f1.WithLogLevel(slog.LevelDebug),
145166
).AddScenario("myScenario", mySetup).Execute()
146167
```
147168

docs/CODEBASE_REVIEW.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ When both `err` and `profilingErr` are non-nil, the returned error wraps only `e
170170
| Item | Status |
171171
|------|--------|
172172
| Installation instructions | Missing |
173-
| Prometheus push gateway | Done (README: env vars + programmatic options + precedence) |
173+
| Prometheus push gateway | Done (README: unified Configuration section with settings reference, precedence, examples) |
174174
| Output mechanisms (Prometheus, logs) | Partial |
175175
| Grafana dashboard example | Missing |
176176
| Screenshots/screencast | Missing |

docs/V3_PLAN.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ type RunFn func(ctx context.Context, t *T)
129129
- [x] Fix `doc.go` example – updated to use `*f1testing.T` and `f1testing` package
130130
- [x] Update README with v3 import paths and any API changes
131131
- [ ] Add installation instructions (no pre-built binary; build from source) — #245
132-
- [x] Document Prometheus push gateway (`PROMETHEUS_PUSH_GATEWAY`), programmatic equivalents, precedence — #4
132+
- [x] Document Prometheus push gateway, programmatic equivalents, precedence, WithSettings#4
133133
- [ ] Document output mechanisms (Prometheus, logs) — #136
134-
- [x] Document programmatic configuration options and precedence (README)
134+
- [x] Document unified configuration: settings reference, WithSettings, precedence, examples (README)
135135
- [ ] Document Scenario.RunFn population (framework sets during setup; see plan §9.1)
136136
- [ ] Add Grafana dashboard example — #149
137137
- [ ] Add screenshots/screencast to README — #16

0 commit comments

Comments
 (0)