Skip to content

Commit

Permalink
httpd: method/namespace call metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
elliefm committed Aug 15, 2017
1 parent 13e8fb1 commit 5824c0b
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 36 deletions.
2 changes: 1 addition & 1 deletion imap/http_admin.c
Expand Up @@ -91,7 +91,7 @@ static int action_conf(struct transaction_t *txn);

/* Namespace for admin service */
struct namespace_t namespace_admin = {
URL_NS_ADMIN, 1, "/admin", NULL,
URL_NS_ADMIN, 1, "admin", "/admin", NULL,
http_allow_noauth_get, /*authschemes*/0,
/*mbtype*/0,
ALLOW_READ,
Expand Down
2 changes: 1 addition & 1 deletion imap/http_applepush.c
Expand Up @@ -57,7 +57,7 @@ static int meth_get_applepush(struct transaction_t *txn, void *params);
static int meth_post_applepush(struct transaction_t *txn, void *params);

struct namespace_t namespace_applepush = {
URL_NS_APPLEPUSH, /*enabled*/0, "/applepush/subscribe", NULL,
URL_NS_APPLEPUSH, /*enabled*/0, "applepush", "/applepush/subscribe", NULL,
http_allow_noauth_get, /*authschemes*/0,
/*mbtype*/0,
ALLOW_READ|ALLOW_POST,
Expand Down
4 changes: 2 additions & 2 deletions imap/http_caldav.c
Expand Up @@ -518,7 +518,7 @@ static struct meth_params caldav_params = {

/* Namespace for CalDAV collections */
struct namespace_t namespace_calendar = {
URL_NS_CALENDAR, 0, "/dav/calendars", "/.well-known/caldav",
URL_NS_CALENDAR, 0, "calendar", "/dav/calendars", "/.well-known/caldav",
http_allow_noauth_get, /*authschemes*/0,
MBTYPE_CALENDAR,
(ALLOW_READ | ALLOW_POST | ALLOW_WRITE | ALLOW_DELETE |
Expand Down Expand Up @@ -558,7 +558,7 @@ struct namespace_t namespace_calendar = {

/* Namespace for Freebusy Read URL */
struct namespace_t namespace_freebusy = {
URL_NS_FREEBUSY, 0, "/freebusy", NULL,
URL_NS_FREEBUSY, 0, "freebusy", "/freebusy", NULL,
http_allow_noauth_get, /*authschemes*/0,
MBTYPE_CALENDAR,
ALLOW_READ,
Expand Down
2 changes: 1 addition & 1 deletion imap/http_carddav.c
Expand Up @@ -304,7 +304,7 @@ static struct meth_params carddav_params = {

/* Namespace for Carddav collections */
struct namespace_t namespace_addressbook = {
URL_NS_ADDRESSBOOK, 0, "/dav/addressbooks", "/.well-known/carddav",
URL_NS_ADDRESSBOOK, 0, "addressbook", "/dav/addressbooks", "/.well-known/carddav",
http_allow_noauth_get, /*authschemes*/0,
MBTYPE_ADDRESSBOOK,
(ALLOW_READ | ALLOW_POST | ALLOW_WRITE | ALLOW_DELETE |
Expand Down
4 changes: 2 additions & 2 deletions imap/http_dav.c
Expand Up @@ -271,7 +271,7 @@ static struct meth_params princ_params = {

/* Namespace for WebDAV principals */
struct namespace_t namespace_principal = {
URL_NS_PRINCIPAL, 0, "/dav/principals", NULL,
URL_NS_PRINCIPAL, 0, "principal", "/dav/principals", NULL,
http_allow_noauth_get, /*authschemes*/0,
/*mbtype */ 0,
ALLOW_READ | ALLOW_DAV,
Expand Down Expand Up @@ -8930,7 +8930,7 @@ struct meth_params notify_params = {

/* Namespace for WebDAV notification collections */
struct namespace_t namespace_notify = {
URL_NS_NOTIFY, 0, "/dav/notifications", NULL,
URL_NS_NOTIFY, 0, "notify", "/dav/notifications", NULL,
http_allow_noauth_get, /*authschemes*/0,
MBTYPE_COLLECTION,
(ALLOW_READ | ALLOW_POST | ALLOW_DELETE |
Expand Down
2 changes: 1 addition & 1 deletion imap/http_dblookup.c
Expand Up @@ -56,7 +56,7 @@ static int meth_get_db(struct transaction_t *txn, void *params);

/* Namespace for DB lookups */
struct namespace_t namespace_dblookup = {
URL_NS_DBLOOKUP, /*enabled*/1, "/dblookup", NULL,
URL_NS_DBLOOKUP, /*enabled*/1, "dblookup", "/dblookup", NULL,
http_allow_noauth, /*authschemes*/0,
/*mbtype*/0,
ALLOW_READ,
Expand Down
4 changes: 2 additions & 2 deletions imap/http_ischedule.c
Expand Up @@ -116,7 +116,7 @@ static struct mime_type_t isched_mime_types[] = {
};

struct namespace_t namespace_ischedule = {
URL_NS_ISCHEDULE, 0, "/ischedule", ISCHED_WELLKNOWN_URI,
URL_NS_ISCHEDULE, 0, "ischedule", "/ischedule", ISCHED_WELLKNOWN_URI,
http_allow_noauth, /*authschemes*/0,
/*mbtype*/0,
(ALLOW_READ | ALLOW_POST | ALLOW_ISCHEDULE),
Expand Down Expand Up @@ -146,7 +146,7 @@ struct namespace_t namespace_ischedule = {
};

struct namespace_t namespace_domainkey = {
URL_NS_DOMAINKEY, 0, "/domainkeys", "/.well-known/domainkey",
URL_NS_DOMAINKEY, 0, "domainkey", "/domainkeys", "/.well-known/domainkey",
http_allow_noauth, /*authschemes*/0,
/*mbtype*/0,
ALLOW_READ,
Expand Down
2 changes: 1 addition & 1 deletion imap/http_jmap.c
Expand Up @@ -103,7 +103,7 @@ static int myrights_byname(struct auth_state *authstate,

/* Namespace for JMAP */
struct namespace_t namespace_jmap = {
URL_NS_JMAP, 0, "/jmap", "/.well-known/jmap",
URL_NS_JMAP, 0, "jmap", "/jmap", "/.well-known/jmap",
jmap_checkurl, 1 << AUTH_BEARER,
/*mbtype*/0,
(ALLOW_READ | ALLOW_POST),
Expand Down
1 change: 1 addition & 0 deletions imap/http_prometheus.c
Expand Up @@ -57,6 +57,7 @@ static int prom_get(struct transaction_t *txn, void *params);
struct namespace_t namespace_prometheus = {
URL_NS_PROMETHEUS,
/*enabled*/ 0,
"prometheus",
"/metrics",
/* XXX .well-known url*/ NULL,
prom_need_auth,
Expand Down
2 changes: 1 addition & 1 deletion imap/http_rss.c
Expand Up @@ -108,7 +108,7 @@ static struct body *body_fetch_section(struct body *body, const char *section);

/* Namespace for RSS feeds of mailboxes */
struct namespace_t namespace_rss = {
URL_NS_RSS, 0, "/rss", NULL,
URL_NS_RSS, 0, "rss", "/rss", NULL,
http_allow_noauth_get, /*authschemes*/0,
/*mbtype*/0,
ALLOW_READ,
Expand Down
2 changes: 1 addition & 1 deletion imap/http_tzdist.c
Expand Up @@ -138,7 +138,7 @@ static struct mime_type_t tz_mime_types[] = {

/* Namespace for tzdist service */
struct namespace_t namespace_tzdist = {
URL_NS_TZDIST, 0, "/tzdist", TZDIST_WELLKNOWN_URI,
URL_NS_TZDIST, 0, "tzdist", "/tzdist", TZDIST_WELLKNOWN_URI,
http_allow_noauth, /*authschemes*/0,
/*mbtype*/0,
ALLOW_READ,
Expand Down
2 changes: 1 addition & 1 deletion imap/http_webdav.c
Expand Up @@ -229,7 +229,7 @@ struct meth_params webdav_params = {

/* Namespace for Webdav collections */
struct namespace_t namespace_drive = {
URL_NS_DRIVE, 0, "/dav/drive", NULL,
URL_NS_DRIVE, 0, "drive", "/dav/drive", NULL,
http_allow_noauth_get, /*authschemes*/0,
MBTYPE_COLLECTION,
(ALLOW_READ | ALLOW_POST | ALLOW_WRITE | ALLOW_DELETE |
Expand Down
50 changes: 28 additions & 22 deletions imap/httpd.c
Expand Up @@ -574,6 +574,9 @@ static int http2_frame_recv_cb(nghttp2_session *session,
&txn->req_tgt.namespace->methods[txn->meth];

ret = (*meth_t->proc)(txn, meth_t->params);

prometheus_increment(prometheus_lookup_label(http_methods[txn->meth].metric,
txn->req_tgt.namespace->name));
}

if (ret == HTTP_UNAUTHORIZED) {
Expand Down Expand Up @@ -1110,32 +1113,32 @@ static struct sasl_callback mysasl_cb[] = {

/* Array of HTTP methods known by our server. */
const struct known_meth_t http_methods[] = {
{ "ACL", 0 },
{ "BIND", 0 },
{ "COPY", METH_NOBODY },
{ "DELETE", METH_NOBODY },
{ "GET", METH_NOBODY },
{ "HEAD", METH_NOBODY },
{ "LOCK", 0 },
{ "MKCALENDAR", 0 },
{ "MKCOL", 0 },
{ "MOVE", METH_NOBODY },
{ "OPTIONS", METH_NOBODY },
{ "PATCH", 0 },
{ "POST", 0 },
{ "PROPFIND", 0 },
{ "PROPPATCH", 0 },
{ "PUT", 0 },
{ "REPORT", 0 },
{ "TRACE", METH_NOBODY },
{ "UNBIND", 0 },
{ "UNLOCK", METH_NOBODY },
{ NULL, 0 }
{ "ACL", 0, CYRUS_HTTP_ACL_TOTAL },
{ "BIND", 0, CYRUS_HTTP_BIND_TOTAL },
{ "COPY", METH_NOBODY, CYRUS_HTTP_COPY_TOTAL },
{ "DELETE", METH_NOBODY, CYRUS_HTTP_DELETE_TOTAL },
{ "GET", METH_NOBODY, CYRUS_HTTP_GET_TOTAL },
{ "HEAD", METH_NOBODY, CYRUS_HTTP_HEAD_TOTAL },
{ "LOCK", 0, CYRUS_HTTP_LOCK_TOTAL },
{ "MKCALENDAR", 0, CYRUS_HTTP_MKCALENDAR_TOTAL },
{ "MKCOL", 0, CYRUS_HTTP_MKCOL_TOTAL },
{ "MOVE", METH_NOBODY, CYRUS_HTTP_MOVE_TOTAL },
{ "OPTIONS", METH_NOBODY, CYRUS_HTTP_OPTIONS_TOTAL },
{ "PATCH", 0, CYRUS_HTTP_PATCH_TOTAL },
{ "POST", 0, CYRUS_HTTP_POST_TOTAL },
{ "PROPFIND", 0, CYRUS_HTTP_PROPFIND_TOTAL },
{ "PROPPATCH", 0, CYRUS_HTTP_PROPPATCH_TOTAL },
{ "PUT", 0, CYRUS_HTTP_PUT_TOTAL },
{ "REPORT", 0, CYRUS_HTTP_REPORT_TOTAL },
{ "TRACE", METH_NOBODY, CYRUS_HTTP_TRACE_TOTAL },
{ "UNBIND", 0, CYRUS_HTTP_UNBIND_TOTAL },
{ "UNLOCK", METH_NOBODY, CYRUS_HTTP_UNLOCK_TOTAL },
{ NULL, 0, 0 }
};

/* Namespace to fetch static content from filesystem */
struct namespace_t namespace_default = {
URL_NS_DEFAULT, 1, "", NULL,
URL_NS_DEFAULT, 1, "default", "", NULL,
http_allow_noauth, /*authschemes*/0,
/*mbtype*/0,
ALLOW_READ,
Expand Down Expand Up @@ -2340,6 +2343,9 @@ static int http1_input(struct transaction_t *txn)
&txn->req_tgt.namespace->methods[txn->meth];

ret = (*meth_t->proc)(txn, meth_t->params);

prometheus_increment(prometheus_lookup_label(http_methods[txn->meth].metric,
txn->req_tgt.namespace->name));
}

if (ret == HTTP_UNAUTHORIZED) {
Expand Down
3 changes: 3 additions & 0 deletions imap/httpd.h
Expand Up @@ -65,6 +65,7 @@ typedef struct { void *value; } nghttp2_nv;
#include "hash.h"
#include "http_client.h"
#include "mailbox.h"
#include "prometheus.h"
#include "spool.h"

#define MAX_REQ_LINE 8000 /* minimum size per RFC 7230 */
Expand Down Expand Up @@ -113,6 +114,7 @@ typedef struct { void *value; } nghttp2_nv;
struct known_meth_t {
const char *name;
unsigned flags;
enum prom_labelled_metric metric;
};
extern const struct known_meth_t http_methods[];

Expand Down Expand Up @@ -441,6 +443,7 @@ struct method_t {
struct namespace_t {
unsigned id; /* Namespace identifier */
unsigned enabled; /* Is this namespace enabled? */
const char *name; /* Text name of this namespace ([A-Z][a-z][0-9]+) */
const char *prefix; /* Prefix of URL path denoting namespace */
const char *well_known; /* Any /.well-known/ URI */
int (*need_auth)(txn_t *); /* Function run prior to unauthorized requests */
Expand Down
40 changes: 40 additions & 0 deletions imap/promdata.p
Expand Up @@ -80,3 +80,43 @@ metric counter cyrus_lmtp_sieve_autorespond_sent_total The number of sieve AUTO
metric counter cyrus_http_connections_total The total number of HTTP connections
metric gauge cyrus_http_active_connections The number of active HTTP connections
metric gauge cyrus_http_ready_listeners The number of currently ready HTTP listeners
metric counter cyrus_http_acl_total The total number of HTTP ACLs
label cyrus_http_acl_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_bind_total The total number of HTTP BINDs
label cyrus_http_bind_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_copy_total The total number of HTTP COPYs
label cyrus_http_copy_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_delete_total The total number of HTTP DELETEs
label cyrus_http_delete_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_get_total The total number of HTTP GETs
label cyrus_http_get_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_head_total The total number of HTTP HEADs
label cyrus_http_head_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_lock_total The total number of HTTP LOCKs
label cyrus_http_lock_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_mkcalendar_total The total number of HTTP MKCALENDARs
label cyrus_http_mkcalendar_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_mkcol_total The total number of HTTP MKCOLs
label cyrus_http_mkcol_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_move_total The total number of HTTP MOVEs
label cyrus_http_move_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_options_total The total number of HTTP OPTIONSs
label cyrus_http_options_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_patch_total The total number of HTTP PATCHs
label cyrus_http_patch_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_post_total The total number of HTTP POSTs
label cyrus_http_post_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_propfind_total The total number of HTTP PROPFINDs
label cyrus_http_propfind_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_proppatch_total The total number of HTTP PROPPATCHs
label cyrus_http_proppatch_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_put_total The total number of HTTP PUTs
label cyrus_http_put_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_report_total The total number of HTTP REPORTs
label cyrus_http_report_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_trace_total The total number of HTTP TRACEs
label cyrus_http_trace_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_unbind_total The total number of HTTP UNBINDs
label cyrus_http_unbind_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive
metric counter cyrus_http_unlock_total The total number of HTTP UNLOCKs
label cyrus_http_unlock_total namespace default admin applepush calendar freebusy addressbook principal notify dblookup ischedule domainkeys jmap prometheus rss tzdist drive

0 comments on commit 5824c0b

Please sign in to comment.