diff --git a/app/kuma-dp/cmd/run.go b/app/kuma-dp/cmd/run.go index 7e7800e3b833..be4223cdaf55 100644 --- a/app/kuma-dp/cmd/run.go +++ b/app/kuma-dp/cmd/run.go @@ -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 { diff --git a/app/kuma-dp/pkg/dataplane/accesslogs/server.go b/app/kuma-dp/pkg/dataplane/accesslogs/server.go index f899c0f6686e..a248473b100a 100644 --- a/app/kuma-dp/pkg/dataplane/accesslogs/server.go +++ b/app/kuma-dp/pkg/dataplane/accesslogs/server.go @@ -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" ) @@ -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, diff --git a/pkg/xds/bootstrap/generator.go b/pkg/xds/bootstrap/generator.go index 05ee08f5fb7c..c2aa74546be5 100644 --- a/pkg/xds/bootstrap/generator.go +++ b/pkg/xds/bootstrap/generator.go @@ -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" @@ -175,7 +177,7 @@ 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 { @@ -183,7 +185,7 @@ func (b *bootstrapGenerator) generateFor(proxyId core_xds.ProxyId, dataplane *co } 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, @@ -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, diff --git a/pkg/xds/bootstrap/testdata/bootstrap.k8s.golden.yaml b/pkg/xds/bootstrap/testdata/bootstrap.k8s.golden.yaml index da6dfcc343dd..59a1d6590fc7 100644 --- a/pkg/xds/bootstrap/testdata/bootstrap.k8s.golden.yaml +++ b/pkg/xds/bootstrap/testdata/bootstrap.k8s.golden.yaml @@ -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: diff --git a/pkg/xds/bootstrap/testdata/bootstrap.overridden.golden.yaml b/pkg/xds/bootstrap/testdata/bootstrap.overridden.golden.yaml index 81c676046b20..72f4fe8c9d95 100644 --- a/pkg/xds/bootstrap/testdata/bootstrap.overridden.golden.yaml +++ b/pkg/xds/bootstrap/testdata/bootstrap.overridden.golden.yaml @@ -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: diff --git a/pkg/xds/bootstrap/testdata/bootstrap.universal.golden.yaml b/pkg/xds/bootstrap/testdata/bootstrap.universal.golden.yaml index 83c8fe19d8af..c22a92877a71 100644 --- a/pkg/xds/bootstrap/testdata/bootstrap.universal.golden.yaml +++ b/pkg/xds/bootstrap/testdata/bootstrap.universal.golden.yaml @@ -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: diff --git a/pkg/xds/bootstrap/testdata/generator.custom-config-minimal-request.golden.yaml b/pkg/xds/bootstrap/testdata/generator.custom-config-minimal-request.golden.yaml index 7dc9299c6eaf..77e5846fbf96 100644 --- a/pkg/xds/bootstrap/testdata/generator.custom-config-minimal-request.golden.yaml +++ b/pkg/xds/bootstrap/testdata/generator.custom-config-minimal-request.golden.yaml @@ -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: diff --git a/pkg/xds/bootstrap/testdata/generator.custom-config.golden.yaml b/pkg/xds/bootstrap/testdata/generator.custom-config.golden.yaml index 42c37570b6ed..7acfbaa9839d 100644 --- a/pkg/xds/bootstrap/testdata/generator.custom-config.golden.yaml +++ b/pkg/xds/bootstrap/testdata/generator.custom-config.golden.yaml @@ -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: diff --git a/pkg/xds/bootstrap/testdata/generator.default-config-minimal-request.golden.yaml b/pkg/xds/bootstrap/testdata/generator.default-config-minimal-request.golden.yaml index 5395f3bfe5d8..ec03e253977b 100644 --- a/pkg/xds/bootstrap/testdata/generator.default-config-minimal-request.golden.yaml +++ b/pkg/xds/bootstrap/testdata/generator.default-config-minimal-request.golden.yaml @@ -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: diff --git a/pkg/xds/bootstrap/testdata/generator.default-config.golden.yaml b/pkg/xds/bootstrap/testdata/generator.default-config.golden.yaml index 23ab19ef60bf..8b32be3d3138 100644 --- a/pkg/xds/bootstrap/testdata/generator.default-config.golden.yaml +++ b/pkg/xds/bootstrap/testdata/generator.default-config.golden.yaml @@ -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: diff --git a/pkg/xds/envoy/access_log.go b/pkg/xds/envoy/access_log.go new file mode 100644 index 000000000000..df9e3f24e434 --- /dev/null +++ b/pkg/xds/envoy/access_log.go @@ -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" +}