Skip to content
This repository was archived by the owner on Oct 9, 2024. It is now read-only.

Commit 9b06b59

Browse files
committed
BREAKING CHANGES: rename LOG_ADDITIONAL_FIELD to LOG_EXTRA_FIELD
1 parent 1daee5e commit 9b06b59

File tree

3 files changed

+46
-46
lines changed

3 files changed

+46
-46
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ TACO accepts the following environment variables:
1414
- `TARGET_NAME`: The name of the target to check (optional, default: inferred from `TARGET_ADDRESS`)\*.
1515
- `INTERVAL`: The interval between connection attempts (optional, default: `2s`).
1616
- `DIAL_TIMEOUT`: The timeout for each connection attempt (optional, default: `1s`).
17-
- `LOG_ADDITIONAL_FIELDS`: Log additional fields (optional, default: `false`).
17+
- `LOG_EXTRA_FIELDS`: Log additional fields (optional, default: `false`).
1818

1919
**\*** If `TARGET_NAME` is not set, the name will be inferred from the host part of the target address as follows: `postgres.default.svc.cluster.local:5432` will be inferred as `postgres`.
2020

@@ -32,7 +32,7 @@ graph TD;
3232

3333
## Logging
3434

35-
With the `LOG_ADDITIONAL_FIELDS` environment variable set to `true` additional fields will be logged.
35+
With the `LOG_EXTRA_FIELDS` environment variable set to `true` additional fields will be logged.
3636

3737
### With additional fields
3838

@@ -67,7 +67,7 @@ initContainers:
6767
# TARGET_NAME inferred from the target address "valkey.default.svc.cluster.local" which is okay for this use case
6868
# INTERVAL defaults to 2 seconds which is okay for this use case
6969
# DIAL_TIMEOUT defaults to 1 seconds which is okay for this use case
70-
- name: LOG_ADDITIONAL_FIELDS
70+
- name: LOG_EXTRA_FIELDS
7171
value: "true"
7272
- name: wait-for-postgres
7373
image: ghcr.io/containeroo/taco:latest

cmd/taco/main.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,34 +14,34 @@ import (
1414
"time"
1515
)
1616

17-
const version = "0.0.25"
17+
const version = "0.0.26"
1818

1919
const (
20-
envTargetName = "TARGET_NAME"
21-
envTargetAddress = "TARGET_ADDRESS"
22-
envInterval = "INTERVAL"
23-
envDialTimeout = "DIAL_TIMEOUT"
24-
envLogAdditionalFields = "LOG_ADDITIONAL_FIELDS"
20+
envTargetName = "TARGET_NAME"
21+
envTargetAddress = "TARGET_ADDRESS"
22+
envInterval = "INTERVAL"
23+
envDialTimeout = "DIAL_TIMEOUT"
24+
envLogExtraFields = "LOG_EXTRA_FIELDS"
2525
)
2626

2727
// Config holds the required environment variables.
2828
type Config struct {
29-
TargetName string // The name of the target to check.
30-
TargetAddress string // The address of the target in the format 'host:port'.
31-
Interval time.Duration // The interval between connection attempts.
32-
DialTimeout time.Duration // The timeout for each connection attempt.
33-
LogAdditionalFields bool // Whether to log the fields in the log message.
29+
TargetName string // The name of the target to check.
30+
TargetAddress string // The address of the target in the format 'host:port'.
31+
Interval time.Duration // The interval between connection attempts.
32+
DialTimeout time.Duration // The timeout for each connection attempt.
33+
LogExtraFields bool // Whether to log the fields in the log message.
3434
}
3535

