This is an automated email from the ASF dual-hosted git repository.
zwoop pushed a commit to branch master
in repository https://git-dual.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push:
new 779fd2f TS-4520 header_rewrite: Add a new ID condition, with 3
types
779fd2f is described below
commit 779fd2ffa5ff871d06fdf8feca81bd71da46ee7a
Author: Leif Hedstrom <[email protected]>
AuthorDate: Mon Jun 13 15:00:50 2016 -0600
TS-4520 header_rewrite: Add a new ID condition, with 3 types
This gives header_rewrite the functionality to get / use the
same UUID / IDs as the new log-formats in TS-4519.
---
doc/admin-guide/plugins/header_rewrite.en.rst | 20 ++++++
plugins/header_rewrite/conditions.cc | 98 +++++++++++++++++++++++++--
plugins/header_rewrite/conditions.h | 19 +++++-
plugins/header_rewrite/factory.cc | 2 +
plugins/header_rewrite/statement.h | 8 +++
5 files changed, 141 insertions(+), 6 deletions(-)
diff --git a/doc/admin-guide/plugins/header_rewrite.en.rst
b/doc/admin-guide/plugins/header_rewrite.en.rst
index 0a78ac3..4082fb0 100644
--- a/doc/admin-guide/plugins/header_rewrite.en.rst
+++ b/doc/admin-guide/plugins/header_rewrite.en.rst
@@ -261,6 +261,26 @@ separated string of the values from every occurrence of
the header. Refer to
If you wish to use a client request header, regardless of hook context, you may
consider using the `CLIENT-HEADER`_ condition instead.
+ID
+~~
+::
+ cond %{ID:REQUEST} >100
+
+This condition provides access to three identifier values that ATS uses
+internally for things like logging and debugging. Since these are IDs, they
+are mostly useful as a value (operand) to other operators. The three types of
+IDs are
+
+ %{ID:REQUEST} A unique, sequence number for the transaction
+ %{ID:PROCESS} A UUID string, generated every time ATS restarts
+ %{ID:UNIQUE} The combination of the previous two IDs
+
+Now, even though these are conditionals, their primary use are as value
+arguments to another operator. For example::
+
+ set-header ATS-Req-UUID %{ID:UNIQUE}
+
+
INCOMING-PORT
~~~~~~~~~~~~~
::
diff --git a/plugins/header_rewrite/conditions.cc
b/plugins/header_rewrite/conditions.cc
index 5f9685a..f5c2042 100644
--- a/plugins/header_rewrite/conditions.cc
+++ b/plugins/header_rewrite/conditions.cc
@@ -738,7 +738,7 @@ ConditionNow::set_qualifier(const std::string &q)
} else if (q == "YEARDAY") {
_now_qual = NOW_QUAL_YEARDAY;
} else {
- TSError("[%s] Unknown Now() qualifier: %s", PLUGIN_NAME, q.c_str());
+ TSError("[%s] Unknown NOW() qualifier: %s", PLUGIN_NAME, q.c_str());
}
}
@@ -965,13 +965,11 @@ ConditionGeo::append_value(std::string &s, const
Resources &res)
if (is_int_type()) {
oss << get_geo_int(TSHttpTxnClientAddrGet(res.txnp));
- s += oss.str();
- TSDebug(PLUGIN_NAME, "Appending GEO() to evaluation value -> %s",
s.c_str());
} else {
oss << get_geo_string(TSHttpTxnClientAddrGet(res.txnp));
- s += oss.str();
- TSDebug(PLUGIN_NAME, "Appending GEO() to evaluation value -> %s",
s.c_str());
}
+ s += oss.str();
+ TSDebug(PLUGIN_NAME, "Appending GEO() to evaluation value -> %s", s.c_str());
}
bool
@@ -993,3 +991,93 @@ ConditionGeo::eval(const Resources &res)
return ret;
}
+
+// ConditionId: Some identifier strings, currently:
+// PROCESS: The process UUID string
+// REQUEST: The request (HttpSM::sm_id) counter
+// UNIQUE: The combination of UUID-sm_id
+void
+ConditionId::initialize(Parser &p)
+{
+ Condition::initialize(p);
+
+ if (_id_qual == ID_QUAL_REQUEST) {
+ Matchers<uint64_t> *match = new Matchers<uint64_t>(_cond_op);
+
+ match->set(static_cast<uint64_t>(strtol(p.get_arg().c_str(), NULL, 10)));
+ _matcher = match;
+ } else {
+ // The default is to have a string matcher
+ Matchers<std::string> *match = new Matchers<std::string>(_cond_op);
+
+ match->set(p.get_arg());
+ _matcher = match;
+ }
+}
+
+void
+ConditionId::set_qualifier(const std::string &q)
+{
+ Condition::set_qualifier(q);
+
+ TSDebug(PLUGIN_NAME, "\tParsing %%{ID:%s} qualifier", q.c_str());
+
+ if (q == "UNIQUE") {
+ _id_qual = ID_QUAL_UNIQUE;
+ } else if (q == "PROCESS") {
+ _id_qual = ID_QUAL_PROCESS;
+ } else if (q == "REQUEST") {
+ _id_qual = ID_QUAL_REQUEST;
+ } else {
+ TSError("[%s] Unknown ID() qualifier: %s", PLUGIN_NAME, q.c_str());
+ }
+}
+
+void
+ConditionId::append_value(std::string &s, const Resources &res ATS_UNUSED)
+{
+ switch (_id_qual) {
+ case ID_QUAL_REQUEST: {
+ std::ostringstream oss;
+
+ oss << TSHttpTxnIdGet(res.txnp);
+ s += oss.str();
+ } break;
+ case ID_QUAL_PROCESS: {
+ TSUuid process = TSProcessUuidGet();
+
+ if (process) {
+ s += TSUuidStringGet(process);
+ }
+ } break;
+ case ID_QUAL_UNIQUE: {
+ std::ostringstream oss;
+ TSUuid process = TSProcessUuidGet();
+
+ if (process) {
+ oss << TSUuidStringGet(process) << '-' << TSHttpTxnIdGet(res.txnp);
+ s += oss.str();
+ }
+ } break;
+ }
+ TSDebug(PLUGIN_NAME, "Appending ID() to evaluation value -> %s", s.c_str());
+}
+
+bool
+ConditionId::eval(const Resources &res)
+{
+ if (_id_qual == ID_QUAL_REQUEST) {
+ uint64_t id = TSHttpTxnIdGet(res.txnp);
+
+ TSDebug(PLUGIN_NAME, "Evaluating GEO() -> %" PRIu64, id);
+ return static_cast<const Matchers<uint64_t> *>(_matcher)->test(id);
+ } else {
+ std::string s;
+
+ append_value(s, res);
+ bool rval = static_cast<const Matchers<std::string> *>(_matcher)->test(s);
+
+ TSDebug(PLUGIN_NAME, "Evaluating ID(): %s - rval: %d", s.c_str(), rval);
+ return rval;
+ }
+}
diff --git a/plugins/header_rewrite/conditions.h
b/plugins/header_rewrite/conditions.h
index 32915c8..3f31126 100644
--- a/plugins/header_rewrite/conditions.h
+++ b/plugins/header_rewrite/conditions.h
@@ -438,7 +438,7 @@ public:
void set_qualifier(const std::string &q);
void append_value(std::string &s, const Resources &res);
- // These are special for this sub-class
+ // Make sure we know if the type is an int-type or a string.
bool
is_int_type() const
{
@@ -463,4 +463,21 @@ private:
bool _int_type;
};
+// id: Various identifiers for the requests, server process etc.
+class ConditionId : public Condition
+{
+public:
+ explicit ConditionId() : _id_qual(ID_QUAL_UNIQUE) { TSDebug(PLUGIN_NAME_DBG,
"Calling CTOR for ConditionId"); };
+ void initialize(Parser &p);
+ void set_qualifier(const std::string &q);
+ void append_value(std::string &s, const Resources &res);
+
+protected:
+ bool eval(const Resources &res);
+
+private:
+ DISALLOW_COPY_AND_ASSIGN(ConditionId);
+ IdQualifiers _id_qual;
+};
+
#endif // __CONDITIONS_H
diff --git a/plugins/header_rewrite/factory.cc
b/plugins/header_rewrite/factory.cc
index b4d2e8b..01b804b 100644
--- a/plugins/header_rewrite/factory.cc
+++ b/plugins/header_rewrite/factory.cc
@@ -135,6 +135,8 @@ condition_factory(const std::string &cond)
c = new ConditionNow();
} else if (c_name == "GEO") {
c = new ConditionGeo();
+ } else if (c_name == "ID") {
+ c = new ConditionId();
} else {
TSError("[%s] Unknown condition: %s", PLUGIN_NAME, c_name.c_str());
return NULL;
diff --git a/plugins/header_rewrite/statement.h
b/plugins/header_rewrite/statement.h
index 1f10de5..ef32fa8 100644
--- a/plugins/header_rewrite/statement.h
+++ b/plugins/header_rewrite/statement.h
@@ -57,6 +57,7 @@ enum NowQualifiers {
NOW_QUAL_YEARDAY
};
+// GEO data
enum GeoQualifiers {
GEO_QUAL_COUNTRY,
GEO_QUAL_COUNTRY_ISO,
@@ -64,6 +65,13 @@ enum GeoQualifiers {
GEO_QUAL_ASN_NAME,
};
+// ID data
+enum IdQualifiers {
+ ID_QUAL_REQUEST,
+ ID_QUAL_PROCESS,
+ ID_QUAL_UNIQUE,
+};
+
class Statement
{
public:
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].