You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
Copy file name to clipboardExpand all lines: README.md
+56-35Lines changed: 56 additions & 35 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,60 +88,81 @@ It provides the following information:
88
88
-`(20/s)` (attempted) rate,
89
89
-`avg: 72ns, min: 125ns, max: 27.590042ms` average, min and max iteration times.
90
90
91
-
### Environment variables
91
+
### Configuration
92
92
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.
|`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`|
| 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).
101
107
102
-
###Programmatic configuration
108
+
#### Configuring without environment variables
103
109
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:
For full control, pass a complete `f1.Settings` struct:
114
121
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
+
```
116
136
117
137
#### Precedence
118
138
119
139
Settings are resolved in this order (highest priority first):
120
140
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
124
144
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:
126
146
127
147
```golang
128
-
// Example: override push gateway and log level programmatically
0 commit comments