Repository: trafficserver Updated Branches: refs/heads/master de1bcc7a6 -> 0c8f9343c
TS-2975: add x-cache header to publish cache lookup status Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/0c8f9343 Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/0c8f9343 Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/0c8f9343 Branch: refs/heads/master Commit: 0c8f9343c2d55c2469af36e368e0b7a86cf6def5 Parents: de1bcc7 Author: James Peach <[email protected]> Authored: Tue Jul 29 13:55:50 2014 -0700 Committer: James Peach <[email protected]> Committed: Wed Jul 30 11:20:04 2014 -0700 ---------------------------------------------------------------------- CHANGES | 2 ++ doc/reference/plugins/xdebug.en.rst | 13 +++++++ plugins/experimental/xdebug/xdebug.cc | 58 ++++++++++++++++++++++++++++-- 3 files changed, 70 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0c8f9343/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index 69df453..1295f23 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,8 @@ -*- coding: utf-8 -*- Changes with Apache Traffic Server 5.1.0 + *) [TS-2975] Add cache lookup status support to the xdebug plugin. + *) [TS-2974] Add a new metrics plugin to support the Epic monitoring system. *) [TS-2973] Add milestones support to the xdebug plugin. http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0c8f9343/doc/reference/plugins/xdebug.en.rst ---------------------------------------------------------------------- diff --git a/doc/reference/plugins/xdebug.en.rst b/doc/reference/plugins/xdebug.en.rst index 003201f..0ee9197 100644 --- a/doc/reference/plugins/xdebug.en.rst +++ b/doc/reference/plugins/xdebug.en.rst @@ -46,6 +46,19 @@ X-Cache-Key Traffic Server cache. This header is particularly useful if a custom cache key is being used. +X-Cache + The ``X-Cache`` header contains the results of any cache lookup. + + ========== =========== + Value Description + ========== =========== + none No cache lookup was attempted. + miss The object was not found in the cache. + hit-stale The object was found in the cache, but it was stale. + hit-fresh The object was fresh in the cache. + skipped The cache lookup was skipped. + ========== =========== + X-Milestones The ``X-Milestones`` header contains detailed information about how long the transaction took to traverse portions of the HTTP http://git-wip-us.apache.org/repos/asf/trafficserver/blob/0c8f9343/plugins/experimental/xdebug/xdebug.cc ---------------------------------------------------------------------- diff --git a/plugins/experimental/xdebug/xdebug.cc b/plugins/experimental/xdebug/xdebug.cc index 883f5ca..2d357c1 100644 --- a/plugins/experimental/xdebug/xdebug.cc +++ b/plugins/experimental/xdebug/xdebug.cc @@ -27,6 +27,7 @@ #define XHEADER_X_CACHE_KEY 0x0004u #define XHEADER_X_MILESTONES 0x0008u +#define XHEADER_X_CACHE 0x0010u static int XArgIndex = 0; static TSCont XInjectHeadersCont = NULL; @@ -99,6 +100,47 @@ done: } static void +InjectCacheHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr) +{ + TSMLoc dst = TS_NULL_MLOC; + int status; + + static const char * names[] = + { + "miss" , // TS_CACHE_LOOKUP_MISS, + "hit-stale", // TS_CACHE_LOOKUP_HIT_STALE, + "hit-fresh", // TS_CACHE_LOOKUP_HIT_FRESH, + "skipped" // TS_CACHE_LOOKUP_SKIPPED + }; + + TSDebug("xdebug", "attempting to inject X-Cache header"); + + // Create a new response header field. + dst = FindOrMakeHdrField(buffer, hdr, "X-Cache", lengthof("X-Cache")); + if (dst == TS_NULL_MLOC) { + goto done; + } + + if (TSHttpTxnCacheLookupStatusGet(txn, &status) == TS_ERROR) { + // If the cache lookup hasn't happened yes, TSHttpTxnCacheLookupStatusGet will fail. + TSReleaseAssert( + TSMimeHdrFieldValueStringInsert(buffer, hdr, dst, 0 /* idx */, "none", 4) == TS_SUCCESS + ); + } else { + const char * msg = (status < 0 || status >= (int)countof(names)) ? "unknown" : names[status]; + + TSReleaseAssert( + TSMimeHdrFieldValueStringInsert(buffer, hdr, dst, 0 /* idx */, msg, -1) == TS_SUCCESS + ); + } + +done: + if (dst != TS_NULL_MLOC) { + TSHandleMLocRelease(buffer, hdr, dst); + } +} + +static void InjectMilestonesHeader(TSHttpTxn txn, TSMBuffer buffer, TSMLoc hdr) { struct milestone { @@ -188,6 +230,10 @@ XInjectResponseHeaders(TSCont /* contp */, TSEvent event, void * edata) InjectCacheKeyHeader(txn, buffer, hdr); } + if (xheaders & XHEADER_X_CACHE) { + InjectCacheHeader(txn, buffer, hdr); + } + if (xheaders & XHEADER_X_MILESTONES) { InjectMilestonesHeader(txn, buffer, hdr); } @@ -230,11 +276,15 @@ XScanRequestHeaders(TSCont /* contp */, TSEvent event, void * edata) continue; } - if (strncasecmp("x-cache-key", value, vsize) == 0) { +#define header_field_eq(name, vptr, vlen) (((int)lengthof(name) == vlen) && (strncasecmp(name, vptr, vlen) == 0)) + + if (header_field_eq("x-cache-key", value, vsize)) { xheaders |= XHEADER_X_CACHE_KEY; - } else if (strncasecmp("x-milestones", value, vsize) == 0) { + } else if (header_field_eq("x-milestones", value, vsize)) { xheaders |= XHEADER_X_MILESTONES; - } else if (strncasecmp("via", value, vsize) == 0) { + } else if (header_field_eq("x-cache", value, vsize)) { + xheaders |= XHEADER_X_CACHE; + } else if (header_field_eq("via", value, vsize)) { // If the client requests the Via header, enable verbose Via debugging for this transaction. TSHttpTxnConfigIntSet(txn, TS_CONFIG_HTTP_INSERT_RESPONSE_VIA_STR, 3); } else { @@ -242,6 +292,8 @@ XScanRequestHeaders(TSCont /* contp */, TSEvent event, void * edata) } } +#undef header_field_eq + // Get the next duplicate. next = TSMimeHdrFieldNextDup(buffer, hdr, field);
