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
Backend mode in varnishncsa #1905
Backend mode in varnishncsa #1905
Conversation
if (t->type != VSL_t_req) | ||
/* Only look at client requests */ | ||
/* In client mode, only look at client requests. | ||
In bacend mode, only look at backend requests. */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing 'k'
I like this but I think we should add support for both -b and -c, and let the user decide without forcing them to run 2 separate processes. This is inline with the rest of the tools. Having to run multiple varnishncsa instances is not ideal from the admin POV. For this to make more sense we'll need to add a format to log whether this is "b"ackend or "c"lient, much as we do in varnishlog for example. |
534d56a
to
317bbc6
Compare
@@ -134,8 +135,8 @@ struct ctx { | |||
|
|||
/* State */ | |||
struct watch_head watch_vcl_log; | |||
struct watch_head watch_reqhdr; | |||
struct watch_head watch_resphdr; | |||
struct watch_head watch_reqhdr; /* also breqhdr */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo. should be bereqhdr
317bbc6
to
a8c7e26
Compare
2 wrongs don't make one right. I'd take code duplication any time over unreadable code. Also, why there are these if .. break when you have the:
|
If I were not to safeguard against bad behavior, then all the if() break; statements would go away. I made a choice, and If the consensus is that it was the wrong one, then I will change it. I guess what I am trying to say is that someone (probably @mbgrydeland) should just decide how it should be, so that I can implement it and we can move on to something else. |
I have thought a lot about this, and think I have found a way to make everyone happy when it comes to readability, maintainability and function. I will update the pull request "soon", and then everyone can look at it again. However, I need to go bug hunting a bit first, on a different part of the code. |
a8c7e26
to
c8f5e6a
Compare
I have now slightly rewritten the most problematic code, and implemented mixed mode (both client and backend requests in the same log). I hope the code is easier to read, easier to maintain, and that the behavior of the old varnishncsa is kept exactly. The switch construction is a bit hackish, but I hope you will like it anyway. |
c8f5e6a
to
245f93e
Compare
} else if (t->type == VSL_t_bereq && CTX.b_opt) { | ||
CTX.side = "backend"; | ||
be_mark = BACKEND_MARKER; | ||
} else continue; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply?
if ((t->type == VSL_t_req && !CTX.c_opt) ||
(t->type == VSL_t_bereq && !CTX.b_opt))
continue;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also perhaps use "c" and "b" to be in sync with other tools, e.g. varnishlog?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"c" and "b" is probably better, yes. Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The if test
if ((t->type == VSL_t_req && !CTX.c_opt) ||
(t->type == VSL_t_bereq && !CTX.b_opt))
continue;
does not work when both b_opt and c_opt are set. Also, similar constructions would remove safety against "impossible" combinations like SLT_PipeAcct when t->type == VSL_t_bereq . In the current version this bad behavior from varnish would be ignored, and I want to keep the current behavior in the new version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In varnishncsa, the variable CTX already had an a_opt member, so for the two other options, b_opt and c_opt was chosen.
Not sure what you meant.
does not work when both b_opt and c_opt are set. Also, similar constructions would remove safety against "impossible" combinations like SLT_PipeAcct when t->type == VSL_t_bereq . In the current version this bad behavior from varnish would be ignored, and I want to keep the current behavior in the new version.
Ugh? How come it will not work?
I don't think the impossible scenarios justify the extra code. If you are concerned about SLT_PipeAcct you can check that particular one. We have different records (e.g. ReqHeader vs BereqHeader) for that specific purpose.
The code does not handle backend records in client requests either.
245f93e
to
154fda0
Compare
Not sure what you meant.
Ugh? How come it will not work? |
I misunderstood, but Dag cleared it up for me, so I changed the reply. You were right all along about "c" and "b" being better than "client" and "backend".
if
If a client request is coming in, then I just looked at the code immediately below the switch, and realized that
is wrong, and I should consider |
varnishncsa only support vxid or request grouping mode. No other records are possible IIRC. |
(void)vsl; | ||
(void)priv; | ||
|
||
#define BACKEND_MARKER VSL_t__MAX |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I liked this better when BACKEND_MARKER was waaay higher than VSL_t__MAX. If the varnishlog and varnishd binaries are out of sync (not completely unlikely if e.g. one considers a log sent to support), then there can be strangeness observed.
Pushing again, after editing according to @mbgrydeland's wishes... |
154fda0
to
8c6086c
Compare
This log record is a counterpart to the SLT_ReqStart for backends, and shows the socket endpoint we are talking to at the start of backend requests. Today this information is only logged on opening a backend connection (SLT_BackendOpen), and is thus not available on the backend log transaction when on a reused backend connection. We need this information to complete the backend view varnishncsa extension.
A new mode, backend mode, in varnishncsa is introduced. It lets you log trafic from varnish to the backends. The normal (default) mode is now named "client mode" and can be explicitly selected using -c. You can run varnishncsa in backend mode in addition to varnishncsa in client mode, but it is also possible to run in mixed mode by specifying both -b and -c. New formatter added: %{Varnish:side}x will be either "b" or "c", depending on where the request was made.
8c6086c
to
eb6ed80
Compare
Now @mbgrydeland has made a patch that adds logging in varnishd, necessary to log the IP of the backend correctly, and this is now part of this pull request (first commit). The second commit is the backend mode in varnishncsa. |
Merged into master and 4.1 manually (fast forward). |
A new mode, backend mode, in varnishncsa is introduced. It lets you
log trafic from varnish to the backends. Typically you will run this
in addition to varnishncsa in normal mode.