New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RFC] Add extended stats #893
Merged
Merged
Changes from 4 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d0dafa0
Improvements to reported stats
deweerdt 99b9acf
- Simplify `h2o_status_handler_t` by removing the type, and making the
deweerdt 7ee8e64
- Split errors in http1/http2
deweerdt ebc247e
- Add a specialized `h2o_send_error_deferred` define so that we can
deweerdt 07f3850
stats: various small fixes
deweerdt a24ec3d
Various renames
deweerdt bd158bc
- Rename 'errors' to 'events', since we're really tracking events here
deweerdt a3b35d1
s/http1-errors/status-errors/ in the json output as well
deweerdt File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -275,6 +275,15 @@ typedef struct st_h2o_protocol_callbacks_t { | |
int (*foreach_request)(h2o_context_t *ctx, int (*cb)(h2o_req_t *req, void *cbdata), void *cbdata); | ||
} h2o_protocol_callbacks_t; | ||
|
||
typedef h2o_iovec_t (*final_status_handler_cb)(void *ctx, h2o_globalconf_t *gconf, h2o_req_t *req); | ||
typedef struct st_h2o_status_handler_t { | ||
h2o_iovec_t name; | ||
void *(*init)(h2o_iovec_t *error); /* optional call back, allocates a context that will be passed to per_thread() */ | ||
void (*per_thread)(void *priv, h2o_context_t *ctx); /* optional callback, will be called for each thread */ | ||
h2o_iovec_t (*final)(void *ctx, h2o_globalconf_t *gconf, h2o_req_t *req); /* mandatory, will be passed the optional context */ | ||
} h2o_status_handler_t; | ||
|
||
typedef H2O_VECTOR(h2o_status_handler_t) h2o_status_callbacks_t; | ||
struct st_h2o_globalconf_t { | ||
/** | ||
* a NULL-terminated list of host contexts (h2o_hostconf_t) | ||
|
@@ -371,10 +380,7 @@ struct st_h2o_globalconf_t { | |
} filecache; | ||
|
||
/* status */ | ||
struct { | ||
/* optional callback set by the user of libh2o to feed additional json to the status handler */ | ||
h2o_iovec_t (*extra_status)(h2o_globalconf_t *conf, h2o_mem_pool_t *pool); | ||
} status; | ||
h2o_status_callbacks_t statuses; | ||
|
||
size_t _num_config_slots; | ||
}; | ||
|
@@ -411,6 +417,40 @@ typedef struct st_h2o_mimemap_type_t { | |
} data; | ||
} h2o_mimemap_type_t; | ||
|
||
/* defined as negated form of the error codes defined in HTTP2-spec section 7 */ | ||
#define H2O_HTTP2_ERROR_NONE 0 | ||
#define H2O_HTTP2_ERROR_PROTOCOL -1 | ||
#define H2O_HTTP2_ERROR_INTERNAL -2 | ||
#define H2O_HTTP2_ERROR_FLOW_CONTROL -3 | ||
#define H2O_HTTP2_ERROR_SETTINGS_TIMEOUT -4 | ||
#define H2O_HTTP2_ERROR_STREAM_CLOSED -5 | ||
#define H2O_HTTP2_ERROR_FRAME_SIZE -6 | ||
#define H2O_HTTP2_ERROR_REFUSED_STREAM -7 | ||
#define H2O_HTTP2_ERROR_CANCEL -8 | ||
#define H2O_HTTP2_ERROR_COMPRESSION -9 | ||
#define H2O_HTTP2_ERROR_CONNECT -10 | ||
#define H2O_HTTP2_ERROR_ENHANCE_YOUR_CALM -11 | ||
#define H2O_HTTP2_ERROR_INADEQUATE_SECURITY -12 | ||
/* end of the HTT2-spec defined errors */ | ||
#define H2O_HTTP2_ERROR_OTHER -13 | ||
#define H2O_HTTP2_ERROR_MAX 14 | ||
#define H2O_HTTP2_ERROR_INCOMPLETE -255 /* an internal value indicating that all data is not ready */ | ||
#define H2O_HTTP2_ERROR_PROTOCOL_CLOSE_IMMEDIATELY -256 | ||
|
||
enum { | ||
/* http1 */ | ||
E_HTTP_400 = 0, | ||
E_HTTP_403, | ||
E_HTTP_404, | ||
E_HTTP_405, | ||
E_HTTP_416, | ||
E_HTTP_417, | ||
E_HTTP_500, | ||
E_HTTP_502, | ||
E_HTTP_503, | ||
E_HTTP_MAX, | ||
}; | ||
|
||
/** | ||
* context of the http server. | ||
*/ | ||
|
@@ -479,6 +519,10 @@ struct st_h2o_context_t { | |
* timeout entry used for graceful shutdown | ||
*/ | ||
h2o_timeout_entry_t _graceful_shutdown_timeout; | ||
/** | ||
* counter for http2 errors internally emitted by h2o | ||
*/ | ||
uint64_t emitted_errors[H2O_HTTP2_ERROR_MAX]; | ||
} http2; | ||
|
||
struct { | ||
|
@@ -503,6 +547,11 @@ struct st_h2o_context_t { | |
h2o_timestamp_string_t *value; | ||
} _timestamp_cache; | ||
|
||
/** | ||
* counter for http1 errors internally emitted by h2o | ||
*/ | ||
unsigned long emitted_errors[E_HTTP_MAX]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The type should be changed to |
||
|
||
H2O_VECTOR(h2o_pathconf_t *) _pathconfs_inited; | ||
}; | ||
|
||
|
@@ -1143,6 +1192,11 @@ h2o_hostconf_t *h2o_config_register_host(h2o_globalconf_t *config, h2o_iovec_t h | |
* * configuration path does not end with a `/`, and the request path begins with the configuration path followed by a `/` | ||
*/ | ||
h2o_pathconf_t *h2o_config_register_path(h2o_hostconf_t *hostconf, const char *path, int flags); | ||
/** | ||
* registers an extra status handler | ||
*/ | ||
void h2o_config_register_status_handler(h2o_globalconf_t *config, h2o_status_handler_t); | ||
void h2o_config_register_simple_status_handler(h2o_globalconf_t *config, h2o_iovec_t name, final_status_handler_cb status_handler); | ||
/** | ||
* disposes of the resources allocated for the global configuration | ||
*/ | ||
|
@@ -1211,7 +1265,6 @@ static void h2o_context_set_filter_context(h2o_context_t *ctx, h2o_filter_t *fil | |
* returns per-module context set by the on_context_init callback | ||
*/ | ||
static void *h2o_context_get_logger_context(h2o_context_t *ctx, h2o_logger_t *logger); | ||
|
||
/* built-in generators */ | ||
|
||
enum { | ||
|
@@ -1232,7 +1285,24 @@ void h2o_send_inline(h2o_req_t *req, const char *body, size_t len); | |
/** | ||
* sends the given information as an error response to the client | ||
*/ | ||
void h2o_send_error(h2o_req_t *req, int status, const char *reason, const char *body, int flags); | ||
void h2o_send_error_generic(h2o_req_t *req, int status, const char *reason, const char *body, int flags); | ||
#define H2O_SEND_ERROR_XXX(status) \ | ||
static inline void h2o_send_error_ ## status(h2o_req_t *req, const char *reason, const char *body, int flags) \ | ||
{ \ | ||
req->conn->ctx->emitted_errors[E_HTTP_ ## status]++; \ | ||
h2o_send_error_generic(req, status, reason, body, flags); \ | ||
} | ||
|
||
H2O_SEND_ERROR_XXX(400) | ||
H2O_SEND_ERROR_XXX(403) | ||
H2O_SEND_ERROR_XXX(404) | ||
H2O_SEND_ERROR_XXX(405) | ||
H2O_SEND_ERROR_XXX(416) | ||
H2O_SEND_ERROR_XXX(417) | ||
H2O_SEND_ERROR_XXX(500) | ||
H2O_SEND_ERROR_XXX(502) | ||
H2O_SEND_ERROR_XXX(503) | ||
|
||
/** | ||
* sends error response using zero timeout; can be called by output filters while processing the headers | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change the names to
H2O_STATUS_ERROR_XXX