Repository: trafficserver Updated Branches: refs/heads/master 1678555d0 -> 2660e4ced
TS-3036 Add a new log tag format for cache medium Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/90f9a5ce Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/90f9a5ce Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/90f9a5ce Branch: refs/heads/master Commit: 90f9a5ce07450732c032cecc90ff87843238c218 Parents: 1678555 Author: Leif Hedstrom <[email protected]> Authored: Fri Nov 21 08:30:07 2014 -0700 Committer: Leif Hedstrom <[email protected]> Committed: Mon Mar 9 17:39:57 2015 -0600 ---------------------------------------------------------------------- proxy/hdrs/HTTP.h | 29 ++++++++++++++++++----------- proxy/http/HttpSM.cc | 14 ++++++++++++-- proxy/http/HttpTransact.cc | 6 ++++-- proxy/http/HttpTransact.h | 8 ++++---- proxy/http/HttpTransactHeaders.cc | 14 ++++++++------ proxy/logging/Log.cc | 34 ++++++++++++++++++++++++++++++++++ proxy/logging/LogAccess.cc | 27 +++++++++++++++++++++++++++ proxy/logging/LogAccess.h | 2 ++ proxy/logging/LogAccessHttp.cc | 13 +++++++++++++ proxy/logging/LogAccessHttp.h | 1 + proxy/logging/LogAccessTest.cc | 13 +++++++++++++ proxy/logging/LogAccessTest.h | 1 + 12 files changed, 137 insertions(+), 25 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/hdrs/HTTP.h ---------------------------------------------------------------------- diff --git a/proxy/hdrs/HTTP.h b/proxy/hdrs/HTTP.h index b686f3c..0f5daff 100644 --- a/proxy/hdrs/HTTP.h +++ b/proxy/hdrs/HTTP.h @@ -204,16 +204,17 @@ enum SquidHierarchyCode /* squid hit/miss codes */ enum SquidHitMissCode { - SQUID_HIT_RESERVED = '0', - SQUID_HIT_LEVEL_1 = '1', - SQUID_HIT_LEVEL_2 = '2', - SQUID_HIT_LEVEL_3 = '3', - SQUID_HIT_LEVEL_4 = '4', - SQUID_HIT_LEVEL_5 = '5', - SQUID_HIT_LEVEL_6 = '6', - SQUID_HIT_LEVEL_7 = '7', - SQUID_HIT_LEVEL_8 = '8', - SQUID_HIT_LEVEl_9 = '9', + SQUID_HIT_RESERVED = '0', // Kinda wonky that this is '0', so skipping 'A' for now + SQUID_HIT_LEVEL_1 = 'B', + SQUID_HIT_LEVEL_2 = 'C', + SQUID_HIT_LEVEL_3 = 'D', + SQUID_HIT_LEVEL_4 = 'E', + SQUID_HIT_LEVEL_5 = 'F', + SQUID_HIT_LEVEL_6 = 'G', + SQUID_HIT_LEVEL_7 = 'H', + SQUID_HIT_LEVEL_8 = 'I', + SQUID_HIT_LEVEl_9 = 'J', + SQUID_HIT_LEVEL_10 = 'K', SQUID_MISS_NONE = '1', SQUID_MISS_ICP_AUTH = '2', SQUID_MISS_HTTP_NON_CACHE = '3', @@ -226,7 +227,13 @@ enum SquidHitMissCode SQUID_MISS_PRE_EXPIRED = 'a', SQUID_MISS_ERROR = 'b', SQUID_MISS_CACHE_BYPASS = 'c', - SQUID_HIT_MISS_INVALID_ASSIGNED_CODE = 'z' + SQUID_HIT_MISS_INVALID_ASSIGNED_CODE = 'z', + // These are pre-allocated with special semantics, added here for convenience + SQUID_HIT_RAM = SQUID_HIT_LEVEL_1, + SQUID_HIT_SSD = SQUID_HIT_LEVEL_2, + SQUID_HIT_DISK = SQUID_HIT_LEVEL_3, + SQUID_HIT_CLUSTER = SQUID_HIT_LEVEL_4, + SQUID_HIT_NET = SQUID_HIT_LEVEL_5 }; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/http/HttpSM.cc ---------------------------------------------------------------------- diff --git a/proxy/http/HttpSM.cc b/proxy/http/HttpSM.cc index a544246..bdbe1d0 100644 --- a/proxy/http/HttpSM.cc +++ b/proxy/http/HttpSM.cc @@ -2446,7 +2446,12 @@ HttpSM::state_cache_open_write(int event, void *data) // The write vector was locked and the cache_sm retried // and got the read vector again. cache_sm.cache_read_vc->get_http_info(&t_state.cache_info.object_read); - t_state.cache_info.is_ram_cache_hit = (cache_sm.cache_read_vc)->is_ram_cache_hit(); + // ToDo: Should support other levels of cache hits here, but the cache does not support it (yet) + if (cache_sm.cache_read_vc->is_ram_cache_hit()) { + t_state.cache_info.hit_miss_code = SQUID_HIT_RAM; + } else { + t_state.cache_info.hit_miss_code = SQUID_HIT_DISK; + } ink_assert(t_state.cache_info.object_read != 0); t_state.source = HttpTransact::SOURCE_CACHE; @@ -2530,7 +2535,12 @@ HttpSM::state_cache_open_read(int event, void *data) t_state.source = HttpTransact::SOURCE_CACHE; cache_sm.cache_read_vc->get_http_info(&t_state.cache_info.object_read); - t_state.cache_info.is_ram_cache_hit = (cache_sm.cache_read_vc)->is_ram_cache_hit(); + // ToDo: Should support other levels of cache hits here, but the cache does not support it (yet) + if (cache_sm.cache_read_vc->is_ram_cache_hit()) { + t_state.cache_info.hit_miss_code = SQUID_HIT_RAM; + } else { + t_state.cache_info.hit_miss_code = SQUID_HIT_DISK; + } ink_assert(t_state.cache_info.object_read != 0); call_transact_and_set_next_state(HttpTransact::HandleCacheOpenRead); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/http/HttpTransact.cc ---------------------------------------------------------------------- diff --git a/proxy/http/HttpTransact.cc b/proxy/http/HttpTransact.cc index 0097a67..1d5ae5f 100644 --- a/proxy/http/HttpTransact.cc +++ b/proxy/http/HttpTransact.cc @@ -2696,7 +2696,8 @@ HttpTransact::HandleCacheOpenReadHit(State* s) DebugTxn("http_trans", "CacheOpenRead --- HIT-FRESH"); DebugTxn("http_seq", "[HttpTransact::HandleCacheOpenReadHit] " "Serve from cache"); - if (s->cache_info.is_ram_cache_hit) { + // ToDo: Should support other levels of cache hits here, but the cache does not support it (yet) + if (SQUID_HIT_RAM == s->cache_info.hit_miss_code) { SET_VIA_STRING(VIA_CACHE_RESULT, VIA_IN_RAM_CACHE_FRESH); } else { SET_VIA_STRING(VIA_CACHE_RESULT, VIA_IN_CACHE_FRESH); @@ -6933,7 +6934,8 @@ bool HttpTransact::delete_all_document_alternates_and_return(State* s, bool cache_hit) { if (cache_hit == true) { - if (s->cache_info.is_ram_cache_hit) { + // ToDo: Should support other levels of cache hits here, but the cache does not support it (yet) + if (SQUID_HIT_RAM == s->cache_info.hit_miss_code) { SET_VIA_STRING(VIA_CACHE_RESULT, VIA_IN_RAM_CACHE_FRESH); } else { SET_VIA_STRING(VIA_CACHE_RESULT, VIA_IN_CACHE_FRESH); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/http/HttpTransact.h ---------------------------------------------------------------------- diff --git a/proxy/http/HttpTransact.h b/proxy/http/HttpTransact.h index 4219677..86660ec 100644 --- a/proxy/http/HttpTransact.h +++ b/proxy/http/HttpTransact.h @@ -646,7 +646,7 @@ public: int open_write_retries; CacheWriteLock_t write_lock_state; int lookup_count; - bool is_ram_cache_hit; + SquidHitMissCode hit_miss_code; _CacheLookupInfo() : action(CACHE_DO_UNDEFINED), @@ -664,9 +664,9 @@ public: directives(), open_read_retries(0), open_write_retries(0), - write_lock_state(CACHE_WL_INIT), - lookup_count(0), - is_ram_cache_hit(false) + write_lock_state(CACHE_WL_INIT), + lookup_count(0), + hit_miss_code(SQUID_MISS_NONE) { } } CacheLookupInfo; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/http/HttpTransactHeaders.cc ---------------------------------------------------------------------- diff --git a/proxy/http/HttpTransactHeaders.cc b/proxy/http/HttpTransactHeaders.cc index f539c7a..aa97296 100644 --- a/proxy/http/HttpTransactHeaders.cc +++ b/proxy/http/HttpTransactHeaders.cc @@ -512,12 +512,15 @@ HttpTransactHeaders::generate_and_set_squid_codes(HTTPHdr *header, (via_string[VIA_DETAIL_CACHE_LOOKUP] == VIA_DETAIL_MISS_CONDITIONAL) || (via_string[VIA_DETAIL_CACHE_LOOKUP] == VIA_DETAIL_HIT_SERVED)) { // its a cache hit. - // INKqa10331 - hit_miss_code = SQUID_HIT_RESERVED; + if (via_string[VIA_CACHE_RESULT] == VIA_IN_RAM_CACHE_FRESH) { + hit_miss_code = SQUID_HIT_RAM; + } else { // TODO: Support other cache tiers here + hit_miss_code = SQUID_HIT_RESERVED; + } } else { int reason_len; const char *reason = header->reason_get(&reason_len); - // INKqa10331 + if (reason != NULL && reason_len >= 24 && reason[0] == '!' && reason[1] == SQUID_HIT_RESERVED) hit_miss_code = SQUID_HIT_RESERVED; // its a miss in the cache. find out why. @@ -647,9 +650,8 @@ HttpTransactHeaders::generate_and_set_squid_codes(HTTPHdr *header, break; } - Debug("http_trans", - "[Squid code generation] Hit/Miss: %d, Log: %d, Hier: %d", - hit_miss_code, log_code, hier_code); + Debug("http_trans", "[Squid code generation] Hit/Miss: %c, Log: %c, Hier: %c", hit_miss_code, log_code, hier_code); + squid_codes->log_code = log_code; squid_codes->hier_code = hier_code; squid_codes->hit_miss_code = hit_miss_code; http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/logging/Log.cc ---------------------------------------------------------------------- diff --git a/proxy/logging/Log.cc b/proxy/logging/Log.cc index c4b8fa6..e8ce657 100644 --- a/proxy/logging/Log.cc +++ b/proxy/logging/Log.cc @@ -626,6 +626,32 @@ Log::init_fields() SQUID_LOG_ERR_FUTURE_1, "ERR_FUTURE_1", SQUID_LOG_ERR_UNKNOWN, "ERR_UNKNOWN"); + Ptr<LogFieldAliasTable> cache_hit_miss_map = make_ptr(new LogFieldAliasTable); + cache_hit_miss_map->init(24, + SQUID_HIT_RESERVED, "HIT", + SQUID_HIT_LEVEL_1, "HIT_RAM", // Also SQUID_HIT_RAM + SQUID_HIT_LEVEL_2, "HIT_SSD", // Also SQUID_HIT_SSD + SQUID_HIT_LEVEL_3, "HIT_DISK", // Also SQUID_HIT_DISK + SQUID_HIT_LEVEL_4, "HIT_CLUSTER", // Also SQUID_HIT_CLUSTER + SQUID_HIT_LEVEL_5, "HIT_NET", // Also SQUID_HIT_NET + SQUID_HIT_LEVEL_6, "HIT_LEVEL_6", + SQUID_HIT_LEVEL_7, "HIT_LEVEL_7", + SQUID_HIT_LEVEL_8, "HIT_LEVEL_8", + SQUID_HIT_LEVEl_9, "HIT_LEVEL_9", + SQUID_MISS_NONE, "MISS", + SQUID_MISS_ICP_AUTH, "MISS_ICP_AUTH", + SQUID_MISS_HTTP_NON_CACHE, "MISS_HTTP_NON_CACHE", + SQUID_MISS_ICP_STOPLIST, "MISS_ICP_STOPLIST", + SQUID_MISS_HTTP_NO_DLE, "MISS_HTTP_NO_DLE", + SQUID_MISS_HTTP_NO_LE, "MISS_HTTP_NO_LE", + SQUID_MISS_HTTP_CONTENT, "MISS_HTTP_CONTENT", + SQUID_MISS_PRAGMA_NOCACHE, "MISS_PRAGMA_NOCACHE", + SQUID_MISS_PASS, "MISS_PASS", + SQUID_MISS_PRE_EXPIRED, "MISS_PRE_EXPIRED", + SQUID_MISS_ERROR, "MISS_ERROR", + SQUID_MISS_CACHE_BYPASS, "MISS_CACHE_BYPASS", + SQUID_HIT_MISS_INVALID_ASSIGNED_CODE, "INVALID_CODE"); + field = new LogField("cache_result_code", "crc", LogField::sINT, &LogAccess::marshal_cache_result_code, @@ -634,6 +660,14 @@ Log::init_fields() global_field_list.add(field, false); ink_hash_table_insert(field_symbol_hash, "crc", field); + field = new LogField("cache_hit_miss", "chm", + LogField::sINT, + &LogAccess::marshal_cache_hit_miss, + &LogAccess::unmarshal_cache_hit_miss, + (Ptr<LogFieldAliasMap>) cache_hit_miss_map); + global_field_list.add(field, false); + ink_hash_table_insert(field_symbol_hash, "chm", field); + // proxy -> server fields field = new LogField("proxy_req_header_len", "pqhl", LogField::sINT, http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/logging/LogAccess.cc ---------------------------------------------------------------------- diff --git a/proxy/logging/LogAccess.cc b/proxy/logging/LogAccess.cc index ce5f04c..cb295a3 100644 --- a/proxy/logging/LogAccess.cc +++ b/proxy/logging/LogAccess.cc @@ -301,6 +301,15 @@ LogAccess::marshal_cache_result_code(char *buf) -------------------------------------------------------------------------*/ int +LogAccess::marshal_cache_hit_miss(char *buf) +{ + DEFAULT_INT_FIELD; +} + +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +int LogAccess::marshal_proxy_req_header_len(char *buf) { DEFAULT_INT_FIELD; @@ -1331,6 +1340,24 @@ LogAccess::unmarshal_cache_code(char **buf, char *dest, int len, Ptr<LogFieldAli } /*------------------------------------------------------------------------- + LogAccess::unmarshal_cache_hit_miss + + Retrieve the int pointed at by the buffer and treat as a SquidHitMissCode. + Use this to index into the local string tables and return the string + equiv of the enum. Advance the pointer. + -------------------------------------------------------------------------*/ + +int +LogAccess::unmarshal_cache_hit_miss(char **buf, char *dest, int len, Ptr<LogFieldAliasMap> map) +{ + ink_assert(buf != NULL); + ink_assert(*buf != NULL); + ink_assert(dest != NULL); + + return (LogAccess::unmarshal_with_map(unmarshal_int(buf), dest, len, map, "HIT_MISS_UNKNOWN")); +} + +/*------------------------------------------------------------------------- LogAccess::unmarshal_entry_type -------------------------------------------------------------------------*/ http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/logging/LogAccess.h ---------------------------------------------------------------------- diff --git a/proxy/logging/LogAccess.h b/proxy/logging/LogAccess.h index 9b1a615..f422c0e 100644 --- a/proxy/logging/LogAccess.h +++ b/proxy/logging/LogAccess.h @@ -197,6 +197,7 @@ public: inkcoreapi virtual int marshal_proxy_finish_status_code(char *); // INT inkcoreapi virtual int marshal_cache_result_code(char *); // INT inkcoreapi virtual int marshal_proxy_host_port(char *); // INT + inkcoreapi virtual int marshal_cache_hit_miss(char *); // INT // // proxy -> server fields @@ -300,6 +301,7 @@ public: static int unmarshal_hierarchy(char **buf, char *dest, int len, Ptr<LogFieldAliasMap> map); static int unmarshal_finish_status(char **buf, char *dest, int len, Ptr<LogFieldAliasMap> map); static int unmarshal_cache_code(char **buf, char *dest, int len, Ptr<LogFieldAliasMap> map); + static int unmarshal_cache_hit_miss(char **buf, char *dest, int len, Ptr<LogFieldAliasMap> map); static int unmarshal_entry_type(char **buf, char *dest, int len, Ptr<LogFieldAliasMap> map); static int unmarshal_cache_write_code(char **buf, char *dest, int len, Ptr<LogFieldAliasMap> map); static int unmarshal_client_protocol_stack(char **buf, char *dest, int len, Ptr<LogFieldAliasMap> map); http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/logging/LogAccessHttp.cc ---------------------------------------------------------------------- diff --git a/proxy/logging/LogAccessHttp.cc b/proxy/logging/LogAccessHttp.cc index 9b41850..d58f58a 100644 --- a/proxy/logging/LogAccessHttp.cc +++ b/proxy/logging/LogAccessHttp.cc @@ -724,6 +724,19 @@ LogAccessHttp::marshal_cache_result_code(char *buf) -------------------------------------------------------------------------*/ int +LogAccessHttp::marshal_cache_hit_miss(char *buf) +{ + if (buf) { + SquidHitMissCode code = m_http_sm->t_state.squid_codes.hit_miss_code; + marshal_int(buf, (int64_t) code); + } + return INK_MIN_ALIGN; +} + +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +int LogAccessHttp::marshal_proxy_req_header_len(char *buf) { if (buf) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/logging/LogAccessHttp.h ---------------------------------------------------------------------- diff --git a/proxy/logging/LogAccessHttp.h b/proxy/logging/LogAccessHttp.h index dc392f5..8b6d5e7 100644 --- a/proxy/logging/LogAccessHttp.h +++ b/proxy/logging/LogAccessHttp.h @@ -82,6 +82,7 @@ public: virtual int marshal_proxy_resp_header_len(char *); // INT virtual int marshal_proxy_finish_status_code(char *); // INT virtual int marshal_cache_result_code(char *); // INT + virtual int marshal_cache_hit_miss(char *); // INT // // proxy -> server fields http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/logging/LogAccessTest.cc ---------------------------------------------------------------------- diff --git a/proxy/logging/LogAccessTest.cc b/proxy/logging/LogAccessTest.cc index 22e2f2a..c58e8f9 100644 --- a/proxy/logging/LogAccessTest.cc +++ b/proxy/logging/LogAccessTest.cc @@ -274,6 +274,19 @@ LogAccessTest::marshal_cache_result_code(char *buf) -------------------------------------------------------------------------*/ int +LogAccessTest::marshal_cache_miss_hit(char *buf) +{ + if (buf) { + int64_t val = 10; + marshal_int(buf, val); + } + return sizeof(int64_t); +} + +/*------------------------------------------------------------------------- + -------------------------------------------------------------------------*/ + +int LogAccessTest::marshal_proxy_req_header_len(char *buf) { if (buf) { http://git-wip-us.apache.org/repos/asf/trafficserver/blob/90f9a5ce/proxy/logging/LogAccessTest.h ---------------------------------------------------------------------- diff --git a/proxy/logging/LogAccessTest.h b/proxy/logging/LogAccessTest.h index 32629fd..ee1ea5c 100644 --- a/proxy/logging/LogAccessTest.h +++ b/proxy/logging/LogAccessTest.h @@ -69,6 +69,7 @@ public: virtual int marshal_proxy_resp_header_len(char *); // INT virtual int marshal_proxy_finish_status_code(char *); // INT virtual int marshal_cache_result_code(char *); // INT + virtual int marshal_cache_miss_hit(char *); // INT // // proxy -> server fields
