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

BuildLogFormatUpstream was always using the default log-format #367

Merged
merged 1 commit into from
Mar 3, 2017
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
11 changes: 9 additions & 2 deletions controllers/nginx/pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ func NewDefault() Configuration {
KeepAlive: 75,
LargeClientHeaderBuffers: "4 8k",
LogFormatStream: logFormatStream,
LogFormatUpstream: BuildLogFormatUpstream(false),
LogFormatUpstream: BuildLogFormatUpstream(false, ""),
MaxWorkerConnections: 16384,
MapHashBucketSize: 64,
ProxyRealIPCIDR: defIPCIDR,
Expand Down Expand Up @@ -307,7 +307,14 @@ func NewDefault() Configuration {
}

// BuildLogFormatUpstream format the log_format upstream based on proxy_protocol
func BuildLogFormatUpstream(useProxyProtocol bool) string {
func BuildLogFormatUpstream(useProxyProtocol bool, curLogFormatUpstream string) string {

// test if log_format comes from configmap
if curLogFormatUpstream != "" &&
curLogFormatUpstream != fmt.Sprintf(logFormatUpstream, "$proxy_protocol_addr") &&
curLogFormatUpstream != fmt.Sprintf(logFormatUpstream, "$remote_addr") {
return curLogFormatUpstream
}

if useProxyProtocol {
return fmt.Sprintf(logFormatUpstream, "$proxy_protocol_addr")
Expand Down
9 changes: 6 additions & 3 deletions controllers/nginx/pkg/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,18 @@ func TestBuildLogFormatUpstream(t *testing.T) {

testCases := []struct {
useProxyProtocol bool // use proxy protocol
curLogFormat string
expected string
}{
{true, fmt.Sprintf(logFormatUpstream, "$proxy_protocol_addr")},
{false, fmt.Sprintf(logFormatUpstream, "$remote_addr")},
{true, "", fmt.Sprintf(logFormatUpstream, "$proxy_protocol_addr")},
{false, "", fmt.Sprintf(logFormatUpstream, "$remote_addr")},
{true, "my-log-format", "my-log-format"},
{false, "john-log-format", "john-log-format"},
}

for _, testCase := range testCases {

result := BuildLogFormatUpstream(testCase.useProxyProtocol)
result := BuildLogFormatUpstream(testCase.useProxyProtocol, testCase.curLogFormat)

if result != testCase.expected {
t.Errorf(" expected %v but return %v", testCase.expected, result)
Expand Down
2 changes: 1 addition & 1 deletion controllers/nginx/pkg/template/template.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ func buildLogFormatUpstream(input interface{}) string {
glog.Errorf("error an ingress.buildLogFormatUpstream type but %T was returned", input)
}

return nginxconfig.BuildLogFormatUpstream(config.UseProxyProtocol)
return nginxconfig.BuildLogFormatUpstream(config.UseProxyProtocol, config.LogFormatUpstream)

}

Expand Down