Skip to content

Commit

Permalink
feat: add log format annotation and helm value
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/helm value is still
necessary.

This PR adds the annotation and helm value to configure log format.

Closes #2491

Signed-off-by: Naseem <naseem@transit.app>
  • Loading branch information
Naseem committed Jun 27, 2020
1 parent aea541d commit aa85bd3
Show file tree
Hide file tree
Showing 87 changed files with 4,515 additions and 5,951 deletions.
1 change: 1 addition & 0 deletions Dockerfile-proxy
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ COPY proxy-identity/run-proxy.sh /usr/bin/linkerd2-proxy-run
ARG LINKERD_VERSION
ENV LINKERD_CONTAINER_VERSION_OVERRIDE=${LINKERD_VERSION}
ENV LINKERD2_PROXY_LOG=warn,linkerd=info
ENV LINKERD2_PROXY_LOG_FORMAT=plain
ENTRYPOINT ["/usr/bin/linkerd2-proxy-run"]
1 change: 1 addition & 0 deletions charts/linkerd2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ their default values.
| `global.proxy.image.pullPolicy` | Pull policy for the proxy container Docker image | `IfNotPresent` |
| `global.proxy.image.version` | Tag for the proxy container Docker image | latest version |
| `global.proxy.logLevel` | Log level for the proxy | `warn,linkerd=info` |
| `global.proxy.logFormat` | Log format (`plain` or `json`) for the proxy | `plain` |
| `global.proxy.ports.admin` | Admin port for the proxy container | `4191` |
| `global.proxy.ports.control` | Control port for the proxy container | `4190` |
| `global.proxy.ports.inbound` | Inbound port for the proxy container | `4143` |
Expand Down
1 change: 1 addition & 0 deletions charts/linkerd2/templates/_config.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"logLevel":{
"level": "{{.Values.global.proxy.logLevel}}"
},
"logFormat": "{{.Values.global.proxy.logFormat}}",
"disableExternalProfiles": {{not .Values.global.proxy.enableExternalProfiles}},
"proxyVersion": "{{.Values.global.proxy.image.version}}",
"proxyInitImageVersion": "{{.Values.global.proxyInit.image.version}}",
Expand Down
1 change: 1 addition & 0 deletions charts/linkerd2/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ global:
pullPolicy: *image_pull_policy
version: *linkerd_version
logLevel: warn,linkerd=info
logFormat: plain
ports:
admin: 4191
control: 4190
Expand Down
8 changes: 5 additions & 3 deletions charts/partials/templates/_proxy.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@ env:
{{ if .Values.global.proxy.requireIdentityOnInboundPorts -}}
- name: LINKERD2_PROXY_INBOUND_PORTS_REQUIRE_IDENTITY
value: "{{.Values.global.proxy.requireIdentityOnInboundPorts}}"
{{ end -}}
{{ end -}}
- name: LINKERD2_PROXY_LOG
value: {{.Values.global.proxy.logLevel}}
- name: LINKERD2_PROXY_LOG_FORMAT
value: {{.Values.global.proxy.logFormat | default "plain"}}
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: {{ternary "localhost.:8086" (printf "linkerd-dst.%s.svc.%s:8086" .Values.global.namespace .Values.global.clusterDomain) (eq .Values.global.proxy.component "linkerd-destination")}}
{{ if .Values.global.proxy.destinationGetNetworks -}}
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
value: "{{.Values.global.proxy.destinationGetNetworks}}"
{{ end -}}
{{ end -}}
- name: LINKERD2_PROXY_CONTROL_LISTEN_ADDR
value: 0.0.0.0:{{.Values.global.proxy.ports.control}}
- name: LINKERD2_PROXY_ADMIN_LISTEN_ADDR
Expand All @@ -23,7 +25,7 @@ env:
{{ if .Values.global.proxy.isGateway -}}
- name: LINKERD2_PROXY_INBOUND_GATEWAY_SUFFIXES
value: {{printf "svc.%s." .Values.global.clusterDomain}}
{{ end -}}
{{ end -}}
- name: LINKERD2_PROXY_DESTINATION_GET_SUFFIXES
value: {{printf "svc.%s." .Values.global.clusterDomain}}
- name: LINKERD2_PROXY_DESTINATION_PROFILE_SUFFIXES
Expand Down
4 changes: 4 additions & 0 deletions cli/cmd/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,10 @@ func generateAnnotationsDocs() []annotationDoc {
Name: k8s.ProxyLogLevelAnnotation,
Description: "Log level for the proxy",
},
{
Name: k8s.ProxyLogFormatAnnotation,
Description: "Log format (plain or json) for the proxy",
},
{
Name: k8s.ProxyEnableExternalProfilesAnnotation,
Description: "Enable service profiles for non-Kubernetes services",
Expand Down
5 changes: 5 additions & 0 deletions cli/cmd/inject.go
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,11 @@ func (options *proxyConfigOptions) overrideConfigs(configs *cfg.All, overrideAnn
overrideAnnotations[k8s.ProxyLogLevelAnnotation] = options.proxyLogLevel
}

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

if options.disableIdentity {
configs.Global.IdentityContext = nil
overrideAnnotations[k8s.ProxyDisableIdentityAnnotation] = strconv.FormatBool(true)
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/inject_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,7 @@ func TestOverrideConfigsParameterized(t *testing.T) {
proxyOutboundPort: 4140,
proxyUID: 999,
proxyLogLevel: "debug",
proxyLogFormat: "plain",
disableIdentity: true,
disableTap: true,
enableExternalProfiles: true,
Expand All @@ -642,6 +643,7 @@ func TestOverrideConfigsParameterized(t *testing.T) {
k8s.ProxyOutboundPortAnnotation: "4140",
k8s.ProxyUIDAnnotation: "999",
k8s.ProxyLogLevelAnnotation: "debug",
k8s.ProxyLogFormatAnnotation: "plain",
k8s.ProxyDisableIdentityAnnotation: "true",
k8s.ProxyDisableTapAnnotation: "true",
k8s.ProxyEnableExternalProfilesAnnotation: "true",
Expand Down
5 changes: 4 additions & 1 deletion cli/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ func newInstallOptionsWithDefaults() (*installOptions, error) {
ignoreOutboundPorts: nil,
proxyUID: defaults.Global.Proxy.UID,
proxyLogLevel: defaults.Global.Proxy.LogLevel,
proxyLogFormat: defaults.Global.Proxy.LogFormat,
proxyControlPort: uint(defaults.Global.Proxy.Ports.Control),
proxyAdminPort: uint(defaults.Global.Proxy.Ports.Admin),
proxyInboundPort: uint(defaults.Global.Proxy.Ports.Inbound),
Expand Down Expand Up @@ -786,7 +787,8 @@ func (options *installOptions) buildValuesWithoutIdentity(configs *pb.All) (*l5d
PullPolicy: options.imagePullPolicy,
Version: options.proxyVersion,
},
LogLevel: options.proxyLogLevel,
LogLevel: options.proxyLogLevel,
LogFormat: options.proxyLogFormat,
Ports: &l5dcharts.Ports{
Admin: int32(options.proxyAdminPort),
Control: int32(options.proxyControlPort),
Expand Down Expand Up @@ -985,6 +987,7 @@ func (options *installOptions) proxyConfig() *pb.Proxy {
LogLevel: &pb.LogLevel{
Level: options.proxyLogLevel,
},
LogFormat: options.proxyLogFormat,
DestinationGetNetworks: strings.Join(options.destinationGetNetworks, ","),
DisableExternalProfiles: !options.enableExternalProfiles,
ProxyVersion: options.proxyVersion,
Expand Down
3 changes: 2 additions & 1 deletion cli/cmd/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ func TestRender(t *testing.T) {
PullPolicy: "ImagePullPolicy",
Version: "ProxyVersion",
},
LogLevel: "warn,linkerd=info",
LogLevel: "warn,linkerd=info",
LogFormat: "plain",
Ports: &charts.Ports{
Admin: 4191,
Control: 4190,
Expand Down
1 change: 1 addition & 0 deletions cli/cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ type proxyConfigOptions struct {
ignoreOutboundPorts []string
proxyUID int64
proxyLogLevel string
proxyLogFormat string
proxyInboundPort uint
proxyOutboundPort uint
proxyControlPort uint
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/testdata/inject-filepath/expected/injected_nginx.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down Expand Up @@ -178,6 +180,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/testdata/inject-filepath/expected/injected_redis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/testdata/inject_contour.golden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
8 changes: 8 additions & 0 deletions cli/cmd/testdata/inject_emojivoto_already_injected.golden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down Expand Up @@ -200,6 +202,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down Expand Up @@ -362,6 +366,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down Expand Up @@ -524,6 +530,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/testdata/inject_emojivoto_deployment.golden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down Expand Up @@ -200,6 +202,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/testdata/inject_emojivoto_deployment_debug.golden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/testdata/inject_emojivoto_deployment_trace.golden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
2 changes: 2 additions & 0 deletions cli/cmd/testdata/inject_emojivoto_deployment_udp.golden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ spec:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
4 changes: 4 additions & 0 deletions cli/cmd/testdata/inject_emojivoto_list.golden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ items:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down Expand Up @@ -196,6 +198,8 @@ items:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ items:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down Expand Up @@ -196,6 +198,8 @@ items:
- env:
- name: LINKERD2_PROXY_LOG
value: warn,linkerd=info
- name: LINKERD2_PROXY_LOG_FORMAT
value: plain
- name: LINKERD2_PROXY_DESTINATION_SVC_ADDR
value: linkerd-dst.linkerd.svc.cluster.local:8086
- name: LINKERD2_PROXY_DESTINATION_GET_NETWORKS
Expand Down
Loading

0 comments on commit aa85bd3

Please sign in to comment.