Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
12 changes: 5 additions & 7 deletions internal/cmd/flags_logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ package cmd
// Logging-related flags

import (
"github.com/github/gh-aw-mcpg/internal/config"
"github.com/github/gh-aw-mcpg/internal/envutil"
"github.com/spf13/cobra"
)

// Logging flag defaults
const (
defaultLogDir = "/tmp/gh-aw/mcp-logs"
defaultPayloadDir = "/tmp/jq-payloads"
defaultPayloadPathPrefix = "" // Empty by default - use actual filesystem path
defaultPayloadSizeThreshold = 524288 // 512KB default threshold
defaultPayloadPathPrefix = "" // Empty by default - use actual filesystem path
)

// Logging flag variables
Expand All @@ -35,13 +33,13 @@ func init() {
// getDefaultLogDir returns the default log directory, checking MCP_GATEWAY_LOG_DIR
// environment variable first, then falling back to the hardcoded default
func getDefaultLogDir() string {
return envutil.GetEnvString("MCP_GATEWAY_LOG_DIR", defaultLogDir)
return envutil.GetEnvString("MCP_GATEWAY_LOG_DIR", config.DefaultLogDir)
}

// getDefaultPayloadDir returns the default payload directory, checking MCP_GATEWAY_PAYLOAD_DIR
// environment variable first, then falling back to the hardcoded default
func getDefaultPayloadDir() string {
return envutil.GetEnvString("MCP_GATEWAY_PAYLOAD_DIR", defaultPayloadDir)
return envutil.GetEnvString("MCP_GATEWAY_PAYLOAD_DIR", config.DefaultPayloadDir)
}

// getDefaultPayloadPathPrefix returns the default payload path prefix, checking MCP_GATEWAY_PAYLOAD_PATH_PREFIX
Expand All @@ -53,5 +51,5 @@ func getDefaultPayloadPathPrefix() string {
// getDefaultPayloadSizeThreshold returns the default payload size threshold, checking
// MCP_GATEWAY_PAYLOAD_SIZE_THRESHOLD environment variable first, then falling back to the hardcoded default
func getDefaultPayloadSizeThreshold() int {
return envutil.GetEnvInt("MCP_GATEWAY_PAYLOAD_SIZE_THRESHOLD", defaultPayloadSizeThreshold)
return envutil.GetEnvInt("MCP_GATEWAY_PAYLOAD_SIZE_THRESHOLD", config.DefaultPayloadSizeThreshold)
}
17 changes: 9 additions & 8 deletions internal/cmd/flags_logging_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"testing"

"github.com/github/gh-aw-mcpg/internal/config"
"github.com/stretchr/testify/assert"
)

Expand All @@ -16,7 +17,7 @@ func TestGetDefaultLogDir(t *testing.T) {
{
name: "no env var - returns default",
setEnv: false,
expected: defaultLogDir,
expected: config.DefaultLogDir,
},
{
name: "env var set - returns custom path",
Expand All @@ -28,7 +29,7 @@ func TestGetDefaultLogDir(t *testing.T) {
name: "empty env var - returns default",
envValue: "",
setEnv: true,
expected: defaultLogDir,
expected: config.DefaultLogDir,
},
}

Expand Down Expand Up @@ -56,7 +57,7 @@ func TestGetDefaultPayloadDir(t *testing.T) {
{
name: "no env var - returns default",
setEnv: false,
expected: defaultPayloadDir,
expected: config.DefaultPayloadDir,
},
{
name: "env var set - returns custom path",
Expand All @@ -68,7 +69,7 @@ func TestGetDefaultPayloadDir(t *testing.T) {
name: "empty env var - returns default",
envValue: "",
setEnv: true,
expected: defaultPayloadDir,
expected: config.DefaultPayloadDir,
},
}

Expand Down Expand Up @@ -96,7 +97,7 @@ func TestGetDefaultPayloadSizeThreshold(t *testing.T) {
{
name: "no env var - returns default",
setEnv: false,
expected: defaultPayloadSizeThreshold,
expected: config.DefaultPayloadSizeThreshold,
},
{
name: "valid env var",
Expand All @@ -120,19 +121,19 @@ func TestGetDefaultPayloadSizeThreshold(t *testing.T) {
name: "invalid value - non-numeric",
envValue: "invalid",
setEnv: true,
expected: defaultPayloadSizeThreshold,
expected: config.DefaultPayloadSizeThreshold,
},
{
name: "invalid value - negative",
envValue: "-100",
setEnv: true,
expected: defaultPayloadSizeThreshold,
expected: config.DefaultPayloadSizeThreshold,
},
{
name: "invalid value - zero",
envValue: "0",
setEnv: true,
expected: defaultPayloadSizeThreshold,
expected: config.DefaultPayloadSizeThreshold,
},
}

Expand Down
4 changes: 2 additions & 2 deletions internal/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ func run(cmd *cobra.Command, args []string) error {
// Apply payload directory flag (if different from default, it was explicitly set)
if cmd.Flags().Changed("payload-dir") {
cfg.Gateway.PayloadDir = payloadDir
} else if payloadDir != "" && payloadDir != defaultPayloadDir {
} else if payloadDir != "" && payloadDir != config.DefaultPayloadDir {
// Environment variable was set
cfg.Gateway.PayloadDir = payloadDir
}
Expand All @@ -236,7 +236,7 @@ func run(cmd *cobra.Command, args []string) error {
// Apply payload size threshold flag (if different from default, it was explicitly set)
if cmd.Flags().Changed("payload-size-threshold") {
cfg.Gateway.PayloadSizeThreshold = payloadSizeThreshold
} else if payloadSizeThreshold != defaultPayloadSizeThreshold {
} else if payloadSizeThreshold != config.DefaultPayloadSizeThreshold {
// Environment variable was set
cfg.Gateway.PayloadSizeThreshold = payloadSizeThreshold
}
Expand Down
6 changes: 6 additions & 0 deletions internal/config/config_logging.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Package config provides configuration loading and parsing.
// This file defines logging-related configuration and defaults.
package config

// DefaultLogDir is the default directory for storing log files.
const DefaultLogDir = "/tmp/gh-aw/mcp-logs"
2 changes: 1 addition & 1 deletion internal/config/validation_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func ValidateContainerizedEnvironment(containerID string) *EnvValidationResult {
// Check if log directory is mounted (warning only)
logDir := os.Getenv("MCP_GATEWAY_LOG_DIR")
if logDir == "" {
logDir = "/tmp/gh-aw/mcp-logs"
logDir = DefaultLogDir
}
result.LogDirMounted = checkLogDirMounted(containerID, logDir)
logEnv.Printf("Log directory mount check: mounted=%v, logDir=%s", result.LogDirMounted, logDir)
Expand Down
Loading