Skip to content

[RFC] Add extended stats - #893

Merged
kazuho merged 8 commits into
h2o:masterfrom
deweerdt:deweerdt/stats
Jun 1, 2016
Merged

kazuho merged 8 commits into
h2o:masterfrom
deweerdt:deweerdt/stats

Conversation

@deweerdt

@deweerdt deweerdt commented May 5, 2016

Copy link
Copy Markdown
Member

This PR aims at adding optional additional counters accessible via the status page. This would be enabled when status has the value EXTENDED.
I post this mainly as a conversation starter, in particular to discuss how the information is gathered. Following our offline discussion, my goal would be to add also http2 counters as well as duration counters in proxy.c.

@deweerdt
deweerdt force-pushed the deweerdt/stats branch 3 times, most recently from ddb4076 to b267e10 Compare May 5, 2016 22:09
- Add a structure to track internally generated errors
- Structure the stats a pluggable modules. New status reporting code can
  use the `h2o_config_register_status_handler` (for queries that need to
  access per thread data) or `h2o_config_register_simple_status_handler`
  (for queries that can be run in the request context) APIs in order to
  add new statuses
- requests statuses and error reporting is moved under
  `lib/handler/status/`
@deweerdt

Copy link
Copy Markdown
Member Author

Here's another attempt at the PR: i've added a registering mechanism for request handlers ('main', 'requests' and 'errors'), and split requests and errors to their own file. I've also removed the jemalloc bits: haven't figured out how to make the detection work in the static linking case, and it feels like it should be a different PR anyway.

Comment thread include/h2o.h Outdated
h2o_iovec_t (*assemble_cb)(void *ctx);
void (*done_cb)(void *ctx);
} per_thread;
};

@kazuho kazuho May 16, 2016

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about having a single type that optionally defines per_thread_cb, instead of having two distinct types.

For example, we could define three callbacks: init, per_thread, final, with the first two being optional callbacks. final should either a) gather the information obtained by calls to per_thread (that updates the struct costructed by init), or b) simply return the information available in a global storage (in this case, init and per_thread can be set to NULL).

Also, you cannot allocate memory from req->pool in a different thread (than the request belongs to). Therefore, you should not pass src_req to alloc_context_cb (and considering the fact that the status handler is rarely called, I think it is not mandatory to use memory pools in the handler).

@kazuho

kazuho commented May 16, 2016

Copy link
Copy Markdown
Member

Thank you for updating the PR.

It seems like we've made a big progress forward. Thank you very much.

I've left high-level design comments inline. Would you please consider them?

@deweerdt

Copy link
Copy Markdown
Member Author

Hello @kazuho, Thanks for taking the time to review the PR! I'll be addressing your comments shortly.

deweerdt added 2 commits May 16, 2016 13:47
  `init` and `per_thread` callbacks optional. Only `final` will be
  mandatory.
- Remove GNUisms
- Fix the doc to reflect the current implementation.
- Use predefined functions for the callsites where the status is known,
  avoiding one indirection level
Comment thread lib/handler/status.c Outdated
pthread_mutex_t mutex;
h2o_iovec_t data;
size_t num_remaining_threads;
h2o_globalconf_t *gconf;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe you do not need to retain a pointer to h2o_globalconf_t. It can be reached by accessing h2o_context_t::globalconf.

  update the counters directly from that function, instead of relying on
  `h2o_context_report_http1_error`
- Remove `h2o_context_report_http1_error` and `E_HTTP_{4,5,X}XX` enums:
  Every call side now uses a well known http return code.
- Simplify the `status_list` logic by calling `h2o_contains_token`. We
  also use `,` as a separator between the modules, rather than the
  reserved `|` (update docs and the test).
- Add a test case verifying the increment of the 404 counter
@kazuho

kazuho commented May 23, 2016

Copy link
Copy Markdown
Member

@deweerdt Should I review the changes now or are you planning to push more?

@deweerdt

Copy link
Copy Markdown
Member Author

@kazuho, I believe the changes are ready for review, thanks!

Comment thread lib/http1.c Outdated
h2o_socket_read_stop(conn->sock);
conn->req.http1_is_persistent = 0;
h2o_send_error(&conn->req, status, reason, body, H2O_SEND_ERROR_HTTP1_CLOSE_CONNECTION);
h2o_send_error_generic(&conn->req, status, reason, body, H2O_SEND_ERROR_HTTP1_CLOSE_CONNECTION);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we better invoke h2o_send_error_XXX in the callers of entity_read_send_error to collect the error codes?

@kazuho

kazuho commented May 23, 2016

