Skip to content

Commit 0a04022

Browse files
kumahq[bot]lukidzilobkovilya
authored
fix(meshaccesslog): deduplicate access logs for shared inbound port (backport of #16374) (#16377)
Automatic cherry-pick of #16374 for branch release-2.12 Generated by [action](https://github.com/kumahq/kuma/actions/runs/24882318941) cherry-picked commit 9a57939 ⚠️ ⚠️ ⚠️ Conflicts happened when cherry-picking! ⚠️ ⚠️ ⚠️ ``` On branch release-2.12 Your branch is up to date with 'origin/release-2.12'. You are currently cherry-picking commit 9a57939. (fix conflicts and run "git cherry-pick --continue") (use "git cherry-pick --skip" to skip this patch) (use "git cherry-pick --abort" to cancel the cherry-pick operation) Changes to be committed: new file: pkg/plugins/policies/meshaccesslog/plugin/v1alpha1/testdata/inbound_route_duplicate_port.listener.golden.yaml Unmerged paths: (use "git add <file>..." to mark resolution) both modified: pkg/plugins/policies/meshaccesslog/plugin/v1alpha1/plugin.go both modified: pkg/plugins/policies/meshaccesslog/plugin/v1alpha1/plugin_test.go ``` --------- Signed-off-by: Lukasz Dziedziak <lukidzi@gmail.com> Signed-off-by: Ilya Lobkov <ilya.lobkov@konghq.com> Co-authored-by: Lukasz Dziedziak <lukidzi@gmail.com> Co-authored-by: Ilya Lobkov <ilya.lobkov@konghq.com>
1 parent 27b9001 commit 0a04022

3 files changed

Lines changed: 128 additions & 13 deletions

File tree

pkg/plugins/policies/meshaccesslog/plugin/v1alpha1/plugin.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,23 @@ func applyToInbounds(
112112
backends *EndpointAccumulator,
113113
accessLogSocketPath string,
114114
) error {
115+
configured := map[core_rules.InboundListener]struct{}{}
115116
for _, inbound := range dataplane.Spec.GetNetworking().GetInbound() {
116117
iface := dataplane.Spec.Networking.ToInboundInterface(inbound)
117118

118119
listenerKey := core_rules.InboundListener{
119120
Address: iface.DataplaneIP,
120121
Port: iface.DataplanePort,
121122
}
123+
if _, ok := configured[listenerKey]; ok {
124+
continue
125+
}
122126
listener, ok := inboundListeners[listenerKey]
123127
if !ok {
124128
continue
125129
}
126130
protocol := core_meta.ParseProtocol(inbound.GetProtocol())
131+
configured[listenerKey] = struct{}{}
127132
conf := rules_inbound.MatchesAllIncomingTraffic[api.Conf](rules.InboundRules[listenerKey])
128133
kumaValues := listeners_v3.KumaValues{
129134
SourceService: mesh_proto.ServiceUnknown,

pkg/plugins/policies/meshaccesslog/plugin/v1alpha1/plugin_test.go

Lines changed: 76 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ var _ = Describe("MeshAccessLog", func() {
7575
expectedClusters []string
7676
features xds_types.Features
7777
meshServicesMode mesh_proto.Mesh_MeshServices_Mode
78+
extraInbounds []*builders.InboundBuilder
7879
}
7980
DescribeTable("should generate proper Envoy config",
8081
func(given sidecarTestCase) {
@@ -99,25 +100,28 @@ var _ = Describe("MeshAccessLog", func() {
99100
AddServiceProtocol("other-service-tcp", core_meta.ProtocolTCP).
100101
Build()
101102

103+
dpBuilder := builders.Dataplane().
104+
WithName("backend").
105+
WithMesh("default").
106+
AddInbound(builders.Inbound().
107+
WithService("backend").
108+
WithAddress("127.0.0.1").
109+
WithPort(17777).
110+
WithTags(map[string]string{
111+
mesh_proto.ProtocolTag: "http",
112+
}),
113+
)
114+
115+
for _, extra := range given.extraInbounds {
116+
dpBuilder = dpBuilder.AddInbound(extra)
117+
}
102118
proxy := xds_builders.Proxy().
103119
WithID(*core_xds.BuildProxyId("default", "backend")).
104120
WithMetadata(&core_xds.DataplaneMetadata{
105121
WorkDir: "/tmp",
106122
Features: given.features,
107123
}).
108-
WithDataplane(
109-
builders.Dataplane().
110-
WithName("backend").
111-
WithMesh("default").
112-
AddInbound(builders.Inbound().
113-
WithService("backend").
114-
WithAddress("127.0.0.1").
115-
WithPort(17777).
116-
WithTags(map[string]string{
117-
mesh_proto.ProtocolTag: "http",
118-
}),
119-
),
120-
).
124+
WithDataplane(dpBuilder).
121125
WithOutbounds(append(given.outbounds, &xds_types.Outbound{
122126
LegacyOutbound: builders.Outbound().
123127
WithService("other-service-http").
@@ -722,6 +726,65 @@ var _ = Describe("MeshAccessLog", func() {
722726
},
723727
expectedListeners: []string{"inbound_route.listener.golden.yaml"},
724728
}),
729+
Entry("inbound with two services on the same port does not duplicate access log", sidecarTestCase{
730+
resources: []core_xds.Resource{{
731+
Name: "inbound",
732+
Origin: metadata.OriginInbound,
733+
Resource: NewInboundListenerBuilder(envoy_common.APIV3, "127.0.0.1", 17777, core_xds.SocketAddressProtocolTCP).
734+
Configure(FilterChain(NewFilterChainBuilder(envoy_common.APIV3, envoy_common.AnonymousResource).
735+
Configure(HttpConnectionManager("127.0.0.1:17777", false, nil, true)).
736+
Configure(
737+
HttpInboundRoutes(
738+
envoy_names.GetInboundRouteName("backend"),
739+
"backend",
740+
envoy_common.Routes{
741+
{
742+
Clusters: []envoy_common.Cluster{envoy_common.NewCluster(
743+
envoy_common.WithService("backend"),
744+
envoy_common.WithWeight(100),
745+
)},
746+
},
747+
},
748+
),
749+
),
750+
)).MustBuild(),
751+
}},
752+
extraInbounds: []*builders.InboundBuilder{
753+
builders.Inbound().
754+
WithService("backend-canary").
755+
WithAddress("127.0.0.1").
756+
WithPort(17777).
757+
WithTags(map[string]string{
758+
mesh_proto.ProtocolTag: "http",
759+
}),
760+
},
761+
fromRules: core_rules.FromRules{
762+
Rules: map[core_rules.InboundListener]core_rules.Rules{
763+
{Address: "127.0.0.1", Port: 17777}: {{
764+
Subset: subsetutils.Subset{},
765+
Conf: api.Conf{
766+
Backends: &[]api.Backend{{
767+
File: &api.FileBackend{
768+
Path: "/tmp/log",
769+
},
770+
}},
771+
},
772+
}},
773+
},
774+
InboundRules: map[core_rules.InboundListener][]*inbound.Rule{
775+
{Address: "127.0.0.1", Port: 17777}: {{
776+
Conf: &api.Rule{Default: api.Conf{
777+
Backends: &[]api.Backend{{
778+
File: &api.FileBackend{
779+
Path: "/tmp/log",
780+
},
781+
}},
782+
}},
783+
}},
784+
},
785+
},
786+
expectedListeners: []string{"inbound_route_duplicate_port.listener.golden.yaml"},
787+
}),
725788
)
726789
type gatewayTestCase struct {
727790
routes []*core_mesh.MeshGatewayRouteResource
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
address:
2+
socketAddress:
3+
address: 127.0.0.1
4+
portValue: 17777
5+
enableReusePort: false
6+
filterChains:
7+
- filters:
8+
- name: envoy.filters.network.http_connection_manager
9+
typedConfig:
10+
'@type': type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
11+
accessLog:
12+
- name: envoy.access_loggers.file
13+
typedConfig:
14+
'@type': type.googleapis.com/envoy.extensions.access_loggers.file.v3.FileAccessLog
15+
logFormat:
16+
textFormatSource:
17+
inlineString: |
18+
[%START_TIME%] default "%REQ(:METHOD)% %REQ(X-ENVOY-ORIGINAL-PATH?:PATH)% %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-B3-TRACEID?X-DATADOG-TRACEID)%" "%REQ(X-REQUEST-ID)%" "%REQ(:AUTHORITY)%" "unknown" "backend" "127.0.0.1" "%UPSTREAM_HOST%"
19+
path: /tmp/log
20+
httpFilters:
21+
- name: envoy.filters.http.router
22+
typedConfig:
23+
'@type': type.googleapis.com/envoy.extensions.filters.http.router.v3.Router
24+
internalAddressConfig:
25+
cidrRanges:
26+
- addressPrefix: 127.0.0.1
27+
prefixLen: 32
28+
- addressPrefix: ::1
29+
prefixLen: 128
30+
routeConfig:
31+
name: inbound:backend
32+
requestHeadersToRemove:
33+
- x-kuma-tags
34+
validateClusters: false
35+
virtualHosts:
36+
- domains:
37+
- '*'
38+
name: backend
39+
routes:
40+
- match:
41+
prefix: /
42+
route:
43+
cluster: backend
44+
timeout: 0s
45+
statPrefix: "127_0_0_1_17777"
46+
name: inbound:127.0.0.1:17777
47+
trafficDirection: INBOUND

0 commit comments

Comments
 (0)