Skip to content

Commit

Permalink
fix(*) traffic logging to tcp backends (#1394)
Browse files Browse the repository at this point in the history
* Revert "fix(kuma-dp): reduce size of access log address (#894)"

This reverts commit 2bec835.

* chore(*) shorten the unix socket name

Signed-off-by: Nikolay Nikolaev <nikolay.nikolaev@konghq.com>
  • Loading branch information
Nikolay Nikolaev authored Jan 7, 2021
1 parent 04cd0de commit 950448d
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/kuma-dp/cmd/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func newRunCmd() *cobra.Command {
if err != nil {
return err
}
server := accesslogs.NewAccessLogServer()
server := accesslogs.NewAccessLogServer(cfg.Dataplane)

componentMgr := component.NewManager(leader_memory.NewNeverLeaderElector())
if err := componentMgr.Add(server, dataplane); err != nil {
Expand Down
8 changes: 5 additions & 3 deletions app/kuma-dp/pkg/dataplane/accesslogs/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@ import (
"net"
"sync/atomic"

"github.com/kumahq/kuma/pkg/xds/envoy"

envoy_accesslog "github.com/envoyproxy/go-control-plane/envoy/service/accesslog/v2"
"github.com/pkg/errors"
"google.golang.org/grpc"

kumadp "github.com/kumahq/kuma/pkg/config/app/kuma-dp"
"github.com/kumahq/kuma/pkg/core"
"github.com/kumahq/kuma/pkg/core/runtime/component"
)
Expand All @@ -31,9 +34,8 @@ func (s *accessLogServer) NeedLeaderElection() bool {
return false
}

func NewAccessLogServer() *accessLogServer {
id := core.NewUUID()
var address = fmt.Sprintf("/tmp/%s.sock", id)
func NewAccessLogServer(dataplane kumadp.Dataplane) *accessLogServer {
address := envoy.AccessLogSocketName(dataplane.Name, dataplane.Mesh)
return &accessLogServer{
server: grpc.NewServer(),
newHandler: defaultHandler,
Expand Down
8 changes: 5 additions & 3 deletions pkg/xds/bootstrap/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (
"strings"
"text/template"

"github.com/kumahq/kuma/pkg/xds/envoy"

"github.com/kumahq/kuma/pkg/core/resources/model"
"github.com/kumahq/kuma/pkg/core/resources/model/rest"
"github.com/kumahq/kuma/pkg/core/validators"
Expand Down Expand Up @@ -175,15 +177,15 @@ func (b *bootstrapGenerator) generateFor(proxyId core_xds.ProxyId, dataplane *co
return nil, err
}

var certBytes string = ""
var certBytes = ""
if b.xdsCertFile != "" {
cert, err := ioutil.ReadFile(b.xdsCertFile)
if err != nil {
return nil, err
}
certBytes = base64.StdEncoding.EncodeToString(cert)
}
accessLogPipe := fmt.Sprintf("/tmp/kuma-access-logs-%s-%s.sock", request.Name, request.Mesh)
accessLogSocket := envoy.AccessLogSocketName(request.Name, request.Mesh)
params := configParameters{
Id: proxyId.String(),
Service: service,
Expand All @@ -193,7 +195,7 @@ func (b *bootstrapGenerator) generateFor(proxyId core_xds.ProxyId, dataplane *co
XdsHost: b.xdsHost(request),
XdsPort: b.config.XdsPort,
XdsConnectTimeout: b.config.XdsConnectTimeout,
AccessLogPipe: accessLogPipe,
AccessLogPipe: accessLogSocket,
DataplaneTokenPath: request.DataplaneTokenPath,
DataplaneResource: request.DataplaneResource,
CertBytes: certBytes,
Expand Down
2 changes: 1 addition & 1 deletion pkg/xds/bootstrap/testdata/bootstrap.k8s.golden.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ staticResources:
- endpoint:
address:
pipe:
path: /tmp/kuma-access-logs-dp-1.default-default.sock
path: /tmp/kuma-al-dp-1.default-default.sock
name: access_log_sink
type: STATIC
upstreamConnectionOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ staticResources:
- endpoint:
address:
pipe:
path: /tmp/kuma-access-logs-dp-1.default-default.sock
path: /tmp/kuma-al-dp-1.default-default.sock
name: access_log_sink
type: STATIC
upstreamConnectionOptions:
Expand Down
2 changes: 1 addition & 1 deletion pkg/xds/bootstrap/testdata/bootstrap.universal.golden.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ staticResources:
- endpoint:
address:
pipe:
path: /tmp/kuma-access-logs-dp-1-default.sock
path: /tmp/kuma-al-dp-1-default.sock
name: access_log_sink
type: STATIC
upstreamConnectionOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ staticResources:
- endpoint:
address:
pipe:
path: /tmp/kuma-access-logs-name.namespace-mesh.sock
path: /tmp/kuma-al-name.namespace-mesh.sock
name: access_log_sink
type: STATIC
upstreamConnectionOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ staticResources:
- endpoint:
address:
pipe:
path: /tmp/kuma-access-logs-name.namespace-mesh.sock
path: /tmp/kuma-al-name.namespace-mesh.sock
name: access_log_sink
type: STATIC
upstreamConnectionOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ staticResources:
- endpoint:
address:
pipe:
path: /tmp/kuma-access-logs-name.namespace-mesh.sock
path: /tmp/kuma-al-name.namespace-mesh.sock
name: access_log_sink
type: STATIC
upstreamConnectionOptions:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ staticResources:
- endpoint:
address:
pipe:
path: /tmp/kuma-access-logs-name.namespace-mesh.sock
path: /tmp/kuma-al-name.namespace-mesh.sock
name: access_log_sink
type: STATIC
upstreamConnectionOptions:
Expand Down
15 changes: 15 additions & 0 deletions pkg/xds/envoy/access_log.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package envoy

import (
"fmt"
)

// AccessLogSocketName generates a socket path that will fit the Unix socket path limitation of 108 chars
func AccessLogSocketName(name, mesh string) string {
socketName := fmt.Sprintf("/tmp/kuma-al-%s-%s", name, mesh)
trimLen := len(socketName)
if trimLen > 100 {
trimLen = 100
}
return socketName[:trimLen] + ".sock"
}

0 comments on commit 950448d

Please sign in to comment.