Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add debug logging configuration and env option for eventhandler #42169

Merged
merged 9 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions examples/chart/event-handler/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ data:
timeout = {{ .Values.eventHandler.timeout | toJson }}
batch = {{ .Values.eventHandler.batch }}
window-size = {{ default "24h" .Values.eventHandler.windowSize | quote }}
debug = {{ default "false" .Values.eventHandler.debug }}

[teleport]
addr = "{{ .Values.teleport.address }}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ should match the snapshot:
timeout = "10s"
batch = 20
window-size = "24h"
debug = false

[teleport]
addr = "teleport.example.com:1234"
Expand Down
14 changes: 12 additions & 2 deletions examples/chart/event-handler/values.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,8 @@
{
"address": "auth.example.com:3025",
"identitySecretName": "teleport-plugin-event-handler-auth-id",
"identitySecretPath": "auth_id"
"identitySecretPath": "auth_id",
"debug": false
}
],
"required": [
Expand Down Expand Up @@ -329,7 +330,8 @@
"storagePath": "/var/lib/teleport/plugins/event-handler/storage",
"timeout": "10s",
"batch": 20,
"window-size": "12h"
"window-size": "12h",
"debug": false
}
],
"required": [
Expand Down Expand Up @@ -360,6 +362,14 @@
"$id": "#/properties/eventHandler/properties/window-size",
"type": "string",
"default": "24h"
},
"debug": {
"$id": "#/properties/eventHandler/properties/debug",
"type": "boolean",
"default": false,
"examples": [
false
]
}
},
"additionalProperties": true
Expand Down
2 changes: 2 additions & 0 deletions examples/chart/event-handler/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ eventHandler:
# for the default window size.
# The window size should be specified as a duration string, parsed by Go's time.ParseDuration.
windowSize: "24h"
# Optional setting to enable debug logging
# debugLogger: true

