Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
wip: add log format annotation and cli flag
Browse files Browse the repository at this point in the history
Json log formatting has been added via linkerd/linkerd2-proxy#500
but wiring the option through as an annotation/CLI flag is still
necessary.

This PR adds the annotation and cli flag to configure log format.

Closes #2491

Signed-off-by: Naseem <naseem@transit.app>
Naseem committed Jun 17, 2020
1 parent bb01b94 commit 4434296
Showing 7 changed files with 144 additions and 72 deletions.
4 changes: 4 additions & 0 deletions cli/cmd/doc.go
Original file line number Diff line number Diff line change
@@ -191,6 +191,10 @@ func generateAnnotationsDocs() []annotationDoc {
Name: k8s.ProxyLogLevelAnnotation,
Description: "Log level for the proxy",
},
{
Name: k8s.ProxyLogFormatAnnotation,
Description: "Log format for the proxy",
},
{
Name: k8s.ProxyEnableExternalProfilesAnnotation,
Description: "Enable service profiles for non-Kubernetes services",
5 changes: 5 additions & 0 deletions cli/cmd/inject.go
Original file line number Diff line number Diff line change
@@ -428,6 +428,11 @@ func (options *proxyConfigOptions) overrideConfigs(configs *cfg.All, overrideAnn
overrideAnnotations[k8s.ProxyLogLevelAnnotation] = options.proxyLogLevel
}

if options.proxyLogFormat != "" {
configs.Proxy.LogFormat = &cfg.LogFormat{Format: options.proxyLogFormat}
overrideAnnotations[k8s.ProxyLogFormatAnnotation] = options.proxyLogFormat
}

if options.disableIdentity {
configs.Global.IdentityContext = nil
overrideAnnotations[k8s.ProxyDisableIdentityAnnotation] = strconv.FormatBool(true)
2 changes: 2 additions & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
@@ -230,6 +230,7 @@ type proxyConfigOptions struct {
ignoreOutboundPorts []string
proxyUID int64
proxyLogLevel string
proxyLogFormat string
proxyInboundPort uint
proxyOutboundPort uint
proxyControlPort uint
@@ -344,6 +345,7 @@ func (options *proxyConfigOptions) flagSet(e pflag.ErrorHandling) *pflag.FlagSet
flags.StringSliceVar(&options.ignoreOutboundPorts, "skip-outbound-ports", options.ignoreOutboundPorts, "Outbound ports and/or port ranges (inclusive) that should skip the proxy")
flags.Int64Var(&options.proxyUID, "proxy-uid", options.proxyUID, "Run the proxy under this user ID")
flags.StringVar(&options.proxyLogLevel, "proxy-log-level", options.proxyLogLevel, "Log level for the proxy")
flags.StringVar(&options.proxyLogFormat, "proxy-log-format", options.proxyLogFormat, "Log format for the proxy")
flags.UintVar(&options.proxyControlPort, "control-port", options.proxyControlPort, "Proxy port to use for control")
flags.UintVar(&options.proxyAdminPort, "admin-port", options.proxyAdminPort, "Proxy port to serve metrics on")
flags.StringVar(&options.proxyCPURequest, "proxy-cpu-request", options.proxyCPURequest, "Amount of CPU units that the proxy sidecar requests")
190 changes: 120 additions & 70 deletions controller/gen/config/config.pb.go

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions controller/gen/public/public.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pkg/k8s/labels.go
Original file line number Diff line number Diff line change
@@ -184,6 +184,9 @@ const (
// ProxyLogLevelAnnotation can be used to override the log level config.
ProxyLogLevelAnnotation = ProxyConfigAnnotationsPrefix + "/proxy-log-level"

// ProxyLogFormatAnnotation can be used to override the log format config.
ProxyLogFormatAnnotation = ProxyConfigAnnotationsPrefix + "/proxy-log-format"

// ProxyEnableExternalProfilesAnnotation can be used to override the
// disableExternalProfilesAnnotation config.
ProxyEnableExternalProfilesAnnotation = ProxyConfigAnnotationsPrefix + "/enable-external-profiles"
6 changes: 6 additions & 0 deletions proto/config/config.proto
Original file line number Diff line number Diff line change
@@ -53,6 +53,8 @@ message Proxy {

Image debug_image = 15;
string debug_image_version = 16;

LogFormat log_format = 17;
}

message Image {
@@ -90,6 +92,10 @@ message LogLevel {
string level = 1;
}

message LogFormat{
string format = 1;
}

// Stores information about the last installation/upgrade.
//
// Useful for driving upgrades.

0 comments on commit 4434296

Please sign in to comment.