mlibbey commented on code in PR #12380:
URL: https://github.com/apache/trafficserver/pull/12380#discussion_r2226076013
##########
doc/developer-guide/cripts/cripts-misc.en.rst:
##########
@@ -259,25 +339,80 @@ work the same as the core metrics, but they are also as
efficient. There are two
================================
=======================================================================
Metric Description
================================
=======================================================================
-``cripts::Metric::Counter`` A simple counter, which can only be
incremented.
-``cripts::Metric::Gauge`` A gauge, which can be incremented and
decremented, and set to a value.
+``cripts::Metrics::Counter`` A simple counter, which can only be
incremented.
+``cripts::Metrics::Gauge`` A gauge, which can be incremented and
decremented, and set to a value.
================================
=======================================================================
+Both metric types support the following operations:
+
+=========================
=======================================================================
+Method Description
+=========================
=======================================================================
+``Increment()`` Increment the metric by 1.
+``Increment(value)`` Increment the metric by the specified value.
+``Decrement()`` Decrement the metric by 1 (Gauge only).
+``Decrement(value)`` Decrement the metric by the specified value (Gauge
only).
+``Name()`` Get the metric name.
+``Id()`` Get the internal metric ID.
+=========================
=======================================================================
+
Example:
.. code-block:: cpp
do_create_instance()
{
instance.metrics[0] =
cripts::Metrics::Counter::Create("cript.example1.instance_calls");
+ instance.metrics[1] =
cripts::Metrics::Gauge::Create("cript.example1.active_requests");
}
do_remap()
{
- static auto plugin_metric =
cripts::Metrics::Counter("cript.example1.plugin_calls");
+ static auto plugin_metric =
cripts::Metrics::Counter::Create("cript.example1.plugin_calls");
- plugin_metric.Increment();
+ plugin_metric->Increment();
instance.metrics[0]->Increment();
+ instance.metrics[1]->Increment();
+ }
+
+ do_txn_close()
+ {
+ instance.metrics[1]->Decrement();
}
-A ``cripts::Metric::Gauge`` can also be set via the ``Setter()`` method.
+A ``cripts::Metrics::Gauge`` can also be set to a specific value using the
assignment operator:
+
+.. code-block:: cpp
+
+ instance.metrics[1] = 42; // Set gauge to specific value
+
+.. _cripts-misc-debugging:
+
+Debugging and Development
+=========================
+
+Cripts provides several debugging and development aids to help with plugin
development:
+
+=========================
=======================================================================
+Function Description
+=========================
=======================================================================
+``CDebug(format, ...)`` Debug logging with format string support.
+``CDebugOn()`` Check if debug logging is enabled for this
instance.
+=========================
=======================================================================
+
+Debug logging uses the same format string syntax as ``fmt::format()`` in
``libfmt``:
+
+.. code-block:: cpp
+
+ do_remap()
+ {
+ if (CDebugOn()) {
+ borrow url = cripts::Client::URL::Get();
+ CDebug("Processing request for: {}", url.path);
+ CDebug("Query parameters: {}", url.query.String());
+ }
+ }
+
+.. note::
+ Debug output is controlled by the ATS debug tags system. Use appropriate
+ debug tags in your ATS configuration to enable debug output for your
Cripts.
Review Comment:
This leaves me wondering what the appropriate tag is. Eg, "the default debug
tag for cripts is ..." (or, link to a section that shows how to set a debug tag
for a particular cript?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]