Skip to content

Commit

Permalink
minor beatification of log messages (netdata#19135)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsaou authored Dec 5, 2024
1 parent 580a36d commit 3ad2f6b
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 49 deletions.
8 changes: 4 additions & 4 deletions src/ml/ml.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1140,8 +1140,8 @@ static enum ml_worker_result ml_worker_create_new_model(ml_worker_t *worker, ml_
AcquiredDimension AcqDim(req.DLI);

if (!AcqDim.acquired()) {
netdata_log_error("Failed to create new model: could not acquire dimension (machine-guid: %s, dimension: '%s.%s')",
req.DLI.machineGuid(), req.DLI.chartId(), req.DLI.dimensionId());
netdata_log_error("Failed to create new model: could not acquire dimension (machine-guid: %s, dimension: '%s.%s', reason: %s)",
req.DLI.machineGuid(), req.DLI.chartId(), req.DLI.dimensionId(), AcqDim.acquire_failure());
return ML_WORKER_RESULT_NULL_ACQUIRED_DIMENSION;
}

Expand All @@ -1156,8 +1156,8 @@ static enum ml_worker_result ml_worker_add_existing_model(ml_worker_t *worker, m
AcquiredDimension AcqDim(req.DLI);

if (!AcqDim.acquired()) {
netdata_log_error("Failed to add existing model: could not acquire dimension (machine-guid: %s, dimension: '%s.%s')",
req.DLI.machineGuid(), req.DLI.chartId(), req.DLI.dimensionId());
netdata_log_error("Failed to add existing model: could not acquire dimension (machine-guid: %s, dimension: '%s.%s', reason: %s)",
req.DLI.machineGuid(), req.DLI.chartId(), req.DLI.dimensionId(), AcqDim.acquire_failure());
return ML_WORKER_RESULT_NULL_ACQUIRED_DIMENSION;
}

Expand Down
14 changes: 11 additions & 3 deletions src/plugins.d/pluginsd_internals.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,22 @@ ssize_t send_to_plugin(const char *txt, PARSER *parser) {
spinlock_lock(&parser->writer.spinlock);

ND_SOCK tmp = { .fd = parser->fd_output, };
const char *destination = "child";
ND_SOCK *s = parser->sock; // try the socket
if(!s) s = &tmp; // socket is not there, use the pipe
if(!s) {
destination = "plugin";
s = &tmp; // socket is not there, use the pipe
}

if(s->fd != -1) {
// plugins pipe or socket (with or without SSL)

size_t total = strlen(txt);
ssize_t bytes = nd_sock_write_persist(s, txt, total, 100);
if(bytes < (ssize_t)total) {
netdata_log_error("PLUGINSD: cannot send command (fd = %d, bytes = %zd out of %zu)", s->fd, bytes, total);
nd_log(NDLS_DAEMON, NDLP_WARNING,
"PLUGINSD: cannot send command to %s (fd = %d, sent bytes = %zd out of %zu)",
destination, s->fd, bytes, total);
spinlock_unlock(&parser->writer.spinlock);
return -3;
}
Expand All @@ -33,7 +39,9 @@ ssize_t send_to_plugin(const char *txt, PARSER *parser) {
}

spinlock_unlock(&parser->writer.spinlock);
netdata_log_error("PLUGINSD: cannot send command (no output socket/pipe/file given to plugins.d parser)");
nd_log(NDLS_DAEMON, NDLP_WARNING,
"PLUGINSD: cannot send command to %s (probably the receiver got disconnected, since no output descriptor is available)",
destination);
return -4;
}

Expand Down
8 changes: 6 additions & 2 deletions src/streaming/protocol/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,17 @@ RRDSET_STREAM_BUFFER stream_send_metrics_init(RRDSET *st, time_t wall_clock_time

if(unlikely(!(host_flags & RRDHOST_FLAG_STREAM_SENDER_LOGGED_STATUS))) {
rrdhost_flag_set(host, RRDHOST_FLAG_STREAM_SENDER_LOGGED_STATUS);
nd_log_daemon(NDLP_NOTICE, "STREAM %s [send]: not ready - collected metrics are not sent to parent.", rrdhost_hostname(host));
nd_log(NDLS_DAEMON, NDLP_INFO,
"STREAM SEND %s: connected but streaming is not ready yet...",
rrdhost_hostname(host));
}

return (RRDSET_STREAM_BUFFER) { .wb = NULL, };
}
else if(unlikely(host_flags & RRDHOST_FLAG_STREAM_SENDER_LOGGED_STATUS)) {
nd_log_daemon(NDLP_INFO, "STREAM %s [send]: sending metrics to parent...", rrdhost_hostname(host));
nd_log(NDLS_DAEMON, NDLP_INFO,
"STREAM SEND %s: streaming is ready, sending metrics to parent...",
rrdhost_hostname(host));
rrdhost_flag_clear(host, RRDHOST_FLAG_STREAM_SENDER_LOGGED_STATUS);
}

Expand Down
2 changes: 1 addition & 1 deletion src/streaming/stream-handshake.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ static struct {
{STREAM_HANDSHAKE_DISCONNECT_NOT_SUFFICIENT_SENDER_SEND_BUFFER, "DISCONNECTED NOT SUFFICIENT SEND BUFFER"},
{STREAM_HANDSHAKE_DISCONNECT_SOCKET_EOF, "DISCONNECTED SOCKET EOF"},
{STREAM_HANDSHAKE_DISCONNECT_SOCKET_READ_FAILED, "DISCONNECTED SOCKET READ FAILED"},
{STREAM_HANDSHAKE_DISCONNECT_SOCKET_READ_TIMEOUT, "DISCONNECTED SOCKET READ TIMEOUT"},
{STREAM_HANDSHAKE_DISCONNECT_SOCKET_TIMEOUT, "DISCONNECTED SOCKET TIMEOUT"},
{STREAM_HANDSHAKE_DISCONNECT_SOCKET_ERROR, "DISCONNECT SOCKET ERROR"},
{STREAM_HANDSHAKE_DISCONNECT_SOCKET_WRITE_FAILED, "DISCONNECTED SOCKET WRITE FAILED"},
{STREAM_HANDSHAKE_DISCONNECT_SOCKET_CLOSED_BY_PARENT, "DISCONNECTED SOCKET CLOSED BY PARENT"},
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/stream-handshake.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef enum {
STREAM_HANDSHAKE_DISCONNECT_NOT_SUFFICIENT_SENDER_SEND_BUFFER = -25,
STREAM_HANDSHAKE_DISCONNECT_SOCKET_EOF = -26,
STREAM_HANDSHAKE_DISCONNECT_SOCKET_READ_FAILED = -27,
STREAM_HANDSHAKE_DISCONNECT_SOCKET_READ_TIMEOUT = -28,
STREAM_HANDSHAKE_DISCONNECT_SOCKET_TIMEOUT = -28,
STREAM_HANDSHAKE_DISCONNECT_SOCKET_ERROR = -29,
STREAM_HANDSHAKE_DISCONNECT_SOCKET_WRITE_FAILED = -30,
STREAM_HANDSHAKE_DISCONNECT_SOCKET_CLOSED_BY_PARENT = -31,
Expand Down
86 changes: 58 additions & 28 deletions src/streaming/stream-receiver-connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ void stream_receiver_log_status(struct receiver_state *rpt, const char *msg, con
, (rpt->machine_guid && *rpt->machine_guid) ? rpt->machine_guid : ""
, msg);

nd_log(NDLS_DAEMON, priority, "STREAM_RECEIVER for '%s': %s %s%s%s"
nd_log(NDLS_DAEMON, priority, "STREAM RECEIVE '%s': %s %s%s%s"
, (rpt->hostname && *rpt->hostname) ? rpt->hostname : ""
, msg
, rpt->exit.reason != STREAM_HANDSHAKE_NEVER?" (":""
, stream_handshake_error_to_string(rpt->exit.reason)
, rpt->exit.reason != STREAM_HANDSHAKE_NEVER?")":""
, rpt->exit.reason != STREAM_HANDSHAKE_NEVER?")":""
);
}

Expand Down Expand Up @@ -139,16 +139,17 @@ static bool stream_receiver_send_first_response(struct receiver_state *rpt) {
stream_receiver_log_status(
rpt,
"failed to find/create host structure, rejecting connection",
STREAM_STATUS_INTERNAL_SERVER_ERROR,
NDLP_ERR);
STREAM_STATUS_INTERNAL_SERVER_ERROR, NDLP_ERR);

stream_send_error_on_taken_over_connection(rpt, START_STREAMING_ERROR_INTERNAL_ERROR);
return false;
}

if (unlikely(rrdhost_flag_check(host, RRDHOST_FLAG_PENDING_CONTEXT_LOAD))) {
stream_receiver_log_status(
rpt, "host is initializing, retry later", STREAM_STATUS_INITIALIZATION_IN_PROGRESS, NDLP_NOTICE);
rpt,
"host is initializing, retry later",
STREAM_STATUS_INITIALIZATION_IN_PROGRESS, NDLP_NOTICE);

stream_send_error_on_taken_over_connection(rpt, START_STREAMING_ERROR_INITIALIZATION);
return false;
Expand All @@ -159,7 +160,9 @@ static bool stream_receiver_send_first_response(struct receiver_state *rpt) {

if(!rrdhost_set_receiver(host, rpt)) {
stream_receiver_log_status(
rpt, "host is already served by another receiver", STREAM_STATUS_DUPLICATE_RECEIVER, NDLP_INFO);
rpt,
"host is already served by another receiver",
STREAM_STATUS_DUPLICATE_RECEIVER, NDLP_INFO);

stream_send_error_on_taken_over_connection(rpt, START_STREAMING_ERROR_ALREADY_STREAMING);
return false;
Expand Down Expand Up @@ -215,15 +218,15 @@ static bool stream_receiver_send_first_response(struct receiver_state *rpt) {
// remove the non-blocking flag from the socket
if(sock_delnonblock(rpt->sock.fd) < 0)
nd_log(NDLS_DAEMON, NDLP_ERR,
"STREAM '%s' [receive from [%s]:%s]: cannot remove the non-blocking flag from socket %d",
"STREAM RECEIVE '%s' [from [%s]:%s]: cannot remove the non-blocking flag from socket %d",
rrdhost_hostname(rpt->host), rpt->client_ip, rpt->client_port, rpt->sock.fd);

struct timeval timeout;
timeout.tv_sec = 600;
timeout.tv_usec = 0;
if (unlikely(setsockopt(rpt->sock.fd, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout) != 0))
nd_log(NDLS_DAEMON, NDLP_ERR,
"STREAM '%s' [receive from [%s]:%s]: cannot set timeout for socket %d",
"STREAM RECEIVE '%s' [from [%s]:%s]: cannot set timeout for socket %d",
rrdhost_hostname(rpt->host), rpt->client_ip, rpt->client_port, rpt->sock.fd);
}

Expand All @@ -238,7 +241,9 @@ static bool stream_receiver_send_first_response(struct receiver_state *rpt) {
if(bytes_sent != (ssize_t)strlen(initial_response)) {
internal_error(true, "Cannot send response, got %zd bytes, expecting %zu bytes", bytes_sent, strlen(initial_response));
stream_receiver_log_status(
rpt, "cannot reply back, dropping connection", STREAM_STATUS_CANT_REPLY, NDLP_ERR);
rpt,
"cannot reply back, dropping connection",
STREAM_STATUS_CANT_REPLY, NDLP_ERR);
rrdhost_clear_receiver(rpt);
return false;
}
Expand Down Expand Up @@ -354,7 +359,7 @@ int stream_receiver_accept_connection(struct web_client *w, char *decoded_query_
rpt->capabilities = convert_stream_version_to_capabilities(1, NULL, false);

if (unlikely(rrdhost_set_system_info_variable(rpt->system_info, name, value))) {
nd_log_daemon(NDLP_NOTICE, "STREAM '%s' [receive from [%s]:%s]: "
nd_log_daemon(NDLP_NOTICE, "STREAM RECEIVE '%s' [from [%s]:%s]: "
"request has parameter '%s' = '%s', which is not used."
, (rpt->hostname && *rpt->hostname) ? rpt->hostname : "-"
, rpt->client_ip, rpt->client_port
Expand Down Expand Up @@ -383,15 +388,19 @@ int stream_receiver_accept_connection(struct web_client *w, char *decoded_query_

if(!rpt->key || !*rpt->key) {
stream_receiver_log_status(
rpt, "request without an API key, rejecting connection", STREAM_STATUS_NO_API_KEY, NDLP_WARNING);
rpt,
"request without an API key, rejecting connection",
STREAM_STATUS_NO_API_KEY, NDLP_WARNING);

stream_receiver_free(rpt);
return stream_receiver_response_permission_denied(w);
}

if(!rpt->hostname || !*rpt->hostname) {
stream_receiver_log_status(
rpt, "request without a hostname, rejecting connection", STREAM_STATUS_NO_HOSTNAME, NDLP_WARNING);
rpt,
"request without a hostname, rejecting connection",
STREAM_STATUS_NO_HOSTNAME, NDLP_WARNING);

stream_receiver_free(rpt);
return stream_receiver_response_permission_denied(w);
Expand All @@ -402,7 +411,9 @@ int stream_receiver_accept_connection(struct web_client *w, char *decoded_query_

if(!rpt->machine_guid || !*rpt->machine_guid) {
stream_receiver_log_status(
rpt, "request without a machine GUID, rejecting connection", STREAM_STATUS_NO_MACHINE_GUID, NDLP_WARNING);
rpt,
"request without a machine GUID, rejecting connection",
STREAM_STATUS_NO_MACHINE_GUID, NDLP_WARNING);

stream_receiver_free(rpt);
return stream_receiver_response_permission_denied(w);
Expand All @@ -415,24 +426,28 @@ int stream_receiver_accept_connection(struct web_client *w, char *decoded_query_
stream_receiver_log_status(
rpt,
"API key is not a valid UUID (use the command uuidgen to generate one)",
STREAM_STATUS_INVALID_API_KEY,
NDLP_WARNING);
STREAM_STATUS_INVALID_API_KEY, NDLP_WARNING);

stream_receiver_free(rpt);
return stream_receiver_response_permission_denied(w);
}

if (regenerate_guid(rpt->machine_guid, buf) == -1) {
stream_receiver_log_status(
rpt, "machine GUID is not a valid UUID", STREAM_STATUS_INVALID_MACHINE_GUID, NDLP_WARNING);
rpt,
"machine GUID is not a valid UUID",
STREAM_STATUS_INVALID_MACHINE_GUID, NDLP_WARNING);

stream_receiver_free(rpt);
return stream_receiver_response_permission_denied(w);
}
}

if(!stream_conf_is_key_type(rpt->key, "api")) {
stream_receiver_log_status(rpt, "API key is a machine GUID", STREAM_STATUS_INVALID_API_KEY, NDLP_WARNING);
stream_receiver_log_status(
rpt,
"API key is a machine GUID",
STREAM_STATUS_INVALID_API_KEY, NDLP_WARNING);

stream_receiver_free(rpt);
return stream_receiver_response_permission_denied(w);
Expand All @@ -441,23 +456,30 @@ int stream_receiver_accept_connection(struct web_client *w, char *decoded_query_
// the default for api keys is false, so that users
// have to enable them manually
if(!stream_conf_api_key_is_enabled(rpt->key, false)) {
stream_receiver_log_status(rpt, "API key is not enabled", STREAM_STATUS_API_KEY_DISABLED, NDLP_WARNING);
stream_receiver_log_status(
rpt,
"API key is not enabled",
STREAM_STATUS_API_KEY_DISABLED, NDLP_WARNING);

stream_receiver_free(rpt);
return stream_receiver_response_permission_denied(w);
}

if(!stream_conf_api_key_allows_client(rpt->key, w->client_ip)) {
stream_receiver_log_status(
rpt, "API key is not allowed from this IP", STREAM_STATUS_NOT_ALLOWED_IP, NDLP_WARNING);
rpt,
"API key is not allowed from this IP",
STREAM_STATUS_NOT_ALLOWED_IP, NDLP_WARNING);

stream_receiver_free(rpt);
return stream_receiver_response_permission_denied(w);
}

if (!stream_conf_is_key_type(rpt->machine_guid, "machine")) {
stream_receiver_log_status(
rpt, "machine GUID is an API key", STREAM_STATUS_INVALID_MACHINE_GUID, NDLP_WARNING);
rpt,
"machine GUID is an API key",
STREAM_STATUS_INVALID_MACHINE_GUID, NDLP_WARNING);

stream_receiver_free(rpt);
return stream_receiver_response_permission_denied(w);
Expand All @@ -467,15 +489,19 @@ int stream_receiver_accept_connection(struct web_client *w, char *decoded_query_
// have to enable them manually
if(!stream_conf_api_key_is_enabled(rpt->machine_guid, true)) {
stream_receiver_log_status(
rpt, "machine GUID is not enabled", STREAM_STATUS_MACHINE_GUID_DISABLED, NDLP_WARNING);
rpt,
"machine GUID is not enabled",
STREAM_STATUS_MACHINE_GUID_DISABLED, NDLP_WARNING);

stream_receiver_free(rpt);
return stream_receiver_response_permission_denied(w);
}

if(!stream_conf_api_key_allows_client(rpt->machine_guid, w->client_ip)) {
stream_receiver_log_status(
rpt, "machine GUID is not allowed from this IP", STREAM_STATUS_NOT_ALLOWED_IP, NDLP_WARNING);
rpt,
"machine GUID is not allowed from this IP",
STREAM_STATUS_NOT_ALLOWED_IP, NDLP_WARNING);

stream_receiver_free(rpt);
return stream_receiver_response_permission_denied(w);
Expand All @@ -484,18 +510,19 @@ int stream_receiver_accept_connection(struct web_client *w, char *decoded_query_
if (strcmp(rpt->machine_guid, localhost->machine_guid) == 0) {
stream_receiver_takeover_web_connection(w, rpt);

stream_receiver_log_status(rpt, "machine GUID is my own", STREAM_STATUS_LOCALHOST, NDLP_DEBUG);
stream_receiver_log_status(
rpt,
"machine GUID is my own",
STREAM_STATUS_LOCALHOST, NDLP_DEBUG);

char initial_response[HTTP_HEADER_SIZE + 1];
snprintfz(initial_response, HTTP_HEADER_SIZE, "%s", START_STREAMING_ERROR_SAME_LOCALHOST);

if(nd_sock_send_timeout(&rpt->sock, initial_response, strlen(initial_response), 0, 60) !=
(ssize_t)strlen(initial_response)) {

nd_log_daemon(NDLP_ERR, "STREAM '%s' [receive from [%s]:%s]: "
"failed to reply."
, rpt->hostname
, rpt->client_ip, rpt->client_port
nd_log_daemon(NDLP_ERR, "STREAM RECEIVE '%s' [from [%s]:%s]: failed to reply.",
rpt->hostname, rpt->client_ip, rpt->client_port
);
}

Expand Down Expand Up @@ -608,7 +635,10 @@ int stream_receiver_accept_connection(struct web_client *w, char *decoded_query_
if(stream_receiver_send_first_response(rpt)) {
// we are the receiver of the node

stream_receiver_log_status(rpt, "connected and ready to receive data", STREAM_STATUS_CONNECTED, NDLP_INFO);
stream_receiver_log_status(
rpt,
"connected and ready to receive data",
STREAM_STATUS_CONNECTED, NDLP_INFO);

// in case we have cloud connection we inform cloud a new child connected
schedule_node_state_update(rpt->host, 300);
Expand Down
Loading

0 comments on commit 3ad2f6b

Please sign in to comment.