mirror of https://github.com/yandex/odyssey.git
show errors per route
This commit is contained in:
parent
20e97cae09
commit
57a9e84150
|
@ -75,9 +75,39 @@ database default {
|
|||
log_debug no
|
||||
|
||||
quantiles "0.99,0.95,0.5"
|
||||
client_max 107
|
||||
}
|
||||
}
|
||||
|
||||
database "postgres" {
|
||||
user "user1" {
|
||||
authentication "none"
|
||||
|
||||
storage "postgres_server"
|
||||
pool "transaction"
|
||||
pool_size 0
|
||||
|
||||
pool_timeout 0
|
||||
|
||||
pool_ttl 60
|
||||
|
||||
pool_discard no
|
||||
|
||||
pool_cancel yes
|
||||
|
||||
pool_rollback yes
|
||||
|
||||
client_fwd_error yes
|
||||
|
||||
application_name_add_host yes
|
||||
|
||||
server_lifetime 3600
|
||||
log_debug no
|
||||
|
||||
quantiles "0.99,0.95,0.5"
|
||||
client_max 107
|
||||
}
|
||||
}
|
||||
storage "local" {
|
||||
type "local"
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ enum
|
|||
OD_LDATABASES,
|
||||
OD_LMODULE,
|
||||
OD_LERRORS,
|
||||
OD_LERRORS_PER_ROUTE,
|
||||
OD_LFRONTEND,
|
||||
OD_LROUTER,
|
||||
OD_LVERSION,
|
||||
|
@ -56,6 +57,7 @@ static od_keyword_t od_console_keywords[] = {
|
|||
od_keyword("create", OD_LCREATE),
|
||||
od_keyword("module", OD_LMODULE),
|
||||
od_keyword("errors", OD_LERRORS),
|
||||
od_keyword("errors_per_route", OD_LERRORS_PER_ROUTE),
|
||||
od_keyword("frontend", OD_LFRONTEND),
|
||||
od_keyword("router", OD_LROUTER),
|
||||
od_keyword("drop", OD_LDROP),
|
||||
|
@ -170,18 +172,8 @@ od_console_show_frontend_stats_err_add(machine_msg_t *stream,
|
|||
if (msg == NULL)
|
||||
return NOT_OK_RESPONSE;
|
||||
|
||||
od_list_t *it = NULL;
|
||||
size_t total_count = od_err_logger_get_aggr_errors_count(
|
||||
route_pool->err_logger_general, od_frontend_status_errs[i]);
|
||||
|
||||
od_list_foreach(&route_pool->list, it)
|
||||
{
|
||||
od_route_t *route = od_container_of(it, od_route_t, link);
|
||||
if (route && route->extra_logging_enabled) {
|
||||
total_count += od_err_logger_get_aggr_errors_count(
|
||||
route->frontend_err_logger, od_frontend_status_errs[i]);
|
||||
}
|
||||
}
|
||||
route_pool->err_logger, od_frontend_status_errs[i]);
|
||||
|
||||
char *err_type = od_frontend_status_to_str(od_frontend_status_errs[i]);
|
||||
|
||||
|
@ -341,6 +333,140 @@ od_console_show_errors(od_client_t *client, machine_msg_t *stream)
|
|||
return rc;
|
||||
}
|
||||
|
||||
static inline int
|
||||
od_console_show_errors_per_route_cb(od_route_t *route, void **argv)
|
||||
{
|
||||
machine_msg_t *stream = argv[0];
|
||||
assert(stream);
|
||||
|
||||
if (!route || !route->extra_logging_enabled || od_route_is_dynamic(route)) {
|
||||
return OK_RESPONSE;
|
||||
}
|
||||
for (size_t i = 0; i < OD_FRONTEND_STATUS_ERRORS_TYPES_COUNT; ++i) {
|
||||
int offset;
|
||||
int rc;
|
||||
machine_msg_t *msg;
|
||||
msg = kiwi_be_write_data_row(stream, &offset);
|
||||
if (msg == NULL)
|
||||
return NOT_OK_RESPONSE;
|
||||
|
||||
size_t total_count = od_err_logger_get_aggr_errors_count(
|
||||
route->err_logger, od_frontend_status_errs[i]);
|
||||
|
||||
char *err_type = od_frontend_status_to_str(od_frontend_status_errs[i]);
|
||||
|
||||
rc = kiwi_be_write_data_row_add(
|
||||
stream, offset, err_type, strlen(err_type));
|
||||
if (rc != OK_RESPONSE) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* route user */
|
||||
|
||||
rc = kiwi_be_write_data_row_add(stream,
|
||||
offset,
|
||||
route->rule->user_name,
|
||||
strlen(route->rule->user_name));
|
||||
if (rc != OK_RESPONSE) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* route database */
|
||||
|
||||
rc = kiwi_be_write_data_row_add(
|
||||
stream, offset, route->rule->db_name, strlen(route->rule->db_name));
|
||||
if (rc != OK_RESPONSE) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* error_type */
|
||||
|
||||
char data[64];
|
||||
int data_len;
|
||||
data_len = od_snprintf(data, sizeof(data), "%" PRIu64, total_count);
|
||||
|
||||
rc = kiwi_be_write_data_row_add(stream, offset, data, data_len);
|
||||
if (rc != OK_RESPONSE) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < OD_ROUTER_ROUTE_STATUS_ERRORS_TYPES_COUNT; ++i) {
|
||||
int offset;
|
||||
int rc;
|
||||
machine_msg_t *msg;
|
||||
msg = kiwi_be_write_data_row(stream, &offset);
|
||||
if (msg == NULL)
|
||||
return NOT_OK_RESPONSE;
|
||||
|
||||
size_t total_count = od_err_logger_get_aggr_errors_count(
|
||||
route->err_logger, od_router_route_status_errs[i]);
|
||||
|
||||
char *err_type =
|
||||
od_router_status_to_str(od_router_route_status_errs[i]);
|
||||
|
||||
rc = kiwi_be_write_data_row_add(
|
||||
stream, offset, err_type, strlen(err_type));
|
||||
if (rc != OK_RESPONSE) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* route user */
|
||||
|
||||
rc = kiwi_be_write_data_row_add(stream,
|
||||
offset,
|
||||
route->rule->user_name,
|
||||
strlen(route->rule->user_name));
|
||||
if (rc != OK_RESPONSE) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* route database */
|
||||
|
||||
rc = kiwi_be_write_data_row_add(
|
||||
stream, offset, route->rule->db_name, strlen(route->rule->db_name));
|
||||
if (rc != OK_RESPONSE) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
/* error_type */
|
||||
|
||||
char data[64];
|
||||
int data_len;
|
||||
data_len = od_snprintf(data, sizeof(data), "%" PRIu64, total_count);
|
||||
|
||||
rc = kiwi_be_write_data_row_add(stream, offset, data, data_len);
|
||||
if (rc != OK_RESPONSE) {
|
||||
return rc;
|
||||
}
|
||||
}
|
||||
|
||||
return OK_RESPONSE;
|
||||
}
|
||||
|
||||
static inline od_retcode_t
|
||||
od_console_show_errors_per_route(od_client_t *client, machine_msg_t *stream)
|
||||
{
|
||||
|
||||
assert(stream);
|
||||
od_router_t *router = client->global->router;
|
||||
|
||||
void *argv[] = { stream };
|
||||
|
||||
machine_msg_t *msg;
|
||||
msg = kiwi_be_write_row_descriptionf(
|
||||
stream, "sssl", "error_type", "user", "database", "count");
|
||||
|
||||
if (msg == NULL) {
|
||||
return NOT_OK_RESPONSE;
|
||||
}
|
||||
|
||||
od_router_foreach(router, od_console_show_errors_per_route_cb, argv);
|
||||
|
||||
od_retcode_t rc = kiwi_be_write_complete(stream, "SHOW", 5);
|
||||
return rc;
|
||||
}
|
||||
|
||||
static inline int
|
||||
od_console_show_version(machine_msg_t *stream)
|
||||
{
|
||||
|
@ -1244,6 +1370,8 @@ od_console_show(od_client_t *client, machine_msg_t *stream, od_parser_t *parser)
|
|||
return od_console_show_lists(client, stream);
|
||||
case OD_LERRORS:
|
||||
return od_console_show_errors(client, stream);
|
||||
case OD_LERRORS_PER_ROUTE:
|
||||
return od_console_show_errors_per_route(client, stream);
|
||||
case OD_LVERSION:
|
||||
return od_console_show_version(stream);
|
||||
}
|
||||
|
|
|
@ -217,11 +217,11 @@ od_cron_err_stat(od_cron_t *cron)
|
|||
{
|
||||
od_route_t *current_route = od_container_of(it, od_route_t, link);
|
||||
if (current_route->extra_logging_enabled) {
|
||||
od_err_logger_inc_interval(current_route->frontend_err_logger);
|
||||
od_err_logger_inc_interval(current_route->err_logger);
|
||||
}
|
||||
}
|
||||
|
||||
od_err_logger_inc_interval(router->route_pool.err_logger_general);
|
||||
od_err_logger_inc_interval(router->route_pool.err_logger);
|
||||
od_err_logger_inc_interval(router->router_err_logger);
|
||||
}
|
||||
|
||||
|
|
|
@ -1289,7 +1289,7 @@ od_frontend(void *arg)
|
|||
/* setup client and run main loop */
|
||||
od_route_t *route = client->route;
|
||||
od_error_logger_t *l;
|
||||
l = router->route_pool.err_logger_general;
|
||||
l = router->route_pool.err_logger;
|
||||
|
||||
od_frontend_status_t status;
|
||||
status = OD_UNDEF;
|
||||
|
@ -1298,6 +1298,11 @@ od_frontend(void *arg)
|
|||
status = od_frontend_local_setup(client);
|
||||
if (od_frontend_status_is_err(status)) {
|
||||
od_error_logger_store_err(l, status);
|
||||
|
||||
if (route->extra_logging_enabled &&
|
||||
!od_route_is_dynamic(route)) {
|
||||
od_error_logger_store_err(route->err_logger, status);
|
||||
}
|
||||
}
|
||||
if (status != OD_OK)
|
||||
break;
|
||||
|
@ -1305,6 +1310,11 @@ od_frontend(void *arg)
|
|||
status = od_frontend_local(client);
|
||||
if (od_frontend_status_is_err(status)) {
|
||||
od_error_logger_store_err(l, status);
|
||||
|
||||
if (route->extra_logging_enabled &&
|
||||
!od_route_is_dynamic(route)) {
|
||||
od_error_logger_store_err(route->err_logger, status);
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -1312,6 +1322,11 @@ od_frontend(void *arg)
|
|||
status = od_frontend_setup(client);
|
||||
if (od_frontend_status_is_err(status)) {
|
||||
od_error_logger_store_err(l, status);
|
||||
|
||||
if (route->extra_logging_enabled &&
|
||||
!od_route_is_dynamic(route)) {
|
||||
od_error_logger_store_err(route->err_logger, status);
|
||||
}
|
||||
}
|
||||
if (status != OD_OK)
|
||||
break;
|
||||
|
@ -1319,6 +1334,11 @@ od_frontend(void *arg)
|
|||
status = od_frontend_remote(client);
|
||||
if (od_frontend_status_is_err(status)) {
|
||||
od_error_logger_store_err(l, status);
|
||||
|
||||
if (route->extra_logging_enabled &&
|
||||
!od_route_is_dynamic(route)) {
|
||||
od_error_logger_store_err(route->err_logger, status);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
|
|
|
@ -27,7 +27,7 @@ struct od_route
|
|||
machine_channel_t *wait_bus;
|
||||
pthread_mutex_t lock;
|
||||
|
||||
od_error_logger_t *frontend_err_logger;
|
||||
od_error_logger_t *err_logger;
|
||||
bool extra_logging_enabled;
|
||||
|
||||
od_list_t link;
|
||||
|
@ -45,10 +45,10 @@ od_route_init(od_route_t *route, bool extra_route_logging)
|
|||
route->stats_mark_db = false;
|
||||
route->extra_logging_enabled = extra_route_logging;
|
||||
if (extra_route_logging) {
|
||||
/* error logging */;
|
||||
route->frontend_err_logger = od_err_logger_create_default();
|
||||
/* error logging */
|
||||
route->err_logger = od_err_logger_create_default();
|
||||
} else {
|
||||
route->frontend_err_logger = NULL;
|
||||
route->err_logger = NULL;
|
||||
}
|
||||
|
||||
od_stat_init(&route->stats);
|
||||
|
@ -75,7 +75,7 @@ od_route_free(od_route_t *route)
|
|||
}
|
||||
|
||||
if (route->extra_logging_enabled) {
|
||||
od_err_logger_free(route->frontend_err_logger);
|
||||
od_err_logger_free(route->err_logger);
|
||||
}
|
||||
|
||||
pthread_mutex_destroy(&route->lock);
|
||||
|
@ -88,7 +88,7 @@ od_route_allocate(int is_shared)
|
|||
od_route_t *route = malloc(sizeof(*route));
|
||||
if (route == NULL)
|
||||
return NULL;
|
||||
od_route_init(route, false);
|
||||
od_route_init(route, true);
|
||||
route->wait_bus = machine_channel_create(is_shared);
|
||||
if (route->wait_bus == NULL) {
|
||||
od_route_free(route);
|
||||
|
|
|
@ -31,7 +31,7 @@ struct od_route_pool
|
|||
/* used for counting error for client without concrete route
|
||||
* like default_db.usr1, db1.default, etc
|
||||
* */
|
||||
od_error_logger_t *err_logger_general;
|
||||
od_error_logger_t *err_logger;
|
||||
int count;
|
||||
};
|
||||
|
||||
|
@ -42,8 +42,8 @@ static inline void
|
|||
od_route_pool_init(od_route_pool_t *pool)
|
||||
{
|
||||
od_list_init(&pool->list);
|
||||
pool->err_logger_general = od_err_logger_create_default();
|
||||
pool->count = 0;
|
||||
pool->err_logger = od_err_logger_create_default();
|
||||
pool->count = 0;
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
|
@ -40,7 +40,7 @@ od_router_free(od_router_t *router)
|
|||
od_rules_free(&router->rules);
|
||||
pthread_mutex_destroy(&router->lock);
|
||||
od_err_logger_free(router->router_err_logger);
|
||||
od_err_logger_free(router->route_pool.err_logger_general);
|
||||
od_err_logger_free(router->route_pool.err_logger);
|
||||
}
|
||||
|
||||
inline int
|
||||
|
@ -297,7 +297,11 @@ od_router_route(od_router_t *router, od_config_t *config, od_client_t *client)
|
|||
*/
|
||||
client->rule = rule;
|
||||
|
||||
return OD_ROUTER_ERROR_LIMIT_ROUTE;
|
||||
od_router_status_t ret = OD_ROUTER_ERROR_LIMIT_ROUTE;
|
||||
if (route->extra_logging_enabled) {
|
||||
od_error_logger_store_err(route->err_logger, ret);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
od_router_unlock(router);
|
||||
|
||||
|
|
|
@ -133,6 +133,14 @@ static const od_router_status_t od_router_status_errs[] = {
|
|||
#define OD_ROUTER_STATUS_ERRORS_TYPES_COUNT \
|
||||
sizeof(od_router_status_errs) / sizeof(od_router_status_errs[0])
|
||||
|
||||
/* errors that could be counted per route */
|
||||
static const od_router_status_t od_router_route_status_errs[] = {
|
||||
OD_ROUTER_ERROR_LIMIT_ROUTE,
|
||||
};
|
||||
|
||||
#define OD_ROUTER_ROUTE_STATUS_ERRORS_TYPES_COUNT \
|
||||
sizeof(od_router_route_status_errs) / sizeof(od_router_route_status_errs[0])
|
||||
|
||||
static inline bool
|
||||
od_router_status_is_err(od_router_status_t status)
|
||||
{
|
||||
|
|
Binary file not shown.
|
@ -1,12 +1,12 @@
|
|||
#!/bin/bash
|
||||
kill -9 $(ps aux | grep odyssey | awk '{print $2}')
|
||||
#kill -9 $(ps aux | grep odyssey | awk '{print $2}')
|
||||
sleep 1
|
||||
|
||||
ody-start
|
||||
#ody-start
|
||||
|
||||
for i in `seq 1 10`
|
||||
do
|
||||
sleep 1
|
||||
sleep 0.1
|
||||
psql -h localhost -p 6432 -c 'select 1' &
|
||||
psql -h 0.0.0.0 -p 6432 -c 'select pg_sleep(1)' &
|
||||
psql -h localhost -p 6432 -c 'select 1' &
|
||||
|
@ -17,7 +17,7 @@ do
|
|||
psql -h 0.0.0.0 -p 6432 -c 'select pg_sleep(1)' &
|
||||
psql -h localhost -p 6432 -c 'select 1' &
|
||||
|
||||
ody-restart
|
||||
#ody-restart
|
||||
ps uax | grep odys
|
||||
|
||||
psql -h localhost -p 6432 -c 'select 1' &
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
#kill -9 $(ps aux | grep odyssey | awk '{print $2}')
|
||||
sleep 1
|
||||
|
||||
#ody-start
|
||||
|
||||
for i in `seq 1 100`
|
||||
do
|
||||
psql -h localhost -p 6432 -c 'select 1' -U user1 -d postgres &
|
||||
psql -h 0.0.0.0 -p 6432 -c 'select pg_sleep(100)' -U user1 -d postgres &
|
||||
done
|
Loading…
Reference in New Issue