Skip to content

Commit

Permalink
feat: gRPC Access Log Service (ALS) logging sink
Browse files Browse the repository at this point in the history
Signed-off-by: David Alger <davidmalger@gmail.com>
  • Loading branch information
davidalger authored and zirain committed Jun 19, 2024
1 parent 88fc0bf commit 33bf73b
Show file tree
Hide file tree
Showing 20 changed files with 840 additions and 14 deletions.
44 changes: 44 additions & 0 deletions internal/gatewayapi/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,50 @@ func (t *Translator) processAccessLog(envoyproxy *egv1a1.EnvoyProxy, resources *
}
irAccessLog.JSON = append(irAccessLog.JSON, al)
}
case egv1a1.ProxyAccessLogSinkTypeALS:
if sink.ALS == nil {
continue
}

var logName string
if sink.ALS.LogName != nil {
logName = *sink.ALS.LogName
} else {
logName = fmt.Sprintf("%s/%s", envoyproxy.Namespace, envoyproxy.Name)
}

// TODO: how to get authority from the backendRefs?
ds, err := t.processBackendRefs(sink.ALS.BackendRefs, envoyproxy.Namespace, resources)
if err != nil {
return nil, err
}

al := &ir.ALSAccessLog{
LogName: logName,
Destination: ir.RouteDestination{
Name: fmt.Sprintf("accesslog-%d", idx), // TODO: rename this, so that we can share backend with tracing?
Settings: ds,
},
Type: sink.ALS.Type,
}

if al.Type == egv1a1.ALSEnvoyProxyAccessLogTypeHTTP {
http := &ir.ALSAccessLogHTTP{
RequestHeaders: sink.ALS.HTTP.RequestHeaders,
ResponseHeaders: sink.ALS.HTTP.ResponseHeaders,
ResponseTrailers: sink.ALS.HTTP.ResponseTrailers,
}
al.HTTP = http
}

switch accessLog.Format.Type {
case egv1a1.ProxyAccessLogFormatTypeJSON:
al.Attributes = accessLog.Format.JSON
case egv1a1.ProxyAccessLogFormatTypeText:
al.Text = accessLog.Format.Text
}

