Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Usage with kubernetes/ingress-nginx #1

Open
zaslavskii opened this issue Mar 26, 2021 · 2 comments
Open

Usage with kubernetes/ingress-nginx #1

zaslavskii opened this issue Mar 26, 2021 · 2 comments

Comments

@zaslavskii
Copy link

zaslavskii commented Mar 26, 2021

Hi!
I'm trying to compile custom dynamic module and use it with ingress-controller 0.44.0 (https://github.com/kubernetes/ingress-nginx/). I made a fork to slightly modify config file to compile it as a dynamic module. https://github.com/chainstack/ngx_http_websocket_stat_module

The resulting dynamic module works fine with pure nginx 1.19.6. But the problem is that when I'm trying to use with ingress-nginx image, it does nothing. No frames are logged and no errors appear:(

I know that it's not a problem of the module itself, but maybe you guys can advise me smth to look at.

This is the dockerfile I came up with to build an nginx with the dynamic module inside.

FROM k8s.gcr.io/ingress-nginx/controller:v0.44.0 as builder
USER root
WORKDIR /tmp
RUN apk add git openssl-dev pcre-dev zlib-dev libc-dev gcc make
RUN NGINX_VERSION=$(nginx -v 2>&1 | sed 's/nginx version: nginx\///') && \
    wget -qO- https://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz | tar xvz && \
    mv nginx-${NGINX_VERSION} nginx
RUN git clone --depth 1 --branch v1.0.0 https://github.com/chainstack/ngx_http_websocket_stat_module.git && \
    cd ./nginx && \
    ./configure  --with-compat --add-dynamic-module=../ngx_http_websocket_stat_module && make modules
FROM k8s.gcr.io/ingress-nginx/controller:v0.44.0
COPY --from=builder /tmp/nginx/objs/ngx_http_websocket_stat_module.so /etc/nginx/modules

The way I was testing it is the following:

  1. I ran docker container from the image
  2. Added load_module /etc/nginx/modules/ngx_http_websocket_stat_module.so; to /etc/nginx/nginx.conf file
  3. Added an nginx service and location sections that accept websocket and proxies it to a dummy websocket backend.
  4. Finally added ws_log* directives to the added service.

P.S.
Maybe you guys know some other way that allows to log each time frame goes through websocket connection.

@zaslavskii
Copy link
Author

This fixes the issue:

diff --git a/ngx_http_websocket_stat_module.c b/ngx_http_websocket_stat_module.c
index f74a386..b81bf2d 100644
--- a/ngx_http_websocket_stat_module.c
+++ b/ngx_http_websocket_stat_module.c
@@ -394,7 +394,7 @@ ngx_http_websocket_stat_body_filter(ngx_http_request_t *r, ngx_chain_t *in)
     template_ctx_s template_ctx;
     template_ctx.ws_ctx = ctx;
 
-    if (r->upstream->upgrade) {
+    if (r->headers_in.upgrade) {
         if (r->upstream->peer.connection) {
             // connection opened
             ctx = ngx_pcalloc(r->pool, sizeof(ngx_http_websocket_stat_ctx));

@JonathanHuot sorry for troubling you on such an outdated repo, but I'd appreciate if you could help me a little. I'd like to know if you guys stopped maintaining this module. If so, could you advise smth with similar functionality. I'm looking for a way to log every time a new message is sent/received over WS.

@alexmeise
Copy link

Any updates on the topic? I am interested in alternatives as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants