-
Notifications
You must be signed in to change notification settings - Fork 690
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
internal/envoy: configurable access log format #3694
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,8 +5,8 @@ go 1.15 | |
require ( | ||
github.com/ahmetb/gen-crd-api-reference-docs v0.3.0 | ||
github.com/bombsimon/logrusr v1.0.0 | ||
github.com/davecgh/go-spew v1.1.1 // indirect | ||
github.com/envoyproxy/go-control-plane v0.9.9-0.20210111201334-f1f47757da33 | ||
github.com/davecgh/go-spew v1.1.1 | ||
github.com/envoyproxy/go-control-plane v0.9.10-0.20210614203518-782de910ff04 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. need to decide if we're comfortable shipping with this commit, or if we want to wait for an official v0.9.10. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've done this in the past as well, but not sure how quickly go-control-plane is releasing. Could even pull this out as a separate commit to verify tests, etc. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think as long as tests are passing (which they are currently), I'm OK with shipping with a specific commit here. |
||
github.com/go-logr/logr v0.4.0 | ||
github.com/golang/protobuf v1.5.2 | ||
github.com/google/go-cmp v0.5.5 | ||
|
@@ -21,7 +21,7 @@ require ( | |
github.com/sirupsen/logrus v1.7.0 | ||
github.com/stretchr/testify v1.7.0 | ||
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a | ||
google.golang.org/grpc v1.27.1 | ||
google.golang.org/grpc v1.36.0 | ||
google.golang.org/protobuf v1.26.0 | ||
gopkg.in/alecthomas/kingpin.v2 v2.2.6 | ||
gopkg.in/yaml.v2 v2.4.0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,29 +17,47 @@ import ( | |
envoy_accesslog_v3 "github.com/envoyproxy/go-control-plane/envoy/config/accesslog/v3" | ||
envoy_config_core_v3 "github.com/envoyproxy/go-control-plane/envoy/config/core/v3" | ||
envoy_file_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/access_loggers/file/v3" | ||
envoy_req_without_query_v3 "github.com/envoyproxy/go-control-plane/envoy/extensions/formatter/req_without_query/v3" | ||
"github.com/envoyproxy/go-control-plane/pkg/wellknown" | ||
_struct "github.com/golang/protobuf/ptypes/struct" | ||
"github.com/projectcontour/contour/internal/protobuf" | ||
"github.com/projectcontour/contour/pkg/config" | ||
) | ||
|
||
// FileAccessLogEnvoy returns a new file based access log filter | ||
// that will output Envoy's default access logs. | ||
func FileAccessLogEnvoy(path string) []*envoy_accesslog_v3.AccessLog { | ||
func FileAccessLogEnvoy(path string, format string, extensions []string) []*envoy_accesslog_v3.AccessLog { | ||
// Nil by default to defer to Envoy's default log format. | ||
var logFormat *envoy_file_v3.FileAccessLog_LogFormat | ||
|
||
if format != "" { | ||
logFormat = &envoy_file_v3.FileAccessLog_LogFormat{ | ||
LogFormat: &envoy_config_core_v3.SubstitutionFormatString{ | ||
Format: &envoy_config_core_v3.SubstitutionFormatString_TextFormatSource{ | ||
TextFormatSource: &envoy_config_core_v3.DataSource{ | ||
Specifier: &envoy_config_core_v3.DataSource_InlineString{ | ||
InlineString: format, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will Envoy blow up if the format is invalid? Or just not log properly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I see there's a parser below. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, the same parser is now used for both JSON and text based logs. If for some reason invalid format would still get through parser, I've tested how Envoy would react, for results see #3576 (comment). There is also one very common error that could be validated: there needs to be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oof, yeah, that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think I'm a 👍 to enforcing/adding the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've now added check for |
||
}, | ||
}, | ||
}, | ||
Formatters: extensionConfig(extensions), | ||
}, | ||
} | ||
} | ||
|
||
return []*envoy_accesslog_v3.AccessLog{{ | ||
Name: wellknown.FileAccessLog, | ||
ConfigType: &envoy_accesslog_v3.AccessLog_TypedConfig{ | ||
TypedConfig: protobuf.MustMarshalAny(&envoy_file_v3.FileAccessLog{ | ||
Path: path, | ||
// AccessLogFormat left blank to defer to Envoy's default log format. | ||
Path: path, | ||
AccessLogFormat: logFormat, | ||
}), | ||
}, | ||
}} | ||
} | ||
|
||
// FileAccessLogJSON returns a new file based access log filter | ||
// that will log in JSON format | ||
func FileAccessLogJSON(path string, fields config.AccessLogFields) []*envoy_accesslog_v3.AccessLog { | ||
func FileAccessLogJSON(path string, fields config.AccessLogFields, extensions []string) []*envoy_accesslog_v3.AccessLog { | ||
|
||
jsonformat := &_struct.Struct{ | ||
Fields: make(map[string]*_struct.Value), | ||
|
@@ -59,6 +77,7 @@ func FileAccessLogJSON(path string, fields config.AccessLogFields) []*envoy_acce | |
Format: &envoy_config_core_v3.SubstitutionFormatString_JsonFormat{ | ||
JsonFormat: jsonformat, | ||
}, | ||
Formatters: extensionConfig(extensions), | ||
}, | ||
}, | ||
}), | ||
|
@@ -73,3 +92,23 @@ func sv(s string) *_struct.Value { | |
}, | ||
} | ||
} | ||
|
||
// extensionConfig returns a list of extension configs required by the access log format. | ||
// | ||
// Note: When adding support for new formatter, update the list of extensions here and | ||
// add the corresponding extension in pkg/config/parameters.go AccessLogFormatterExtensions(). | ||
// Currently only one extension exist in Envoy. | ||
func extensionConfig(extensions []string) []*envoy_config_core_v3.TypedExtensionConfig { | ||
var config []*envoy_config_core_v3.TypedExtensionConfig | ||
|
||
for _, e := range extensions { | ||
if e == "envoy.formatter.req_without_query" { | ||
tsaarni marked this conversation as resolved.
Show resolved
Hide resolved
|
||
config = append(config, &envoy_config_core_v3.TypedExtensionConfig{ | ||
Name: "envoy.formatter.req_without_query", | ||
TypedConfig: protobuf.MustMarshalAny(&envoy_req_without_query_v3.ReqWithoutQuery{ /* empty */ }), | ||
}) | ||
} | ||
} | ||
|
||
return config | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might need to be docs on the site. I worry we're getting too many comments in the config file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've shortened the text by removing the link to Envoy docs and the full example (still leaving short example value
accesslog-format-string: "...\n"
)The config file is bit hard to read in general. Maybe one small improvement would be changing indentation of fields-vs-comments, see e.g. sshd_config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
d'oh, it obviously fails anyways to be readable due to structs having indentations :-D
maybe double-hash for comments:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this formatting is not great. I filed #3843 to make some improvements here.