2 * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
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.
9 #ifndef SQUID_SRC_ADAPTATION_HISTORY_H
10 #define SQUID_SRC_ADAPTATION_HISTORY_H
12 #include "adaptation/DynamicGroupCfg.h"
13 #include "adaptation/forward.h"
14 #include "base/RefCount.h"
15 #include "HttpHeader.h"
17 #include "sbuf/SBuf.h"
18 #include "SquidString.h"
23 /// collects information about adaptations related to a master transaction
24 class History
: public RefCountable
27 typedef RefCount
<Adaptation::History
> Pointer
;
31 /// record the start of a xact, return xact history ID
32 int recordXactStart(const String
&serviceId
, const timeval
&when
, bool retrying
);
34 /// record the end of a xact identified by its history ID
35 void recordXactFinish(int hid
);
37 /// dump individual xaction times to a string
38 void allLogString(const char *serviceId
, SBuf
&);
40 /// dump xaction times, merging retried and retry times together
41 void sumLogString(const char *serviceId
, SBuf
&);
43 /// sets or resets a cross-transactional database record
44 void updateXxRecord(const char *name
, const String
&value
);
46 /// returns true and fills the record fields iff there is a db record
47 bool getXxRecord(String
&name
, String
&value
) const;
49 /// sets or resets next services for the Adaptation::Iterator to notice
50 void updateNextServices(const String
&services
);
52 /// returns true, fills the value, and resets iff next services were set
53 bool extractNextServices(String
&value
);
55 /// store the last meta header fields received from the adaptation service
56 void recordMeta(const HttpHeader
*lm
);
58 void recordAdaptationService(SBuf
&srvId
);
60 /// Last received meta header (REQMOD or RESPMOD, whichever comes last).
62 /// All REQMOD and RESPMOD meta headers merged. Last field wins conflicts.
64 /// key:value pairs set by adaptation_meta, to be added to
65 /// AccessLogEntry::notes when ALE becomes available
66 NotePairs::Pointer metaHeaders
;
68 typedef std::vector
<SBuf
> AdaptationServices
;
69 AdaptationServices theAdaptationServices
; ///< The service groups used
71 /// sets future services for the Adaptation::AccessCheck to notice
72 void setFutureServices(const DynamicGroupCfg
&services
);
74 /// returns and forgets planned/future services matching the given filter
75 DynamicGroupCfg
extractCurrentServices(const ServiceFilter
&);
78 /// single Xaction stats (i.e., a historical record entry)
82 Entry(const String
&serviceId
, const timeval
&when
);
83 Entry(); // required by Vector<>
85 void stop(); ///< updates stats on transaction end
86 int rptm(); ///< returns response time [msec], calculates it if needed
88 String service
; ///< adaptation service ID
89 timeval start
; ///< when the xaction was started
92 int theRptm
; ///< calculated and cached response time value in msec
95 bool retried
; ///< whether the xaction was replaced by another
98 typedef std::vector
<Entry
> Entries
;
99 Entries theEntries
; ///< historical record, in the order of xact starts
101 // theXx* will become a map<string,string>, but we only support one record
102 String theXxName
; ///< name part of the cross-transactional database record
103 String theXxValue
; ///< value part of the cross-xactional database record
105 String theNextServices
; ///< services Adaptation::Iterator must use next
106 DynamicGroupCfg theFutureServices
; ///< services AccessCheck must use
109 } // namespace Adaptation
111 #endif /* SQUID_SRC_ADAPTATION_HISTORY_H */