]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
For OPTIONS and HEAD, only 2xx and 3xx are considered "passing"
authorJim Jagielski <jim@apache.org>
Tue, 19 Jan 2016 14:14:27 +0000 (14:14 +0000)
committerJim Jagielski <jim@apache.org>
Tue, 19 Jan 2016 14:14:27 +0000 (14:14 +0000)
(until I implement the conditions expr testing)... honor
the pass/fail count and LOG_INFO when the health check enables
or disables a backend worker.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1725523 13f79535-47bb-0310-9956-ffa450edef68

modules/proxy/mod_proxy.h
modules/proxy/mod_proxy_hcheck.c

index d973f1f027b00e20e959b825743d6c35688b50ba..44a1494c6ef0a79387786568bfd5bfa8e7cec1d7 100644 (file)
@@ -328,6 +328,8 @@ PROXY_WORKER_HC_FAIL )
 
 #define PROXY_WORKER_IS_GENERIC(f)   ( (f)->s->status &  PROXY_WORKER_GENERIC )
 
+#define PROXY_WORKER_IS_HCFAILED(f)   ( (f)->s->status &  PROXY_WORKER_HC_FAIL )
+
 /* default worker retry timeout in seconds */
 #define PROXY_WORKER_DEFAULT_RETRY    60
 
index f3d93a03762cacd4b69ee3833c335376bde72fee..58f033ac2a9c3e363913d19f22a6095e59ea048c 100644 (file)
@@ -491,7 +491,9 @@ static apr_status_t hc_check_tcp(sctx_t *ctx, apr_pool_t *p, proxy_worker *worke
 static void hc_send(sctx_t *ctx, apr_pool_t *p, const char *out, proxy_conn_rec *backend)
 {
     apr_bucket_brigade *tmp_bb = apr_brigade_create(p, ctx->ba);
+#ifdef DEBUG
     ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ctx->s, APLOGNO(03253) "%s", out);
+#endif
     APR_BRIGADE_INSERT_TAIL(tmp_bb, apr_bucket_pool_create(out, strlen(out), p,
                             ctx->ba));
     APR_BRIGADE_INSERT_TAIL(tmp_bb, apr_bucket_flush_create(ctx->ba));
@@ -544,8 +546,10 @@ static int hc_read_headers(sctx_t *ctx, request_rec *r)
         if (!(value = strchr(buffer, ':'))) {
             return !OK;
         }
+#ifdef DEBUG
         ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, ctx->s, APLOGNO(03255)
                 "%s", buffer);
+#endif
         *value = '\0';
         ++value;
         while (apr_isspace(*value))
@@ -557,6 +561,12 @@ static int hc_read_headers(sctx_t *ctx, request_rec *r)
     return OK;
 }
 
+/*
+ * Send the OPTIONS or HEAD HTTP request to the backend
+ * server associated w/ worker. If we have Conditions,
+ * then apply those to the resulting response, otherwise
+ * any status code 2xx or 3xx is considered "passing"
+ */
 static apr_status_t hc_check_headers(sctx_t *ctx, apr_pool_t *p, proxy_worker *worker)
 {
     int status;
@@ -613,8 +623,13 @@ static apr_status_t hc_check_headers(sctx_t *ctx, apr_pool_t *p, proxy_worker *w
 
     r = create_request_rec(p, backend->connection);
     r->pool = p;
-    status = hc_read_headers(ctx, r);
-
+    if ((status = hc_read_headers(ctx, r)) != OK) {
+        return backend_cleanup("HCOH", backend, ctx->s, status);
+    }
+    /* TODO: Check conditions here */
+    if (r->status < 200 || r->status > 399) {
+        status = !OK;
+    }
     return backend_cleanup("HCOH", backend, ctx->s, status);
 }
 
@@ -647,10 +662,29 @@ static void hc_check(sctx_t *ctx, apr_pool_t *p, apr_time_t now,
                          "Somehow tried to use unimplemented hcheck method: %d", (int)worker->s->method);
         return;
     }
-    /* TODO Honor fails and passes */
-    ap_proxy_set_wstatus('#', (rv == APR_SUCCESS ? 0 : 1), worker);
-    if (rv != APR_SUCCESS) {
-        worker->s->error_time = now;
+    /* what state are we in ? */
+    if (PROXY_WORKER_IS_HCFAILED(worker)) {
+        if (rv == APR_SUCCESS) {
+            worker->s->pcount += 1;
+            if (worker->s->pcount >= worker->s->passes) {
+                ap_proxy_set_wstatus('#', 0, worker);
+                worker->s->pcount = 0;
+                ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO()
+                             "Health check re-enabling %s", worker->s->name);
+
+            }
+        }
+    } else {
+        if (rv != APR_SUCCESS) {
+            worker->s->error_time = now;
+            worker->s->fcount += 1;
+            if (worker->s->fcount >= worker->s->fails) {
+                ap_proxy_set_wstatus('#', 1, worker);
+                worker->s->fcount = 0;
+                ap_log_error(APLOG_MARK, APLOG_INFO, 0, s, APLOGNO()
+                             "Health check disabling %s", worker->s->name);
+            }
+        }
     }
     worker->s->updated = now;
 }