[GitHub] trafficserver pull request #1111: TS-4972: Configure collapsed_forwarding pl...

2016-10-20 Thread shinrich
Github user shinrich closed the pull request at:

https://github.com/apache/trafficserver/pull/


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] trafficserver pull request #1111: TS-4972: Configure collapsed_forwarding pl...

2016-10-14 Thread shinrich
Github user shinrich commented on a diff in the pull request:

https://github.com/apache/trafficserver/pull/#discussion_r83489086
  
--- Diff: plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc 
---
@@ -265,49 +307,69 @@ collapsed_cont(TSCont contp, TSEvent event, void 
*edata)
   return TS_SUCCESS;
 }
 
-TSReturnCode
-TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* 
errbuf_size */)
-{
-  TSDebug(DEBUG_TAG, "plugin is succesfully initialized");
-  return TS_SUCCESS;
-}
-
-TSReturnCode
-TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* 
errbuf */, int /* errbuf_size */)
+void
+process_args(int argc, const char **argv)
 {
   // basic argv processing..
-  for (int i = 2; i < argc; ++i) {
+  for (int i = 1; i < argc; ++i) {
 if (strncmp(argv[i], "--delay=", 8) == 0) {
   OPEN_WRITE_FAIL_REQ_DELAY_TIMEOUT = atoi((char *)(argv[i] + 8));
 } else if (strncmp(argv[i], "--retries=", 10) == 0) {
   OPEN_WRITE_FAIL_MAX_REQ_DELAY_RETRIES = atoi((char *)(argv[i] + 10));
 }
   }
-
-  return TS_SUCCESS;
 }
 
-TSRemapStatus
-TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
+/*
+ * Initialize globally
+ */
+void
+TSPluginInit(int argc, const char *argv[])
 {
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = (char *)DEBUG_TAG;
+  info.vendor_name   = (char *)"Apache Software Foundation";
+  info.support_email = (char *)"d...@trafficserver.apache.org";
+
+  if (TS_SUCCESS != TSPluginRegister(&info)) {
+TSError("[%s] Plugin registration failed.", DEBUG_TAG);
+  }
+
+  process_args(argc, argv);
+
   TSCont cont = TSContCreate(collapsed_cont, TSMutexCreate());
 
-  RequestData *req_data = new RequestData();
+  TSDebug(DEBUG_TAG, "Global Initialized");
+  // Set up the per transaction state in the READ_REQUEST event
+  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont);
 
-  req_data->txnp = rh;
-  req_data->wl_retry = 0;
+  global_init = true;
+}
 
-  int url_len = 0;
-  char *url   = TSHttpTxnEffectiveUrlStringGet(rh, &url_len);
-  req_data->req_url.assign(url, url_len);
+TSReturnCode
+TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* 
errbuf_size */)
+{
+  if (global_init) {
+TSError("Cannot initialize %s as both global and remap plugin", 
DEBUG_TAG);
+return TS_ERROR;
+  } else {
+TSDebug(DEBUG_TAG, "plugin is succesfully initialized for remap");
+return TS_SUCCESS;
+  }
+}
 
-  TSfree(url);
-  TSContDataSet(cont, req_data);
+TSReturnCode
+TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* 
errbuf */, int /* errbuf_size */)
+{
+  process_args(argc, const_cast(argv + 1));
--- End diff --

Updated new version that decrements argc appropriately.  Verified that it 
is correct in the remap case.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] trafficserver pull request #1111: TS-4972: Configure collapsed_forwarding pl...

2016-10-14 Thread shinrich
Github user shinrich commented on a diff in the pull request:

https://github.com/apache/trafficserver/pull/#discussion_r83475325
  
--- Diff: plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc 
---
@@ -265,49 +307,69 @@ collapsed_cont(TSCont contp, TSEvent event, void 
*edata)
   return TS_SUCCESS;
 }
 
