Skip to content

Commit

Permalink
reduce amount of required parameters, stream to local Loki by default
Browse files Browse the repository at this point in the history
  • Loading branch information
skudasov committed Nov 4, 2024
1 parent c53b6e0 commit 7c17b87
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 28 deletions.
19 changes: 10 additions & 9 deletions book/src/framework/configuration.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# Configuration

### Environment variables
| Name | Description | Possible values | Default | Required? |
|:----------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------:|-------------------------:|:-------:|:------------------------:|
| CTF_CONFIGS | Path(s) to test config files. <br/>Can be more than one, ex.: smoke.toml,smoke_1.toml,smoke_2.toml.<br/>First filepath will hold all the merged values | Any valid TOML file path | ||
| CTF_LOG_LEVEL | Harness log level | `info`, `debug`, `trace` | `info` | 🚫 |
| CTF_LOKI_STREAM | Streams all components logs to `Loki`, see params below | `true`, `false` | `false` | 🚫 |
| LOKI_URL | URL to `Loki` push api, should be like`${host}/loki/api/v1/push` | URL | - | If you use `Loki` then ✅ |
| LOKI_TENANT_ID | Streams all components logs to `Loki`, see params below | `true`, `false` | - | If you use `Loki` then ✅ |
| TESTCONTAINERS_RYUK_DISABLED | Testcontainers-Go reaper container, removes all the containers after the test exit | `true`, `false` | `false` | 🚫 |
| RESTY_DEBUG | Log all Resty client HTTP calls | `true`, `false` | `false` | 🚫 |
| Name | Description | Possible values | Default | Required? |
|:----------------------------:|:------------------------------------------------------------------------------------------------------------------------------------------------------:|-------------------------:|:---------------------------------------------------:|:---------:|
| TESTCONTAINERS_RYUK_DISABLED | Testcontainers-Go reaper container, removes all the containers after the test exit | `true`, `false` | `false` | 🚫 |
| CTF_CONFIGS | Path(s) to test config files. <br/>Can be more than one, ex.: smoke.toml,smoke_1.toml,smoke_2.toml.<br/>First filepath will hold all the merged values | Any valid TOML file path | - ||
| CTF_LOG_LEVEL | Harness log level | `info`, `debug`, `trace` | `info` | 🚫 |
| CTF_PROMTAIL_DEBUG | Set `true` if you are integrating with remote `Loki` push API to debug Promtail | `true`, `false` | `false` | 🚫 |
| LOKI_URL | URL to `Loki` push api, should be like`${host}/loki/api/v1/push` | URL | `http://host.docker.internal:3030/loki/api/v1/push` | 🚫 |
| LOKI_TENANT_ID | Streams all components logs to `Loki`, see params below | `string` | `promtail` | 🚫 |
| LOKI_BASIC_AUTH | Basic auth in format $user:$password | `$user:$password` | - | 🚫 |
| RESTY_DEBUG | Log all Resty client HTTP calls | `true`, `false` | `false` | 🚫 |
10 changes: 3 additions & 7 deletions book/src/framework/getting_started.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,15 @@ More CLI [docs](./cli.md)

Create an `.envrc` file and put common parameters there (you can use [direnv](https://direnv.net/) to sync them more easily)
```
export CTF_LOG_LEVEL=info
export CTF_LOKI_STREAM=true
export TESTCONTAINERS_RYUK_DISABLED=true
export CTF_CONFIGS=smoke.toml
export PRIVATE_KEY="ac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"
export TESTCONTAINERS_RYUK_DISABLED=true # do not remove containers while we develop locally
export CTF_CONFIGS=smoke.toml # our configuration file
```

Now you are ready to write your [first test](./first_test.md)

## Tools setup (Optional)

This setup is optional, and it explains how to setup a local observability stack for on-chain and off-chain components.
This setup is optional, and it explains how to create a local observability stack for on-chain and off-chain components.

Spin up your local obserability stack (Grafana LGTM)
```
Expand Down
10 changes: 2 additions & 8 deletions framework/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const (

const (
EnvVarTestConfigs = "CTF_CONFIGS"
EnvVarLokiStream = "CTF_LOKI_STREAM"
EnvVarAWSSecretsManager = "CTF_AWS_SECRETS_MANAGER"
// EnvVarCI this is a default env variable many CI runners use so code can detect we run in CI
EnvVarCI = "CI"
Expand Down Expand Up @@ -141,13 +140,8 @@ func Load[X any](t *testing.T) (*X, error) {
//}
err = DefaultNetwork(once)
require.NoError(t, err)
if err != nil {
return input, err
}
if os.Getenv(EnvVarLokiStream) == "true" {
err = NewPromtail()
require.NoError(t, err)
}
err = NewPromtail()
require.NoError(t, err)
return input, nil
}

Expand Down
11 changes: 7 additions & 4 deletions framework/promtail.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ scrape_configs:
lokiURL := os.Getenv("LOKI_URL")
lokiTenantID := os.Getenv("LOKI_TENANT_ID")

if lokiURL == "" || lokiTenantID == "" {
return "", errors.New("LOKI_URL or LOKI_TENANT_ID environment variable is missing")
if lokiURL == "" {
lokiURL = "http://host.docker.internal:3030/loki/api/v1/push"
}
if lokiTenantID == "" {
lokiTenantID = "promtail"
}

lokiBasicAuth := os.Getenv("LOKI_BASIC_AUTH")
Expand Down Expand Up @@ -99,8 +102,8 @@ scrape_configs:
if err != nil {
return "", fmt.Errorf("could not execute promtail config template: %w", err)
}
L.Debug().Str("Path", filePath).Msg("Promtail configuration written to")

fmt.Printf("Promtail config written to %s\n", filePath)
return configFile.Name(), nil
}

Expand All @@ -115,7 +118,7 @@ func NewPromtail() error {

cmd := make([]string, 0)
cmd = append(cmd, "-config.file=/etc/promtail/promtail-config.yml")
if os.Getenv("CTF_LOKI_STREAM_DEBUG") != "" {
if os.Getenv("CTF_PROMTAIL_DEBUG") != "" {
cmd = append(cmd, "-log.level=debug")
}

Expand Down

0 comments on commit 7c17b87

Please sign in to comment.