Skip to content

Commit

Permalink
[#263] add setting header Model-Endpoint if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelbotsman committed Jan 9, 2019
1 parent 5250aba commit 55048d8
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions k8s/edge/nginx.conf.ltmpl
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,7 @@ http {
-- arg[2] is true if this is the last chunk

local edge = require("edge")
local endpoint_header = ngx.header["Model-Endpoint"]
local chunkInfo = edge.catch_model_api_response_chunk("{{ model_endpoint.model_service.id }}", "{{ model_endpoint.model_service.version }}",
endpoint_header, ngx.arg[1], ngx.arg[2])
local chunkInfo = edge.catch_model_api_response_chunk("{{ model_endpoint.model_service.id }}", "{{ model_endpoint.model_service.version }}", ngx.arg[1], ngx.arg[2])

if chunkInfo then
local fluentd_logger = require "fluentd_logger"
Expand Down Expand Up @@ -155,6 +153,14 @@ http {
ngx.log(ngx.INFO, "Request ID has been generated: "..requestID)
end

-- Model-Endpoint generation if it is missing
local model_endpoint = ngx.req.get_headers()["Model-Endpoint"]
if not model_endpoint then
model_endpoint = "default"
ngx.req.set_header("Model-Endpoint", model_endpoint)
ngx.log(ngx.INFO, "Model Endpoint has been set to "..model_endpoint)
end

ngx.header["Request-ID"] = requestID
}

Expand All @@ -172,12 +178,11 @@ http {
-- HTTP requests timing metrics for statsd
local statistics_sender = require "statistics_sender"
local latency = math.floor((ngx.now() - ngx.req.start_time()) * 1000)
statistics_sender.send_request_statistics("{{ model_endpoint.model_service.metrics_name }}", endpoint_header, latency)
statistics_sender.send_request_statistics("{{ model_endpoint.model_service.metrics_name }}", latency)

-- Request info gathering
local edge = require("edge")
local requestInfo = edge.catch_model_api_call("{{ model_endpoint.model_service.id }}", "{{ model_endpoint.model_service.version }}",
endpoint_header)
local requestInfo = edge.catch_model_api_call("{{ model_endpoint.model_service.id }}", "{{ model_endpoint.model_service.version }}")

local fluentd_logger = require "fluentd_logger"
fluentd_logger.post(ngx.req.start_time(), "request_response", requestInfo)
Expand Down

0 comments on commit 55048d8

Please sign in to comment.