-TSReturnCode
-TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* 
errbuf_size */)
-{
-  TSDebug(DEBUG_TAG, "plugin is succesfully initialized");
-  return TS_SUCCESS;
-}
-
-TSReturnCode
-TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* 
errbuf */, int /* errbuf_size */)
+void
+process_args(int argc, const char **argv)
 {
   // basic argv processing..
-  for (int i = 2; i < argc; ++i) {
+  for (int i = 1; i < argc; ++i) {
 if (strncmp(argv[i], "--delay=", 8) == 0) {
   OPEN_WRITE_FAIL_REQ_DELAY_TIMEOUT = atoi((char *)(argv[i] + 8));
 } else if (strncmp(argv[i], "--retries=", 10) == 0) {
   OPEN_WRITE_FAIL_MAX_REQ_DELAY_RETRIES = atoi((char *)(argv[i] + 10));
 }
   }
-
-  return TS_SUCCESS;
 }
 
-TSRemapStatus
-TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
+/*
+ * Initialize globally
+ */
+void
+TSPluginInit(int argc, const char *argv[])
 {
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = (char *)DEBUG_TAG;
+  info.vendor_name   = (char *)"Apache Software Foundation";
+  info.support_email = (char *)"d...@trafficserver.apache.org";
+
+  if (TS_SUCCESS != TSPluginRegister(&info)) {
+TSError("[%s] Plugin registration failed.", DEBUG_TAG);
+  }
+
+  process_args(argc, argv);
+
   TSCont cont = TSContCreate(collapsed_cont, TSMutexCreate());
 
-  RequestData *req_data = new RequestData();
+  TSDebug(DEBUG_TAG, "Global Initialized");
+  // Set up the per transaction state in the READ_REQUEST event
+  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont);
 
-  req_data->txnp = rh;
-  req_data->wl_retry = 0;
+  global_init = true;
+}
 
-  int url_len = 0;
-  char *url   = TSHttpTxnEffectiveUrlStringGet(rh, &url_len);
-  req_data->req_url.assign(url, url_len);
+TSReturnCode
+TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* 
errbuf_size */)
+{
+  if (global_init) {
+TSError("Cannot initialize %s as both global and remap plugin", 
DEBUG_TAG);
+return TS_ERROR;
+  } else {
+TSDebug(DEBUG_TAG, "plugin is succesfully initialized for remap");
+return TS_SUCCESS;
+  }
+}
 
-  TSfree(url);
-  TSContDataSet(cont, req_data);
+TSReturnCode
+TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* 
errbuf */, int /* errbuf_size */)
+{
+  process_args(argc, const_cast(argv + 1));
--- End diff --

Good point.  I'll check out that case.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] trafficserver pull request #1111: TS-4972: Configure collapsed_forwarding pl...

2016-10-14 Thread SolidWallOfCode
Github user SolidWallOfCode commented on a diff in the pull request:

https://github.com/apache/trafficserver/pull/#discussion_r83473939
  
--- Diff: plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc 
---
@@ -265,49 +307,69 @@ collapsed_cont(TSCont contp, TSEvent event, void 
*edata)
   return TS_SUCCESS;
 }
 