3636
// parseConfig retrieves and parses the required environment variables.
3737
// Provides default values if the environment variables are not set.
3838
func parseConfig(getenv func(string) string) (Config, error) {
3939
cfg := Config{
40-
TargetName: getenv(envTargetName),
41-
TargetAddress: getenv(envTargetAddress),
42-
Interval: 2 * time.Second, // default interval
43-
DialTimeout: 1 * time.Second, // default dial timeout
44-
LogAdditionalFields: false,
40+
TargetName: getenv(envTargetName),
41+
TargetAddress: getenv(envTargetAddress),
42+
Interval: 2 * time.Second, // default interval
43+
DialTimeout: 1 * time.Second, // default dial timeout
44+
LogExtraFields: false,
4545
}
4646

4747
if intervalStr := getenv(envInterval); intervalStr != "" {
@@ -60,11 +60,11 @@ func parseConfig(getenv func(string) string) (Config, error) {
6060
}
6161
}
6262

63-
if logFieldsStr := getenv(envLogAdditionalFields); logFieldsStr != "" {
63+
if logFieldsStr := getenv(envLogExtraFields); logFieldsStr != "" {
6464
var err error
65-
cfg.LogAdditionalFields, err = strconv.ParseBool(logFieldsStr)
65+
cfg.LogExtraFields, err = strconv.ParseBool(logFieldsStr)
6666
if err != nil {
67-
return Config{}, fmt.Errorf("invalid %s value: %s", envLogAdditionalFields, err)
67+
return Config{}, fmt.Errorf("invalid %s value: %s", envLogExtraFields, err)
6868
}
6969
}
7070

@@ -107,7 +107,7 @@ func validateConfig(cfg *Config) error {
107107
func setupLogger(cfg Config, output io.Writer) *slog.Logger {
108108
handlerOpts := &slog.HandlerOptions{}
109109

110-
if cfg.LogAdditionalFields {
110+
if cfg.LogExtraFields {
111111
return slog.New(slog.NewTextHandler(output, handlerOpts)).With(
112112
slog.String("target_address", cfg.TargetAddress),
113113
slog.String("interval", cfg.Interval.String()),

cmd/taco/main_test.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,11 @@ func TestParseEnv(t *testing.T) {
1717
t.Parallel()
1818

1919
env := map[string]string{
20-
"TARGET_NAME": "database",
21-
"TARGET_ADDRESS": "localhost:5432",
22-
"INTERVAL": "1s",
23-
"DIAL_TIMEOUT": "1s",
24-
"LOG_ADDITIONAL_FIELDS": "true",
20+
"TARGET_NAME": "database",
21+
"TARGET_ADDRESS": "localhost:5432",
22+
"INTERVAL": "1s",
23+
"DIAL_TIMEOUT": "1s",
24+
"LOG_EXTRA_FIELDS": "true",
2525
}
2626

2727
getenv := func(key string) string {
@@ -34,11 +34,11 @@ func TestParseEnv(t *testing.T) {
3434
}
3535

3636
expected := Config{
37-
TargetName: "database",
38-
TargetAddress: "localhost:5432",
39-
Interval: 1 * time.Second,
40-
DialTimeout: 1 * time.Second,
41-
LogAdditionalFields: true,
37+
TargetName: "database",
38+
TargetAddress: "localhost:5432",
39+
Interval: 1 * time.Second,
40+
DialTimeout: 1 * time.Second,
41+
LogExtraFields: true,
4242
}
4343
if !reflect.DeepEqual(cfg, expected) {
4444
t.Errorf("Expected %+v, got %+v", expected, cfg)
@@ -89,11 +89,11 @@ func TestParseEnv(t *testing.T) {
8989
}
9090
})
9191

92-
t.Run("Invalid LOG_ADDITIONAL_FIELDS", func(t *testing.T) {
92+
t.Run("Invalid LOG_EXTRA_FIELDS", func(t *testing.T) {
9393
t.Parallel()
9494

9595
env := map[string]string{
96-
"LOG_ADDITIONAL_FIELDS": "tr",
96+
"LOG_EXTRA_FIELDS": "tr",
9797
}
9898

9999
getenv := func(key string) string {
@@ -105,7 +105,7 @@ func TestParseEnv(t *testing.T) {
105105
t.Error("Expected error but got none")
106106
}
107107

108-
expected := fmt.Sprintf("invalid LOG_ADDITIONAL_FIELDS value: strconv.ParseBool: parsing \"%s\": invalid syntax", env["LOG_ADDITIONAL_FIELDS"])
108+
expected := fmt.Sprintf("invalid LOG_EXTRA_FIELDS value: strconv.ParseBool: parsing \"%s\": invalid syntax", env["LOG_EXTRA_FIELDS"])
109109
if err.Error() != expected {
110110
t.Errorf("Expected output %q but got %q", expected, err.Error())
111111
}
@@ -366,11 +366,11 @@ func TestWaitForTarget(t *testing.T) {
366366
t.Parallel()
367367

368368
cfg := Config{
369-
TargetName: "PostgreSQL",
370-
TargetAddress: "localhost:5432",
371-
Interval: 50 * time.Millisecond,
372-
DialTimeout: 50 * time.Millisecond,
373-
LogAdditionalFields: true,
369+
TargetName: "PostgreSQL",
370+
TargetAddress: "localhost:5432",
371+
Interval: 50 * time.Millisecond,
372+
DialTimeout: 50 * time.Millisecond,
373+
LogExtraFields: true,
374374
}
375375

376376
var wg sync.WaitGroup
@@ -677,11 +677,11 @@ func TestRun(t *testing.T) {
677677
t.Parallel()
678678

679679
env := map[string]string{
680-
"TARGET_NAME": "database",
681-
"TARGET_ADDRESS": "localhost:8092",
682-
"INTERVAL": "1s",
683-
"DIAL_TIMEOUT": "1s",
684-
"LOG_ADDITIONAL_FIELDS": "true",
680+
"TARGET_NAME": "database",
681+
"TARGET_ADDRESS": "localhost:8092",
682+
"INTERVAL": "1s",
683+
"DIAL_TIMEOUT": "1s",
684+
"LOG_EXTRA_FIELDS": "true",
685685
}
686686

687687
getenv := func(key string) string {

0 commit comments

Comments
 (0)