LogTags.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #include "squid.h"
10 #include "debug/Stream.h"
11 #include "LogTags.h"
12 
13 void
15 {
16  ignored = ignored || other.ignored;
17  timedout = timedout || other.timedout;
18  aborted = aborted || other.aborted;
19 }
20 
22 LogTagsErrors::FromErrno(const int errNo)
23 {
24  LogTagsErrors lte;
25  lte.timedout = (errNo == ETIMEDOUT);
26  lte.aborted = !lte.timedout; // intentionally true for zero errNo
27  return lte;
28 }
29 
30 /* LogTags */
31 
32 // old deprecated tag strings
33 const char * LogTags::Str_[] = {
34  "TAG_NONE",
35  "TCP_HIT",
36  "TCP_MISS",
37  "TCP_REFRESH_UNMODIFIED",
38  "TCP_REFRESH_FAIL_OLD",
39  "TCP_REFRESH_FAIL_ERR",
40  "TCP_REFRESH_MODIFIED",
41  "TCP_REFRESH",
42  "TCP_CLIENT_REFRESH_MISS",
43  "TCP_IMS_HIT",
44  "TCP_INM_HIT",
45  "TCP_SWAPFAIL_MISS",
46  "TCP_NEGATIVE_HIT",
47  "TCP_MEM_HIT",
48  "TCP_DENIED",
49  "TCP_DENIED_REPLY",
50  "TCP_OFFLINE_HIT",
51  "TCP_REDIRECT",
52  "TCP_TUNNEL",
53  "UDP_HIT",
54  "UDP_MISS",
55  "UDP_DENIED",
56  "UDP_INVALID",
57  "UDP_MISS_NOFETCH",
58  "ICP_QUERY",
59  "TYPE_MAX"
60 };
61 
62 void
64 {
65  assert(t < LOG_TYPE_MAX);
66  debugs(83, 7, Str_[oldType] << " to " << Str_[t]);
67  oldType = t;
68 }
69 
70 /*
71  * This method is documented in https://wiki.squid-cache.org/SquidFaq/SquidLogs#squid-result-codes
72  * Please keep the wiki up to date
73  */
74 const char *
76 {
77  static char buf[1024];
78  *buf = 0;
79  int pos = 0;
80 
81  // source tags
82  const int protoLen = 3;
83  if (oldType && oldType < LOG_TYPE_MAX) {
84  assert(Str_[oldType][protoLen] == '_');
85  snprintf(buf, protoLen + 1, "%s", Str_[oldType]);
86  pos += protoLen;
87  }
88  else
89  pos += snprintf(buf, sizeof(buf), "NONE");
90 
92  pos += snprintf(buf + pos, sizeof(buf) - pos, "_CF");
93 
94  const char *tag = Str_[oldType] + protoLen;
95  pos += snprintf(buf + pos, sizeof(buf) - pos, "%s", tag);
96 
97  if (err.ignored)
98  pos += snprintf(buf+pos,sizeof(buf)-pos, "_IGNORED");
99 
100  // error tags
101  if (err.timedout)
102  pos += snprintf(buf+pos,sizeof(buf)-pos, "_TIMEDOUT");
103  if (err.aborted)
104  pos += snprintf(buf+pos,sizeof(buf)-pos, "_ABORTED");
105 
106  return buf;
107 }
108 
109 bool
111 {
112  return
113  (oldType == LOG_TCP_HIT) ||
114  (oldType == LOG_TCP_IMS_HIT) ||
115  (oldType == LOG_TCP_INM_HIT) ||
119  (oldType == LOG_TCP_MEM_HIT) ||
121 }
122 
123 const char *
125 {
126  // see draft-ietf-httpbis-cache-header for the (quoted below) specs
127  switch (oldType) {
128  case LOG_TAG_NONE:
129  return nullptr;
130 
131  case LOG_TCP_HIT:
132  case LOG_TCP_IMS_HIT:
133  case LOG_TCP_INM_HIT:
137  case LOG_TCP_MEM_HIT:
138  case LOG_TCP_OFFLINE_HIT:
139  // We put LOG_TCP_REFRESH_UNMODIFIED and LOG_TCP_REFRESH_FAIL_OLD here
140  // because the specs probably classify master transactions where the
141  // client request did "go forward" but the to-client response was
142  // ultimately "obtained from the cache" as "hit" transactions.
143  return ";hit";
144 
145  case LOG_TCP_MISS:
146 #if USE_DELAY_POOLS
147  // do not lie until we get a better solution for bugs 1000, 2096
148  return nullptr;
149 #else
150  // TODO: "distinguish between uri-miss and vary-miss"
151  return ";fwd=miss";
152 #endif
153 
155  case LOG_TCP_REFRESH:
156  return ";fwd=stale";
157 
159  return ";fwd=request";
160 
163  // Ignore "to be used when the implementation cannot distinguish between
164  // uri-miss and vary-miss" specs condition as being too restrictive,
165  // especially when there is no fwd=other or a more suitable parameter.
166  return ";fwd=miss";
167 
168  case LOG_TCP_DENIED:
170  case LOG_TCP_REDIRECT:
171  // We served a Squid-generated response (with or without forwarding).
172  // The response itself should provide enough classification clues.
173  return nullptr;
174 
175  case LOG_TCP_TUNNEL:
176  // could use fwd=bypass, but the CONNECT request was not really bypassed
177  return nullptr;
178 
179  case LOG_UDP_HIT:
180  case LOG_UDP_MISS:
181  case LOG_UDP_DENIED:
182  case LOG_UDP_INVALID:
184  case LOG_ICP_QUERY:
185  // do not bother classifying these non-HTTP outcomes for now
186  return nullptr;
187 
188  case LOG_TYPE_MAX:
189  // should not happen
190  return nullptr;
191  }
192 
193  // should not happen
194  return nullptr;
195 }
196 
@ LOG_TCP_IMS_HIT
Definition: LogTags.h:50
LogTagsErrors err
various problems augmenting the primary log tag
Definition: LogTags.h:87
CollapsingHistory collapsingHistory
controls CF tag presence
Definition: LogTags.h:98
const char * cacheStatusSource() const
Definition: LogTags.cc:124
void update(const LogTagsErrors &other)
Definition: LogTags.cc:14
bool isTcpHit() const
determine if the log tag code indicates a cache HIT
Definition: LogTags.cc:110
@ LOG_TCP_CLIENT_REFRESH_MISS
Definition: LogTags.h:49
@ LOG_TCP_HIT
Definition: LogTags.h:42
@ LOG_TCP_MISS
Definition: LogTags.h:43
@ LOG_TYPE_MAX
Definition: LogTags.h:66
@ LOG_TCP_REFRESH_FAIL_OLD
Definition: LogTags.h:45
const char * c_str() const
compute the status access.log field
Definition: LogTags.cc:75
static const char * Str_[]
list of string representations for LogTags_ot
Definition: LogTags.h:91
void update(const LogTags_ot t)
Definition: LogTags.cc:63
@ LOG_TCP_DENIED_REPLY
Definition: LogTags.h:56
@ LOG_UDP_HIT
Definition: LogTags.h:60
@ LOG_TCP_REFRESH_FAIL_ERR
Definition: LogTags.h:46
@ LOG_TCP_TUNNEL
an attempt to establish a bidirectional TCP tunnel
Definition: LogTags.h:59
@ LOG_TCP_REFRESH_MODIFIED
Definition: LogTags.h:47
@ LOG_TAG_NONE
Definition: LogTags.h:41
@ LOG_TCP_REFRESH_UNMODIFIED
Definition: LogTags.h:44
@ LOG_UDP_INVALID
Definition: LogTags.h:63
#define assert(EX)
Definition: assert.h:17
@ LOG_TCP_REFRESH
Definition: LogTags.h:48
@ LOG_TCP_INM_HIT
Definition: LogTags.h:51
@ LOG_TCP_DENIED
Definition: LogTags.h:55
bool timedout
_TIMEDOUT: terminated due to a lifetime or I/O timeout
Definition: LogTags.h:28
bool collapsed() const
whether at least one request was collapsed
@ LOG_TCP_OFFLINE_HIT
Definition: LogTags.h:57
static LogTagsErrors FromErrno(int errNo)
constructs an object matching errno(3) of a failed I/O call
Definition: LogTags.cc:22
LogTags_ot
Definition: LogTags.h:40
LogTags_ot oldType
a set of client protocol, cache use, and other transaction outcome tags
Definition: LogTags.h:96
@ LOG_TCP_REDIRECT
Definition: LogTags.h:58
bool ignored
_IGNORED: the response was not used for anything
Definition: LogTags.h:27
@ LOG_UDP_MISS_NOFETCH
Definition: LogTags.h:64
@ LOG_UDP_DENIED
Definition: LogTags.h:62
@ LOG_TCP_MEM_HIT
Definition: LogTags.h:54
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192
bool aborted
_ABORTED: other abnormal termination (e.g., I/O error)
Definition: LogTags.h:29
@ LOG_TCP_SWAPFAIL_MISS
Definition: LogTags.h:52
@ LOG_TCP_NEGATIVE_HIT
Definition: LogTags.h:53
@ LOG_ICP_QUERY
Definition: LogTags.h:65
@ LOG_UDP_MISS
Definition: LogTags.h:61

 

Introduction

Documentation

Support

Miscellaneous