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

balancer_by_lua #7

Closed
wants to merge 17 commits into from
Closed

balancer_by_lua #7

wants to merge 17 commits into from

Conversation

splitice
Copy link

@splitice splitice commented Feb 4, 2016

Here is my first attempt at porting balancer_by_lua from the http module to stream.

TODO:

  • Implement ngx_stream_lua_ffi_balancer_get_last_failure, if its possible?

If you have any comments, please dont hesitate. This is an early pull request to facilitate that discussion. I have tried to make it a direct conversion, and used a few string replacements where possible, some comments are hence a bit silly.

I have also thrown #if (NGX_DEBUG) around the unused ngx_connection_t's that where annoying me with errors (and with the right flags, warnings). I can take them out, but I guess they are a plus?

@agentzh
Copy link
Member

agentzh commented Feb 4, 2016

@splitice Thanks for looking into this. Will you port the tests too?

@splitice
Copy link
Author

splitice commented Feb 4, 2016

I dont have an environment to run them, but a bit of regex would probably do the configuration changes necessary. The error messages would need to be done manually I guess.

I'd be happy to do that much.

@agentzh
Copy link
Member

agentzh commented Feb 4, 2016

@splitice There are perl scripts under util/ that can do most of the modifications needed when porting the tests.

@splitice
Copy link
Author

splitice commented Feb 4, 2016

I'll take a look, its probably not dissimilar to what I whipped up.

Currently looking for the cause of a bug, s->connection->log is null in the balancer context causing a segfault when any error occurs or with ngx.log.

@splitice
Copy link
Author

splitice commented Feb 4, 2016

Fix stream session session passing, now it works. Successfully set the current peer to a dynamic value.

{
lua_State *L;
ngx_int_t rc;
ngx_stream_session_t *r;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to run the ngx-releng script to catch obvious NGINX coding style issues like this :) See

https://github.com/openresty/nginx-devel-utils

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't tell me anything for some reason.

# ./ngx-releng
=======================================
# ls -las src
0 lrwxrwxrwx 1 root root 30 Feb  4 19:37 src -> ../stream-lua-nginx-module/src
# ls -las src/ | head -n 6
total 1064
  4 drwxr-xr-x 3 root root   4096 Feb  3 19:14 .
  4 drwxr-xr-x 6 root root   4096 Feb  3 19:21 ..
  4 drwxr-xr-x 2 root root   4096 Feb  3 19:14 api
  4 -rw-r--r-- 1 root root    771 Feb  3 19:13 ddebug.h
 16 -rw-r--r-- 1 root root  15790 Feb  4 18:15 ngx_stream_lua_balancer.c

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@splitice Found a lot of things on your PR's branch on my side:

agentzh@fedora64 ~/git/stream-lua-nginx-module (master)$ which ngx-releng
~/git/nginx-devel-utils/ngx-releng
gentzh@fedora64 ~/git/stream-lua-nginx-module (master)$ g hub pr-fetch 7
remote: Counting objects: 42, done.
remote: Compressing objects: 100% (42/42), done.
g remote: Total 42 (delta 22), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (42/42), done.
From github.com:openresty/stream-lua-nginx-module
 * [new ref]         refs/pull/7/head -> PR/7