irAccessLog.ALS = append(irAccessLog.ALS, al)
case egv1a1.ProxyAccessLogSinkTypeOpenTelemetry:
if sink.OpenTelemetry == nil {
continue
Expand Down
132 changes: 132 additions & 0 deletions internal/gatewayapi/testdata/envoyproxy-accesslog-als-json.in.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
envoyproxy:
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
namespace: envoy-gateway-system
name: test
spec:
telemetry:
accessLog:
settings:
- format:
type: JSON
json:
attr1: val1
attr2: val2
sinks:
- type: ALS
als:
logName: accesslog
backendRefs:
- name: envoy-als
namespace: monitoring
port: 9000
http:
requestHeaders:
- x-client-ip-address
responseHeaders:
- cache-control
responseTrailers:
- expires
type: HTTP
- type: ALS
als:
backendRefs:
- name: envoy-als
namespace: monitoring
port: 9000
type: TCP
provider:
type: Kubernetes
kubernetes:
envoyService:
type: LoadBalancer
envoyDeployment:
replicas: 2
container:
env:
- name: env_a
value: env_a_value
- name: env_b
value: env_b_name
image: "envoyproxy/envoy:distroless-dev"
resources:
requests:
cpu: 100m
memory: 512Mi
securityContext:
runAsUser: 2000
allowPrivilegeEscalation: false
pod:
annotations:
key1: val1
key2: val2
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: cloud.google.com/gke-nodepool
operator: In
values:
- router-node
tolerations:
- effect: NoSchedule
key: node-type
operator: Exists
value: "router"
securityContext:
runAsUser: 1000
runAsGroup: 3000
fsGroup: 2000
fsGroupChangePolicy: "OnRootMismatch"
volumes:
- name: certs
secret:
secretName: envoy-cert
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
namespace: envoy-gateway
name: gateway-1
spec:
gatewayClassName: envoy-gateway-class
listeners:
- name: http
protocol: HTTP
port: 80
allowedRoutes:
namespaces:
from: Same
services:
- apiVersion: v1
kind: Service
metadata:
name: envoy-als
namespace: monitoring
spec:
type: ClusterIP
ports:
- name: grpc
port: 9000
protocol: TCP
targetPort: 9000
endpointSlices:
- apiVersion: discovery.k8s.io/v1
kind: EndpointSlice
metadata:
name: endpointslice-envoy-als
namespace: monitoring
labels:
kubernetes.io/service-name: envoy-als
addressType: IPv4
ports:
- name: grpc
protocol: TCP
port: 9090
endpoints:
- addresses:
- "10.240.0.10"
conditions:
ready: true
193 changes: 193 additions & 0 deletions internal/gatewayapi/testdata/envoyproxy-accesslog-als-json.out.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
gateways:
- apiVersion: gateway.networking.k8s.io/v1
kind: Gateway
metadata:
creationTimestamp: null
name: gateway-1
namespace: envoy-gateway
spec:
gatewayClassName: envoy-gateway-class
listeners:
- allowedRoutes:
namespaces:
from: Same
name: http
port: 80
protocol: HTTP
status:
listeners:
- attachedRoutes: 0
conditions:
- lastTransitionTime: null
message: Sending translated listener configuration to the data plane
reason: Programmed
status: "True"
type: Programmed
- lastTransitionTime: null
message: Listener has been successfully translated
reason: Accepted
status: "True"
type: Accepted
- lastTransitionTime: null
message: Listener references have been resolved
reason: ResolvedRefs
status: "True"
type: ResolvedRefs
name: http
supportedKinds:
- group: gateway.networking.k8s.io
kind: HTTPRoute
- group: gateway.networking.k8s.io
kind: GRPCRoute
infraIR:
envoy-gateway/gateway-1:
proxy:
config:
apiVersion: gateway.envoyproxy.io/v1alpha1
kind: EnvoyProxy
metadata:
creationTimestamp: null
name: test
namespace: envoy-gateway-system
spec:
logging: {}
provider:
kubernetes:
envoyDeployment:
container:
env:
- name: env_a
value: env_a_value
- name: env_b
value: env_b_name
image: envoyproxy/envoy:distroless-dev
resources:
requests:
cpu: 100m
memory: 512Mi
securityContext:
allowPrivilegeEscalation: false
runAsUser: 2000
pod:
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: cloud.google.com/gke-nodepool
operator: In
values:
- router-node
annotations:
key1: val1
key2: val2
securityContext:
fsGroup: 2000
fsGroupChangePolicy: OnRootMismatch
runAsGroup: 3000
runAsUser: 1000
tolerations:
- effect: NoSchedule
key: node-type
operator: Exists
value: router
volumes:
- name: certs
secret:
secretName: envoy-cert
replicas: 2
envoyService:
type: LoadBalancer
type: Kubernetes
telemetry:
accessLog:
settings:
- format:
json:
attr1: val1
attr2: val2
type: JSON
sinks:
- als:
backendRefs:
- name: envoy-als
namespace: monitoring
port: 9000
http:
requestHeaders:
- x-client-ip-address
responseHeaders:
- cache-control
responseTrailers:
- expires
logName: accesslog
type: HTTP
type: ALS
- als:
backendRefs:
- name: envoy-als
namespace: monitoring
port: 9000
type: TCP
type: ALS
status: {}
listeners:
- address: null
name: envoy-gateway/gateway-1/http
ports:
- containerPort: 10080
name: http-80
protocol: HTTP
servicePort: 80
metadata:
labels:
gateway.envoyproxy.io/owning-gateway-name: gateway-1
gateway.envoyproxy.io/owning-gateway-namespace: envoy-gateway
name: envoy-gateway/gateway-1
xdsIR:
envoy-gateway/gateway-1:
accessLog:
als:
- attributes:
attr1: val1
attr2: val2
destination:
name: accesslog-0
settings:
- addressType: IP
endpoints:
- host: 10.240.0.10
port: 9090
protocol: GRPC
http:
requestHeaders:
- x-client-ip-address
responseHeaders:
- cache-control
responseTrailers:
- expires
name: accesslog
type: HTTP
- attributes:
attr1: val1
attr2: val2
destination:
name: accesslog-0
settings:
- addressType: IP
endpoints:
- host: 10.240.0.10
port: 9090
protocol: GRPC
name: envoy-gateway-system/test
type: TCP
http:
- address: 0.0.0.0
hostnames:
- '*'
isHTTP2: false
name: envoy-gateway/gateway-1/http
path:
escapedSlashesAction: UnescapeAndRedirect
mergeSlashes: true
port: 10080
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ envoyproxy:
[%START_TIME%] "%REQ(:METHOD)% %PROTOCOL%" %RESPONSE_CODE% %RESPONSE_FLAGS% %BYTES_RECEIVED% %BYTES_SENT% %DURATION% %RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)% "%REQ(X-FORWARDED-FOR)%" "%REQ(USER-AGENT)%" "%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" "%UPSTREAM_HOST%"\n
sinks:
- type: File
- type: ALS
- type: OpenTelemetry
provider:
type: Kubernetes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ infraIR:
type: Text
sinks:
- type: File
- type: ALS
- type: OpenTelemetry
status: {}
listeners:
Expand Down
Loading

0 comments on commit 33bf73b

Please sign in to comment.