Commit 32240055 authored by Vaastav Anand's avatar Vaastav Anand

Add instrumentation to lua files

parent 87f3f60a
local _M = {} local _M = {}
local xtracer = require "luaxtrace"
function _M.WriteCastInfo() function _M.WriteCastInfo()
local bridge_tracer = require "opentracing_bridge_tracer" local bridge_tracer = require "opentracing_bridge_tracer"
local GenericObjectPool = require "GenericObjectPool" local GenericObjectPool = require "GenericObjectPool"
local CastInfoServiceClient = require 'media_service_CastInfoService' local CastInfoServiceClient = require 'media_service_CastInfoService'
local ngx = ngx local ngx = ngx
xtracer.StartLuaTrace("NginxWebServer", "WriteCastInfo")
xtracer.LogXTrace("Processing Request")
local cjson = require("cjson") local cjson = require("cjson")
local req_id = tonumber(string.sub(ngx.var.request_id, 0, 15), 16) local req_id = tonumber(string.sub(ngx.var.request_id, 0, 15), 16)
...@@ -21,6 +26,8 @@ function _M.WriteCastInfo() ...@@ -21,6 +26,8 @@ function _M.WriteCastInfo()
ngx.status = ngx.HTTP_BAD_REQUEST ngx.status = ngx.HTTP_BAD_REQUEST
ngx.say("Empty body") ngx.say("Empty body")
ngx.log(ngx.ERR, "Empty body") ngx.log(ngx.ERR, "Empty body")
xtracer.LogXTrace("Empty body")
xtracer.DeleteBaggage()
ngx.exit(ngx.HTTP_BAD_REQUEST) ngx.exit(ngx.HTTP_BAD_REQUEST)
end end
...@@ -30,14 +37,18 @@ function _M.WriteCastInfo() ...@@ -30,14 +37,18 @@ function _M.WriteCastInfo()
ngx.status = ngx.HTTP_BAD_REQUEST ngx.status = ngx.HTTP_BAD_REQUEST
ngx.say("Incomplete arguments") ngx.say("Incomplete arguments")
ngx.log(ngx.ERR, "Incomplete arguments") ngx.log(ngx.ERR, "Incomplete arguments")
xtracer.LogXTrace("Incomplete arguments")
xtracer.DeleteBaggage()
ngx.exit(ngx.HTTP_BAD_REQUEST) ngx.exit(ngx.HTTP_BAD_REQUEST)
end end
carrier["baggage"] = xtracer.BranchBaggage()
local client = GenericObjectPool:connection(CastInfoServiceClient, "cast-info-service", 9090) local client = GenericObjectPool:connection(CastInfoServiceClient, "cast-info-service", 9090)
client:WriteCastInfo(req_id, cast_info["cast_info_id"], cast_info["name"], local status, err = client:WriteCastInfo(req_id, cast_info["cast_info_id"], cast_info["name"],
cast_info["gender"], cast_info["intro"], carrier) cast_info["gender"], cast_info["intro"], carrier)
xtracer.JoinBaggage(err.baggage)
GenericObjectPool:returnConnection(client) GenericObjectPool:returnConnection(client)
xtracer.DeleteBaggage()
end end
return _M return _M
\ No newline at end of file
local _M = {} local _M = {}
local xtracer = require "luaxtrace"
function _M.WriteMovieInfo() function _M.WriteMovieInfo()
local bridge_tracer = require "opentracing_bridge_tracer" local bridge_tracer = require "opentracing_bridge_tracer"
...@@ -10,6 +10,9 @@ function _M.WriteMovieInfo() ...@@ -10,6 +10,9 @@ function _M.WriteMovieInfo()
local ngx = ngx local ngx = ngx
local cjson = require("cjson") local cjson = require("cjson")
xtracer.StartLuaTrace("NginxWebServer", "WriteMovieInfo")
xtracer.LogXtrace("Processing Request")
local req_id = tonumber(string.sub(ngx.var.request_id, 0, 15), 16) local req_id = tonumber(string.sub(ngx.var.request_id, 0, 15), 16)
local tracer = bridge_tracer.new_from_global() local tracer = bridge_tracer.new_from_global()
local parent_span_context = tracer:binary_extract(ngx.var.opentracing_binary_context) local parent_span_context = tracer:binary_extract(ngx.var.opentracing_binary_context)
...@@ -24,6 +27,8 @@ function _M.WriteMovieInfo() ...@@ -24,6 +27,8 @@ function _M.WriteMovieInfo()
ngx.status = ngx.HTTP_BAD_REQUEST ngx.status = ngx.HTTP_BAD_REQUEST
ngx.say("Empty body") ngx.say("Empty body")
ngx.log(ngx.ERR, "Empty body") ngx.log(ngx.ERR, "Empty body")
xtracer.LogXTrace("Empty body")
xtracer.DeleteBaggage()
ngx.exit(ngx.HTTP_BAD_REQUEST) ngx.exit(ngx.HTTP_BAD_REQUEST)
end end
...@@ -36,6 +41,8 @@ function _M.WriteMovieInfo() ...@@ -36,6 +41,8 @@ function _M.WriteMovieInfo()
ngx.status = ngx.HTTP_BAD_REQUEST ngx.status = ngx.HTTP_BAD_REQUEST
ngx.say("Incomplete arguments") ngx.say("Incomplete arguments")
ngx.log(ngx.ERR, "Incomplete arguments") ngx.log(ngx.ERR, "Incomplete arguments")
xtracer.LogXTrace("Incomplete arguments")
xtracer.DeleteBaggage()
ngx.exit(ngx.HTTP_BAD_REQUEST) ngx.exit(ngx.HTTP_BAD_REQUEST)
end end
...@@ -49,14 +56,17 @@ function _M.WriteMovieInfo() ...@@ -49,14 +56,17 @@ function _M.WriteMovieInfo()
end end
carrier["baggage"] = xtracer.BranchBaggage()
local client = GenericObjectPool:connection(MovieInfoServiceClient, "movie-info-service", 9090) local client = GenericObjectPool:connection(MovieInfoServiceClient, "movie-info-service", 9090)
client:WriteMovieInfo(req_id, movie_info["movie_id"], movie_info["title"], local status, err = client:WriteMovieInfo(req_id, movie_info["movie_id"], movie_info["title"],
casts, movie_info["plot_id"], movie_info["thumbnail_ids"], casts, movie_info["plot_id"], movie_info["thumbnail_ids"],
movie_info["photo_ids"], movie_info["video_ids"], tostring(movie_info["avg_rating"]), movie_info["photo_ids"], movie_info["video_ids"], tostring(movie_info["avg_rating"]),
movie_info["num_rating"], carrier) movie_info["num_rating"], carrier)
ngx.say(movie_info["avg_rating"]) ngx.say(movie_info["avg_rating"])
xtracer.JoinBaggag(err.baggage)
GenericObjectPool:returnConnection(client) GenericObjectPool:returnConnection(client)
xtracer.DeleteBaggage()
end end
return _M return _M
\ No newline at end of file
local _M = {} local _M = {}
local xtracer = require "luaxtrace"
local function _StrIsEmpty(s) local function _StrIsEmpty(s)
return s == nil or s == '' return s == nil or s == ''
...@@ -10,6 +11,9 @@ function _M.RegisterMovie() ...@@ -10,6 +11,9 @@ function _M.RegisterMovie()
local MovieIdServiceClient = require'media_service_MovieIdService' local MovieIdServiceClient = require'media_service_MovieIdService'
local ngx = ngx local ngx = ngx
xtracer.StartLuaTrace("NginxWebServer", "RegisterMovie")
xtracer.LogXTrace("Processing Request")
local req_id = tonumber(string.sub(ngx.var.request_id, 0, 15), 16) local req_id = tonumber(string.sub(ngx.var.request_id, 0, 15), 16)
local tracer = bridge_tracer.new_from_global() local tracer = bridge_tracer.new_from_global()
local parent_span_context = tracer:binary_extract(ngx.var.opentracing_binary_context) local parent_span_context = tracer:binary_extract(ngx.var.opentracing_binary_context)
...@@ -24,15 +28,20 @@ function _M.RegisterMovie() ...@@ -24,15 +28,20 @@ function _M.RegisterMovie()
ngx.status = ngx.HTTP_BAD_REQUEST ngx.status = ngx.HTTP_BAD_REQUEST
ngx.say("Incomplete arguments") ngx.say("Incomplete arguments")
ngx.log(ngx.ERR, "Incomplete arguments") ngx.log(ngx.ERR, "Incomplete arguments")
xtracer.LogXTrace("Incomplete arguments")
xtracer.DeleteBaggage()
ngx.exit(ngx.HTTP_BAD_REQUEST) ngx.exit(ngx.HTTP_BAD_REQUEST)
end end
carrier["baggage"] = xtracer.BranchBaggage()
local client = GenericObjectPool:connection(MovieIdServiceClient,"movie-id-service",9090) local client = GenericObjectPool:connection(MovieIdServiceClient,"movie-id-service",9090)
client:RegisterMovieId(req_id, post.title, tostring(post.movie_id), carrier) local status, err = client:RegisterMovieId(req_id, post.title, tostring(post.movie_id), carrier)
xtracer.JoinBaggage(err.baggage)
GenericObjectPool:returnConnection(client) GenericObjectPool:returnConnection(client)
span:finish() span:finish()
xtracer.DeleteBaggage()
end end
return _M return _M
\ No newline at end of file
...@@ -8,6 +8,9 @@ function _M.WritePlot() ...@@ -8,6 +8,9 @@ function _M.WritePlot()
local ngx = ngx local ngx = ngx
local cjson = require("cjson") local cjson = require("cjson")
xtracer.StartLuaTrace("NginxWebServer", "WritePlot")
xtracer.LogXTrace("Processing Request")
local req_id = tonumber(string.sub(ngx.var.request_id, 0, 15), 16) local req_id = tonumber(string.sub(ngx.var.request_id, 0, 15), 16)
local tracer = bridge_tracer.new_from_global() local tracer = bridge_tracer.new_from_global()
local parent_span_context = tracer:binary_extract(ngx.var.opentracing_binary_context) local parent_span_context = tracer:binary_extract(ngx.var.opentracing_binary_context)
...@@ -22,6 +25,8 @@ function _M.WritePlot() ...@@ -22,6 +25,8 @@ function _M.WritePlot()
ngx.status = ngx.HTTP_BAD_REQUEST ngx.status = ngx.HTTP_BAD_REQUEST
ngx.say("Empty body") ngx.say("Empty body")
ngx.log(ngx.ERR, "Empty body") ngx.log(ngx.ERR, "Empty body")
xtracer.LogXTrace("Empty body")
xtracer.DeleteBaggage()
ngx.exit(ngx.HTTP_BAD_REQUEST) ngx.exit(ngx.HTTP_BAD_REQUEST)
end end
...@@ -30,12 +35,17 @@ function _M.WritePlot() ...@@ -30,12 +35,17 @@ function _M.WritePlot()
ngx.status = ngx.HTTP_BAD_REQUEST ngx.status = ngx.HTTP_BAD_REQUEST
ngx.say("Incomplete arguments") ngx.say("Incomplete arguments")
ngx.log(ngx.ERR, "Incomplete arguments") ngx.log(ngx.ERR, "Incomplete arguments")
xtracer.LogXTrace("Incomplete arguments")
xtracer.DeleteBaggage()
ngx.exit(ngx.HTTP_BAD_REQUEST) ngx.exit(ngx.HTTP_BAD_REQUEST)
end end
carrier["baggage"] = xtracer.BranchBaggage()
local client = GenericObjectPool:connection(PlotServiceClient, "plot-service", 9090) local client = GenericObjectPool:connection(PlotServiceClient, "plot-service", 9090)
client:WritePlot(req_id, plot["plot_id"], plot["plot"], carrier) local status, err = client:WritePlot(req_id, plot["plot_id"], plot["plot"], carrier)
xtracer.JoinBaggage(err.baggage)
GenericObjectPool:returnConnection(client) GenericObjectPool:returnConnection(client)
xtracer.DeleteBaggage()
end end
return _M return _M
...@@ -6,29 +6,38 @@ local function _StrIsEmpty(s) ...@@ -6,29 +6,38 @@ local function _StrIsEmpty(s)
end end
local function _UploadUserId(req_id, post, carrier, baggage) local function _UploadUserId(req_id, post, carrier, baggage)
xtracer.SetBaggage(baggage)
local GenericObjectPool = require "GenericObjectPool" local GenericObjectPool = require "GenericObjectPool"
local UserServiceClient = require 'media_service_UserService' local UserServiceClient = require 'media_service_UserService'
carrier["baggage"] = xtracer.BranchBaggage()
local user_client = GenericObjectPool:connection( local user_client = GenericObjectPool:connection(
UserServiceClient,"user-service",9090) UserServiceClient,"user-service",9090)
user_client:UploadUserWithUsername(req_id, post.username, carrier) local status, err = user_client:UploadUserWithUsername(req_id, post.username, carrier)
xtracer.JoinBaggage(err.baggage)
GenericObjectPool:returnConnection(user_client) GenericObjectPool:returnConnection(user_client)
end end
local function _UploadText(req_id, post, carrier, baggage) local function _UploadText(req_id, post, carrier, baggage)
xtracer.SetBaggage(baggage)
local GenericObjectPool = require "GenericObjectPool" local GenericObjectPool = require "GenericObjectPool"
local TextServiceClient = require 'media_service_TextService' local TextServiceClient = require 'media_service_TextService'
carrier["baggage"] = xtracer.BranchBaggage()
local text_client = GenericObjectPool:connection( local text_client = GenericObjectPool:connection(
TextServiceClient,"text-service",9090) TextServiceClient,"text-service",9090)
text_client:UploadText(req_id, post.text, carrier) local status, err = text_client:UploadText(req_id, post.text, carrier)
xtracer.JoinBaggage(err.baggage)
GenericObjectPool:returnConnection(text_client) GenericObjectPool:returnConnection(text_client)
end end
local function _UploadMovieId(req_id, post, carrier, baggage) local function _UploadMovieId(req_id, post, carrier, baggage)
xtracer.SetBaggage(baggage)
local GenericObjectPool = require "GenericObjectPool" local GenericObjectPool = require "GenericObjectPool"
local MovieIdServiceClient = require 'media_service_MovieIdService' local MovieIdServiceClient = require 'media_service_MovieIdService'
carrier["baggage"] = xtracer.BranchBaggage()
local movie_id_client = GenericObjectPool:connection( local movie_id_client = GenericObjectPool:connection(
MovieIdServiceClient,"movie-id-service",9090) MovieIdServiceClient,"movie-id-service",9090)
movie_id_client:UploadMovieId(req_id, post.title, tonumber(post.rating), carrier) local status, err = movie_id_client:UploadMovieId(req_id, post.title, tonumber(post.rating), carrier)
xtracer.JoinBaggage(err.baggage)
GenericObjectPool:returnConnection(movie_id_client) GenericObjectPool:returnConnection(movie_id_client)
end end
...@@ -69,15 +78,15 @@ function _M.ComposeReview() ...@@ -69,15 +78,15 @@ function _M.ComposeReview()
ngx.exit(ngx.HTTP_BAD_REQUEST) ngx.exit(ngx.HTTP_BAD_REQUEST)
end end
local movieid_baggage = xtracer.BranchBaggage()
local userid_baggage = xtracer.BranchBaggage() local userid_baggage = xtracer.BranchBaggage()
local movieid_baggage = xtracer.BranchBaggage()
local text_baggage = xtracer.BranchBaggage() local text_baggage = xtracer.BranchBaggage()
local uuid_baggage = xtracer.BranchBaggage() local uuid_baggage = xtracer.BranchBaggage()
local threads = { local threads = {
ngx.thread.spawn(_UploadUserId, req_id, post, carrier), ngx.thread.spawn(_UploadUserId, req_id, post, carrier, userid_baggage),
ngx.thread.spawn(_UploadMovieId, req_id, post, carrier), ngx.thread.spawn(_UploadMovieId, req_id, post, carrier, movieid_baggage),
ngx.thread.spawn(_UploadText, req_id, post, carrier), ngx.thread.spawn(_UploadText, req_id, post, carrier, text_baggage),
ngx.thread.spawn(_UploadUniqueId, req_id, carrier) ngx.thread.spawn(_UploadUniqueId, req_id, carrier, uuid_baggage)
} }
local baggages = { local baggages = {
......
...@@ -35,6 +35,7 @@ function _M.RegisterUser() ...@@ -35,6 +35,7 @@ function _M.RegisterUser()
local client = GenericObjectPool:connection(UserServiceClient, "user-service", 9090) local client = GenericObjectPool:connection(UserServiceClient, "user-service", 9090)
carrier["baggage"] = xtracer.BranchBaggage()
local status, err = client:RegisterUser(req_id, post.first_name, post.last_name, local status, err = client:RegisterUser(req_id, post.first_name, post.last_name,
post.username, post.password, carrier) post.username, post.password, carrier)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment