-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path09-counts-release2.yml
58 lines (58 loc) · 2.01 KB
/
09-counts-release2.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
apiVersion: networking.istio.io/v1alpha3
kind: EnvoyFilter
metadata:
name: counts-release2
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(request_handle, request_body, depth)
local counter = 0
for k,v in pairs(request_body) do
if type(v) == "table" then
counter = counter + 1
element_counts(request_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_request(request_handle)
local body_obj = request_handle:body()
if body_obj ~= nil then
local body_bytes = body_obj:getBytes(0, body_obj:length())
request_handle:logCritical("Body:"..body_bytes)
local raw_json_text = tostring(body_bytes)
local body_json = JSON:decode(raw_json_text)
element_counts(request_handle, body_json, 1)
local log_suffix = table.concat(aggre, ", ")
request_handle:logCritical(log_suffix)
aggre = {}
end
end