fluentd:
url: ""
Expand Down
2 changes: 1 addition & 1 deletion integrations/event-handler/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ type CLI struct {
Config kong.ConfigFlag `help:"Path to TOML configuration file" optional:"true" short:"c" type:"existingfile" env:"FDFWD_CONFIG"`

// Debug is a debug logging mode flag
Debug bool `help:"Debug logging" short:"d"`
Debug bool `help:"Debug logging" short:"d" env:"FDFWD_DEBUG"`
espadolini marked this conversation as resolved.
Show resolved Hide resolved

// Version is the version print command
Version struct{} `cmd:"true" help:"Print plugin version"`
Expand Down
139 changes: 110 additions & 29 deletions integrations/event-handler/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,40 +36,119 @@ func TestStartCmdConfig(t *testing.T) {
name string
args []string

want StartCmdConfig
want CLI
}{
{
name: "standard",
args: []string{"start", "--config", "testdata/config.toml"},
want: StartCmdConfig{
FluentdConfig: FluentdConfig{
FluentdURL: "https://localhost:8888/test.log",
FluentdSessionURL: "https://localhost:8888/session",
FluentdCert: path.Join(wd, "testdata", "fake-file"),
FluentdKey: path.Join(wd, "testdata", "fake-file"),
FluentdCA: path.Join(wd, "testdata", "fake-file"),
},
TeleportConfig: TeleportConfig{
TeleportAddr: "localhost:3025",
TeleportIdentityFile: path.Join(wd, "testdata", "fake-file"),
TeleportRefreshEnabled: true,
TeleportRefreshInterval: 2 * time.Minute,
want: CLI{
Debug: false,
Start: StartCmdConfig{
FluentdConfig: FluentdConfig{
FluentdURL: "https://localhost:8888/test.log",
FluentdSessionURL: "https://localhost:8888/session",
FluentdCert: path.Join(wd, "testdata", "fake-file"),
FluentdKey: path.Join(wd, "testdata", "fake-file"),
FluentdCA: path.Join(wd, "testdata", "fake-file"),
},
TeleportConfig: TeleportConfig{
TeleportAddr: "localhost:3025",
TeleportIdentityFile: path.Join(wd, "testdata", "fake-file"),
TeleportRefreshEnabled: true,
TeleportRefreshInterval: 2 * time.Minute,
},
IngestConfig: IngestConfig{
StorageDir: "./storage",
BatchSize: 20,
SkipEventTypes: map[string]struct{}{},
SkipSessionTypesRaw: []string{"print"},
SkipSessionTypes: map[string]struct{}{
"print": {},
},
Timeout: 10 * time.Second,
Concurrency: 5,
WindowSize: 24 * time.Hour,
},
LockConfig: LockConfig{
LockFailedAttemptsCount: 3,
LockPeriod: time.Minute,
},
},
IngestConfig: IngestConfig{
StorageDir: "./storage",
BatchSize: 20,
SkipEventTypes: map[string]struct{}{},
SkipSessionTypesRaw: []string{"print"},
SkipSessionTypes: map[string]struct{}{
"print": {},
},
},
{
name: "standard with debug enabled flag",
args: []string{"--debug", "start", "--config", "testdata/config.toml"},
want: CLI{
Debug: true,
Start: StartCmdConfig{
FluentdConfig: FluentdConfig{
FluentdURL: "https://localhost:8888/test.log",
FluentdSessionURL: "https://localhost:8888/session",
FluentdCert: path.Join(wd, "testdata", "fake-file"),
FluentdKey: path.Join(wd, "testdata", "fake-file"),
FluentdCA: path.Join(wd, "testdata", "fake-file"),
},
TeleportConfig: TeleportConfig{
TeleportAddr: "localhost:3025",
TeleportIdentityFile: path.Join(wd, "testdata", "fake-file"),
TeleportRefreshEnabled: true,
TeleportRefreshInterval: 2 * time.Minute,
},
IngestConfig: IngestConfig{
StorageDir: "./storage",
BatchSize: 20,
SkipEventTypes: map[string]struct{}{},
SkipSessionTypesRaw: []string{"print"},
SkipSessionTypes: map[string]struct{}{
"print": {},
},
Timeout: 10 * time.Second,
Concurrency: 5,
WindowSize: 24 * time.Hour,
},
LockConfig: LockConfig{
LockFailedAttemptsCount: 3,
LockPeriod: time.Minute,
},
Timeout: 10 * time.Second,
Concurrency: 5,
WindowSize: 24 * time.Hour,
},
LockConfig: LockConfig{
LockFailedAttemptsCount: 3,
LockPeriod: time.Minute,
},
},
{
name: "debug enabled",
args: []string{"start", "--config", "testdata/config-debug.toml"},
want: CLI{
Debug: true,
Start: StartCmdConfig{
FluentdConfig: FluentdConfig{
FluentdURL: "https://localhost:8888/test.log",
FluentdSessionURL: "https://localhost:8888/session",
FluentdCert: path.Join(wd, "testdata", "fake-file"),
FluentdKey: path.Join(wd, "testdata", "fake-file"),
FluentdCA: path.Join(wd, "testdata", "fake-file"),
},
TeleportConfig: TeleportConfig{
TeleportAddr: "localhost:3025",
TeleportIdentityFile: path.Join(wd, "testdata", "fake-file"),
TeleportRefreshEnabled: true,
TeleportRefreshInterval: 2 * time.Minute,
},
IngestConfig: IngestConfig{
StorageDir: "./storage",
BatchSize: 20,
SkipEventTypes: map[string]struct{}{},
SkipSessionTypesRaw: []string{"print"},
SkipSessionTypes: map[string]struct{}{
"print": {},
},
Timeout: 10 * time.Second,
Concurrency: 5,
WindowSize: 24 * time.Hour,
},
LockConfig: LockConfig{
LockFailedAttemptsCount: 3,
LockPeriod: time.Minute,
},
},
},
},
Expand All @@ -88,8 +167,10 @@ func TestStartCmdConfig(t *testing.T) {
require.NoError(t, err)
_, err = parser.Parse(tc.args)
require.NoError(t, err)

require.Equal(t, tc.want, cli.Start)
// reset config file and configure values since we only want to verify Start and Debug fields
cli.Config = ""
cli.Configure = ConfigureCmdConfig{}
require.Equal(t, tc.want, cli)
})
}
}
16 changes: 11 additions & 5 deletions integrations/event-handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,7 @@ func main() {
)

if cli.Debug {
err := logger.Setup(logger.Config{Severity: "debug", Output: "stderr"})
if err != nil {
fmt.Println(trace.DebugReport(err))
os.Exit(-1)
}
enableLogDebug()
}

switch {
Expand All @@ -83,8 +79,18 @@ func main() {
}
}

// turn on log debugging
func enableLogDebug() {
err := logger.Setup(logger.Config{Severity: "debug", Output: "stderr"})
if err != nil {
fmt.Println(trace.DebugReport(err))
os.Exit(-1)
}
}

// start spawns the main process
func start() error {

stevenGravy marked this conversation as resolved.
Show resolved Hide resolved
app, err := NewApp(&cli.Start)
if err != nil {
return trace.Wrap(err)
Expand Down
17 changes: 17 additions & 0 deletions integrations/event-handler/testdata/config-debug.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
storage = "./storage" # Plugin will save its state here
timeout = "10s"
batch = 20
debug = true

[forward.fluentd]
cert = "testdata/fake-file"
key = "testdata/fake-file"
ca = "testdata/fake-file"
url = "https://localhost:8888/test.log"
session-url = "https://localhost:8888/session"

[teleport]
addr = "localhost:3025"
identity = "testdata/fake-file"
refresh.enabled = true
refresh.interval = "2m"
stevenGravy marked this conversation as resolved.
Show resolved Hide resolved
Loading