-TSReturnCode
-TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* 
errbuf_size */)
-{
-  TSDebug(DEBUG_TAG, "plugin is succesfully initialized");
-  return TS_SUCCESS;
-}
-
-TSReturnCode
-TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* 
errbuf */, int /* errbuf_size */)
+void
+process_args(int argc, const char **argv)
 {
   // basic argv processing..
-  for (int i = 2; i < argc; ++i) {
+  for (int i = 1; i < argc; ++i) {
 if (strncmp(argv[i], "--delay=", 8) == 0) {
   OPEN_WRITE_FAIL_REQ_DELAY_TIMEOUT = atoi((char *)(argv[i] + 8));
 } else if (strncmp(argv[i], "--retries=", 10) == 0) {
   OPEN_WRITE_FAIL_MAX_REQ_DELAY_RETRIES = atoi((char *)(argv[i] + 10));
 }
   }
-
-  return TS_SUCCESS;
 }
 
-TSRemapStatus
-TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
+/*
+ * Initialize globally
+ */
+void
+TSPluginInit(int argc, const char *argv[])
 {
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = (char *)DEBUG_TAG;
+  info.vendor_name   = (char *)"Apache Software Foundation";
+  info.support_email = (char *)"d...@trafficserver.apache.org";
+
+  if (TS_SUCCESS != TSPluginRegister(&info)) {
+TSError("[%s] Plugin registration failed.", DEBUG_TAG);
+  }
+
+  process_args(argc, argv);
+
   TSCont cont = TSContCreate(collapsed_cont, TSMutexCreate());
 
-  RequestData *req_data = new RequestData();
+  TSDebug(DEBUG_TAG, "Global Initialized");
+  // Set up the per transaction state in the READ_REQUEST event
+  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont);
 
-  req_data->txnp = rh;
-  req_data->wl_retry = 0;
+  global_init = true;
--- End diff --

I wondered about that. But I would be concerned about the plugin firing 
twice for the same transaction. Not to mention, what's the point of a remap 
rule if it's already enabled for every transaction?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] trafficserver pull request #1111: TS-4972: Configure collapsed_forwarding pl...

2016-10-14 Thread jpeach
Github user jpeach commented on a diff in the pull request:

https://github.com/apache/trafficserver/pull/#discussion_r83461915
  
--- Diff: plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc 
---
@@ -265,49 +307,69 @@ collapsed_cont(TSCont contp, TSEvent event, void 
*edata)
   return TS_SUCCESS;
 }
 
-TSReturnCode
-TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* 
errbuf_size */)
-{
-  TSDebug(DEBUG_TAG, "plugin is succesfully initialized");
-  return TS_SUCCESS;
-}
-
-TSReturnCode
-TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* 
errbuf */, int /* errbuf_size */)
+void
+process_args(int argc, const char **argv)
 {
   // basic argv processing..
-  for (int i = 2; i < argc; ++i) {
+  for (int i = 1; i < argc; ++i) {
 if (strncmp(argv[i], "--delay=", 8) == 0) {
   OPEN_WRITE_FAIL_REQ_DELAY_TIMEOUT = atoi((char *)(argv[i] + 8));
 } else if (strncmp(argv[i], "--retries=", 10) == 0) {
   OPEN_WRITE_FAIL_MAX_REQ_DELAY_RETRIES = atoi((char *)(argv[i] + 10));
 }
   }
-
-  return TS_SUCCESS;
 }
 
-TSRemapStatus
-TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
+/*
+ * Initialize globally
+ */
+void
+TSPluginInit(int argc, const char *argv[])
 {
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = (char *)DEBUG_TAG;
+  info.vendor_name   = (char *)"Apache Software Foundation";
+  info.support_email = (char *)"d...@trafficserver.apache.org";
+
+  if (TS_SUCCESS != TSPluginRegister(&info)) {
+TSError("[%s] Plugin registration failed.", DEBUG_TAG);
+  }
+
+  process_args(argc, argv);
+
   TSCont cont = TSContCreate(collapsed_cont, TSMutexCreate());
 
-  RequestData *req_data = new RequestData();
+  TSDebug(DEBUG_TAG, "Global Initialized");
+  // Set up the per transaction state in the READ_REQUEST event
+  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont);
 
-  req_data->txnp = rh;
-  req_data->wl_retry = 0;
+  global_init = true;
+}
 
-  int url_len = 0;
-  char *url   = TSHttpTxnEffectiveUrlStringGet(rh, &url_len);
-  req_data->req_url.assign(url, url_len);
+TSReturnCode
+TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* 
errbuf_size */)
+{
+  if (global_init) {
+TSError("Cannot initialize %s as both global and remap plugin", 
DEBUG_TAG);
+return TS_ERROR;
+  } else {
+TSDebug(DEBUG_TAG, "plugin is succesfully initialized for remap");
+return TS_SUCCESS;
+  }
+}
 
