]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - src/adaptation/Iterator.cc
SourceFormat Enforcement
[thirdparty/squid.git] / src / adaptation / Iterator.cc
index 11505edf2b41d38aa0cc8a9bed870abc81cd031f..e32f38bad0b6f7a1016971260c17fea8d7b196e5 100644 (file)
@@ -1,7 +1,13 @@
 /*
- * DEBUG: section 93    Adaptation
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
  */
 
+/* DEBUG: section 93    Adaptation */
+
 #include "squid.h"
 #include "adaptation/Answer.h"
 #include "adaptation/Config.h"
 #include "adaptation/ServiceFilter.h"
 #include "adaptation/ServiceGroups.h"
 #include "base/TextException.h"
-#include "HttpRequest.h"
-#include "HttpReply.h"
 #include "HttpMsg.h"
+#include "HttpReply.h"
+#include "HttpRequest.h"
+#include "sbuf/StringConvert.h"
 
 Adaptation::Iterator::Iterator(
     HttpMsg *aMsg, HttpRequest *aCause,
+    AccessLogEntry::Pointer &alp,
     const ServiceGroupPointer &aGroup):
-        AsyncJob("Iterator"),
-        Adaptation::Initiate("Iterator"),
-        theGroup(aGroup),
-        theMsg(aMsg),
-        theCause(aCause),
-        theLauncher(0),
-        iterations(0),
-        adapted(false)
+    AsyncJob("Iterator"),
+    Adaptation::Initiate("Iterator"),
+    theGroup(aGroup),
+    theMsg(aMsg),
+    theCause(aCause),
+    al(alp),
+    theLauncher(0),
+    iterations(0),
+    adapted(false)
 {
     if (theCause != NULL)
         HTTPMSGLOCK(theCause);
@@ -45,6 +54,19 @@ void Adaptation::Iterator::start()
     Adaptation::Initiate::start();
 
     thePlan = ServicePlan(theGroup, filter());
+
+    // Add adaptation group name once and now, before
+    // dynamic groups change it at step() time.
+    if (Adaptation::Config::needHistory && !thePlan.exhausted() && (dynamic_cast<ServiceSet *>(theGroup.getRaw()) || dynamic_cast<ServiceChain *>(theGroup.getRaw()))) {
+        HttpRequest *request = dynamic_cast<HttpRequest*>(theMsg);
+        if (!request)
+            request = theCause;
+        Must(request);
+        Adaptation::History::Pointer ah = request->adaptHistory(true);
+        auto gid = StringToSBuf(theGroup->id);
+        ah->recordAdaptationService(gid);
+    }
+
     step();
 }
 
@@ -79,8 +101,14 @@ void Adaptation::Iterator::step()
     Must(service != NULL);
     debugs(93,5, HERE << "using adaptation service: " << service->cfg().key);
 
+    if (Adaptation::Config::needHistory) {
+        Adaptation::History::Pointer ah = request->adaptHistory(true);
+        auto uid = StringToSBuf(thePlan.current()->cfg().key);
+        ah->recordAdaptationService(uid);
+    }
+
     theLauncher = initiateAdaptation(
-                      service->makeXactLauncher(theMsg, theCause));
+                      service->makeXactLauncher(theMsg, theCause, al));
     Must(initiated(theLauncher));
     Must(!done());
 }
@@ -257,7 +285,8 @@ Adaptation::ServiceFilter Adaptation::Iterator::filter() const
         Must(false); // should not happen
     }
 
-    return ServiceFilter(method, theGroup->point, req, rep);
+    return ServiceFilter(method, theGroup->point, req, rep, al);
 }
 
 CBDATA_NAMESPACED_CLASS_INIT(Adaptation, Iterator);
+