Skip to content

Commit

Permalink
feat(translator): Set statPrefix for HCM and TCPProxy (envoyproxy#3728)
Browse files Browse the repository at this point in the history
* Set statPrefix for hcm and tcpproxy

Signed-off-by: Dingkang Li <[email protected]>

* Add port as suffix of statPrefix

Signed-off-by: Dingkang Li <[email protected]>

* Undo irrelevant change

Signed-off-by: Dingkang Li <[email protected]>

* add tls prefix on passthrough and terminate statPrefix

Signed-off-by: Dingkang Li <[email protected]>

* regenerate testdata

Signed-off-by: Dingkang Li <[email protected]>

* regenerate testdata

Signed-off-by: Dingkang Li <[email protected]>

* set right prefix in connection limit e2e case

Signed-off-by: Dingkang Li <[email protected]>

---------

Signed-off-by: Dingkang Li <[email protected]>
Co-authored-by: zirain <[email protected]>
Co-authored-by: Guy Daich <[email protected]>
  • Loading branch information
3 people authored Aug 2, 2024
1 parent f4c53f4 commit a43cc6c
Show file tree
Hide file tree
Showing 116 changed files with 175 additions and 167 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ xds:
resourceApiVersion: V3
routeConfigName: default/eg/http
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: default/eg/http
drainType: MODIFY_ONLY
Expand Down Expand Up @@ -986,7 +986,7 @@ xds:
resourceApiVersion: V3
routeConfigName: default/eg/grpc
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-8080
useRemoteAddress: true
name: default/eg/grpc
drainType: MODIFY_ONLY
Expand Down Expand Up @@ -1028,7 +1028,7 @@ xds:
{"start_time":"%START_TIME%","method":"%REQ(:METHOD)%","x-envoy-origin-path":"%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%","protocol":"%PROTOCOL%","response_code":"%RESPONSE_CODE%","response_flags":"%RESPONSE_FLAGS%","response_code_details":"%RESPONSE_CODE_DETAILS%","connection_termination_details":"%CONNECTION_TERMINATION_DETAILS%","upstream_transport_failure_reason":"%UPSTREAM_TRANSPORT_FAILURE_REASON%","bytes_received":"%BYTES_RECEIVED%","bytes_sent":"%BYTES_SENT%","duration":"%DURATION%","x-envoy-upstream-service-time":"%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%","x-forwarded-for":"%REQ(X-FORWARDED-FOR)%","user-agent":"%REQ(USER-AGENT)%","x-request-id":"%REQ(X-REQUEST-ID)%",":authority":"%REQ(:AUTHORITY)%","upstream_host":"%UPSTREAM_HOST%","upstream_cluster":"%UPSTREAM_CLUSTER%","upstream_local_address":"%UPSTREAM_LOCAL_ADDRESS%","downstream_local_address":"%DOWNSTREAM_LOCAL_ADDRESS%","downstream_remote_address":"%DOWNSTREAM_REMOTE_ADDRESS%","requested_server_name":"%REQUESTED_SERVER_NAME%","route_name":"%ROUTE_NAME%"}
path: /dev/stdout
cluster: tcproute/default/backend/rule/-1
statPrefix: tcp
statPrefix: tcp-1234
name: tcproute/default/backend
name: default/eg/tcp
perConnectionBufferLimitBytes: 32768
Expand Down Expand Up @@ -1071,7 +1071,7 @@ xds:
{"start_time":"%START_TIME%","method":"%REQ(:METHOD)%","x-envoy-origin-path":"%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%","protocol":"%PROTOCOL%","response_code":"%RESPONSE_CODE%","response_flags":"%RESPONSE_FLAGS%","response_code_details":"%RESPONSE_CODE_DETAILS%","connection_termination_details":"%CONNECTION_TERMINATION_DETAILS%","upstream_transport_failure_reason":"%UPSTREAM_TRANSPORT_FAILURE_REASON%","bytes_received":"%BYTES_RECEIVED%","bytes_sent":"%BYTES_SENT%","duration":"%DURATION%","x-envoy-upstream-service-time":"%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%","x-forwarded-for":"%REQ(X-FORWARDED-FOR)%","user-agent":"%REQ(USER-AGENT)%","x-request-id":"%REQ(X-REQUEST-ID)%",":authority":"%REQ(:AUTHORITY)%","upstream_host":"%UPSTREAM_HOST%","upstream_cluster":"%UPSTREAM_CLUSTER%","upstream_local_address":"%UPSTREAM_LOCAL_ADDRESS%","downstream_local_address":"%DOWNSTREAM_LOCAL_ADDRESS%","downstream_remote_address":"%DOWNSTREAM_REMOTE_ADDRESS%","requested_server_name":"%REQUESTED_SERVER_NAME%","route_name":"%ROUTE_NAME%"}
path: /dev/stdout
cluster: tlsroute/default/backend/rule/-1
statPrefix: passthrough
statPrefix: tls-passthrough-8443
name: tlsroute/default/backend
listenerFilters:
- name: envoy.filters.listener.tls_inspector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@
"routeConfigName": "default/eg/http"
},
"serverHeaderTransformation": "PASS_THROUGH",
"statPrefix": "http",
"statPrefix": "http-10080",
"useRemoteAddress": true
}
}
Expand Down Expand Up @@ -787,7 +787,7 @@
"routeConfigName": "default/eg/grpc"
},
"serverHeaderTransformation": "PASS_THROUGH",
"statPrefix": "http",
"statPrefix": "http-8080",
"useRemoteAddress": true
}
}
Expand Down Expand Up @@ -854,7 +854,7 @@
}
],
"cluster": "tcproute/default/backend/rule/-1",
"statPrefix": "tcp"
"statPrefix": "tcp-1234"
}
}
],
Expand Down Expand Up @@ -925,7 +925,7 @@
}
],
"cluster": "tlsroute/default/backend/rule/-1",
"statPrefix": "passthrough"
"statPrefix": "tls-passthrough-8443"
}
}
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ xds:
resourceApiVersion: V3
routeConfigName: default/eg/http
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: default/eg/http
drainType: MODIFY_ONLY
Expand Down Expand Up @@ -467,7 +467,7 @@ xds:
resourceApiVersion: V3
routeConfigName: default/eg/grpc
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-8080
useRemoteAddress: true
name: default/eg/grpc
drainType: MODIFY_ONLY
Expand Down Expand Up @@ -509,7 +509,7 @@ xds:
{"start_time":"%START_TIME%","method":"%REQ(:METHOD)%","x-envoy-origin-path":"%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%","protocol":"%PROTOCOL%","response_code":"%RESPONSE_CODE%","response_flags":"%RESPONSE_FLAGS%","response_code_details":"%RESPONSE_CODE_DETAILS%","connection_termination_details":"%CONNECTION_TERMINATION_DETAILS%","upstream_transport_failure_reason":"%UPSTREAM_TRANSPORT_FAILURE_REASON%","bytes_received":"%BYTES_RECEIVED%","bytes_sent":"%BYTES_SENT%","duration":"%DURATION%","x-envoy-upstream-service-time":"%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%","x-forwarded-for":"%REQ(X-FORWARDED-FOR)%","user-agent":"%REQ(USER-AGENT)%","x-request-id":"%REQ(X-REQUEST-ID)%",":authority":"%REQ(:AUTHORITY)%","upstream_host":"%UPSTREAM_HOST%","upstream_cluster":"%UPSTREAM_CLUSTER%","upstream_local_address":"%UPSTREAM_LOCAL_ADDRESS%","downstream_local_address":"%DOWNSTREAM_LOCAL_ADDRESS%","downstream_remote_address":"%DOWNSTREAM_REMOTE_ADDRESS%","requested_server_name":"%REQUESTED_SERVER_NAME%","route_name":"%ROUTE_NAME%"}
path: /dev/stdout
cluster: tcproute/default/backend/rule/-1
statPrefix: tcp
statPrefix: tcp-1234
name: tcproute/default/backend
name: default/eg/tcp
perConnectionBufferLimitBytes: 32768
Expand Down Expand Up @@ -552,7 +552,7 @@ xds:
{"start_time":"%START_TIME%","method":"%REQ(:METHOD)%","x-envoy-origin-path":"%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%","protocol":"%PROTOCOL%","response_code":"%RESPONSE_CODE%","response_flags":"%RESPONSE_FLAGS%","response_code_details":"%RESPONSE_CODE_DETAILS%","connection_termination_details":"%CONNECTION_TERMINATION_DETAILS%","upstream_transport_failure_reason":"%UPSTREAM_TRANSPORT_FAILURE_REASON%","bytes_received":"%BYTES_RECEIVED%","bytes_sent":"%BYTES_SENT%","duration":"%DURATION%","x-envoy-upstream-service-time":"%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%","x-forwarded-for":"%REQ(X-FORWARDED-FOR)%","user-agent":"%REQ(USER-AGENT)%","x-request-id":"%REQ(X-REQUEST-ID)%",":authority":"%REQ(:AUTHORITY)%","upstream_host":"%UPSTREAM_HOST%","upstream_cluster":"%UPSTREAM_CLUSTER%","upstream_local_address":"%UPSTREAM_LOCAL_ADDRESS%","downstream_local_address":"%DOWNSTREAM_LOCAL_ADDRESS%","downstream_remote_address":"%DOWNSTREAM_REMOTE_ADDRESS%","requested_server_name":"%REQUESTED_SERVER_NAME%","route_name":"%ROUTE_NAME%"}
path: /dev/stdout
cluster: tlsroute/default/backend/rule/-1
statPrefix: passthrough
statPrefix: tls-passthrough-8443
name: tlsroute/default/backend
listenerFilters:
- name: envoy.filters.listener.tls_inspector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ xds:
resourceApiVersion: V3
routeConfigName: default/eg/http
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: default/eg/http
drainType: MODIFY_ONLY
Expand Down Expand Up @@ -124,7 +124,7 @@ xds:
resourceApiVersion: V3
routeConfigName: default/eg/grpc
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-8080
useRemoteAddress: true
name: default/eg/grpc
drainType: MODIFY_ONLY
Expand Down Expand Up @@ -166,7 +166,7 @@ xds:
{"start_time":"%START_TIME%","method":"%REQ(:METHOD)%","x-envoy-origin-path":"%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%","protocol":"%PROTOCOL%","response_code":"%RESPONSE_CODE%","response_flags":"%RESPONSE_FLAGS%","response_code_details":"%RESPONSE_CODE_DETAILS%","connection_termination_details":"%CONNECTION_TERMINATION_DETAILS%","upstream_transport_failure_reason":"%UPSTREAM_TRANSPORT_FAILURE_REASON%","bytes_received":"%BYTES_RECEIVED%","bytes_sent":"%BYTES_SENT%","duration":"%DURATION%","x-envoy-upstream-service-time":"%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%","x-forwarded-for":"%REQ(X-FORWARDED-FOR)%","user-agent":"%REQ(USER-AGENT)%","x-request-id":"%REQ(X-REQUEST-ID)%",":authority":"%REQ(:AUTHORITY)%","upstream_host":"%UPSTREAM_HOST%","upstream_cluster":"%UPSTREAM_CLUSTER%","upstream_local_address":"%UPSTREAM_LOCAL_ADDRESS%","downstream_local_address":"%DOWNSTREAM_LOCAL_ADDRESS%","downstream_remote_address":"%DOWNSTREAM_REMOTE_ADDRESS%","requested_server_name":"%REQUESTED_SERVER_NAME%","route_name":"%ROUTE_NAME%"}
path: /dev/stdout
cluster: tcproute/default/backend/rule/-1
statPrefix: tcp
statPrefix: tcp-1234
name: tcproute/default/backend
name: default/eg/tcp
perConnectionBufferLimitBytes: 32768
Expand Down Expand Up @@ -209,7 +209,7 @@ xds:
{"start_time":"%START_TIME%","method":"%REQ(:METHOD)%","x-envoy-origin-path":"%REQ(X-ENVOY-ORIGINAL-PATH?:PATH)%","protocol":"%PROTOCOL%","response_code":"%RESPONSE_CODE%","response_flags":"%RESPONSE_FLAGS%","response_code_details":"%RESPONSE_CODE_DETAILS%","connection_termination_details":"%CONNECTION_TERMINATION_DETAILS%","upstream_transport_failure_reason":"%UPSTREAM_TRANSPORT_FAILURE_REASON%","bytes_received":"%BYTES_RECEIVED%","bytes_sent":"%BYTES_SENT%","duration":"%DURATION%","x-envoy-upstream-service-time":"%RESP(X-ENVOY-UPSTREAM-SERVICE-TIME)%","x-forwarded-for":"%REQ(X-FORWARDED-FOR)%","user-agent":"%REQ(USER-AGENT)%","x-request-id":"%REQ(X-REQUEST-ID)%",":authority":"%REQ(:AUTHORITY)%","upstream_host":"%UPSTREAM_HOST%","upstream_cluster":"%UPSTREAM_CLUSTER%","upstream_local_address":"%UPSTREAM_LOCAL_ADDRESS%","downstream_local_address":"%DOWNSTREAM_LOCAL_ADDRESS%","downstream_remote_address":"%DOWNSTREAM_REMOTE_ADDRESS%","requested_server_name":"%REQUESTED_SERVER_NAME%","route_name":"%ROUTE_NAME%"}
path: /dev/stdout
cluster: tlsroute/default/backend/rule/-1
statPrefix: passthrough
statPrefix: tls-passthrough-8443
name: tlsroute/default/backend
listenerFilters:
- name: envoy.filters.listener.tls_inspector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@
"routeConfigName": "envoy-gateway-system/eg/http"
},
"serverHeaderTransformation": "PASS_THROUGH",
"statPrefix": "http",
"statPrefix": "http-10080",
"useRemoteAddress": true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ xds:
resourceApiVersion: V3
routeConfigName: envoy-gateway-system/eg/http
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: envoy-gateway-system/eg/http
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ xds:
resourceApiVersion: V3
routeConfigName: envoy-gateway-system/eg/http
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: envoy-gateway-system/eg/http
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ xds:
resourceApiVersion: V3
routeConfigName: envoy-gateway-system/eg/http
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: envoy-gateway-system/eg/http
drainType: MODIFY_ONLY
Expand Down
12 changes: 10 additions & 2 deletions internal/xds/translator/listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ package translator

