[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=28891&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-28891 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 12/Sep/16 23:32 Start Date: 12/Sep/16 23:32 Worklog Time Spent: 10m Work Description: Github user bryancall closed the pull request at: https://github.com/apache/trafficserver/pull/877 Issue Time Tracking --- Worklog Id: (was: 28891) Time Spent: 3h (was: 2h 50m) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 3h > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=28047&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-28047 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 03/Sep/16 02:41 Start Date: 03/Sep/16 02:41 Worklog Time Spent: 10m Work Description: Github user atsci commented on the issue: https://github.com/apache/trafficserver/pull/877 FreeBSD build *successful*! See https://ci.trafficserver.apache.org/job/Github-FreeBSD/690/ for details. Issue Time Tracking --- Worklog Id: (was: 28047) Time Spent: 2h 50m (was: 2h 40m) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 2h 50m > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=28046&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-28046 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 03/Sep/16 02:34 Start Date: 03/Sep/16 02:34 Worklog Time Spent: 10m Work Description: Github user atsci commented on the issue: https://github.com/apache/trafficserver/pull/877 Linux build *successful*! See https://ci.trafficserver.apache.org/job/Github-Linux/586/ for details. Issue Time Tracking --- Worklog Id: (was: 28046) Time Spent: 2h 40m (was: 2.5h) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 2h 40m > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=28044&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-28044 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 03/Sep/16 02:21 Start Date: 03/Sep/16 02:21 Worklog Time Spent: 10m Work Description: Github user zwoop commented on the issue: https://github.com/apache/trafficserver/pull/877 [approve ci] Issue Time Tracking --- Worklog Id: (was: 28044) Time Spent: 2.5h (was: 2h 20m) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 2.5h > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26706&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26706 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 20/Aug/16 02:55 Start Date: 20/Aug/16 02:55 Worklog Time Spent: 10m Work Description: Github user zwoop commented on the issue: https://github.com/apache/trafficserver/pull/877 Have to run clang format, (I highly recommend installing the git hook that we have, see https://github.com/apache/trafficserver/blob/master/tools/pre-commit Also, I think we suggested/agreed on moving this to a new directory, like plugins/test ? Issue Time Tracking --- Worklog Id: (was: 26706) Time Spent: 2h 20m (was: 2h 10m) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 2h 20m > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26705&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26705 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 20/Aug/16 02:53 Start Date: 20/Aug/16 02:53 Worklog Time Spent: 10m Work Description: Github user atsci commented on the issue: https://github.com/apache/trafficserver/pull/877 FreeBSD build *successful*! See https://ci.trafficserver.apache.org/job/Github-FreeBSD/566/ for details. Issue Time Tracking --- Worklog Id: (was: 26705) Time Spent: 2h 10m (was: 2h) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 2h 10m > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26704&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26704 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 20/Aug/16 02:48 Start Date: 20/Aug/16 02:48 Worklog Time Spent: 10m Work Description: Github user atsci commented on the issue: https://github.com/apache/trafficserver/pull/877 Linux build *failed*! See https://ci.trafficserver.apache.org/job/Github-Linux/462/ for details. Issue Time Tracking --- Worklog Id: (was: 26704) Time Spent: 2h (was: 1h 50m) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 2h > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26702&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26702 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 20/Aug/16 02:42 Start Date: 20/Aug/16 02:42 Worklog Time Spent: 10m Work Description: Github user zwoop commented on the issue: https://github.com/apache/trafficserver/pull/877 [approve ci] Issue Time Tracking --- Worklog Id: (was: 26702) Time Spent: 1h 50m (was: 1h 40m) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 1h 50m > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26655&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26655 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 19/Aug/16 15:52 Start Date: 19/Aug/16 15:52 Worklog Time Spent: 10m Work Description: Github user bryancall commented on a diff in the pull request: https://github.com/apache/trafficserver/pull/877#discussion_r75506303 --- Diff: plugins/experimental/header_freq/header_freq.cc --- @@ -0,0 +1,260 @@ +/** @file + + This plugin counts the number of times every header has appeared. + Maintains separate counts for client and origin headers. + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + + +// plugin registration info +static char plugin_name[] = "header_freq"; +static char vendor_name[] = "Apache Software Foundation"; +static char support_email[] = "d...@trafficserver.apache.org"; + +// debug messages during one-time initialization +static const char DEBUG_TAG_INIT[] = "header_freq.init"; + +// debug messages in continuation callbacks +static const char DEBUG_TAG_HOOK[] = "header_freq.hook"; + +// maps from header name to # of times encountered +static std::map client_freq; +static std::map origin_freq; + +// for traffic_ctl, name is a convenient identifier +static const char *ctl_tag = plugin_name; +static const char *ctl_log = "log"; // log all data + +static TSMutex freq_mutex; // lock on global data +static const int retry_time = 10; // spin after TSMutexLockTry failures + +static const char *log_name = plugin_name; +static TSTextLogObject log; + +static bool +freq_lock_try(TSCont contp) +{ + if (TSMutexLockTry(freq_mutex) != TS_SUCCESS) { +TSDebug(DEBUG_TAG_HOOK, "Unable to acquire lock. Retrying in %d " +"milliseconds", retry_time); +TSContSchedule(contp, retry_time, TS_THREAD_POOL_DEFAULT); +return false; + } + return true; +} + +/** + * Logs the data collected, first the client, and then + * the origin headers. + */ +static void +log_frequencies() +{ + std::stringstream ss(""); + + ss << std::endl << std::string(100, '+') << std::endl; + + ss << "CLIENT HEADERS" << std::endl; + for (auto &elem: client_freq) { +ss << elem.first << ": " << elem.second << std::endl; + } + + ss << std::endl; + + ss << "ORIGIN HEADERS" << std::endl; + for (auto &elem: origin_freq) { +ss << elem.first << ": " << elem.second << std::endl; + } + + ss << std::string(100, '+') << std::endl; + TSTextLogObjectWrite(log, "%s", ss.str().c_str()); +} + +/** + * Records all headers found in the buffer in the map provided. Comparison + * against existing entries is case-insensitive. + */ +static void +count_all_headers(TSMBuffer &bufp, TSMLoc &hdr_loc, std::map &map) +{ + TSMLoc hdr, next_hdr; + hdr = TSMimeHdrFieldGet(bufp, hdr_loc, 0); + int n_headers = TSMimeHdrFieldsCount(bufp, hdr_loc); + TSDebug(DEBUG_TAG_HOOK, "%d headers found", n_headers); + + // iterate through all headers + for (int i = 0; i < n_headers; ++i) { +if (hdr == NULL) + break; +next_hdr = TSMimeHdrFieldNext(bufp, hdr_loc, hdr); +int hdr_len; +const char *hdr_name = TSMimeHdrFieldNameGet(bufp, hdr_loc, hdr, &hdr_len); + +std::string str = std::string(hdr_name, hdr_len); + +// make case-insensitive by converting to lowercase +for (auto &c: str) { + c = tolower(c); +} + +// count the header +if (map.find(str) == map.end()) { + // Not found.
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26623&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26623 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 19/Aug/16 01:31 Start Date: 19/Aug/16 01:31 Worklog Time Spent: 10m Work Description: Github user petarpenkov commented on a diff in the pull request: https://github.com/apache/trafficserver/pull/877#discussion_r75416546 --- Diff: plugins/experimental/header_freq/header_freq.cc --- @@ -0,0 +1,260 @@ +/** @file + + This plugin counts the number of times every header has appeared. + Maintains separate counts for client and origin headers. + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + + +// plugin registration info +static char plugin_name[] = "header_freq"; +static char vendor_name[] = "Apache Software Foundation"; +static char support_email[] = "d...@trafficserver.apache.org"; + +// debug messages during one-time initialization +static const char DEBUG_TAG_INIT[] = "header_freq.init"; + +// debug messages in continuation callbacks +static const char DEBUG_TAG_HOOK[] = "header_freq.hook"; + +// maps from header name to # of times encountered +static std::map client_freq; +static std::map origin_freq; + +// for traffic_ctl, name is a convenient identifier +static const char *ctl_tag = plugin_name; +static const char *ctl_log = "log"; // log all data + +static TSMutex freq_mutex; // lock on global data +static const int retry_time = 10; // spin after TSMutexLockTry failures + +static const char *log_name = plugin_name; +static TSTextLogObject log; + +static bool +freq_lock_try(TSCont contp) +{ + if (TSMutexLockTry(freq_mutex) != TS_SUCCESS) { +TSDebug(DEBUG_TAG_HOOK, "Unable to acquire lock. Retrying in %d " +"milliseconds", retry_time); +TSContSchedule(contp, retry_time, TS_THREAD_POOL_DEFAULT); +return false; + } + return true; +} + +/** + * Logs the data collected, first the client, and then + * the origin headers. + */ +static void +log_frequencies() +{ + std::stringstream ss(""); + + ss << std::endl << std::string(100, '+') << std::endl; + + ss << "CLIENT HEADERS" << std::endl; + for (auto &elem: client_freq) { +ss << elem.first << ": " << elem.second << std::endl; + } + + ss << std::endl; + + ss << "ORIGIN HEADERS" << std::endl; + for (auto &elem: origin_freq) { +ss << elem.first << ": " << elem.second << std::endl; + } + + ss << std::string(100, '+') << std::endl; + TSTextLogObjectWrite(log, "%s", ss.str().c_str()); +} + +/** + * Records all headers found in the buffer in the map provided. Comparison + * against existing entries is case-insensitive. + */ +static void +count_all_headers(TSMBuffer &bufp, TSMLoc &hdr_loc, std::map &map) +{ + TSMLoc hdr, next_hdr; + hdr = TSMimeHdrFieldGet(bufp, hdr_loc, 0); + int n_headers = TSMimeHdrFieldsCount(bufp, hdr_loc); + TSDebug(DEBUG_TAG_HOOK, "%d headers found", n_headers); + + // iterate through all headers + for (int i = 0; i < n_headers; ++i) { +if (hdr == NULL) + break; +next_hdr = TSMimeHdrFieldNext(bufp, hdr_loc, hdr); +int hdr_len; +const char *hdr_name = TSMimeHdrFieldNameGet(bufp, hdr_loc, hdr, &hdr_len); + +std::string str = std::string(hdr_name, hdr_len); + +// make case-insensitive by converting to lowercase +for (auto &c: str) { + c = tolower(c); +} + +// count the header +if (map.find(str) == map.end()) { + // Not foun
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26620&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26620 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 19/Aug/16 00:14 Start Date: 19/Aug/16 00:14 Worklog Time Spent: 10m Work Description: Github user zwoop commented on the issue: https://github.com/apache/trafficserver/pull/877 I have mixed feelings on the custom log for this. This is really for intermittent testing of behavior, similar to e.g. the memory usage dump feature. I.e. I can't imagine someone would use this in a way where it dumps the metrics more than a handful of times. Issue Time Tracking --- Worklog Id: (was: 26620) Time Spent: 1h 20m (was: 1h 10m) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 1h 20m > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26619&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26619 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 18/Aug/16 23:53 Start Date: 18/Aug/16 23:53 Worklog Time Spent: 10m Work Description: Github user SolidWallOfCode commented on a diff in the pull request: https://github.com/apache/trafficserver/pull/877#discussion_r75409617 --- Diff: plugins/experimental/header_freq/header_freq.cc --- @@ -0,0 +1,260 @@ +/** @file + + This plugin counts the number of times every header has appeared. + Maintains separate counts for client and origin headers. + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + + +// plugin registration info +static char plugin_name[] = "header_freq"; +static char vendor_name[] = "Apache Software Foundation"; +static char support_email[] = "d...@trafficserver.apache.org"; + +// debug messages during one-time initialization +static const char DEBUG_TAG_INIT[] = "header_freq.init"; + +// debug messages in continuation callbacks +static const char DEBUG_TAG_HOOK[] = "header_freq.hook"; + +// maps from header name to # of times encountered +static std::map client_freq; +static std::map origin_freq; + +// for traffic_ctl, name is a convenient identifier +static const char *ctl_tag = plugin_name; +static const char *ctl_log = "log"; // log all data + +static TSMutex freq_mutex; // lock on global data +static const int retry_time = 10; // spin after TSMutexLockTry failures + +static const char *log_name = plugin_name; +static TSTextLogObject log; + +static bool +freq_lock_try(TSCont contp) +{ + if (TSMutexLockTry(freq_mutex) != TS_SUCCESS) { +TSDebug(DEBUG_TAG_HOOK, "Unable to acquire lock. Retrying in %d " +"milliseconds", retry_time); +TSContSchedule(contp, retry_time, TS_THREAD_POOL_DEFAULT); +return false; + } + return true; +} + +/** + * Logs the data collected, first the client, and then + * the origin headers. + */ +static void +log_frequencies() +{ + std::stringstream ss(""); + + ss << std::endl << std::string(100, '+') << std::endl; + + ss << "CLIENT HEADERS" << std::endl; + for (auto &elem: client_freq) { +ss << elem.first << ": " << elem.second << std::endl; + } + + ss << std::endl; + + ss << "ORIGIN HEADERS" << std::endl; + for (auto &elem: origin_freq) { +ss << elem.first << ": " << elem.second << std::endl; + } + + ss << std::string(100, '+') << std::endl; + TSTextLogObjectWrite(log, "%s", ss.str().c_str()); +} + +/** + * Records all headers found in the buffer in the map provided. Comparison + * against existing entries is case-insensitive. + */ +static void +count_all_headers(TSMBuffer &bufp, TSMLoc &hdr_loc, std::map &map) +{ + TSMLoc hdr, next_hdr; + hdr = TSMimeHdrFieldGet(bufp, hdr_loc, 0); + int n_headers = TSMimeHdrFieldsCount(bufp, hdr_loc); + TSDebug(DEBUG_TAG_HOOK, "%d headers found", n_headers); + + // iterate through all headers + for (int i = 0; i < n_headers; ++i) { +if (hdr == NULL) + break; +next_hdr = TSMimeHdrFieldNext(bufp, hdr_loc, hdr); +int hdr_len; +const char *hdr_name = TSMimeHdrFieldNameGet(bufp, hdr_loc, hdr, &hdr_len); + +std::string str = std::string(hdr_name, hdr_len); + +// make case-insensitive by converting to lowercase +for (auto &c: str) { + c = tolower(c); +} + +// count the header +if (map.find(str) == map.end()) { + // Not
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26618&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26618 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 18/Aug/16 23:52 Start Date: 18/Aug/16 23:52 Worklog Time Spent: 10m Work Description: Github user SolidWallOfCode commented on a diff in the pull request: https://github.com/apache/trafficserver/pull/877#discussion_r75409533 --- Diff: plugins/experimental/header_freq/header_freq.cc --- @@ -0,0 +1,260 @@ +/** @file + + This plugin counts the number of times every header has appeared. + Maintains separate counts for client and origin headers. + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + + +// plugin registration info +static char plugin_name[] = "header_freq"; +static char vendor_name[] = "Apache Software Foundation"; +static char support_email[] = "d...@trafficserver.apache.org"; + +// debug messages during one-time initialization +static const char DEBUG_TAG_INIT[] = "header_freq.init"; + +// debug messages in continuation callbacks +static const char DEBUG_TAG_HOOK[] = "header_freq.hook"; + +// maps from header name to # of times encountered +static std::map client_freq; +static std::map origin_freq; + +// for traffic_ctl, name is a convenient identifier +static const char *ctl_tag = plugin_name; +static const char *ctl_log = "log"; // log all data + +static TSMutex freq_mutex; // lock on global data +static const int retry_time = 10; // spin after TSMutexLockTry failures + +static const char *log_name = plugin_name; +static TSTextLogObject log; + +static bool +freq_lock_try(TSCont contp) +{ + if (TSMutexLockTry(freq_mutex) != TS_SUCCESS) { +TSDebug(DEBUG_TAG_HOOK, "Unable to acquire lock. Retrying in %d " +"milliseconds", retry_time); +TSContSchedule(contp, retry_time, TS_THREAD_POOL_DEFAULT); +return false; + } + return true; +} + +/** + * Logs the data collected, first the client, and then + * the origin headers. + */ +static void +log_frequencies() +{ + std::stringstream ss(""); + + ss << std::endl << std::string(100, '+') << std::endl; + + ss << "CLIENT HEADERS" << std::endl; + for (auto &elem: client_freq) { +ss << elem.first << ": " << elem.second << std::endl; + } + + ss << std::endl; + + ss << "ORIGIN HEADERS" << std::endl; + for (auto &elem: origin_freq) { +ss << elem.first << ": " << elem.second << std::endl; + } + + ss << std::string(100, '+') << std::endl; + TSTextLogObjectWrite(log, "%s", ss.str().c_str()); +} + +/** + * Records all headers found in the buffer in the map provided. Comparison + * against existing entries is case-insensitive. + */ +static void +count_all_headers(TSMBuffer &bufp, TSMLoc &hdr_loc, std::map &map) +{ + TSMLoc hdr, next_hdr; + hdr = TSMimeHdrFieldGet(bufp, hdr_loc, 0); + int n_headers = TSMimeHdrFieldsCount(bufp, hdr_loc); + TSDebug(DEBUG_TAG_HOOK, "%d headers found", n_headers); + + // iterate through all headers + for (int i = 0; i < n_headers; ++i) { +if (hdr == NULL) + break; +next_hdr = TSMimeHdrFieldNext(bufp, hdr_loc, hdr); +int hdr_len; +const char *hdr_name = TSMimeHdrFieldNameGet(bufp, hdr_loc, hdr, &hdr_len); + +std::string str = std::string(hdr_name, hdr_len); + +// make case-insensitive by converting to lowercase +for (auto &c: str) { + c = tolower(c); +} + +// count the header +if (map.find(str) == map.end()) { + // Not
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26617&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26617 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 18/Aug/16 23:42 Start Date: 18/Aug/16 23:42 Worklog Time Spent: 10m Work Description: Github user SolidWallOfCode commented on a diff in the pull request: https://github.com/apache/trafficserver/pull/877#discussion_r75408582 --- Diff: plugins/experimental/header_freq/header_freq.cc --- @@ -0,0 +1,260 @@ +/** @file + + This plugin counts the number of times every header has appeared. + Maintains separate counts for client and origin headers. + + @section license License + + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + */ + +#include +#include +#include +#include +#include +#include +#include + + +// plugin registration info +static char plugin_name[] = "header_freq"; +static char vendor_name[] = "Apache Software Foundation"; +static char support_email[] = "d...@trafficserver.apache.org"; + +// debug messages during one-time initialization +static const char DEBUG_TAG_INIT[] = "header_freq.init"; + +// debug messages in continuation callbacks +static const char DEBUG_TAG_HOOK[] = "header_freq.hook"; + +// maps from header name to # of times encountered +static std::map client_freq; +static std::map origin_freq; + +// for traffic_ctl, name is a convenient identifier +static const char *ctl_tag = plugin_name; +static const char *ctl_log = "log"; // log all data + +static TSMutex freq_mutex; // lock on global data +static const int retry_time = 10; // spin after TSMutexLockTry failures + +static const char *log_name = plugin_name; +static TSTextLogObject log; + +static bool +freq_lock_try(TSCont contp) +{ + if (TSMutexLockTry(freq_mutex) != TS_SUCCESS) { +TSDebug(DEBUG_TAG_HOOK, "Unable to acquire lock. Retrying in %d " +"milliseconds", retry_time); +TSContSchedule(contp, retry_time, TS_THREAD_POOL_DEFAULT); +return false; + } + return true; +} + +/** + * Logs the data collected, first the client, and then + * the origin headers. + */ +static void +log_frequencies() +{ + std::stringstream ss(""); + + ss << std::endl << std::string(100, '+') << std::endl; + + ss << "CLIENT HEADERS" << std::endl; + for (auto &elem: client_freq) { +ss << elem.first << ": " << elem.second << std::endl; + } + + ss << std::endl; + + ss << "ORIGIN HEADERS" << std::endl; + for (auto &elem: origin_freq) { +ss << elem.first << ": " << elem.second << std::endl; + } + + ss << std::string(100, '+') << std::endl; + TSTextLogObjectWrite(log, "%s", ss.str().c_str()); +} + +/** + * Records all headers found in the buffer in the map provided. Comparison + * against existing entries is case-insensitive. + */ +static void +count_all_headers(TSMBuffer &bufp, TSMLoc &hdr_loc, std::map &map) +{ + TSMLoc hdr, next_hdr; + hdr = TSMimeHdrFieldGet(bufp, hdr_loc, 0); + int n_headers = TSMimeHdrFieldsCount(bufp, hdr_loc); + TSDebug(DEBUG_TAG_HOOK, "%d headers found", n_headers); + + // iterate through all headers + for (int i = 0; i < n_headers; ++i) { +if (hdr == NULL) + break; +next_hdr = TSMimeHdrFieldNext(bufp, hdr_loc, hdr); +int hdr_len; +const char *hdr_name = TSMimeHdrFieldNameGet(bufp, hdr_loc, hdr, &hdr_len); + +std::string str = std::string(hdr_name, hdr_len); + +// make case-insensitive by converting to lowercase +for (auto &c: str) { + c = tolower(c); +} + +// count the header +if (map.find(str) == map.end()) { + // Not
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26586&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26586 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 18/Aug/16 18:27 Start Date: 18/Aug/16 18:27 Worklog Time Spent: 10m Work Description: Github user jpeach commented on the issue: https://github.com/apache/trafficserver/pull/877 Should this use a TextLog rather than standard output? Then you would get log rotation, etc, which is probably desirable. Issue Time Tracking --- Worklog Id: (was: 26586) Time Spent: 40m (was: 0.5h) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 40m > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26585&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26585 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 18/Aug/16 18:27 Start Date: 18/Aug/16 18:27 Worklog Time Spent: 10m Work Description: Github user petarpenkov commented on the issue: https://github.com/apache/trafficserver/pull/877 Aw yeah, totally meant to do that and forgot. Will update ASAP. Issue Time Tracking --- Worklog Id: (was: 26585) Time Spent: 0.5h (was: 20m) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 0.5h > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26584&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26584 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 18/Aug/16 18:24 Start Date: 18/Aug/16 18:24 Worklog Time Spent: 10m Work Description: Github user bryancall commented on the issue: https://github.com/apache/trafficserver/pull/877 Looks good, but I didn't see any locking when updating client_freq and origin_freq. Issue Time Tracking --- Worklog Id: (was: 26584) Time Spent: 20m (was: 10m) > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 20m > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)
[jira] [Work logged] (TS-4755) Create a plugin that would count the frequency of headers
[ https://issues.apache.org/jira/browse/TS-4755?focusedWorklogId=26583&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-26583 ] ASF GitHub Bot logged work on TS-4755: -- Author: ASF GitHub Bot Created on: 18/Aug/16 18:02 Start Date: 18/Aug/16 18:02 Worklog Time Spent: 10m Work Description: GitHub user petarpenkov opened a pull request: https://github.com/apache/trafficserver/pull/877 TS-4755: Header Frequency plugin. Initial version Very basic version of the plugin. Additional options can be added to traffic_ctl to reset the counters, to print specific headers, maybe regex support. Additionally, the simple counters can be converted to decimal fractions. You can merge this pull request into a Git repository by running: $ git pull https://github.com/petarpenkov/trafficserver header_freq Alternatively you can review and apply these changes as the patch at: https://github.com/apache/trafficserver/pull/877.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 #877 Issue Time Tracking --- Worklog Id: (was: 26583) Time Spent: 10m Remaining Estimate: 0h > Create a plugin that would count the frequency of headers > - > > Key: TS-4755 > URL: https://issues.apache.org/jira/browse/TS-4755 > Project: Traffic Server > Issue Type: Improvement > Components: Plugins >Reporter: Bryan Call >Assignee: Petar Penkov > Fix For: 7.2.0 > > Time Spent: 10m > Remaining Estimate: 0h > > Create a plugin that would count the frequency of headers. Have separate > frequency counters for origin and client. -- This message was sent by Atlassian JIRA (v6.3.4#6332)