You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Jim Jagielski <ji...@jaguNET.com> on 2016/01/21 18:55:52 UTC

Re: svn commit: r1726038 - /httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c

This implies that the kept_body() func added to ap_expr should
be removed, right? 

> On Jan 21, 2016, at 12:49 PM, rjung@apache.org wrote:
> 
> Author: rjung
> Date: Thu Jan 21 17:49:21 2016
> New Revision: 1726038
> 
> URL: http://svn.apache.org/viewvc?rev=1726038&view=rev
> Log:
> Implement expr lookup in mod_proxy_hcheck for
> variables whose names start with "HC_" and for
> the new function hc().
> 
> Currently only HC_BODY and hc(body) are supported.
> Both return the saved body of the health check
> response to be used in an expr that decides about
> success of a check.
> 
> Modified:
>    httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c
> 
> Modified: httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c
> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c?rev=1726038&r1=1726037&r2=1726038&view=diff
> ==============================================================================
> --- httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c (original)
> +++ httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c Thu Jan 21 17:49:21 2016
> @@ -926,6 +926,75 @@ static void hc_show_exprs(request_rec *r
>     ap_rputs("</table><hr/>\n", r);
> }
> 
> +static const char *hc_get_body(request_rec *r)
> +{
> +    apr_off_t length;
> +    apr_size_t len;
> +    apr_status_t rv;
> +    char *buf;
> +
> +    if (!r || !r->kept_body)
> +        return "";
> +
> +    rv = apr_brigade_length(r->kept_body, 1, &length);
> +    len = (apr_size_t)length;
> +    if (rv != APR_SUCCESS || len == 0)
> +        return "";
> +
> +    buf = apr_palloc(r->pool, len + 1);
> +    rv = apr_brigade_flatten(r->kept_body, buf, &len);
> +    if (rv != APR_SUCCESS)
> +        return "";
> +    buf[len] = '\0'; /* ensure */
> +    return (const char*)buf;
> +}
> +
> +static const char *hc_expr_var_fn(ap_expr_eval_ctx_t *ctx, const void *data)
> +{
> +    char *var = (char *)data;
> +
> +    if (var && *var && ctx->r && ap_casecmpstr(var, "BODY") == 0) {
> +        return hc_get_body(ctx->r);
> +    }
> +    return NULL;
> +}
> +
> +static const char *hc_expr_func_fn(ap_expr_eval_ctx_t *ctx, const void *data,
> +                                const char *arg)
> +{
> +    char *var = (char *)arg;
> +
> +    if (var && *var && ctx->r && ap_casecmpstr(var, "BODY") == 0) {
> +        return hc_get_body(ctx->r);
> +    }
> +    return NULL;
> +}
> +
> +static int hc_expr_lookup(ap_expr_lookup_parms *parms)
> +{
> +    switch (parms->type) {
> +    case AP_EXPR_FUNC_VAR:
> +        /* for now, we just handle everything that starts with HC_.
> +         */
> +        if (strncasecmp(parms->name, "HC_", 3) == 0) {
> +            *parms->func = hc_expr_var_fn;
> +            *parms->data = parms->name + 4;
> +            return OK;
> +        }
> +        break;
> +    case AP_EXPR_FUNC_STRING:
> +        /* Function HC() is implemented by us.
> +         */
> +        if (strcasecmp(parms->name, "HC") == 0) {
> +            *parms->func = hc_expr_func_fn;
> +            *parms->data = NULL;
> +            return OK;
> +        }
> +        break;
> +    }
> +    return DECLINED;
> +}
> +
> static const command_rec command_table[] = {
>     AP_INIT_RAW_ARGS("ProxyHCTemplate", set_hc_template, NULL, OR_FILEINFO,
>                      "Health check template"),
> @@ -941,6 +1010,7 @@ static void hc_register_hooks(apr_pool_t
>     APR_REGISTER_OPTIONAL_FN(set_worker_hc_param);
>     APR_REGISTER_OPTIONAL_FN(hc_show_exprs);
>     ap_hook_post_config(hc_post_config, aszPre, aszSucc, APR_HOOK_LAST);
> +    ap_hook_expr_lookup(hc_expr_lookup, NULL, NULL, APR_HOOK_MIDDLE);
> }
> 
> /* the main config structure */
> 
> 


Re: svn commit: r1726038 - /httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c

Posted by Rainer Jung <ra...@kippdata.de>.
Am 21.01.2016 um 18:59 schrieb Jim Jagielski:
> BTW: that is so cool. No idea we could do that w/ ap_expr!

Don't know whether it is useful but you can now easily provide more 
hcheck info to expr as long as there's code that returns that info and 
using it in success formulas is helpful. Like success or failure count 
(number of consecutive successes or failures) via hc(successes) or 
hc(failures). Simply connect the argument names with a function that 
returns the info.

Regards,

Rainer

>> On Jan 21, 2016, at 12:55 PM, Jim Jagielski <ji...@jaguNET.com> wrote:
>>
>> This implies that the kept_body() func added to ap_expr should
>> be removed, right?
>>
>>> On Jan 21, 2016, at 12:49 PM, rjung@apache.org wrote:
>>>
>>> Author: rjung
>>> Date: Thu Jan 21 17:49:21 2016
>>> New Revision: 1726038
>>>
>>> URL: http://svn.apache.org/viewvc?rev=1726038&view=rev
>>> Log:
>>> Implement expr lookup in mod_proxy_hcheck for
>>> variables whose names start with "HC_" and for
>>> the new function hc().
>>>
>>> Currently only HC_BODY and hc(body) are supported.
>>> Both return the saved body of the health check
>>> response to be used in an expr that decides about
>>> success of a check.
>>>
>>> Modified:
>>>    httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c
>>>
>>> Modified: httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c
>>> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c?rev=1726038&r1=1726037&r2=1726038&view=diff
>>> ==============================================================================
>>> --- httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c (original)
>>> +++ httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c Thu Jan 21 17:49:21 2016
>>> @@ -926,6 +926,75 @@ static void hc_show_exprs(request_rec *r
>>>     ap_rputs("</table><hr/>\n", r);
>>> }
>>>
>>> +static const char *hc_get_body(request_rec *r)
>>> +{
>>> +    apr_off_t length;
>>> +    apr_size_t len;
>>> +    apr_status_t rv;
>>> +    char *buf;
>>> +
>>> +    if (!r || !r->kept_body)
>>> +        return "";
>>> +
>>> +    rv = apr_brigade_length(r->kept_body, 1, &length);
>>> +    len = (apr_size_t)length;
>>> +    if (rv != APR_SUCCESS || len == 0)
>>> +        return "";
>>> +
>>> +    buf = apr_palloc(r->pool, len + 1);
>>> +    rv = apr_brigade_flatten(r->kept_body, buf, &len);
>>> +    if (rv != APR_SUCCESS)
>>> +        return "";
>>> +    buf[len] = '\0'; /* ensure */
>>> +    return (const char*)buf;
>>> +}
>>> +
>>> +static const char *hc_expr_var_fn(ap_expr_eval_ctx_t *ctx, const void *data)
>>> +{
>>> +    char *var = (char *)data;
>>> +
>>> +    if (var && *var && ctx->r && ap_casecmpstr(var, "BODY") == 0) {
>>> +        return hc_get_body(ctx->r);
>>> +    }
>>> +    return NULL;
>>> +}
>>> +
>>> +static const char *hc_expr_func_fn(ap_expr_eval_ctx_t *ctx, const void *data,
>>> +                                const char *arg)
>>> +{
>>> +    char *var = (char *)arg;
>>> +
>>> +    if (var && *var && ctx->r && ap_casecmpstr(var, "BODY") == 0) {
>>> +        return hc_get_body(ctx->r);
>>> +    }
>>> +    return NULL;
>>> +}
>>> +
>>> +static int hc_expr_lookup(ap_expr_lookup_parms *parms)
>>> +{
>>> +    switch (parms->type) {
>>> +    case AP_EXPR_FUNC_VAR:
>>> +        /* for now, we just handle everything that starts with HC_.
>>> +         */
>>> +        if (strncasecmp(parms->name, "HC_", 3) == 0) {
>>> +            *parms->func = hc_expr_var_fn;
>>> +            *parms->data = parms->name + 4;
>>> +            return OK;
>>> +        }
>>> +        break;
>>> +    case AP_EXPR_FUNC_STRING:
>>> +        /* Function HC() is implemented by us.
>>> +         */
>>> +        if (strcasecmp(parms->name, "HC") == 0) {
>>> +            *parms->func = hc_expr_func_fn;
>>> +            *parms->data = NULL;
>>> +            return OK;
>>> +        }
>>> +        break;
>>> +    }
>>> +    return DECLINED;
>>> +}
>>> +
>>> static const command_rec command_table[] = {
>>>     AP_INIT_RAW_ARGS("ProxyHCTemplate", set_hc_template, NULL, OR_FILEINFO,
>>>                      "Health check template"),
>>> @@ -941,6 +1010,7 @@ static void hc_register_hooks(apr_pool_t
>>>     APR_REGISTER_OPTIONAL_FN(set_worker_hc_param);
>>>     APR_REGISTER_OPTIONAL_FN(hc_show_exprs);
>>>     ap_hook_post_config(hc_post_config, aszPre, aszSucc, APR_HOOK_LAST);
>>> +    ap_hook_expr_lookup(hc_expr_lookup, NULL, NULL, APR_HOOK_MIDDLE);
>>> }
>>>
>>> /* the main config structure */

Re: svn commit: r1726038 - /httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c

Posted by Jim Jagielski <ji...@jaguNET.com>.
BTW: that is so cool. No idea we could do that w/ ap_expr!

> On Jan 21, 2016, at 12:55 PM, Jim Jagielski <ji...@jaguNET.com> wrote:
> 
> This implies that the kept_body() func added to ap_expr should
> be removed, right? 
> 
>> On Jan 21, 2016, at 12:49 PM, rjung@apache.org wrote:
>> 
>> Author: rjung
>> Date: Thu Jan 21 17:49:21 2016
>> New Revision: 1726038
>> 
>> URL: http://svn.apache.org/viewvc?rev=1726038&view=rev
>> Log:
>> Implement expr lookup in mod_proxy_hcheck for
>> variables whose names start with "HC_" and for
>> the new function hc().
>> 
>> Currently only HC_BODY and hc(body) are supported.
>> Both return the saved body of the health check
>> response to be used in an expr that decides about
>> success of a check.
>> 
>> Modified:
>>   httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c
>> 
>> Modified: httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c
>> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c?rev=1726038&r1=1726037&r2=1726038&view=diff
>> ==============================================================================
>> --- httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c (original)
>> +++ httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c Thu Jan 21 17:49:21 2016
>> @@ -926,6 +926,75 @@ static void hc_show_exprs(request_rec *r
>>    ap_rputs("</table><hr/>\n", r);
>> }
>> 
>> +static const char *hc_get_body(request_rec *r)
>> +{
>> +    apr_off_t length;
>> +    apr_size_t len;
>> +    apr_status_t rv;
>> +    char *buf;
>> +
>> +    if (!r || !r->kept_body)
>> +        return "";
>> +
>> +    rv = apr_brigade_length(r->kept_body, 1, &length);
>> +    len = (apr_size_t)length;
>> +    if (rv != APR_SUCCESS || len == 0)
>> +        return "";
>> +
>> +    buf = apr_palloc(r->pool, len + 1);
>> +    rv = apr_brigade_flatten(r->kept_body, buf, &len);
>> +    if (rv != APR_SUCCESS)
>> +        return "";
>> +    buf[len] = '\0'; /* ensure */
>> +    return (const char*)buf;
>> +}
>> +
>> +static const char *hc_expr_var_fn(ap_expr_eval_ctx_t *ctx, const void *data)
>> +{
>> +    char *var = (char *)data;
>> +
>> +    if (var && *var && ctx->r && ap_casecmpstr(var, "BODY") == 0) {
>> +        return hc_get_body(ctx->r);
>> +    }
>> +    return NULL;
>> +}
>> +
>> +static const char *hc_expr_func_fn(ap_expr_eval_ctx_t *ctx, const void *data,
>> +                                const char *arg)
>> +{
>> +    char *var = (char *)arg;
>> +
>> +    if (var && *var && ctx->r && ap_casecmpstr(var, "BODY") == 0) {
>> +        return hc_get_body(ctx->r);
>> +    }
>> +    return NULL;
>> +}
>> +
>> +static int hc_expr_lookup(ap_expr_lookup_parms *parms)
>> +{
>> +    switch (parms->type) {
>> +    case AP_EXPR_FUNC_VAR:
>> +        /* for now, we just handle everything that starts with HC_.
>> +         */
>> +        if (strncasecmp(parms->name, "HC_", 3) == 0) {
>> +            *parms->func = hc_expr_var_fn;
>> +            *parms->data = parms->name + 4;
>> +            return OK;
>> +        }
>> +        break;
>> +    case AP_EXPR_FUNC_STRING:
>> +        /* Function HC() is implemented by us.
>> +         */
>> +        if (strcasecmp(parms->name, "HC") == 0) {
>> +            *parms->func = hc_expr_func_fn;
>> +            *parms->data = NULL;
>> +            return OK;
>> +        }
>> +        break;
>> +    }
>> +    return DECLINED;
>> +}
>> +
>> static const command_rec command_table[] = {
>>    AP_INIT_RAW_ARGS("ProxyHCTemplate", set_hc_template, NULL, OR_FILEINFO,
>>                     "Health check template"),
>> @@ -941,6 +1010,7 @@ static void hc_register_hooks(apr_pool_t
>>    APR_REGISTER_OPTIONAL_FN(set_worker_hc_param);
>>    APR_REGISTER_OPTIONAL_FN(hc_show_exprs);
>>    ap_hook_post_config(hc_post_config, aszPre, aszSucc, APR_HOOK_LAST);
>> +    ap_hook_expr_lookup(hc_expr_lookup, NULL, NULL, APR_HOOK_MIDDLE);
>> }
>> 
>> /* the main config structure */
>> 
>> 
> 


Re: svn commit: r1726038 - /httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c

Posted by Rainer Jung <ra...@kippdata.de>.
Am 21.01.2016 um 18:55 schrieb Jim Jagielski:
> This implies that the kept_body() func added to ap_expr should
> be removed, right?

At least it is no longer needed for proxy_hcheck. If we want to provide 
the original kept_body as used by mod_request to expr we can keep it. I 
don't know whether such use is sensible, but maybe best at this point to 
remove it after you can confirm the new approach works for you.

Regards,

Rainer

>> On Jan 21, 2016, at 12:49 PM, rjung@apache.org wrote:
>>
>> Author: rjung
>> Date: Thu Jan 21 17:49:21 2016
>> New Revision: 1726038
>>
>> URL: http://svn.apache.org/viewvc?rev=1726038&view=rev
>> Log:
>> Implement expr lookup in mod_proxy_hcheck for
>> variables whose names start with "HC_" and for
>> the new function hc().
>>
>> Currently only HC_BODY and hc(body) are supported.
>> Both return the saved body of the health check
>> response to be used in an expr that decides about
>> success of a check.
>>
>> Modified:
>>     httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c
>>
>> Modified: httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c
>> URL: http://svn.apache.org/viewvc/httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c?rev=1726038&r1=1726037&r2=1726038&view=diff
>> ==============================================================================
>> --- httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c (original)
>> +++ httpd/httpd/trunk/modules/proxy/mod_proxy_hcheck.c Thu Jan 21 17:49:21 2016
>> @@ -926,6 +926,75 @@ static void hc_show_exprs(request_rec *r
>>      ap_rputs("</table><hr/>\n", r);
>> }
>>
>> +static const char *hc_get_body(request_rec *r)
>> +{
>> +    apr_off_t length;
>> +    apr_size_t len;
>> +    apr_status_t rv;
>> +    char *buf;
>> +
>> +    if (!r || !r->kept_body)
>> +        return "";
>> +
>> +    rv = apr_brigade_length(r->kept_body, 1, &length);
>> +    len = (apr_size_t)length;
>> +    if (rv != APR_SUCCESS || len == 0)
>> +        return "";
>> +
>> +    buf = apr_palloc(r->pool, len + 1);
>> +    rv = apr_brigade_flatten(r->kept_body, buf, &len);
>> +    if (rv != APR_SUCCESS)
>> +        return "";
>> +    buf[len] = '\0'; /* ensure */
>> +    return (const char*)buf;
>> +}
>> +
>> +static const char *hc_expr_var_fn(ap_expr_eval_ctx_t *ctx, const void *data)
>> +{
>> +    char *var = (char *)data;
>> +
>> +    if (var && *var && ctx->r && ap_casecmpstr(var, "BODY") == 0) {
>> +        return hc_get_body(ctx->r);
>> +    }
>> +    return NULL;
>> +}
>> +
>> +static const char *hc_expr_func_fn(ap_expr_eval_ctx_t *ctx, const void *data,
>> +                                const char *arg)
>> +{
>> +    char *var = (char *)arg;
>> +
>> +    if (var && *var && ctx->r && ap_casecmpstr(var, "BODY") == 0) {
>> +        return hc_get_body(ctx->r);
>> +    }
>> +    return NULL;
>> +}
>> +
>> +static int hc_expr_lookup(ap_expr_lookup_parms *parms)
>> +{
>> +    switch (parms->type) {
>> +    case AP_EXPR_FUNC_VAR:
>> +        /* for now, we just handle everything that starts with HC_.
>> +         */
>> +        if (strncasecmp(parms->name, "HC_", 3) == 0) {
>> +            *parms->func = hc_expr_var_fn;
>> +            *parms->data = parms->name + 4;
>> +            return OK;
>> +        }
>> +        break;
>> +    case AP_EXPR_FUNC_STRING:
>> +        /* Function HC() is implemented by us.
>> +         */
>> +        if (strcasecmp(parms->name, "HC") == 0) {
>> +            *parms->func = hc_expr_func_fn;
>> +            *parms->data = NULL;
>> +            return OK;
>> +        }
>> +        break;
>> +    }
>> +    return DECLINED;
>> +}
>> +
>> static const command_rec command_table[] = {
>>      AP_INIT_RAW_ARGS("ProxyHCTemplate", set_hc_template, NULL, OR_FILEINFO,
>>                       "Health check template"),
>> @@ -941,6 +1010,7 @@ static void hc_register_hooks(apr_pool_t
>>      APR_REGISTER_OPTIONAL_FN(set_worker_hc_param);
>>      APR_REGISTER_OPTIONAL_FN(hc_show_exprs);
>>      ap_hook_post_config(hc_post_config, aszPre, aszSucc, APR_HOOK_LAST);
>> +    ap_hook_expr_lookup(hc_expr_lookup, NULL, NULL, APR_HOOK_MIDDLE);
>> }
>>
>> /* the main config structure */