-  TSfree(url);
-  TSContDataSet(cont, req_data);
+TSReturnCode
+TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* 
errbuf */, int /* errbuf_size */)
+{
+  process_args(argc, const_cast(argv + 1));
--- End diff --

Don't you also need to adjust ``argc``?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] trafficserver pull request #1111: TS-4972: Configure collapsed_forwarding pl...

2016-10-14 Thread jpeach
Github user jpeach commented on a diff in the pull request:

https://github.com/apache/trafficserver/pull/#discussion_r83462452
  
--- Diff: plugins/experimental/collapsed_forwarding/collapsed_forwarding.cc 
---
@@ -265,49 +307,69 @@ collapsed_cont(TSCont contp, TSEvent event, void 
*edata)
   return TS_SUCCESS;
 }
 
-TSReturnCode
-TSRemapInit(TSRemapInterface * /* api_info */, char * /* errbuf */, int /* 
errbuf_size */)
-{
-  TSDebug(DEBUG_TAG, "plugin is succesfully initialized");
-  return TS_SUCCESS;
-}
-
-TSReturnCode
-TSRemapNewInstance(int argc, char *argv[], void ** /* ih */, char * /* 
errbuf */, int /* errbuf_size */)
+void
+process_args(int argc, const char **argv)
 {
   // basic argv processing..
-  for (int i = 2; i < argc; ++i) {
+  for (int i = 1; i < argc; ++i) {
 if (strncmp(argv[i], "--delay=", 8) == 0) {
   OPEN_WRITE_FAIL_REQ_DELAY_TIMEOUT = atoi((char *)(argv[i] + 8));
 } else if (strncmp(argv[i], "--retries=", 10) == 0) {
   OPEN_WRITE_FAIL_MAX_REQ_DELAY_RETRIES = atoi((char *)(argv[i] + 10));
 }
   }
-
-  return TS_SUCCESS;
 }
 
-TSRemapStatus
-TSRemapDoRemap(void *ih, TSHttpTxn rh, TSRemapRequestInfo *rri)
+/*
+ * Initialize globally
+ */
+void
+TSPluginInit(int argc, const char *argv[])
 {
+  TSPluginRegistrationInfo info;
+
+  info.plugin_name   = (char *)DEBUG_TAG;
+  info.vendor_name   = (char *)"Apache Software Foundation";
+  info.support_email = (char *)"d...@trafficserver.apache.org";
+
+  if (TS_SUCCESS != TSPluginRegister(&info)) {
+TSError("[%s] Plugin registration failed.", DEBUG_TAG);
+  }
+
+  process_args(argc, argv);
+
   TSCont cont = TSContCreate(collapsed_cont, TSMutexCreate());
 
-  RequestData *req_data = new RequestData();
+  TSDebug(DEBUG_TAG, "Global Initialized");
+  // Set up the per transaction state in the READ_REQUEST event
+  TSHttpHookAdd(TS_HTTP_READ_REQUEST_HDR_HOOK, cont);
 
-  req_data->txnp = rh;
-  req_data->wl_retry = 0;
+  global_init = true;
--- End diff --

It seems like the only reason I can't have this as a global and a 
transaction plugin is the config is in globals. What do you think about moving 
that into an instance config for the remap case?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---


[GitHub] trafficserver pull request #1111: TS-4972: Configure collapsed_forwarding pl...

2016-10-14 Thread shinrich
GitHub user shinrich opened a pull request:

https://github.com/apache/trafficserver/pull/

TS-4972: Configure collapsed_forwarding plugin as global or remap.

Add the ability to configure collapsed_forwarding plugin globally.  
Original version can only be configured per remap.

Also cleaned up a memory leak in the event of failed transaction.

You can merge this pull request into a Git repository by running:

$ git pull https://github.com/shinrich/trafficserver ts-4972

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/trafficserver/pull/.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #


commit 0bebc97d000e09058d4c8c28c085145c694c1973
Author: Susan Hinrichs 
Date:   2016-10-14T15:38:12Z

TS-4972: Configure collapsed_forwarding plugin as global or remap.




---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---