Skip to content

Commit 9d2ebd4

Browse files
committed
Switch from ngx_txid to lua-resty-txid for generating request IDs.
The IDs should be functionally equivalent, this is just a pure-Lua implementation to reduce our need for custom nginx modules.
1 parent 4ac3d48 commit 9d2ebd4

File tree

5 files changed

+16
-23
lines changed

5 files changed

+16
-23
lines changed

build/cmake/app-deps/core-lua-deps.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ set(OPM_LIBCIDR_VERSION 0.1.3)
3030
set(OPM_LIBCIDR_HASH 9d995b83a7d857fcdec949725711b784)
3131
set(OPM_RESTY_HTTP_VERSION 0.12)
3232
set(OPM_RESTY_HTTP_HASH edc5d6deb82c1f5f628e382290c79209)
33+
set(OPM_RESTY_TXID_VERSION 1.0.0)
34+
set(OPM_RESTY_TXID_HASH 0c2ebfef460d537316e52f696d8bbfb7)
3335

3436
# LuaRock app dependencies
3537
luarocks_install(argparse ${LUAROCK_ARGPARSE_VERSION} ${LUAROCK_ARGPARSE_HASH})
@@ -45,6 +47,7 @@ luarocks_install(penlight ${LUAROCK_PENLIGHT_VERSION} ${LUAROCK_PENLIGHT_HASH})
4547
# OPM app dependencies
4648
opm_install(lua-libcidr-ffi GUI ${OPM_LIBCIDR_VERSION} ${OPM_LIBCIDR_HASH} libcidr)
4749
opm_install(lua-resty-http pintsized ${OPM_RESTY_HTTP_VERSION} ${OPM_RESTY_HTTP_HASH})
50+
opm_install(lua-resty-txid GUI ${OPM_RESTY_TXID_VERSION} ${OPM_RESTY_TXID_HASH})
4851

4952
ExternalProject_Add(
5053
opm_lua-icu-date
@@ -127,6 +130,7 @@ set(
127130
opm_lua-icu-date
128131
opm_lua-libcidr-ffi
129132
opm_lua-resty-http
133+
opm_lua-resty-txid
130134
)
131135

132136
# Also depend on the internal stamp files used by ExternalProject_Add, since

build/cmake/deps/openresty.cmake

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ set(LUAROCKS_VERSION 2.4.4)
66
set(LUAROCKS_HASH 04e8b19d565e86b1d08f745adc4b1a56)
77
set(NGX_DYUPS_VERSION a5e75737e04ff3e5040a80f5f739171e96c3359c)
88
set(NGX_DYUPS_HASH e16860efcd0629f38f514469052d998a)
9-
set(NGX_TXID_VERSION f1c197cb9c42e364a87fbb28d5508e486592ca42)
10-
set(NGX_TXID_HASH 408ee86eb6e42e27a51514f711c41d6b)
119
set(OPENRESTY_VERSION 1.13.6.1)
1210
set(OPENRESTY_HASH 637f82d0b36c74aec1c01bd3b8e0289c)
1311
set(OPENSSL_VERSION 1.0.2o)
@@ -28,19 +26,6 @@ ExternalProject_Add(
2826
ExternalProject_Get_Property(ngx_dyups SOURCE_DIR)
2927
set(NGX_DYUPS_SOURCE_DIR ${SOURCE_DIR})
3028

31-
# ngx_txid: Generate unique request IDs
32-
ExternalProject_Add(
33-
ngx_txid
34-
EXCLUDE_FROM_ALL 1
35-
URL https://github.com/streadway/ngx_txid/archive/${NGX_TXID_VERSION}.tar.gz
36-
URL_HASH MD5=${NGX_TXID_HASH}
37-
CONFIGURE_COMMAND ""
38-
BUILD_COMMAND ""
39-
INSTALL_COMMAND ""
40-
)
41-
ExternalProject_Get_Property(ngx_txid SOURCE_DIR)
42-
set(NGX_TXID_SOURCE_DIR ${SOURCE_DIR})
43-
4429
# Pull in newer version of PCRE (8.20+) for OpenResty to enable PCRE JIT.
4530
ExternalProject_Add(
4631
pcre
@@ -85,12 +70,11 @@ list(APPEND OPENRESTY_CONFIGURE_CMD --with-http_realip_module)
8570
list(APPEND OPENRESTY_CONFIGURE_CMD --with-http_ssl_module)
8671
list(APPEND OPENRESTY_CONFIGURE_CMD --with-http_stub_status_module)
8772
list(APPEND OPENRESTY_CONFIGURE_CMD --add-module=${NGX_DYUPS_SOURCE_DIR})
88-
list(APPEND OPENRESTY_CONFIGURE_CMD --add-module=${NGX_TXID_SOURCE_DIR})
8973

9074
ExternalProject_Add(
9175
openresty
9276
EXCLUDE_FROM_ALL 1
93-
DEPENDS libgeoip ngx_dyups ngx_txid openssl pcre
77+
DEPENDS libgeoip ngx_dyups openssl pcre
9478
URL https://openresty.org/download/openresty-${OPENRESTY_VERSION}.tar.gz
9579
URL_HASH MD5=${OPENRESTY_HASH}
9680
BUILD_IN_SOURCE 1

scripts/rake/outdated_packages.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ class OutdatedPackages
100100
:git => "https://github.com/yzprofile/ngx_http_dyups_module.git",
101101
:git_ref => "master",
102102
},
103-
"ngx_txid" => {
104-
:git => "https://github.com/streadway/ngx_txid.git",
105-
:git_ref => "master",
106-
},
107103
"nodejs" => {
108104
:git => "https://github.com/nodejs/node.git",
109105
:constraint => "~> 8.10",
@@ -128,6 +124,9 @@ class OutdatedPackages
128124
"opm_resty_http" => {
129125
:git => "https://github.com/pintsized/lua-resty-http.git",
130126
},
127+
"opm_resty_txid" => {
128+
:git => "https://github.com/GUI/lua-resty-txid.git",
129+
},
131130
"pcre" => {
132131
:http => "https://ftp.pcre.org/pub/pcre/",
133132
},

src/api-umbrella/proxy/hooks/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
DEBUG = false
22

3+
-- Pre-load modules.
4+
require "resty.txid"
5+
36
inspect = require "inspect"
47

58
-- Generate a unique ID to represent this group of worker processes. This value

templates/etc/nginx/gatekeeper.conf.mustache

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
1-
set $x_api_umbrella_request_id $txid;
2-
proxy_set_header X-Api-Umbrella-Request-ID $txid;
1+
set_by_lua_block $x_api_umbrella_request_id {
2+
local txid = require "resty.txid"
3+
return txid()
4+
}
5+
proxy_set_header X-Api-Umbrella-Request-ID $x_api_umbrella_request_id;
36

47
# Normalize the Accept-Encoding header to increase cache hit rates.
58
# We're not currently using TrafficServer, but this is based on what it does by

0 commit comments

Comments
 (0)