trafficserver-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bnol...@apache.org
Subject [trafficserver] branch master updated: regex_revalidate: add stats for miss/stale counts (#7950)
Date Fri, 18 Jun 2021 12:23:17 GMT
This is an automated email from the ASF dual-hosted git repository.

bnolsen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new f3fb74e  regex_revalidate: add stats for miss/stale counts (#7950)
f3fb74e is described below

commit f3fb74eafdfd1dbc66c8b176e2f4cb5c923f47f7
Author: Brian Olsen <bnolsen@gmail.com>
AuthorDate: Fri Jun 18 06:23:07 2021 -0600

    regex_revalidate: add stats for miss/stale counts (#7950)
---
 doc/admin-guide/plugins/regex_revalidate.en.rst    |  2 +
 plugins/regex_revalidate/regex_revalidate.c        | 47 ++++++++++++++++++++++
 .../pluginTest/regex_revalidate/gold/metrics.gold  |  2 +
 .../regex_revalidate/gold/metrics_miss.gold        |  2 +
 .../pluginTest/regex_revalidate/metrics.sh         | 30 ++++++++++++++
 .../pluginTest/regex_revalidate/metrics_miss.sh    | 30 ++++++++++++++
 .../regex_revalidate/regex_revalidate.test.py      | 11 +++++
 .../regex_revalidate/regex_revalidate_miss.test.py | 14 +++++--
 8 files changed, 135 insertions(+), 3 deletions(-)

diff --git a/doc/admin-guide/plugins/regex_revalidate.en.rst b/doc/admin-guide/plugins/regex_revalidate.en.rst
index 7fb68e9..d122134 100644
--- a/doc/admin-guide/plugins/regex_revalidate.en.rst
+++ b/doc/admin-guide/plugins/regex_revalidate.en.rst
@@ -40,6 +40,8 @@ regular expression against your origin URLs permits. Thus, individual cache
 objects may have rules created for them, or entire path prefixes, or even any
 cache objects with a particular file extension.
 
+Revalidate count  stats for MISS and STALE are recorded under plugins
+
 Installation
 ============
 
diff --git a/plugins/regex_revalidate/regex_revalidate.c b/plugins/regex_revalidate/regex_revalidate.c
index ecd900a..31fffad 100644
--- a/plugins/regex_revalidate/regex_revalidate.c
+++ b/plugins/regex_revalidate/regex_revalidate.c
@@ -51,6 +51,50 @@ static char const *const RESULT_MISS    = "MISS";
 static char const *const RESULT_STALE   = "STALE";
 static char const *const RESULT_UNKNOWN = "UNKNOWN";
 
+static int stat_id_stale                 = TS_ERROR;
+static char const *const stat_name_stale = "plugin.regex_revalidate.stale";
+static int stat_id_miss                  = TS_ERROR;
+static char const *const stat_name_miss  = "plugin.regex_revalidate.miss";
+
+static void
+create_stats()
+{
+  if (TS_ERROR == stat_id_stale && TS_ERROR == TSStatFindName(stat_name_stale, &stat_id_stale))
{
+    stat_id_stale = TSStatCreate(stat_name_stale, TS_RECORDDATATYPE_INT, TS_STAT_NON_PERSISTENT,
TS_STAT_SYNC_COUNT);
+    if (TS_ERROR != stat_id_stale) {
+      TSDebug(PLUGIN_NAME, "Created stat '%s'", stat_name_stale);
+    }
+  }
+
+  if (TS_ERROR == stat_id_miss && TS_ERROR == TSStatFindName(stat_name_miss, &stat_id_miss))
{
+    stat_id_miss = TSStatCreate(stat_name_miss, TS_RECORDDATATYPE_INT, TS_STAT_NON_PERSISTENT,
TS_STAT_SYNC_COUNT);
+    if (TS_ERROR != stat_id_miss) {
+      TSDebug(PLUGIN_NAME, "Created stat '%s'", stat_name_miss);
+    }
+  }
+}
+
+static void
+increment_stat(TSCacheLookupResult const result)
+{
+  switch (result) {
+  case TS_CACHE_LOOKUP_MISS:
+    if (TS_ERROR != stat_id_miss) {
+      TSStatIntIncrement(stat_id_miss, 1);
+      TSDebug(PLUGIN_NAME, "Incrementing stat '%s'", stat_name_miss);
+    }
+    break;
+  case TS_CACHE_LOOKUP_HIT_STALE:
+    if (TS_ERROR != stat_id_stale) {
+      TSStatIntIncrement(stat_id_stale, 1);
+      TSDebug(PLUGIN_NAME, "Incrementing stat '%s'", stat_name_stale);
+    }
+    break;
+  default:
+    break;
+  }
+}
+
 static char const *const
 strForResult(TSCacheLookupResult const result)
 {
@@ -585,6 +629,7 @@ main_handler(TSCont cont, TSEvent event, void *edata)
             }
             if (pcre_exec(iptr->regex, iptr->regex_extra, url, url_len, 0, 0, NULL,
0) >= 0) {
               TSHttpTxnCacheLookupStatusSet(txn, iptr->new_result);
+              increment_stat(iptr->new_result);
               TSDebug(PLUGIN_NAME, "Forced revalidate - %.*s %s", url_len, url, strForResult(iptr->new_result));
               iptr = NULL;
             }
@@ -700,6 +745,8 @@ TSPluginInit(int argc, const char *argv[])
     TSDebug(PLUGIN_NAME, "Plugin registration succeeded");
   }
 
+  create_stats();
+
   main_cont = TSContCreate(main_handler, NULL);
   TSContDataSet(main_cont, (void *)pstate);
   TSHttpHookAdd(TS_HTTP_CACHE_LOOKUP_COMPLETE_HOOK, main_cont);
diff --git a/tests/gold_tests/pluginTest/regex_revalidate/gold/metrics.gold b/tests/gold_tests/pluginTest/regex_revalidate/gold/metrics.gold
new file mode 100644
index 0000000..bc7052b
--- /dev/null
+++ b/tests/gold_tests/pluginTest/regex_revalidate/gold/metrics.gold
@@ -0,0 +1,2 @@
+plugin.regex_revalidate.stale 3
+plugin.regex_revalidate.miss 0
diff --git a/tests/gold_tests/pluginTest/regex_revalidate/gold/metrics_miss.gold b/tests/gold_tests/pluginTest/regex_revalidate/gold/metrics_miss.gold
new file mode 100644
index 0000000..1eee8c8
--- /dev/null
+++ b/tests/gold_tests/pluginTest/regex_revalidate/gold/metrics_miss.gold
@@ -0,0 +1,2 @@
+plugin.regex_revalidate.stale 1
+plugin.regex_revalidate.miss 2
diff --git a/tests/gold_tests/pluginTest/regex_revalidate/metrics.sh b/tests/gold_tests/pluginTest/regex_revalidate/metrics.sh
new file mode 100755
index 0000000..4365a0e
--- /dev/null
+++ b/tests/gold_tests/pluginTest/regex_revalidate/metrics.sh
@@ -0,0 +1,30 @@
+#  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.
+
+N=60
+while (( N > 0 ))
+do
+    rm -f metrics.out
+    traffic_ctl metric match regex_revalidate > metrics.out
+    sleep 1
+    if diff metrics.out ${AUTEST_TEST_DIR}/gold/metrics.gold
+    then
+        exit 0
+    fi
+    let N=N-1
+done
+echo TIMEOUT
+exit 1
diff --git a/tests/gold_tests/pluginTest/regex_revalidate/metrics_miss.sh b/tests/gold_tests/pluginTest/regex_revalidate/metrics_miss.sh
new file mode 100755
index 0000000..164a4e4
--- /dev/null
+++ b/tests/gold_tests/pluginTest/regex_revalidate/metrics_miss.sh
@@ -0,0 +1,30 @@
+#  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.
+
+N=60
+while (( N > 0 ))
+do
+    rm -f metrics.out
+    traffic_ctl metric match regex_revalidate > metrics.out
+    sleep 1
+    if diff metrics.out ${AUTEST_TEST_DIR}/gold/metrics_miss.gold
+    then
+        exit 0
+    fi
+    let N=N-1
+done
+echo TIMEOUT
+exit 1
diff --git a/tests/gold_tests/pluginTest/regex_revalidate/regex_revalidate.test.py b/tests/gold_tests/pluginTest/regex_revalidate/regex_revalidate.test.py
index b037051..cd3b581 100644
--- a/tests/gold_tests/pluginTest/regex_revalidate/regex_revalidate.test.py
+++ b/tests/gold_tests/pluginTest/regex_revalidate/regex_revalidate.test.py
@@ -44,6 +44,9 @@ server = Test.MakeOriginServer("server")
 # Define ATS and configure
 ts = Test.MakeATSProcess("ts", command="traffic_manager", select_ports=True)
 
+Test.testName = "regex_revalidate"
+Test.Setup.Copy("metrics.sh")
+
 # default root
 request_header_0 = {"headers":
                     "GET / HTTP/1.1\r\n" +
@@ -264,3 +267,11 @@ tr.Processes.Default.Command = curl_and_args + ' http://127.0.0.1:{}/path2a'.for
 tr.Processes.Default.ReturnCode = 0
 tr.Processes.Default.Streams.stdout = "gold/regex_reval-stale.gold"
 tr.StillRunningAfter = ts
+
+# 12 Stats check
+tr = Test.AddTestRun("Check stats")
+tr.DelayStart = 5
+tr.Processes.Default.Command = "bash -c ./metrics.sh"
+tr.Processes.Default.Env = ts.Env
+tr.Processes.Default.ReturnCode = 0
+tr.StillRunningAfter = ts
diff --git a/tests/gold_tests/pluginTest/regex_revalidate/regex_revalidate_miss.test.py b/tests/gold_tests/pluginTest/regex_revalidate/regex_revalidate_miss.test.py
index bf765eb..3a48382 100644
--- a/tests/gold_tests/pluginTest/regex_revalidate/regex_revalidate_miss.test.py
+++ b/tests/gold_tests/pluginTest/regex_revalidate/regex_revalidate_miss.test.py
@@ -38,8 +38,8 @@ server = Test.MakeOriginServer("server")
 # Define ATS and configure
 ts = Test.MakeATSProcess("ts", command="traffic_manager")
 
-# **testname is required**
-#testName = "regex_reval"
+Test.testName = "regex_revalidate_miss"
+Test.Setup.Copy("metrics_miss.sh")
 
 # default root
 request_header_0 = {"headers":
@@ -220,7 +220,7 @@ ps.ReturnCode = 0
 ps.TimeOut = 5
 tr.TimeOut = 5
 
-# 8 Test - Cache stale
+# 10 Test - Cache stale
 tr = Test.AddTestRun("Cache stale path1")
 ps = tr.Processes.Default
 tr.DelayStart = 5
@@ -228,3 +228,11 @@ ps.Command = curl_and_args + ' http://ats/path1'
 ps.ReturnCode = 0
 ps.Streams.stdout.Content = Testers.ContainsExpression("X-Cache: hit-fresh", "expected cache
hit response")
 tr.StillRunningAfter = ts
+
+# 11 Stats check
+tr = Test.AddTestRun("Check stats")
+tr.DelayStart = 5
+tr.Processes.Default.Command = "bash -c ./metrics_miss.sh"
+tr.Processes.Default.Env = ts.Env
+tr.Processes.Default.ReturnCode = 0
+tr.StillRunningAfter = ts

Mime
View raw message