agentzh@fedora64 ~/git/stream-lua-nginx-module (master)$ g co PR/7
Switched to branch 'PR/7'
agentzh@fedora64 ~/git/stream-lua-nginx-module (PR/7)$ ngx-releng
=======================================
src/ngx_stream_lua_balancer.h
14:ngx_int_t ngx_stream_lua_balancer_handler_inline(ngx_stream_session_t *s, ngx_log_t *r,
17:ngx_int_t ngx_stream_lua_balancer_handler_file(ngx_stream_session_t *s, ngx_log_t *r,

src/ngx_stream_lua_balancer.c
174:        p = ngx_copy(p, NGX_STREAM_LUA_INLINE_TAG, NGX_STREAM_LUA_INLINE_TAG_LEN);
220:    bp = ngx_pcalloc(r->connection->pool, sizeof(ngx_stream_lua_balancer_peer_data_t));
333:ngx_stream_lua_balancer_by_chunk(lua_State *L, ngx_log_t *log, ngx_stream_session_t *s)

src/ngx_stream_lua_common.h
118:typedef ngx_int_t (*ngx_stream_lua_srv_conf_handler_pt)(ngx_stream_session_t *s, ngx_log_t *log,
src/ngx_stream_lua_balancer.c
547:    //ngx_stream_upstream_state_t  *state;
src/ngx_stream_lua_phase.c
60:
61:

src/ngx_stream_lua_balancer.c
532:

src/ngx_stream_lua_module.c
107:

src/ngx_stream_lua_common.h
117:
165:
232:
src/ngx_stream_lua_balancer.c
533:    *err = NULL;
544:    /* NOT PORTED: IS IT POSSIBLE? */

src/ngx_stream_lua_common.h
233:    struct {
t/123-lua-path.t
19:master_on();
t/servroot/logs/error.log
t/cert/equifax.crt
t/cert/startcom.crt
src/api/ngx_stream_lua_api.h
22:#define ngx_stream_lua_version  1

src/ngx_stream_lua_phase.c:
found unnecessary tail space
60:
found unnecessary tail space
61:

src/ngx_stream_lua_balancer.c:
incorrect front space, unclosed bracket
60:                                      lscf->balancer.src.data,
incorrect front space, unclosed bracket
80:                                        lscf->balancer.src.data,
variable name should align with the previous line
121:     ngx_stream_lua_srv_conf_t     *lscf = conf;
incorrect front space, unclosed bracket
144:                                         value[1].len);
variable name should align with the previous line
249:     ngx_stream_session_t                 *r;
variable name should align with the previous line
413:     ngx_stream_lua_ctx_t    *ctx;
found unnecessary tail space
532:

src/ngx_stream_lua_module.c:
found unnecessary tail space
107:

src/ngx_stream_lua_common.h:
found unnecessary tail space
117:
found unnecessary tail space
165:
found unnecessary tail space
232:
incorrect front space, level indent
234:         ngx_str_t           src;
done.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@splitice Are you sure your nginx-devel-utils clone is up to date? Also, better add the path of your nginx-devel-utils directory to your PATH environment.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@splitice The git master is clean BTW:

agentzh@fedora64 ~/git/stream-lua-nginx-module (master)$ ngx-releng
=======================================
t/123-lua-path.t
19:master_on();
t/servroot/logs/error.log
t/cert/equifax.crt
t/cert/startcom.crt
src/api/ngx_stream_lua_api.h
22:#define ngx_stream_lua_version  1
done.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its the latest, I just cloned it now.

I just created a symlink to src in the directory out of lazyness so the scripts are in the cwd/pwd.

agentzh added a commit that referenced this pull request Feb 5, 2016
…ithout --with-debug. thanks Mathew Heard for the report in #7.
@splitice
Copy link
Author

splitice commented Feb 5, 2016

There is a bunch of style fixes

@agentzh
Copy link
Member

agentzh commented Feb 5, 2016

@splitice The ngx-releng tool does not follow symlinks BTW.

@agentzh
Copy link
Member

agentzh commented Feb 5, 2016

@splitice Thanks for your quick updates.

@doujiang24 Please have a look at this PR when you have a chance. Thanks!

@daxiong380380
Copy link

@splitice
Could you give me your balancer_by_lua source code,I'd like to have a look.
Thank you.

@splitice
Copy link
Author

This is a pull request for the code.

@daxiong380380
Copy link

@splitice
The pull request has not been accepted,has it ?
How can I get your source code?

@splitice
Copy link
Author

@daxiong380380
Copy link

daxiong380380 commented Jun 28, 2016

@splitice
In the page of https://github.com/splitice/stream-lua-nginx-module , there is no description to tell us how to use this function,also we'd like to know the detail introduction .

@daxiong380380
Copy link

@splitice
Hi,
Cloud you give me some advises to use the function of balance_by_lua,I have been trapped here for long time,please help me.
One more question,In the balancer_by_lua_block,can I set the proxy address .

@agentzh
Copy link
Member

agentzh commented Jun 30, 2016

@daxiong380380 balancer_by_lua* is officially documented in lua-nginx-module:

https://github.com/openresty/lua-nginx-module#balancer_by_lua_block

What is implemented here should be (mostly) compatible.

@agentzh agentzh mentioned this pull request Jun 30, 2016
@rshriram
Copy link

@agentzh any ETA on when this PR will be merged? What needs to be done to get this merged into upstream? I can try to help, if I manage to get my head around the nginx module stuff.

int *status, char **err)
{

// This is not yet implemented.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Style: bad indentation and the C++-style line comments should be avoided.

@agentzh
Copy link
Member

agentzh commented Jul 20, 2016

This needs to be rebased to the latest master branch before it can get merged.

Also it has various coding style issues that need to be fixed before the merge.

@agentzh
Copy link
Member

agentzh commented Jul 20, 2016

@rshriram No ETA yet since it has unresolved issues (see my comments above).

@agentzh
Copy link
Member

agentzh commented Jul 20, 2016

We need to pass as many test cases as possible from ngx_http_lua_module for balancer_by_lua* and ngx.balancer here.

@splitice
Copy link
Author

I currently do not have any time to spend on this patch. PR's welcome to my fork.

I am happy to re-base, but without style work its frivolous currently. I just don't have time for that currently.

@rshriram
Copy link

rshriram commented Aug 9, 2016

@splitice @agentzh I have fixed all the styling issues.. and my branch is here: https://github.com/rshriram/stream-lua-nginx-module
Should I send a PR to @splitice so that the issue history is maintained, or shall I open up a new PR ? All of @splitice 's commit history is maintained in either case. Just want to avoid the extra hop.

@agentzh
Copy link
Member

agentzh commented Aug 9, 2016

@rshriram Creating your own PR is more convenient given that @splitice is busy atm.

@splitice
Copy link
Author

No concerns on my end, do whichever is easiest / Github allows :)

@splitice
Copy link
Author

Closed in favour of further work by @rshriram

@splitice splitice closed this Sep 23, 2016
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

Successfully merging this pull request may close these issues.

4 participants