-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path11-counts-response-release.yml
62 lines (62 loc) · 2.26 KB
/
11-counts-response-release.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: response-counts
namespace: sock-shop
spec:
# workloadSelector:
# labels:
# name: front-end
configPatches:
- applyTo: HTTP_FILTER
match:
context: SIDECAR_INBOUND
listener:
portNumber: 8079
filterChain:
filter:
name: "envoy.filters.network.http_connection_manager"
subFilter:
name: "envoy.filters.http.router"
patch:
operation: INSERT_BEFORE
value:
name: envoy.filters.http.lua
typed_config:
"@type": "type.googleapis.com/envoy.extensions.filters.http.lua.v3.Lua"
inlineCode: |
JSON = (loadfile "/var/lib/lua/JSON.lua")()
aggre = {}
function element_counts(response_handle, response_body, depth)
response_handle:logInfo("invoke; depth="..tostring(depth))
local counter = 0
for k,v in pairs(response_body) do
if type(v) == "table" then
counter = counter + 1
element_counts(response_handle, v, depth+1)
else
counter = counter + 1
end
end
if aggre[depth] == nil then
aggre[depth] = counter
else
aggre[depth] = counter + aggre[depth]
end
end
function envoy_on_response(response_handle)
response_handle:logInfo("Start envoy_on_response 1")
local body_obj = response_handle:body()
local log_suffix = ""
if body_obj ~= nil then
local body_bytes = body_obj:getBytes(0, body_obj:length())
response_handle:logInfo("Body:"..body_bytes)
local raw_json_text = tostring(body_bytes)
local body_json = JSON:decode(raw_json_text)
element_counts(response_handle, body_json, 1)
log_suffix = table.concat(aggre, ", ")
response_handle:logInfo(log_suffix)
aggre = {}
end
response_handle:headers():add("log-suffix", log_suffix)
end