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
Copy file name to clipboardExpand all lines: book/src/lib.md
+9-108Lines changed: 9 additions & 108 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -252,38 +252,13 @@ Builder will read the location of chain configuration from env var named `PRIVAT
252
252
253
253
`net` is an instance of `blockchain.EVMNetwork`, which contains characteristics of the network and can be used to connect to it using an EVM client. `rpc` variable contains arrays of public and private RPC endpoints, where "private" means URL that's accessible from the same Docker network as the chain is running in.
254
254
255
-
# Using LogStream
255
+
## Logs
256
+
By default, we will save logs of all Docker containers running on the host machine, when the test ends (regardless whether it failed or succeeded). They will be available in the `./logs/<test-name><date>` directory. Same goes for dumping the databases of PostgresDBs
257
+
used by the Chainlink nodes. These will be saves in the `./db_dumps/<test-name><date>` directory.
256
258
257
-
LogStream is a package that allows to connect to a Docker container and then flush logs to configured targets. Currently 3 targets are supported:
259
+
## Loki and Grafana
258
260
259
-
-`file` - saves logs to a file in `./logs` folder
260
-
-`loki` - sends logs to Loki
261
-
-`in-memory` - stores logs in memory
262
-
263
-
It can be configured to use multiple targets at once. If no target is specified, it becomes a no-op.
264
-
265
-
LogStream has to be configured by passing an instance of `LoggingConfig` to the constructor.
266
-
267
-
When you connect a container LogStream will create a new consumer and start a detached goroutine that listens to logs emitted by that container and which reconnects and re-requests logs if listening fails for whatever reason. Retry limit and timeout can both be configured using functional options. In most cases one container should have one consumer, but it's possible to have multiple consumers for one container.
268
-
269
-
LogStream stores all logs in gob temporary file. To actually send/save them, you need to flush them. When you do it, LogStream will decode the file and send logs to configured targets. If log handling results in an error it won't be retried and processing of logs for given consumer will stop (if you think we should add a retry mechanism please let us know).
270
-
271
-
_Important:_ Flushing and accepting logs is blocking operation. That's because they both share the same cursor to temporary file and otherwise it's position would be racey and could result in mixed up logs.
272
-
273
-
## Configuration
274
-
275
-
Basic `LogStream` TOML configuration is following:
276
-
277
-
```toml
278
-
[LogStream]
279
-
log_targets=["file"]
280
-
log_producer_timeout="10s"
281
-
log_producer_retry_limit=10
282
-
```
283
-
284
-
You can find it here: [logging_default.toml](https://github.com/smartcontractkit/chainlink-testing-framework/blob/main/lib/config/tomls/logging_default.toml)
285
-
286
-
When using `in-memory` or `file` target no other configuration variables are required. When using `loki` target, following ones must be set:
261
+
If you need to pass Loki or Grafana configuration to your tests you can do that by providing the following config:
Also, do remember that different URL should be used when running in CI and everywhere else. In CI it should be a public endpoint, while in local environment it should be a private one.
297
272
298
-
If your test has a Grafana dashboard in order for the url to be correctly printed you should provide the following config:
273
+
If your test has a Grafana dashboard you should provide the following config:
299
274
300
275
```toml
301
276
[Logging.Grafana]
302
-
url="http://grafana.somwhere.com/my_dashboard"
303
-
```
304
-
305
-
## Initialisation
306
-
307
-
First you need to create a new instance:
308
-
309
-
```golang
310
-
// t - instance of *testing.T (can be nil)
311
-
// testConfig.Logging - pointer to logging part of TestConfig
If using `testcontainers-go` Docker containers it is recommended to use life cycle hooks for connecting and disconnecting LogStream from the container. You can do that when creating `ContainerRequest` in the following way:
You can print log location for each target using this function: `(m *LogStream) PrintLogTargetsLocations()`. For `file` target it will print relative folder path, for `loki` it will print URL of a Grafana Dashboard scoped to current execution and container ids. For `in-memory` target it's no-op.
343
-
344
-
It is recommended to shutdown LogStream at the end of your tests. Here's an example:
345
-
346
-
```golang
347
-
t.Cleanup(func() {
348
-
l.Warn().Msg("Shutting down Log Stream")
349
-
350
-
if t.Failed() || os.Getenv("TEST_LOG_COLLECT") == "true" {
351
-
// we can't do much if this fails, so we just log the error
352
-
_ = logStream.FlushLogsToTargets()
353
-
// this will log log locations for each target (for file it will be a folder, for Loki Grafana dashboard -- remember to provide it's url in config!)
354
-
logStream.PrintLogTargetsLocations()
355
-
// this will save log locations in test summary, so that they can be easily accessed in GH's step summary
356
-
logStream.SaveLogLocationInTestSummary()
357
-
}
358
-
359
-
// we can't do much if this fails, so we just log the error
360
-
_ = logStream.Shutdown(testcontext.Get(b.t))
361
-
})
362
-
```
363
-
364
-
or in a bit shorter way:
365
-
366
-
```golang
367
-
t.Cleanup(func() {
368
-
l.Warn().Msg("Shutting down Log Stream")
369
-
370
-
if t.Failed() || os.Getenv("TEST_LOG_COLLECT") == "true" {
371
-
// this will log log locations for each target (for file it will be a folder, for Loki Grafana dashboard -- remember to provide it's url in config!)
372
-
logStream.PrintLogTargetsLocations()
373
-
// this will save log locations in test summary, so that they can be easily accessed in GH's step summary
0 commit comments