Skip to content

Commit a1c0c3c

Browse files
authored
Switch to JSON formatted access logs (#44)
I'd like to emit access logs in JSON format so as to be able to improve their visibility in our OpenSearch index. In addition to this I made a number of changes: * I did a general update of direct dependencies (apologies for the vendor folder changes) * I removed references and flags related to legacy Kubernetes versions in our manifest/CRD generation * I've switched to using the latest version of `controller-gen` * I'm using docker buildx build with a platform flag specifying the architecture to be linux amd64 * I've extended some of the RBAC roles to align with changes in our internal "deployment" repo Example pod logs showing admin logs and cluster access logs (admin logs left as default - but we can move these to JSON to if we want): ![image](https://github.com/user-attachments/assets/eb7d431d-787b-454f-a66e-f78c0ae5b9f8) JSON access log (prettified): ```json { "response_code": 0, "upstream_cluster": "example-www_TCP_443", "bytes_received": 1294, "bytes_sent": 5999, "downstream_local_address": "10.129.191.27:443", "duration": 445, "upstream_host": "93.184.215.14:443", "downstream_remote_address": "10.129.187.50:48990", "response_flags": "-", "start_time": "2025-01-08T14:12:19.041Z", "upstream_local_address": "10.129.191.27:37028" } ```
1 parent ee0a5d2 commit a1c0c3c

File tree

3,717 files changed

+332876
-125905
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

3,717 files changed

+332876
-125905
lines changed

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
vendor/**/* linguist-generated=true

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang@sha256:d6df8b2e22c9c87fde828b18e0d0d5707bfe03034a49c0bde72ff5a1f5ebb5fe as builder
2+
FROM golang:1.23.4@sha256:7ea4c9dcb2b97ff8ee80a67db3d44f98c8ffa0d191399197007d8459c1453041 AS builder
33

44
WORKDIR /workspace
55
# Copy the Go Modules manifests

Makefile

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Image URL to use all building/pushing image targets
22
IMG ?= ${ACC}.dkr.ecr.eu-west-1.amazonaws.com/monzo/egress-operator:manager-$(shell git rev-parse --short head)
3-
# Produce CRDs that work back to Kubernetes 1.11 (no version conversion)
4-
CRD_OPTIONS ?= "crd:trivialVersions=true"
53

64
# Get the currently used golang install path (in GOPATH/bin, unless GOBIN is set)
75
ifeq (,$(shell go env GOBIN))
@@ -39,7 +37,7 @@ deploy: manifests
3937

4038
# Generate manifests e.g. CRD, RBAC etc.
4139
manifests: controller-gen
42-
$(CONTROLLER_GEN) $(CRD_OPTIONS) rbac:roleName=manager-role webhook paths="./..." output:crd:artifacts:config=config/crd/bases
40+
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/crd/bases
4341

4442
# Run go fmt against code
4543
fmt:
@@ -55,7 +53,7 @@ generate: controller-gen
5553

5654
# Build the docker image
5755
docker-build: test
58-
docker build . -t ${IMG}
56+
docker buildx build . -t ${IMG} --platform=linux/amd64
5957

6058
# Push the docker image
6159
docker-push:
@@ -66,14 +64,11 @@ docker-push:
6664
controller-gen:
6765
ifeq (, $(shell which controller-gen))
6866
@{ \
69-
set -e ;\
70-
CONTROLLER_GEN_TMP_DIR=$$(mktemp -d) ;\
71-
cd $$CONTROLLER_GEN_TMP_DIR ;\
72-
go mod init tmp ;\
73-
go get sigs.k8s.io/controller-tools/cmd/[email protected] ;\
74-
rm -rf $$CONTROLLER_GEN_TMP_DIR ;\
67+
set -ex ;\
68+
mkdir -p bin ;\
69+
GOBIN=$$(pwd)/bin go install sigs.k8s.io/controller-tools/cmd/[email protected] ;\
7570
}
76-
CONTROLLER_GEN=$(GOBIN)/controller-gen
71+
CONTROLLER_GEN=./bin/controller-gen
7772
else
7873
CONTROLLER_GEN=$(shell which controller-gen)
7974
endif

api/v1/externalservice_types.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,16 @@ type ExternalServiceSpec struct {
7979
// Provides a way to override the global default
8080
// +optional
8181
ServiceTopologyMode string `json:"serviceTopologyMode,omitempty"`
82+
83+
// Output admin logs in JSON format as opposed to a text string.
84+
// Defaults to false
85+
// +optional
86+
JsonAdminAccessLogs bool `json:"envoyJsonAdminAccessLogs,omitempty"`
87+
88+
// Output access logs in JSON format as opposed to a text string.
89+
// Defaults to false
90+
// +optional
91+
JsonClusterAccessLogs bool `json:"envoyJsonClusterAccessLogs,omitempty"`
8292
}
8393

8494
type ExternalServicePort struct {

api/v1/zz_generated.deepcopy.go

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/egress.monzo.com_externalservices.yaml

Lines changed: 59 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
21
---
32
apiVersion: apiextensions.k8s.io/v1
43
kind: CustomResourceDefinition
54
metadata:
65
annotations:
7-
controller-gen.kubebuilder.io/version: v0.4.0
8-
creationTimestamp: null
6+
controller-gen.kubebuilder.io/version: v0.17.0
97
name: externalservices.egress.monzo.com
108
spec:
119
group: egress.monzo.com
@@ -22,14 +20,19 @@ spec:
2220
description: ExternalService is the Schema for the externalservices API
2321
properties:
2422
apiVersion:
25-
description: 'APIVersion defines the versioned schema of this representation
26-
of an object. Servers should convert recognized schemas to the latest
27-
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
23+
description: |-
24+
APIVersion defines the versioned schema of this representation of an object.
25+
Servers should convert recognized schemas to the latest internal value, and
26+
may reject unrecognized values.
27+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
2828
type: string
2929
kind:
30-
description: 'Kind is a string value representing the REST resource this
31-
object represents. Servers may infer this from the endpoint the client
32-
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
30+
description: |-
31+
Kind is a string value representing the REST resource this object represents.
32+
Servers may infer this from the endpoint the client submits requests to.
33+
Cannot be updated.
34+
In CamelCase.
35+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
3336
type: string
3437
metadata:
3538
type: object
@@ -40,29 +43,38 @@ spec:
4043
description: DnsName is a DNS name target for the external service
4144
type: string
4245
envoyClusterMaxConnections:
43-
description: The maximum number of connections that Envoy will establish
44-
to all hosts in an upstream cluster (defaults to 1024). If this
45-
circuit breaker overflows the upstream_cx_overflow counter for the
46-
cluster will increment.
46+
description: |-
47+
The maximum number of connections that Envoy will establish to all hosts in an upstream cluster (defaults to 1024).
48+
If this circuit breaker overflows the upstream_cx_overflow counter for the cluster will increment.
4749
format: int32
4850
type: integer
4951
envoyDnsRefreshRateS:
5052
description: "Corresponds to Envoy's dns_refresh_rate config field
51-
for this cluster, in seconds See\thttps://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/cluster.proto"
53+
for this cluster, in seconds\nSee\thttps://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/cluster.proto"
5254
format: int64
5355
type: integer
56+
envoyJsonAdminAccessLogs:
57+
description: |-
58+
Output admin logs in JSON format as opposed to a text string.
59+
Defaults to false
60+
type: boolean
61+
envoyJsonClusterAccessLogs:
62+
description: |-
63+
Output access logs in JSON format as opposed to a text string.
64+
Defaults to false
65+
type: boolean
5466
envoyLogLevel:
5567
description: Input to the --log-level command line option. See the
5668
help text for the available log levels and the default.
5769
type: string
5870
envoyRespectDnsTTL:
5971
description: "Corresponds to Envoy's respect_dns_ttl config field
60-
for this cluster. See\thttps://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/cluster.proto"
72+
for this cluster.\nSee\thttps://www.envoyproxy.io/docs/envoy/latest/api-v3/config/cluster/v3/cluster.proto"
6173
type: boolean
6274
hijackDns:
63-
description: 'If true, add a `egress.monzo.com/hijack-dns: true` label
64-
to produced Service objects CoreDNS can watch this label and decide
65-
to rewrite DnsName -> clusterIP'
75+
description: |-
76+
If true, add a `egress.monzo.com/hijack-dns: true` label to produced Service objects
77+
CoreDNS can watch this label and decide to rewrite DnsName -> clusterIP
6678
type: boolean
6779
ipOverride:
6880
description: When set allows overwriting the A records of the DNS
@@ -90,8 +102,9 @@ spec:
90102
format: int32
91103
type: integer
92104
protocol:
93-
description: The protocol (TCP or UDP) which traffic must match.
94-
If not specified, this field defaults to TCP.
105+
description: |-
106+
The protocol (TCP or UDP) which traffic must match. If not specified, this
107+
field defaults to TCP.
95108
type: string
96109
type: object
97110
type: array
@@ -100,18 +113,28 @@ spec:
100113
for gateway pods. Defaults to 100m, 50Mi, 2, 1Gi
101114
properties:
102115
claims:
103-
description: "Claims lists the names of resources, defined in
104-
spec.resourceClaims, that are used by this container. \n This
105-
is an alpha field and requires enabling the DynamicResourceAllocation
106-
feature gate. \n This field is immutable. It can only be set
107-
for containers."
116+
description: |-
117+
Claims lists the names of resources, defined in spec.resourceClaims,
118+
that are used by this container.
119+
120+
This is an alpha field and requires enabling the
121+
DynamicResourceAllocation feature gate.
122+
123+
This field is immutable. It can only be set for containers.
108124
items:
109125
description: ResourceClaim references one entry in PodSpec.ResourceClaims.
110126
properties:
111127
name:
112-
description: Name must match the name of one entry in pod.spec.resourceClaims
113-
of the Pod where this field is used. It makes that resource
114-
available inside a container.
128+
description: |-
129+
Name must match the name of one entry in pod.spec.resourceClaims of
130+
the Pod where this field is used. It makes that resource available
131+
inside a container.
132+
type: string
133+
request:
134+
description: |-
135+
Request is the name chosen for a request in the referenced claim.
136+
If empty, everything from the claim is made available, otherwise
137+
only the result of this request.
115138
type: string
116139
required:
117140
- name
@@ -127,8 +150,9 @@ spec:
127150
- type: string
128151
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
129152
x-kubernetes-int-or-string: true
130-
description: 'Limits describes the maximum amount of compute resources
131-
allowed. More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
153+
description: |-
154+
Limits describes the maximum amount of compute resources allowed.
155+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
132156
type: object
133157
requests:
134158
additionalProperties:
@@ -137,11 +161,11 @@ spec:
137161
- type: string
138162
pattern: ^(\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))(([KMGTPE]i)|[numkMGTPE]|([eE](\+|-)?(([0-9]+(\.[0-9]*)?)|(\.[0-9]+))))?$
139163
x-kubernetes-int-or-string: true
140-
description: 'Requests describes the minimum amount of compute
141-
resources required. If Requests is omitted for a container,
142-
it defaults to Limits if that is explicitly specified, otherwise
143-
to an implementation-defined value. Requests cannot exceed Limits.
144-
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/'
164+
description: |-
165+
Requests describes the minimum amount of compute resources required.
166+
If Requests is omitted for a container, it defaults to Limits if that is explicitly specified,
167+
otherwise to an implementation-defined value. Requests cannot exceed Limits.
168+
More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
145169
type: object
146170
type: object
147171
serviceTopologyMode:
@@ -159,9 +183,3 @@ spec:
159183
type: object
160184
served: true
161185
storage: true
162-
status:
163-
acceptedNames:
164-
kind: ""
165-
plural: ""
166-
conditions: []
167-
storedVersions: []

config/rbac/kustomization.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,16 @@ resources:
99
- auth_proxy_service.yaml
1010
- auth_proxy_role.yaml
1111
- auth_proxy_role_binding.yaml
12+
patches:
13+
- target:
14+
group: rbac.authorization.k8s.io
15+
version: v1
16+
kind: ClusterRole
17+
name: manager-role
18+
path: patches/manager_clusterrole_additions.yaml
19+
- target:
20+
group: rbac.authorization.k8s.io
21+
version: v1
22+
kind: Role
23+
name: manager-role
24+
path: patches/manager_role_additions.yaml
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
- op: add
2+
path: /rules/0
3+
value:
4+
apiGroups:
5+
- coordination.k8s.io
6+
resources:
7+
- leases
8+
verbs:
9+
- create
10+
- delete
11+
- get
12+
- list
13+
- patch
14+
- update
15+
- watch
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
- op: add
2+
path: /rules/0
3+
value:
4+
apiGroups:
5+
- policy
6+
resources:
7+
- poddisruptionbudgets
8+
verbs:
9+
- create
10+
- get
11+
- list
12+
- patch
13+
- watch

config/rbac/role.yaml

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
21
---
32
apiVersion: rbac.authorization.k8s.io/v1
43
kind: ClusterRole
54
metadata:
6-
creationTimestamp: null
75
name: manager-role
86
rules:
97
- apiGroups:
@@ -26,49 +24,38 @@ rules:
2624
- get
2725
- patch
2826
- update
29-
3027
---
3128
apiVersion: rbac.authorization.k8s.io/v1
3229
kind: Role
3330
metadata:
34-
creationTimestamp: null
3531
name: manager-role
3632
namespace: egress-operator-system
3733
rules:
3834
- apiGroups:
39-
- apps
40-
resources:
41-
- deployments
42-
verbs:
43-
- create
44-
- get
45-
- list
46-
- patch
47-
- watch
48-
- apiGroups:
49-
- autoscaling
35+
- ""
5036
resources:
51-
- horizontalpodautoscalers
37+
- configmaps
38+
- services
5239
verbs:
5340
- create
5441
- get
5542
- list
5643
- patch
5744
- watch
5845
- apiGroups:
59-
- ""
46+
- apps
6047
resources:
61-
- configmaps
48+
- deployments
6249
verbs:
6350
- create
6451
- get
6552
- list
6653
- patch
6754
- watch
6855
- apiGroups:
69-
- ""
56+
- autoscaling
7057
resources:
71-
- services
58+
- horizontalpodautoscalers
7259
verbs:
7360
- create
7461
- get

0 commit comments

Comments
 (0)