]> git.ipfire.org Git - thirdparty/squid.git/blob - src/adaptation/History.h
CI: Upgrade GitHub Setup Node and CodeQL actions to Node 20 (#1845)
[thirdparty/squid.git] / src / adaptation / History.h
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 #ifndef SQUID_SRC_ADAPTATION_HISTORY_H
10 #define SQUID_SRC_ADAPTATION_HISTORY_H
11
12 #include "adaptation/DynamicGroupCfg.h"
13 #include "adaptation/forward.h"
14 #include "base/RefCount.h"
15 #include "HttpHeader.h"
16 #include "Notes.h"
17 #include "sbuf/SBuf.h"
18 #include "SquidString.h"
19
20 namespace Adaptation
21 {
22
23 /// collects information about adaptations related to a master transaction
24 class History: public RefCountable
25 {
26 public:
27 typedef RefCount<Adaptation::History> Pointer;
28
29 History();
30
31 /// record the start of a xact, return xact history ID
32 int recordXactStart(const String &serviceId, const timeval &when, bool retrying);
33
34 /// record the end of a xact identified by its history ID
35 void recordXactFinish(int hid);
36
37 /// dump individual xaction times to a string
38 void allLogString(const char *serviceId, SBuf &);
39
40 /// dump xaction times, merging retried and retry times together
41 void sumLogString(const char *serviceId, SBuf &);
42
43 /// sets or resets a cross-transactional database record
44 void updateXxRecord(const char *name, const String &value);
45
46 /// returns true and fills the record fields iff there is a db record
47 bool getXxRecord(String &name, String &value) const;
48
49 /// sets or resets next services for the Adaptation::Iterator to notice
50 void updateNextServices(const String &services);
51
52 /// returns true, fills the value, and resets iff next services were set
53 bool extractNextServices(String &value);
54
55 /// store the last meta header fields received from the adaptation service
56 void recordMeta(const HttpHeader *lm);
57
58 void recordAdaptationService(SBuf &srvId);
59 public:
60 /// Last received meta header (REQMOD or RESPMOD, whichever comes last).
61 HttpHeader lastMeta;
62 /// All REQMOD and RESPMOD meta headers merged. Last field wins conflicts.
63 HttpHeader allMeta;
64 /// key:value pairs set by adaptation_meta, to be added to
65 /// AccessLogEntry::notes when ALE becomes available
66 NotePairs::Pointer metaHeaders;
67
68 typedef std::vector<SBuf> AdaptationServices;
69 AdaptationServices theAdaptationServices; ///< The service groups used
70
71 /// sets future services for the Adaptation::AccessCheck to notice
72 void setFutureServices(const DynamicGroupCfg &services);
73
74 /// returns and forgets planned/future services matching the given filter
75 DynamicGroupCfg extractCurrentServices(const ServiceFilter &);
76
77 private:
78 /// single Xaction stats (i.e., a historical record entry)
79 class Entry
80 {
81 public:
82 Entry(const String &serviceId, const timeval &when);
83 Entry(); // required by Vector<>
84
85 void stop(); ///< updates stats on transaction end
86 int rptm(); ///< returns response time [msec], calculates it if needed
87
88 String service; ///< adaptation service ID
89 timeval start; ///< when the xaction was started
90
91 private:
92 int theRptm; ///< calculated and cached response time value in msec
93
94 public:
95 bool retried; ///< whether the xaction was replaced by another
96 };
97
98 typedef std::vector<Entry> Entries;
99 Entries theEntries; ///< historical record, in the order of xact starts
100
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
104
105 String theNextServices; ///< services Adaptation::Iterator must use next
106 DynamicGroupCfg theFutureServices; ///< services AccessCheck must use
107 };
108
109 } // namespace Adaptation
110
111 #endif /* SQUID_SRC_ADAPTATION_HISTORY_H */
112