-
Notifications
You must be signed in to change notification settings - Fork 857
Add ability for stats over http to run as a remap plugin #12316
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -43,6 +43,7 @@ | |
| #include <zlib.h> | ||
|
|
||
| #include <ts/remap.h> | ||
| #include <ts/remap_version.h> | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Separate issue, but seeing this, makes me thing we ought to add the define from this file into ts/remap.h. |
||
| #include "swoc/TextView.h" | ||
| #include "tscore/ink_config.h" | ||
| #include <tsutil/ts_ip.h> | ||
|
|
@@ -653,7 +654,7 @@ stats_dostuff(TSCont contp, TSEvent event, void *edata) | |
| } | ||
|
|
||
| static int | ||
| stats_origin(TSCont contp, TSEvent /* event ATS_UNUSED */, void *edata) | ||
| stats_origin(config_t *this_config, TSEvent /* event ATS_UNUSED */, void *edata, bool is_remap) | ||
| { | ||
| TSCont icontp; | ||
| stats_state *my_state; | ||
|
|
@@ -670,7 +671,7 @@ stats_origin(TSCont contp, TSEvent /* event ATS_UNUSED */, void *edata) | |
| bool path_had_explicit_format = false; | ||
|
|
||
| Dbg(dbg_ctl, "in the read stuff"); | ||
| config = get_config(contp); | ||
| config = this_config; | ||
|
|
||
| if (TSHttpTxnClientReqGet(txnp, &reqp, &hdr_loc) != TS_SUCCESS) { | ||
| goto cleanup; | ||
|
|
@@ -783,6 +784,7 @@ stats_origin(TSCont contp, TSEvent /* event ATS_UNUSED */, void *edata) | |
|
|
||
| TSContDataSet(icontp, my_state); | ||
| TSHttpTxnIntercept(icontp, txnp); | ||
|
|
||
| goto cleanup; | ||
|
|
||
| notforme: | ||
|
|
@@ -800,10 +802,54 @@ stats_origin(TSCont contp, TSEvent /* event ATS_UNUSED */, void *edata) | |
| if (accept_encoding_field) { | ||
| TSHandleMLocRelease(reqp, TS_NULL_MLOC, accept_encoding_field); | ||
| } | ||
| TSHttpTxnReenable(txnp, reenable); | ||
| if (!is_remap) { | ||
| TSHttpTxnReenable(txnp, reenable); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int | ||
| stats_origin_global_wrapper(TSCont contp, TSEvent, void *edata) | ||
| { | ||
| config_t *config = get_config(contp); | ||
| return stats_origin(config, TS_EVENT_NONE, edata, false); | ||
| } | ||
|
|
||
| TSReturnCode | ||
| TSRemapInit(TSRemapInterface *api_info, char *errbuf, int errbuf_size) | ||
| { | ||
| CHECK_REMAP_API_COMPATIBILITY(api_info, errbuf, errbuf_size); | ||
| return TS_SUCCESS; | ||
| } | ||
|
|
||
| TSReturnCode | ||
| TSRemapNewInstance(int argc, char *argv[], void **instance, char * /* errBuf ATS_UNUSED */, int /* errBufSize ATS_UNUSED */) | ||
| { | ||
| config_holder_t *config_holder; | ||
| config_holder = new_config_holder(argc > 1 ? argv[2] : nullptr); | ||
| *instance = static_cast<void *>(config_holder); | ||
| /* Path was not set during load, so the param was not a config file, we also | ||
| have an argument so it must be the path, set it here. Otherwise if no argument | ||
| then use the default _stats path */ | ||
| if ((config_holder->config != nullptr) && (config_holder->config->stats_path.empty()) && (argc > 1) && | ||
| (config_holder->config_path == nullptr)) { | ||
| config_holder->config->stats_path = argv[2] + ('/' == argv[2][0] ? 1 : 0); | ||
| } else if ((config_holder->config != nullptr) && (config_holder->config->stats_path.empty())) { | ||
| config_holder->config->stats_path = DEFAULT_URL_PATH; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I'm not reading this right, but shouldn't the default path here be the "from_url" path in the RRI (the remap.config "from URL") ? It kinda feels weird that you can override the path with the pparam or config file. What would happen if I do How could that ever match on the path now ? |
||
| } | ||
| return TS_SUCCESS; | ||
| } | ||
|
|
||
| TSRemapStatus | ||
| TSRemapDoRemap(void *id, TSHttpTxn rh, TSRemapRequestInfo * /* ATS_UNUSED */) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
| { | ||
| config_holder_t *configh = static_cast<config_holder_t *>(id); | ||
| stats_origin(configh->config, TS_EVENT_NONE, rh, true); | ||
|
|
||
| return TSREMAP_NO_REMAP; | ||
| } | ||
|
|
||
| void | ||
| TSPluginInit(int argc, const char *argv[]) | ||
| { | ||
|
|
@@ -860,7 +906,7 @@ TSPluginInit(int argc, const char *argv[]) | |
|
|
||
| /* Create a continuation with a mutex as there is a shared global structure | ||
| containing the headers to add */ | ||
| main_cont = TSContCreate(stats_origin, nullptr); | ||
| main_cont = TSContCreate(stats_origin_global_wrapper, nullptr); | ||
| TSContDataSet(main_cont, (void *)config_holder); | ||
| TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, main_cont); | ||
|
|
||
|
|
@@ -971,6 +1017,13 @@ delete_config(config_t *config) | |
| TSfree(config); | ||
| } | ||
|
|
||
| void | ||
| TSRemapDeleteInstance(void *ih) | ||
| { | ||
| config_holder_t *configh = static_cast<config_holder_t *>(ih); | ||
| delete_config(configh->config); | ||
| } | ||
|
|
||
| // standard api below... | ||
| static config_t * | ||
| get_config(TSCont cont) | ||
|
|
||
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.
Nitpicky, but this seems like a dangerous example :). Shouldn't we use a more specific path here, like
or maybe even more specific (since the above captures the path for all hosts)?
Also, maybe mention that the "target" doesn't imply / mean anything, and can be whatever ?