Skip to content

Commit 8cbb808

Browse files
committed
clean up dynamic lua filter
1 parent 338e947 commit 8cbb808

File tree

2 files changed

+4
-80
lines changed

2 files changed

+4
-80
lines changed

helm/supersonic/cfg/envoy-filter-dynamic.lua

Lines changed: 2 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -2,61 +2,6 @@ function envoy_on_request(request_handle)
22
local path = request_handle:headers():get(":path")
33
local contentType = request_handle:headers():get("content-type")
44

5-
if path == "/inference.GRPCInferenceService/RepositoryIndex" and contentType == "application/grpc" then
6-
request_handle:streamInfo():dynamicMetadata():set("envoy.lua", "accept_request", false)
7-
8-
local query = SERVER_LOAD_METRIC
9-
local metric_threshold = tonumber(SERVER_LOAD_THRESHOLD)
10-
local query_response_template = '"value":%[%d+%.%d+,"([%d%.]+)"%]'
11-
local encoded_query = encode_query(query)
12-
13-
request_handle:logInfo("Prometheus scheme: " .. "PROMETHEUS_SCHEME")
14-
request_handle:logInfo("Prometheus host: " .. "PROMETHEUS_HOST")
15-
request_handle:logInfo("Prometheus port: " .. "PROMETHEUS_PORT")
16-
request_handle:logInfo("Query: " .. query)
17-
request_handle:logInfo("Encoded query: " .. encoded_query)
18-
19-
local headers, body = request_handle:httpCall(
20-
"prometheus_cluster",
21-
{
22-
[":method"] = "GET",
23-
[":path"] = "/api/v1/query?query=" .. encoded_query,
24-
[":scheme"] = "PROMETHEUS_SCHEME",
25-
[":authority"] = "PROMETHEUS_HOST" .. ":" .. "PROMETHEUS_PORT"
26-
},
27-
"",
28-
5000
29-
)
30-
if not headers then
31-
request_handle:logErr("HTTP call to Prometheus failed.")
32-
return
33-
end
34-
35-
if not body or body == "" then
36-
request_handle:logErr("Prometheus could not be reached or returned no data.")
37-
return
38-
end
39-
40-
request_handle:logInfo("Query response body: " .. body)
41-
local metric_value_str = string.match(body, query_response_template)
42-
request_handle:logInfo("Extracted metric: " .. metric_value_str)
43-
44-
if metric_value_str then
45-
local metric_value = tonumber(metric_value_str)
46-
if metric_value > metric_threshold then
47-
request_handle:logInfo("Metric value exceeds threshold: " .. metric_value .. " > " .. metric_threshold)
48-
else
49-
request_handle:logInfo("Metric value below threshold: " .. metric_value .. " < " .. metric_threshold)
50-
request_handle:streamInfo():dynamicMetadata():set("envoy.lua", "accept_request", true)
51-
end
52-
else
53-
request_handle:logErr("Failed to parse metric value from Prometheus response.")
54-
---- Temporary ----
55-
request_handle:logErr("Accepting request regardless of metric value.")
56-
request_handle:streamInfo():dynamicMetadata():set("envoy.lua", "accept_request", true)
57-
end
58-
end
59-
605
---- Extract model_name from ModelInferRequest ----
616
if contentType == "application/grpc" then
627
if path == "/inference.GRPCInferenceService/ModelInfer" then
@@ -76,7 +21,7 @@ function envoy_on_request(request_handle)
7621
-- log and propagate via dynamic metadata
7722
request_handle:logInfo("ModelInfer model_name = " .. model_name)
7823
if model_name then
79-
local hostHeader = model_name .. ".cms.svc.cluster.local:8001"
24+
local hostHeader = model_name .. ".NAMESPACE.svc.cluster.local:8001"
8025
request_handle:logInfo("route-to = " .. hostHeader)
8126
request_handle:headers():add("route-to", hostHeader)
8227
end
@@ -89,30 +34,7 @@ function envoy_on_request(request_handle)
8934
end
9035
else
9136
--- for non-inference calls, for now just forward to default service
92-
request_handle:headers():add("route-to", "supersonic-test-triton.cms.svc.cluster.local:8001")
93-
end
94-
end
95-
end
96-
97-
function envoy_on_response(response_handle)
98-
local md = response_handle:streamInfo():dynamicMetadata():get("envoy.lua")
99-
100-
if not md or md.accept_request == nil then
101-
return
102-
end
103-
104-
if not response_handle:streamInfo():dynamicMetadata():get("envoy.lua")["accept_request"] then
105-
response_handle:logInfo("Sending error as a response.")
106-
local body = response_handle:body()
107-
if body then
108-
body:setBytes("")
37+
request_handle:headers():add("route-to", "RELEASE-triton.NAMESPACE.svc.cluster.local:8001")
10938
end
110-
response_handle:headers():replace("grpc-status", "1")
11139
end
112-
end
113-
114-
function encode_query(query)
115-
return query:gsub("([^%w _%%%-%.~])", function(c)
116-
return string.format("%%%02X", string.byte(c))
117-
end):gsub(" ", "+")
11840
end

helm/supersonic/templates/envoy/configmaps.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,8 @@ data:
282282
{{- $luaConfig = $luaConfig | replace "PROMETHEUS_SCHEME" (include "supersonic.prometheusScheme" .) }}
283283
{{- $luaConfig = $luaConfig | replace "PROMETHEUS_HOST" (include "supersonic.prometheusHost" .) }}
284284
{{- $luaConfig = $luaConfig | replace "PROMETHEUS_PORT" (include "supersonic.prometheusPort" .) }}
285+
{{- $luaConfig = $luaConfig | replace "RELEASE" .Release.Name }}
286+
{{- $luaConfig = $luaConfig | replace "NAMESPACE" .Release.Namespace }}
285287
{{ $luaConfig | indent 4 }}
286288
287289
---

0 commit comments

Comments
 (0)