Copy link
Copy Markdown
Member

@deweerdt I've gone through the code and left my comments. Please update the code or let me know how you think. Thank you in advance.

- simplify `st_h2o_status_handler_t` error handler in `init` removing
  error handling that level, and deferring to `final`.
- Remove H2O_HTTP2_ERROR_OTHER in favor of dedicated `read_closed` and
  `write_closed` errors.
- rename http1 errors under H2O_STATUS_ERROR_XXX
- replace the remaining callers to `h2o_send_error_generic` to use
  hardcoded errors
- append `DECL_` to the names of function declaring macros for clarity
@deweerdt

Copy link
Copy Markdown
Member Author

Hello @kazuho , I believe 07f3850 addresses all your remarks. Thanks!

@kazuho

kazuho commented May 25, 2016

Copy link
Copy Markdown
Member

Thank you for the updates. All we have left are some naming issues. Once they get updated I will merge the PR (or if you want me to change the names please let me know).

PS. Regarding the names, it might be better to rename the "error" status handler to "events" status handler considering the fact that it can be used to collect numbers of any kind of events (and that italready collects the number of connection closes).

@deweerdt

deweerdt commented May 25, 2016

Copy link
Copy Markdown
Member Author

Thank you for the updates. All we have left are some naming issues. Once they get updated I will merge the PR (or if you want me to change the names please let me know).

I'll update the code, thanks. I'll await your decision on the json formatting and the naming of the handler below before updating the PR.

PS. Regarding the names, it might be better to rename the "error" status handler to "events" status handler considering the fact that it can be used to collect numbers of any kind of events (and that italready collects the number of connection closes).

My initial idea was to mirror what would be found in the error log, but you're right that collecting read and write closes are better described by being events than errors. Another argument in favor of 'events' is that those aren't really errors that are actionable by the administrator, they are just useful to monitor because a sudden change in rates might mean that an action is required. How about 'networking_events'?

s/http1_status_errors/emitted_error_status/
s/DECL_H2O_SEND_ERROR_XXX/H2O_SEND_ERROR_XXX/
s/errors_status_ctx/st_errors_status_ctx_t/
rename aggregated errors to something that matches the data being
aggregated
@kazuho

kazuho commented May 26, 2016

Copy link
Copy Markdown
Member

Do you mean have the json member look like h2o-http2-error-flow-control and h2o-status-error-400?
Alternatively, we could have the json object look like something like:

I do not have a strong preference, but using the former with h2o- omitted (e.g. http2-error-flow-control) might be better. The reason is because it is easier to handle non-structured name-values pairs (e.g. when converting to CSV), while in case you have the power to handle structured JSON it is likely that you can easily extract some fields with certain prefix.

PS. I'd also suggest using . to for denoting category and use - to connect the words that consist a single name (example: http2-error.flow-control).

My initial idea was to mirror what would be found in the error log, but you're right that collecting read and write closes are better described by being events than errors. Another argument in favor of 'events' is that those aren't really errors that are actionable by the administrator, they are just useful to monitor because a sudden change in rates might mean that an action is required.

Agreed.

How about 'networking_events'?

I'd suggest omitting networking, since we might want to enhance the handler to count non-networking events (e.g. number of times a file-based mmap is issued).

- Modify the json key naming: s/_/-/ and add a dot to denote categories
@deweerdt

Copy link
Copy Markdown
Member Author

@kazuho , i believe bd158bc addresses everything we've discussed so far.

Comment thread lib/handler/status/events.c Outdated
" \"http1-errors.417\": %" PRIu64 ",\n"
" \"http1-errors.500\": %" PRIu64 ",\n"
" \"http1-errors.502\": %" PRIu64 ",\n"
" \"http1-errors.503\": %" PRIu64 ",\n"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please rename the errors to status-errors, as discussed in #893 (comment).

I believe that is the only change required to getting this merged. Thank you!

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kazuho ah yes, of course. That's fixed in a3b35d1

@kazuho kazuho added this to the v2.1 milestone May 31, 2016
@deweerdt

deweerdt commented Jun 1, 2016

Copy link
Copy Markdown
Member Author

@kazuho, a3b35d1 has the last batch of renames. Thanks!

@kazuho
kazuho merged commit a3b35d1 into h2o:master Jun 1, 2016
kazuho added a commit that referenced this pull request Jun 1, 2016
[RFC] Add extended stats

clang-format applied to the updated files
kazuho added a commit that referenced this pull request Jun 1, 2016
@kazuho

kazuho commented Jun 1, 2016

Copy link
Copy Markdown
Member

Thank you for your hard work! Merged to master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants