Skip to content

Commit

Permalink
Merge pull request #306 from Kong/fix/grpc-access-log-server-on-k8s
Browse files Browse the repository at this point in the history
kuma-cp: fix an issue with Access Log Server on Kubernetes by replacing Google gRPC client with Envoy gRPC client
  • Loading branch information
yskopets authored Oct 2, 2019
2 parents ce0c4d2 + 38f335e commit f7ff4f7
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 19 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@

## [0.2.0]

> Released on 2019/10/01
> Released on 2019/10/02
Changes:

* Fix an issue with `Access Log Server` (integrated into `kuma-dp`) on Kubernetes
by replacing `Google gRPC client` with `Envoy gRPC client`
[#306](https://github.com/Kong/kuma/pull/306)
* Settings of a `kuma-sidecar` container, such as `ReadinessProbe`, `LivenessProbe` and `Resources`,
are now configurable
[#304](https://github.com/Kong/kuma/pull/304)
Expand Down
13 changes: 8 additions & 5 deletions pkg/xds/bootstrap/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package bootstrap
import (
"bytes"
"context"
"fmt"
"text/template"

"github.com/Kong/kuma/pkg/xds/bootstrap/rest"
Expand Down Expand Up @@ -53,12 +54,14 @@ func (b *bootstrapGenerator) Generate(ctx context.Context, request rest.Bootstra
if request.AdminPort != 0 {
adminPort = request.AdminPort
}
accessLogPipe := fmt.Sprintf("/tmp/kuma-access-logs-%s-%s-%s.sock", dataplane.Meta.GetName(), dataplane.Meta.GetMesh(), dataplane.Meta.GetNamespace())
params := configParameters{
Id: proxyId.String(),
Service: service,
AdminPort: adminPort,
XdsHost: b.config.XdsHost,
XdsPort: b.config.XdsPort,
Id: proxyId.String(),
Service: service,
AdminPort: adminPort,
XdsHost: b.config.XdsHost,
XdsPort: b.config.XdsPort,
AccessLogPipe: accessLogPipe,
}
log.WithValues("params", params).Info("Generating bootstrap config")
return b.ConfigForParameters(params)
Expand Down
28 changes: 23 additions & 5 deletions pkg/xds/bootstrap/template.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package bootstrap

type configParameters struct {
Id string
Service string
AdminPort uint32
XdsHost string
XdsPort uint32
Id string
Service string
AdminPort uint32
XdsHost string
XdsPort uint32
AccessLogPipe string
}

const configTemplate string = `
Expand Down Expand Up @@ -52,4 +53,21 @@ static_resources:
socket_address:
address: {{ .XdsHost }}
port_value: {{ .XdsPort }}
- name: access_log_sink
connect_timeout: 1s
type: STATIC
lb_policy: ROUND_ROBIN
http2_protocol_options: {}
upstream_connection_options:
# configure a TCP keep-alive to detect and reconnect to the admin
# server in the event of a TCP socket half open connection
tcp_keepalive: {}
load_assignment:
cluster_name: access_log_sink
endpoints:
- lb_endpoints:
- endpoint:
address:
pipe:
path: {{ .AccessLogPipe }}
`
14 changes: 14 additions & 0 deletions pkg/xds/bootstrap/testdata/bootstrap.golden.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,19 @@ staticResources:
portValue: 5678
name: ads_cluster
type: STRICT_DNS
upstreamConnectionOptions:
tcpKeepalive: {}
- connectTimeout: 1s
http2ProtocolOptions: {}
loadAssignment:
clusterName: access_log_sink
endpoints:
- lbEndpoints:
- endpoint:
address:
pipe:
path: /tmp/kuma-access-logs-dp-1-default-default.sock
name: access_log_sink
type: STATIC
upstreamConnectionOptions:
tcpKeepalive: {}
16 changes: 15 additions & 1 deletion pkg/xds/bootstrap/testdata/bootstrap.overridden.golden.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,18 @@ staticResources:
name: ads_cluster
type: STRICT_DNS
upstreamConnectionOptions:
tcpKeepalive: {}
tcpKeepalive: {}
- connectTimeout: 1s
http2ProtocolOptions: {}
loadAssignment:
clusterName: access_log_sink
endpoints:
- lbEndpoints:
- endpoint:
address:
pipe:
path: /tmp/kuma-access-logs-dp-1-default-default.sock
name: access_log_sink
type: STATIC
upstreamConnectionOptions:
tcpKeepalive: {}
9 changes: 5 additions & 4 deletions pkg/xds/envoy/access_logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (

const AccessLogDefaultFormat = "[%START_TIME%] %KUMA_SOURCE_ADDRESS%(%KUMA_SOURCE_SERVICE%)->%UPSTREAM_HOST%(%KUMA_DESTINATION_SERVICE%) took %DURATION%ms, sent %BYTES_SENT% bytes, received: %BYTES_RECEIVED% bytes\n"

const AccessLogSink = "access_log_sink"

func convertLoggingBackends(sourceService string, destinationService string, backends []*v1alpha1.LoggingBackend, proxy *core_xds.Proxy) ([]*filter_accesslog.AccessLog, error) {
var result []*filter_accesslog.AccessLog
for _, backend := range backends {
Expand Down Expand Up @@ -56,10 +58,9 @@ func tcpAccessLog(format string, tcp *v1alpha1.LoggingBackend_Tcp_, id core_xds.
CommonConfig: &accesslog.CommonGrpcAccessLogConfig{
LogName: fmt.Sprintf("%s;%s", tcp.Tcp.Address, format),
GrpcService: &core.GrpcService{
TargetSpecifier: &core.GrpcService_GoogleGrpc_{
GoogleGrpc: &core.GrpcService_GoogleGrpc{
StatPrefix: "grpc_service",
TargetUri: fmt.Sprintf("unix:///tmp/kuma-access-logs-%s-%s.sock", id.Name, id.Mesh),
TargetSpecifier: &core.GrpcService_EnvoyGrpc_{
EnvoyGrpc: &core.GrpcService_EnvoyGrpc{
ClusterName: AccessLogSink,
},
},
},
Expand Down
5 changes: 2 additions & 3 deletions pkg/xds/envoy/envoy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -799,9 +799,8 @@ name: inbound:192.168.0.1:8080
'@type': type.googleapis.com/envoy.config.accesslog.v2.HttpGrpcAccessLogConfig
commonConfig:
grpcService:
googleGrpc:
statPrefix: grpc_service
targetUri: unix:///tmp/kuma-access-logs-backend-example.sock
envoyGrpc:
clusterName: access_log_sink
logName: 127.0.0.1:1234;custom format
cluster: outbound:127.0.0.1:18080
statPrefix: outbound:127.0.0.1:18080
Expand Down

0 comments on commit f7ff4f7

Please sign in to comment.