import (
"errors"
"strconv"
"strings"

xdscore "github.com/cncf/xds/go/xds/core/v3"
matcher "github.com/cncf/xds/go/xds/type/matcher/v3"
Expand Down Expand Up @@ -226,6 +228,9 @@ func (t *Translator) addHCMToXDSListener(xdsListener *listenerv3.Listener, irLis
statPrefix = "http"
}

// Append port to the statPrefix.
statPrefix = strings.Join([]string{statPrefix, strconv.Itoa(int(irListener.Port))}, "-")

// Client IP detection
useRemoteAddress := true
originalIPDetectionExtensions := originalIPDetectionExtensions(irListener.ClientIPDetection)
Expand Down Expand Up @@ -403,13 +408,16 @@ func addXdsTCPFilterChain(xdsListener *listenerv3.Listener, irRoute *ir.TCPRoute
isTLSTerminate := irRoute.TLS != nil && irRoute.TLS.Terminate != nil
statPrefix := "tcp"
if isTLSPassthrough {
statPrefix = "passthrough"
statPrefix = "tls-passthrough"
}

if isTLSTerminate {
statPrefix = "terminate"
statPrefix = "tls-terminate"
}

// Append port to the statPrefix.
statPrefix = strings.Join([]string{statPrefix, strconv.Itoa(int(xdsListener.Address.GetSocketAddress().GetPortValue()))}, "-")

mgr := &tcpv3.TcpProxy{
AccessLog: buildXdsAccessLog(accesslog, false),
StatPrefix: statPrefix,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
resourceApiVersion: V3
routeConfigName: envoy-gateway/gateway-1/http1
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: envoy-gateway/gateway-1/http1
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
resourceApiVersion: V3
routeConfigName: extension-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: extension-listener
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: first-listener
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
resourceApiVersion: V3
routeConfigName: policyextension-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10081
useRemoteAddress: true
name: policyextension-listener
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: first-listener
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: first-listener
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: first-listener
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: first-listener
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: first-listener
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: first-listener
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
resourceApiVersion: V3
routeConfigName: envoy-gateway/gateway-1/http
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: envoy-gateway/gateway-1/http
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: first-listener
drainType: MODIFY_ONLY
Expand All @@ -44,7 +44,7 @@
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
cluster: tcp-route-dest
statPrefix: tcp
statPrefix: tcp-10081
name: tcp-route-dest
name: second-listener
perConnectionBufferLimitBytes: 1500
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
resourceApiVersion: V3
routeConfigName: default/gateway-1/http
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: default/gateway-1/http
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: first-listener
drainType: MODIFY_ONLY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
resourceApiVersion: V3
routeConfigName: first-listener
serverHeaderTransformation: PASS_THROUGH
statPrefix: http
statPrefix: http-10080
useRemoteAddress: true
name: first-listener
drainType: MODIFY_ONLY
Expand All @@ -44,7 +44,7 @@
typedConfig:
'@type': type.googleapis.com/envoy.extensions.filters.network.tcp_proxy.v3.TcpProxy
cluster: tcp-route-dest
statPrefix: tcp
statPrefix: tcp-10081
name: tcp-route-dest
name: second-listener
perConnectionBufferLimitBytes: 1500
Loading

0 comments on commit a43cc6c

Please sign in to comment.