diff options
author | David Garcia Quintas <dgq@google.com> | 2016-05-04 19:44:37 -0700 |
---|---|---|
committer | David Garcia Quintas <dgq@google.com> | 2016-05-04 19:44:37 -0700 |
commit | 1621c4d37c4cc9cfe01b99be3eb82e8b3a8b17a4 (patch) | |
tree | 6ae905c3e7cbe6cd674433c78a6b696028035af6 | |
parent | 1acf9131a1dab7510e49979fa00d89e2fc9fd116 (diff) |
Added support for trailing metadata
-rw-r--r-- | src/core/ext/load_reporting/load_reporting.c | 20 | ||||
-rw-r--r-- | src/core/ext/load_reporting/load_reporting.h | 29 | ||||
-rw-r--r-- | src/core/ext/load_reporting/load_reporting_filter.c | 63 | ||||
-rw-r--r-- | src/core/lib/transport/static_metadata.c | 11 | ||||
-rw-r--r-- | src/core/lib/transport/static_metadata.h | 124 | ||||
-rw-r--r-- | test/core/end2end/fixtures/h2_loadreporting.c | 37 | ||||
-rw-r--r-- | test/core/end2end/fuzzers/hpack.dictionary | 2 | ||||
-rwxr-xr-x | tools/codegen/core/gen_static_metadata.py | 1 |
8 files changed, 182 insertions, 105 deletions
diff --git a/src/core/ext/load_reporting/load_reporting.c b/src/core/ext/load_reporting/load_reporting.c index fb32685dc9..60082dbaaa 100644 --- a/src/core/ext/load_reporting/load_reporting.c +++ b/src/core/ext/load_reporting/load_reporting.c @@ -44,32 +44,32 @@ struct grpc_load_reporting_config { grpc_load_reporting_fn fn; - void *data; + void *user_data; }; grpc_load_reporting_config *grpc_load_reporting_config_create( - grpc_load_reporting_fn fn, void *data) { + grpc_load_reporting_fn fn, void *user_data) { + GPR_ASSERT(fn != NULL); grpc_load_reporting_config *lrc = gpr_malloc(sizeof(grpc_load_reporting_config)); lrc->fn = fn; - lrc->data = data; + lrc->user_data = user_data; return lrc; } grpc_load_reporting_config *grpc_load_reporting_config_copy( grpc_load_reporting_config *src) { - return grpc_load_reporting_config_create(src->fn, src->data); + return grpc_load_reporting_config_create(src->fn, src->user_data); } void grpc_load_reporting_config_destroy(grpc_load_reporting_config *lrc) { gpr_free(lrc); } -void grpc_load_reporting_config_call(grpc_load_reporting_config *lrc, - const grpc_call_stats *stats) { - if (lrc->fn != NULL) { - lrc->fn(stats, lrc->data); - } +void grpc_load_reporting_config_call( + grpc_load_reporting_config *lrc, + const grpc_load_reporting_call_data *call_data) { + lrc->fn(call_data, lrc->user_data); } static bool is_load_reporting_enabled(const grpc_channel_args *a) { @@ -102,7 +102,7 @@ static void *lrd_arg_copy(void *p) { static int lrd_arg_cmp(void *a, void *b) { grpc_load_reporting_config *lhs = a; grpc_load_reporting_config *rhs = b; - return !(lhs->fn == rhs->fn && lhs->data == rhs->data); + return !(lhs->fn == rhs->fn && lhs->user_data == rhs->user_data); } static const grpc_arg_pointer_vtable lrd_ptr_vtable = { diff --git a/src/core/ext/load_reporting/load_reporting.h b/src/core/ext/load_reporting/load_reporting.h index 806af2bda7..316cd89bd7 100644 --- a/src/core/ext/load_reporting/load_reporting.h +++ b/src/core/ext/load_reporting/load_reporting.h @@ -39,24 +39,35 @@ typedef struct grpc_load_reporting_config grpc_load_reporting_config; +/** Call information to be passed to the provided load reporting function upon + * completion of the call */ +typedef struct grpc_load_reporting_call_data { + const grpc_call_stats *stats; /**< Stats for the call */ + const char *trailing_md_string; /**< LR trailing metadata info */ +} grpc_load_reporting_call_data; + /** Custom function to be called by the load reporting filter. */ -typedef void (*grpc_load_reporting_fn)(const grpc_call_stats *stats, - void *data); +typedef void (*grpc_load_reporting_fn)( + const grpc_load_reporting_call_data *call_data, void *user_data); -/** Register \a fn as the function to be invoked by the load reporting filter, - * passing \a data alongisde the call stats */ +/** Register \a fn as the function to be invoked by the load reporting filter. + * \a fn will be invoked at the beginning and at the end of the call. + * + * For the first invocation, \a fn's first argument + * (grpc_load_reporting_call_data*) will be NULL. \a user_data is always passed + * as-is. */ grpc_load_reporting_config *grpc_load_reporting_config_create( - grpc_load_reporting_fn fn, void *data); + grpc_load_reporting_fn fn, void *user_data); grpc_load_reporting_config *grpc_load_reporting_config_copy( grpc_load_reporting_config *src); void grpc_load_reporting_config_destroy(grpc_load_reporting_config *lrc); -/** Invoke the function registered by \a grpc_load_reporting_init, passing it \a - * stats as one of the arguments (see \a load_reporting_fn). */ -void grpc_load_reporting_config_call(grpc_load_reporting_config *lrc, - const grpc_call_stats *stats); +/** Invoke the function registered by \a grpc_load_reporting_init. */ +void grpc_load_reporting_config_call( + grpc_load_reporting_config *lrc, + const grpc_load_reporting_call_data *call_data); /** Return a \a grpc_arg enabling load reporting */ grpc_arg grpc_load_reporting_config_create_arg(grpc_load_reporting_config *lrc); diff --git a/src/core/ext/load_reporting/load_reporting_filter.c b/src/core/ext/load_reporting/load_reporting_filter.c index 902c110212..f49730fac3 100644 --- a/src/core/ext/load_reporting/load_reporting_filter.c +++ b/src/core/ext/load_reporting/load_reporting_filter.c @@ -32,6 +32,7 @@ */ #include <grpc/support/log.h> +#include <grpc/support/string_util.h> #include <grpc/support/sync.h> #include <string.h> @@ -39,28 +40,40 @@ #include "src/core/ext/load_reporting/load_reporting_filter.h" #include "src/core/lib/channel/channel_args.h" #include "src/core/lib/profiling/timers.h" +#include "src/core/lib/transport/static_metadata.h" -typedef struct call_data { void *dummy; } call_data; +typedef struct call_data { const char *trailing_md_string; } call_data; typedef struct channel_data { gpr_mu mu; grpc_load_reporting_config *lrc; } channel_data; +static void invoke_lr_fn_locked(grpc_load_reporting_config *lrc, + grpc_load_reporting_call_data *lr_call_data) { + GPR_TIMER_BEGIN("load_reporting_config_fn", 0); + grpc_load_reporting_config_call(lrc, lr_call_data); + GPR_TIMER_END("load_reporting_config_fn", 0); +} + /* Constructor for call_data */ static void init_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, - grpc_call_element_args *args) {} + grpc_call_element_args *args) { + call_data *calld = elem->call_data; + memset(calld, 0, sizeof(call_data)); +} /* Destructor for call_data */ static void destroy_call_elem(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, const grpc_call_stats *stats, void *ignored) { channel_data *chand = elem->channel_data; - if (chand->lrc != NULL) { - GPR_TIMER_BEGIN("load_reporting_filter", 0); - gpr_mu_lock(&chand->mu); - grpc_load_reporting_config_call(chand->lrc, stats); - gpr_mu_unlock(&chand->mu); - GPR_TIMER_END("load_reporting_filter", 0); - } + call_data *calld = elem->call_data; + + grpc_load_reporting_call_data lr_call_data = {stats, + calld->trailing_md_string}; + + gpr_mu_lock(&chand->mu); + invoke_lr_fn_locked(chand->lrc, &lr_call_data); + gpr_mu_unlock(&chand->mu); } /* Constructor for channel_data */ @@ -84,6 +97,10 @@ static void init_channel_elem(grpc_exec_ctx *exec_ctx, } } GPR_ASSERT(chand->lrc != NULL); /* arg actually found */ + + gpr_mu_lock(&chand->mu); + invoke_lr_fn_locked(chand->lrc, NULL); + gpr_mu_unlock(&chand->mu); } /* Destructor for channel data */ @@ -94,8 +111,34 @@ static void destroy_channel_elem(grpc_exec_ctx *exec_ctx, grpc_load_reporting_config_destroy(chand->lrc); } +static grpc_mdelem *lr_trailing_md_filter(void *user_data, grpc_mdelem *md) { + grpc_call_element *elem = user_data; + call_data *calld = elem->call_data; + + if (md->key == GRPC_MDSTR_LOAD_REPORTING) { + calld->trailing_md_string = gpr_strdup(grpc_mdstr_as_c_string(md->value)); + return NULL; + } + + return md; +} + +static void lr_start_transport_stream_op(grpc_exec_ctx *exec_ctx, + grpc_call_element *elem, + grpc_transport_stream_op *op) { + GPR_TIMER_BEGIN("lr_start_transport_stream_op", 0); + + if (op->send_trailing_metadata) { + grpc_metadata_batch_filter(op->send_trailing_metadata, + lr_trailing_md_filter, elem); + } + grpc_call_next_op(exec_ctx, elem, op); + + GPR_TIMER_END("lr_start_transport_stream_op", 0); +} + const grpc_channel_filter grpc_load_reporting_filter = { - grpc_call_next_op, + lr_start_transport_stream_op, grpc_channel_next_op, sizeof(call_data), init_call_elem, diff --git a/src/core/lib/transport/static_metadata.c b/src/core/lib/transport/static_metadata.c index 73b0041fd4..c5f16e530d 100644 --- a/src/core/lib/transport/static_metadata.c +++ b/src/core/lib/transport/static_metadata.c @@ -48,7 +48,7 @@ uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 8, 6, 2, 4, 8, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2] = {11, 35, 10, 35, 12, 35, 12, 49, 13, 35, 14, 35, 15, 35, 16, 35, 17, 35, @@ -56,10 +56,10 @@ const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2] = 30, 18, 30, 35, 31, 35, 32, 35, 36, 35, 37, 35, 38, 35, 39, 35, 42, 33, 42, 34, 42, 48, 42, 53, 42, 54, 42, 55, 42, 56, 43, 33, 43, 48, 43, 53, 46, 0, 46, 1, 46, 2, 50, 35, 57, 35, 58, 35, 59, 35, 60, 35, 61, 35, - 62, 35, 63, 35, 64, 35, 65, 35, 66, 40, 66, 68, 66, 71, 67, 79, 67, 80, - 69, 35, 70, 35, 72, 35, 73, 35, 74, 35, 75, 35, 76, 41, 76, 51, 76, 52, - 77, 35, 78, 35, 81, 3, 81, 4, 81, 5, 81, 6, 81, 7, 81, 8, 81, 9, - 82, 35, 83, 84, 85, 35, 86, 35, 87, 35, 88, 35, 89, 35}; + 62, 35, 63, 35, 64, 35, 65, 35, 66, 35, 67, 40, 67, 69, 67, 72, 68, 80, + 68, 81, 70, 35, 71, 35, 73, 35, 74, 35, 75, 35, 76, 35, 77, 41, 77, 51, + 77, 52, 78, 35, 79, 35, 82, 3, 82, 4, 82, 5, 82, 6, 82, 7, 82, 8, + 82, 9, 83, 35, 84, 85, 86, 35, 87, 35, 88, 35, 89, 35, 90, 35}; const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT] = { "0", @@ -126,6 +126,7 @@ const char *const grpc_static_metadata_strings[GRPC_STATIC_MDSTR_COUNT] = { "if-unmodified-since", "last-modified", "link", + "load-reporting", "location", "max-forwards", ":method", diff --git a/src/core/lib/transport/static_metadata.h b/src/core/lib/transport/static_metadata.h index f9d8bcdc8f..5ff0d2f3bc 100644 --- a/src/core/lib/transport/static_metadata.h +++ b/src/core/lib/transport/static_metadata.h @@ -44,7 +44,7 @@ #include "src/core/lib/transport/metadata.h" -#define GRPC_STATIC_MDSTR_COUNT 90 +#define GRPC_STATIC_MDSTR_COUNT 91 extern grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT]; /* "0" */ #define GRPC_MDSTR_0 (&grpc_static_mdstr_table[0]) @@ -175,60 +175,62 @@ extern grpc_mdstr grpc_static_mdstr_table[GRPC_STATIC_MDSTR_COUNT]; #define GRPC_MDSTR_LAST_MODIFIED (&grpc_static_mdstr_table[62]) /* "link" */ #define GRPC_MDSTR_LINK (&grpc_static_mdstr_table[63]) +/* "load-reporting" */ +#define GRPC_MDSTR_LOAD_REPORTING (&grpc_static_mdstr_table[64]) /* "location" */ -#define GRPC_MDSTR_LOCATION (&grpc_static_mdstr_table[64]) +#define GRPC_MDSTR_LOCATION (&grpc_static_mdstr_table[65]) /* "max-forwards" */ -#define GRPC_MDSTR_MAX_FORWARDS (&grpc_static_mdstr_table[65]) +#define GRPC_MDSTR_MAX_FORWARDS (&grpc_static_mdstr_table[66]) /* ":method" */ -#define GRPC_MDSTR_METHOD (&grpc_static_mdstr_table[66]) +#define GRPC_MDSTR_METHOD (&grpc_static_mdstr_table[67]) /* ":path" */ -#define GRPC_MDSTR_PATH (&grpc_static_mdstr_table[67]) +#define GRPC_MDSTR_PATH (&grpc_static_mdstr_table[68]) /* "POST" */ -#define GRPC_MDSTR_POST (&grpc_static_mdstr_table[68]) +#define GRPC_MDSTR_POST (&grpc_static_mdstr_table[69]) /* "proxy-authenticate" */ -#define GRPC_MDSTR_PROXY_AUTHENTICATE (&grpc_static_mdstr_table[69]) +#define GRPC_MDSTR_PROXY_AUTHENTICATE (&grpc_static_mdstr_table[70]) /* "proxy-authorization" */ -#define GRPC_MDSTR_PROXY_AUTHORIZATION (&grpc_static_mdstr_table[70]) +#define GRPC_MDSTR_PROXY_AUTHORIZATION (&grpc_static_mdstr_table[71]) /* "PUT" */ -#define GRPC_MDSTR_PUT (&grpc_static_mdstr_table[71]) +#define GRPC_MDSTR_PUT (&grpc_static_mdstr_table[72]) /* "range" */ -#define GRPC_MDSTR_RANGE (&grpc_static_mdstr_table[72]) +#define GRPC_MDSTR_RANGE (&grpc_static_mdstr_table[73]) /* "referer" */ -#define GRPC_MDSTR_REFERER (&grpc_static_mdstr_table[73]) +#define GRPC_MDSTR_REFERER (&grpc_static_mdstr_table[74]) /* "refresh" */ -#define GRPC_MDSTR_REFRESH (&grpc_static_mdstr_table[74]) +#define GRPC_MDSTR_REFRESH (&grpc_static_mdstr_table[75]) /* "retry-after" */ -#define GRPC_MDSTR_RETRY_AFTER (&grpc_static_mdstr_table[75]) +#define GRPC_MDSTR_RETRY_AFTER (&grpc_static_mdstr_table[76]) /* ":scheme" */ -#define GRPC_MDSTR_SCHEME (&grpc_static_mdstr_table[76]) +#define GRPC_MDSTR_SCHEME (&grpc_static_mdstr_table[77]) /* "server" */ -#define GRPC_MDSTR_SERVER (&grpc_static_mdstr_table[77]) +#define GRPC_MDSTR_SERVER (&grpc_static_mdstr_table[78]) /* "set-cookie" */ -#define GRPC_MDSTR_SET_COOKIE (&grpc_static_mdstr_table[78]) +#define GRPC_MDSTR_SET_COOKIE (&grpc_static_mdstr_table[79]) /* "/" */ -#define GRPC_MDSTR_SLASH (&grpc_static_mdstr_table[79]) +#define GRPC_MDSTR_SLASH (&grpc_static_mdstr_table[80]) /* "/index.html" */ -#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (&grpc_static_mdstr_table[80]) +#define GRPC_MDSTR_SLASH_INDEX_DOT_HTML (&grpc_static_mdstr_table[81]) /* ":status" */ -#define GRPC_MDSTR_STATUS (&grpc_static_mdstr_table[81]) +#define GRPC_MDSTR_STATUS (&grpc_static_mdstr_table[82]) /* "strict-transport-security" */ -#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (&grpc_static_mdstr_table[82]) +#define GRPC_MDSTR_STRICT_TRANSPORT_SECURITY (&grpc_static_mdstr_table[83]) /* "te" */ -#define GRPC_MDSTR_TE (&grpc_static_mdstr_table[83]) +#define GRPC_MDSTR_TE (&grpc_static_mdstr_table[84]) /* "trailers" */ -#define GRPC_MDSTR_TRAILERS (&grpc_static_mdstr_table[84]) +#define GRPC_MDSTR_TRAILERS (&grpc_static_mdstr_table[85]) /* "transfer-encoding" */ -#define GRPC_MDSTR_TRANSFER_ENCODING (&grpc_static_mdstr_table[85]) +#define GRPC_MDSTR_TRANSFER_ENCODING (&grpc_static_mdstr_table[86]) /* "user-agent" */ -#define GRPC_MDSTR_USER_AGENT (&grpc_static_mdstr_table[86]) +#define GRPC_MDSTR_USER_AGENT (&grpc_static_mdstr_table[87]) /* "vary" */ -#define GRPC_MDSTR_VARY (&grpc_static_mdstr_table[87]) +#define GRPC_MDSTR_VARY (&grpc_static_mdstr_table[88]) /* "via" */ -#define GRPC_MDSTR_VIA (&grpc_static_mdstr_table[88]) +#define GRPC_MDSTR_VIA (&grpc_static_mdstr_table[89]) /* "www-authenticate" */ -#define GRPC_MDSTR_WWW_AUTHENTICATE (&grpc_static_mdstr_table[89]) +#define GRPC_MDSTR_WWW_AUTHENTICATE (&grpc_static_mdstr_table[90]) -#define GRPC_STATIC_MDELEM_COUNT 79 +#define GRPC_STATIC_MDELEM_COUNT 80 extern grpc_mdelem grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT]; extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; /* "accept-charset": "" */ @@ -333,71 +335,73 @@ extern uintptr_t grpc_static_mdelem_user_data[GRPC_STATIC_MDELEM_COUNT]; #define GRPC_MDELEM_LAST_MODIFIED_EMPTY (&grpc_static_mdelem_table[45]) /* "link": "" */ #define GRPC_MDELEM_LINK_EMPTY (&grpc_static_mdelem_table[46]) +/* "load-reporting": "" */ +#define GRPC_MDELEM_LOAD_REPORTING_EMPTY (&grpc_static_mdelem_table[47]) /* "location": "" */ -#define GRPC_MDELEM_LOCATION_EMPTY (&grpc_static_mdelem_table[47]) +#define GRPC_MDELEM_LOCATION_EMPTY (&grpc_static_mdelem_table[48]) /* "max-forwards": "" */ -#define GRPC_MDELEM_MAX_FORWARDS_EMPTY (&grpc_static_mdelem_table[48]) +#define GRPC_MDELEM_MAX_FORWARDS_EMPTY (&grpc_static_mdelem_table[49]) /* ":method": "GET" */ -#define GRPC_MDELEM_METHOD_GET (&grpc_static_mdelem_table[49]) +#define GRPC_MDELEM_METHOD_GET (&grpc_static_mdelem_table[50]) /* ":method": "POST" */ -#define GRPC_MDELEM_METHOD_POST (&grpc_static_mdelem_table[50]) +#define GRPC_MDELEM_METHOD_POST (&grpc_static_mdelem_table[51]) /* ":method": "PUT" */ -#define GRPC_MDELEM_METHOD_PUT (&grpc_static_mdelem_table[51]) +#define GRPC_MDELEM_METHOD_PUT (&grpc_static_mdelem_table[52]) /* ":path": "/" */ -#define GRPC_MDELEM_PATH_SLASH (&grpc_static_mdelem_table[52]) +#define GRPC_MDELEM_PATH_SLASH (&grpc_static_mdelem_table[53]) /* ":path": "/index.html" */ -#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML (&grpc_static_mdelem_table[53]) +#define GRPC_MDELEM_PATH_SLASH_INDEX_DOT_HTML (&grpc_static_mdelem_table[54]) /* "proxy-authenticate": "" */ -#define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[54]) +#define GRPC_MDELEM_PROXY_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[55]) /* "proxy-authorization": "" */ -#define GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY (&grpc_static_mdelem_table[55]) +#define GRPC_MDELEM_PROXY_AUTHORIZATION_EMPTY (&grpc_static_mdelem_table[56]) /* "range": "" */ -#define GRPC_MDELEM_RANGE_EMPTY (&grpc_static_mdelem_table[56]) +#define GRPC_MDELEM_RANGE_EMPTY (&grpc_static_mdelem_table[57]) /* "referer": "" */ -#define GRPC_MDELEM_REFERER_EMPTY (&grpc_static_mdelem_table[57]) +#define GRPC_MDELEM_REFERER_EMPTY (&grpc_static_mdelem_table[58]) /* "refresh": "" */ -#define GRPC_MDELEM_REFRESH_EMPTY (&grpc_static_mdelem_table[58]) +#define GRPC_MDELEM_REFRESH_EMPTY (&grpc_static_mdelem_table[59]) /* "retry-after": "" */ -#define GRPC_MDELEM_RETRY_AFTER_EMPTY (&grpc_static_mdelem_table[59]) +#define GRPC_MDELEM_RETRY_AFTER_EMPTY (&grpc_static_mdelem_table[60]) /* ":scheme": "grpc" */ -#define GRPC_MDELEM_SCHEME_GRPC (&grpc_static_mdelem_table[60]) +#define GRPC_MDELEM_SCHEME_GRPC (&grpc_static_mdelem_table[61]) /* ":scheme": "http" */ -#define GRPC_MDELEM_SCHEME_HTTP (&grpc_static_mdelem_table[61]) +#define GRPC_MDELEM_SCHEME_HTTP (&grpc_static_mdelem_table[62]) /* ":scheme": "https" */ -#define GRPC_MDELEM_SCHEME_HTTPS (&grpc_static_mdelem_table[62]) +#define GRPC_MDELEM_SCHEME_HTTPS (&grpc_static_mdelem_table[63]) /* "server": "" */ -#define GRPC_MDELEM_SERVER_EMPTY (&grpc_static_mdelem_table[63]) +#define GRPC_MDELEM_SERVER_EMPTY (&grpc_static_mdelem_table[64]) /* "set-cookie": "" */ -#define GRPC_MDELEM_SET_COOKIE_EMPTY (&grpc_static_mdelem_table[64]) +#define GRPC_MDELEM_SET_COOKIE_EMPTY (&grpc_static_mdelem_table[65]) /* ":status": "200" */ -#define GRPC_MDELEM_STATUS_200 (&grpc_static_mdelem_table[65]) +#define GRPC_MDELEM_STATUS_200 (&grpc_static_mdelem_table[66]) /* ":status": "204" */ -#define GRPC_MDELEM_STATUS_204 (&grpc_static_mdelem_table[66]) +#define GRPC_MDELEM_STATUS_204 (&grpc_static_mdelem_table[67]) /* ":status": "206" */ -#define GRPC_MDELEM_STATUS_206 (&grpc_static_mdelem_table[67]) +#define GRPC_MDELEM_STATUS_206 (&grpc_static_mdelem_table[68]) /* ":status": "304" */ -#define GRPC_MDELEM_STATUS_304 (&grpc_static_mdelem_table[68]) +#define GRPC_MDELEM_STATUS_304 (&grpc_static_mdelem_table[69]) /* ":status": "400" */ -#define GRPC_MDELEM_STATUS_400 (&grpc_static_mdelem_table[69]) +#define GRPC_MDELEM_STATUS_400 (&grpc_static_mdelem_table[70]) /* ":status": "404" */ -#define GRPC_MDELEM_STATUS_404 (&grpc_static_mdelem_table[70]) +#define GRPC_MDELEM_STATUS_404 (&grpc_static_mdelem_table[71]) /* ":status": "500" */ -#define GRPC_MDELEM_STATUS_500 (&grpc_static_mdelem_table[71]) +#define GRPC_MDELEM_STATUS_500 (&grpc_static_mdelem_table[72]) /* "strict-transport-security": "" */ #define GRPC_MDELEM_STRICT_TRANSPORT_SECURITY_EMPTY \ - (&grpc_static_mdelem_table[72]) + (&grpc_static_mdelem_table[73]) /* "te": "trailers" */ -#define GRPC_MDELEM_TE_TRAILERS (&grpc_static_mdelem_table[73]) +#define GRPC_MDELEM_TE_TRAILERS (&grpc_static_mdelem_table[74]) /* "transfer-encoding": "" */ -#define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY (&grpc_static_mdelem_table[74]) +#define GRPC_MDELEM_TRANSFER_ENCODING_EMPTY (&grpc_static_mdelem_table[75]) /* "user-agent": "" */ -#define GRPC_MDELEM_USER_AGENT_EMPTY (&grpc_static_mdelem_table[75]) +#define GRPC_MDELEM_USER_AGENT_EMPTY (&grpc_static_mdelem_table[76]) /* "vary": "" */ -#define GRPC_MDELEM_VARY_EMPTY (&grpc_static_mdelem_table[76]) +#define GRPC_MDELEM_VARY_EMPTY (&grpc_static_mdelem_table[77]) /* "via": "" */ -#define GRPC_MDELEM_VIA_EMPTY (&grpc_static_mdelem_table[77]) +#define GRPC_MDELEM_VIA_EMPTY (&grpc_static_mdelem_table[78]) /* "www-authenticate": "" */ -#define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[78]) +#define GRPC_MDELEM_WWW_AUTHENTICATE_EMPTY (&grpc_static_mdelem_table[79]) extern const uint8_t grpc_static_metadata_elem_indices[GRPC_STATIC_MDELEM_COUNT * 2]; diff --git a/test/core/end2end/fixtures/h2_loadreporting.c b/test/core/end2end/fixtures/h2_loadreporting.c index 13feba29f1..4ed02f9728 100644 --- a/test/core/end2end/fixtures/h2_loadreporting.c +++ b/test/core/end2end/fixtures/h2_loadreporting.c @@ -76,15 +76,26 @@ static grpc_end2end_test_fixture chttp2_create_fixture_fullstack( typedef struct { int64_t total_bytes; - bool processed; + bool fully_processed; + uint32_t initial_token; + uint32_t final_token; } aggregated_bw_stats; -static void sample_fn(const grpc_call_stats *stats, void *lr_data) { - aggregated_bw_stats *custom_stats = (aggregated_bw_stats *)lr_data; - custom_stats->total_bytes = - (int64_t)(stats->transport_stream_stats.outgoing.data_bytes + - stats->transport_stream_stats.incoming.data_bytes); - custom_stats->processed = true; +static void sample_fn(const grpc_load_reporting_call_data *call_data, + void *user_data) { + GPR_ASSERT(user_data != NULL); + aggregated_bw_stats *custom_stats = (aggregated_bw_stats *)user_data; + if (call_data == NULL) { + /* initial invocation */ + custom_stats->initial_token = 0xDEADBEEF; + } else { + /* final invocation */ + custom_stats->total_bytes = + (int64_t)(call_data->stats->transport_stream_stats.outgoing.data_bytes + + call_data->stats->transport_stream_stats.incoming.data_bytes); + custom_stats->final_token = 0xCAFED00D; + custom_stats->fully_processed = true; + } } void chttp2_init_client_fullstack(grpc_end2end_test_fixture *f, @@ -131,11 +142,11 @@ int main(int argc, char **argv) { aggregated_bw_stats *aggr_stats_client = gpr_malloc(sizeof(aggregated_bw_stats)); aggr_stats_client->total_bytes = -1; - aggr_stats_client->processed = false; + aggr_stats_client->fully_processed = false; aggregated_bw_stats *aggr_stats_server = gpr_malloc(sizeof(aggregated_bw_stats)); aggr_stats_server->total_bytes = -1; - aggr_stats_server->processed = false; + aggr_stats_server->fully_processed = false; g_client_lrc = grpc_load_reporting_config_create(sample_fn, aggr_stats_client); @@ -155,11 +166,15 @@ int main(int argc, char **argv) { grpc_load_reporting_config_destroy(g_client_lrc); grpc_load_reporting_config_destroy(g_server_lrc); - if (aggr_stats_client->processed) { + if (aggr_stats_client->fully_processed) { GPR_ASSERT(aggr_stats_client->total_bytes >= 0); + GPR_ASSERT(aggr_stats_client->initial_token == 0xDEADBEEF); + GPR_ASSERT(aggr_stats_client->final_token == 0xCAFED00D); } - if (aggr_stats_server->processed) { + if (aggr_stats_server->fully_processed) { GPR_ASSERT(aggr_stats_server->total_bytes >= 0); + GPR_ASSERT(aggr_stats_server->initial_token == 0xDEADBEEF); + GPR_ASSERT(aggr_stats_server->final_token == 0xCAFED00D); } gpr_free(aggr_stats_client); diff --git a/test/core/end2end/fuzzers/hpack.dictionary b/test/core/end2end/fuzzers/hpack.dictionary index b081368ff6..097e9a8922 100644 --- a/test/core/end2end/fuzzers/hpack.dictionary +++ b/test/core/end2end/fuzzers/hpack.dictionary @@ -63,6 +63,7 @@ "\x13if-unmodified-since" "\x0Dlast-modified" "\x04link" +"\x0Eload-reporting" "\x08location" "\x0Cmax-forwards" "\x07:method" @@ -136,6 +137,7 @@ "\x00\x13if-unmodified-since\x00" "\x00\x0Dlast-modified\x00" "\x00\x04link\x00" +"\x00\x0Eload-reporting\x00" "\x00\x08location\x00" "\x00\x0Cmax-forwards\x00" "\x00\x07:method\x03GET" diff --git a/tools/codegen/core/gen_static_metadata.py b/tools/codegen/core/gen_static_metadata.py index b38555e355..faa83867a6 100755 --- a/tools/codegen/core/gen_static_metadata.py +++ b/tools/codegen/core/gen_static_metadata.py @@ -108,6 +108,7 @@ CONFIG = [ ('if-range', ''), ('if-unmodified-since', ''), ('last-modified', ''), + ('load-reporting', ''), ('link', ''), ('location', ''), ('max-forwards', ''), |