Skip to content

Commit

Permalink
aesthetic changes in the code (netdata#18808)
Browse files Browse the repository at this point in the history
  • Loading branch information
ktsaou authored Oct 17, 2024
1 parent eeb5551 commit a612572
Show file tree
Hide file tree
Showing 14 changed files with 39 additions and 39 deletions.
14 changes: 7 additions & 7 deletions src/collectors/systemd-journal.plugin/systemd-journal.c
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ static int netdata_systemd_journal_query(BUFFER *wb, LOGS_QUERY_STATUS *lqs) {
for(size_t f = 0; f < files_used ;f++)
dictionary_acquired_item_release(journal_files_registry, file_items[f]);

return rrd_call_function_error(wb, "not modified", HTTP_RESP_NOT_MODIFIED);
return rrd_call_function_error(wb, "No new data since the previous call.", HTTP_RESP_NOT_MODIFIED);
}

// sort the files, so that they are optimal for facets
Expand Down Expand Up @@ -911,27 +911,27 @@ static int netdata_systemd_journal_query(BUFFER *wb, LOGS_QUERY_STATUS *lqs) {
switch (status) {
case ND_SD_JOURNAL_OK:
if(lqs->rq.if_modified_since && !lqs->c.rows_useful)
return rrd_call_function_error(wb, "no useful logs, not modified", HTTP_RESP_NOT_MODIFIED);
return rrd_call_function_error(wb, "No additional useful data since the previous call.", HTTP_RESP_NOT_MODIFIED);
break;

case ND_SD_JOURNAL_TIMED_OUT:
case ND_SD_JOURNAL_NO_FILE_MATCHED:
break;

case ND_SD_JOURNAL_CANCELLED:
return rrd_call_function_error(wb, "client closed connection", HTTP_RESP_CLIENT_CLOSED_REQUEST);
return rrd_call_function_error(wb, "Request cancelled.", HTTP_RESP_CLIENT_CLOSED_REQUEST);

case ND_SD_JOURNAL_NOT_MODIFIED:
return rrd_call_function_error(wb, "not modified", HTTP_RESP_NOT_MODIFIED);
return rrd_call_function_error(wb, "No new data since the previous call.", HTTP_RESP_NOT_MODIFIED);

case ND_SD_JOURNAL_FAILED_TO_OPEN:
return rrd_call_function_error(wb, "failed to open journal", HTTP_RESP_INTERNAL_SERVER_ERROR);
return rrd_call_function_error(wb, "Failed to open systemd journal file.", HTTP_RESP_INTERNAL_SERVER_ERROR);

case ND_SD_JOURNAL_FAILED_TO_SEEK:
return rrd_call_function_error(wb, "failed to seek in journal", HTTP_RESP_INTERNAL_SERVER_ERROR);
return rrd_call_function_error(wb, "Failed to seek in systemd journal file.", HTTP_RESP_INTERNAL_SERVER_ERROR);

default:
return rrd_call_function_error(wb, "unknown status", HTTP_RESP_INTERNAL_SERVER_ERROR);
return rrd_call_function_error(wb, "Unknown status", HTTP_RESP_INTERNAL_SERVER_ERROR);
}

buffer_json_member_add_uint64(wb, "status", HTTP_RESP_OK);
Expand Down
2 changes: 1 addition & 1 deletion src/daemon/config/dyncfg-tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ static int dyncfg_config_execute_cb(struct rrd_function_execute *rfe, void *data

rrd_call_function_error(
rfe->result.wb,
"unknown config id given", code);
"Unknown config id given.", code);
}

cleanup:
Expand Down
8 changes: 4 additions & 4 deletions src/database/rrdfunctions-exporters.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ static void functions2json(DICTIONARY *functions, BUFFER *wb) {
struct rrd_host_function *t;
dfe_start_read(functions, t) {
if (!rrd_collector_running(t->collector)) continue;
if(t->options & (RRD_FUNCTION_DYNCFG|RRD_FUNCTION_HIDDEN)) continue;
if(t->options & (RRD_FUNCTION_DYNCFG| RRD_FUNCTION_RESTRICTED)) continue;

buffer_json_member_add_object(wb, t_dfe.name);
{
Expand Down Expand Up @@ -99,7 +99,7 @@ void host_functions2json(RRDHOST *host, BUFFER *wb) {
struct rrd_host_function *t;
dfe_start_read(host->functions, t) {
if(!rrd_collector_running(t->collector)) continue;
if(t->options & (RRD_FUNCTION_DYNCFG|RRD_FUNCTION_HIDDEN)) continue;
if(t->options & (RRD_FUNCTION_DYNCFG| RRD_FUNCTION_RESTRICTED)) continue;

buffer_json_member_add_object(wb, t_dfe.name);
{
Expand Down Expand Up @@ -130,7 +130,7 @@ void chart_functions_to_dict(DICTIONARY *rrdset_functions_view, DICTIONARY *dst,
struct rrd_host_function *t;
dfe_start_read(rrdset_functions_view, t) {
if(!rrd_collector_running(t->collector)) continue;
if(t->options & (RRD_FUNCTION_DYNCFG|RRD_FUNCTION_HIDDEN)) continue;
if(t->options & (RRD_FUNCTION_DYNCFG| RRD_FUNCTION_RESTRICTED)) continue;

dictionary_set(dst, t_dfe.name, value, value_size);
}
Expand All @@ -144,7 +144,7 @@ void host_functions_to_dict(RRDHOST *host, DICTIONARY *dst, void *value, size_t
struct rrd_host_function *t;
dfe_start_read(host->functions, t) {
if(!rrd_collector_running(t->collector)) continue;
if(t->options & (RRD_FUNCTION_DYNCFG|RRD_FUNCTION_HIDDEN)) continue;
if(t->options & (RRD_FUNCTION_DYNCFG| RRD_FUNCTION_RESTRICTED)) continue;

if(help)
*help = t->help;
Expand Down
14 changes: 7 additions & 7 deletions src/database/rrdfunctions-inflight.c
Original file line number Diff line number Diff line change
Expand Up @@ -351,15 +351,15 @@ static int rrd_call_function_async_and_wait(struct rrd_function_inflight *r) {
HTTP_RESP_CLIENT_CLOSED_REQUEST);
else
code = rrd_call_function_error(r->result.wb,
"Timeout while waiting for a response from the collector.",
"Timeout while waiting for a response from the plugin that serves this features",
HTTP_RESP_GATEWAY_TIMEOUT);

tmp->free_with_signal = true;
we_should_free = false;
}
else {
code = rrd_call_function_error(
r->result.wb, "Internal error while communicating with the collector",
r->result.wb, "Internal error while communicating with the plugin that serves this feature.",
HTTP_RESP_INTERNAL_SERVER_ERROR);

tmp->free_with_signal = true;
Expand Down Expand Up @@ -398,7 +398,7 @@ int rrd_function_run(RRDHOST *host, BUFFER *result_wb, int timeout_s,
rrd_function_result_callback_t result_cb, void *result_cb_data,
rrd_function_progress_cb_t progress_cb, void *progress_cb_data,
rrd_function_is_cancelled_cb_t is_cancelled_cb, void *is_cancelled_cb_data,
BUFFER *payload, const char *source, bool hidden) {
BUFFER *payload, const char *source, bool allow_restricted) {

int code;
char sanitized_cmd[PLUGINSD_LINE_MAX + 1];
Expand All @@ -412,7 +412,7 @@ int rrd_function_run(RRDHOST *host, BUFFER *result_wb, int timeout_s,
if(!host) {
code = HTTP_RESP_INTERNAL_SERVER_ERROR;

rrd_call_function_error(result_wb, "no host given for running the function", code);
rrd_call_function_error(result_wb, "No host given for routing this request to.", code);

if(result_cb)
result_cb(result_wb, code, result_cb_data);
Expand All @@ -436,9 +436,9 @@ int rrd_function_run(RRDHOST *host, BUFFER *result_wb, int timeout_s,

struct rrd_host_function *rdcf = dictionary_acquired_item_value(host_function_acquired);

if((rdcf->options & RRD_FUNCTION_HIDDEN) && !hidden) {
if((rdcf->options & RRD_FUNCTION_RESTRICTED) && !allow_restricted) {
code = rrd_call_function_error(result_wb,
"You cannot access a hidden function like this. ",
"This feature is not available via this API.",
HTTP_ACCESS_PERMISSION_DENIED_HTTP_CODE(user_access));
dictionary_acquired_item_release(host->functions, host_function_acquired);

Expand Down Expand Up @@ -546,7 +546,7 @@ int rrd_function_run(RRDHOST *host, BUFFER *result_wb, int timeout_s,
"FUNCTIONS: duplicate transaction '%s', function: '%s'",
t.transaction, t.cmd);

code = rrd_call_function_error(result_wb, "duplicate transaction", HTTP_RESP_BAD_REQUEST);
code = rrd_call_function_error(result_wb, "Duplicate transaction.", HTTP_RESP_BAD_REQUEST);

rrd_functions_inflight_cleanup(&t);
dictionary_acquired_item_release(r->host->functions, t.host_function_acquired);
Expand Down
2 changes: 1 addition & 1 deletion src/database/rrdfunctions-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ typedef enum __attribute__((packed)) {
RRD_FUNCTION_LOCAL = (1 << 0),
RRD_FUNCTION_GLOBAL = (1 << 1),
RRD_FUNCTION_DYNCFG = (1 << 2),
RRD_FUNCTION_HIDDEN = (1 << 3),
RRD_FUNCTION_RESTRICTED = (1 << 3), // this function is restricted (hidden from user)

// this is 8-bit
} RRD_FUNCTION_OPTIONS;
Expand Down
8 changes: 4 additions & 4 deletions src/database/rrdfunctions.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ void rrd_functions_host_destroy(RRDHOST *host) {

// ----------------------------------------------------------------------------

static inline bool is_function_hidden(const char *name, const char *tags) {
static inline bool is_function_restricted(const char *name, const char *tags) {
return (name && name[0] == '_' && name[1] == '_') || (tags && strstr(tags, RRDFUNCTIONS_TAG_HIDDEN) != NULL);
}

Expand All @@ -185,7 +185,7 @@ static inline RRD_FUNCTION_OPTIONS get_function_options(RRDSET *st, const char *

RRD_FUNCTION_OPTIONS options = st ? RRD_FUNCTION_LOCAL : RRD_FUNCTION_GLOBAL;

return options | (is_function_hidden(name, tags) ? RRD_FUNCTION_HIDDEN : 0);
return options | (is_function_restricted(name, tags) ? RRD_FUNCTION_RESTRICTED : 0);
}

void rrd_function_add(RRDHOST *host, RRDSET *st, const char *name, int timeout, int priority,
Expand Down Expand Up @@ -283,11 +283,11 @@ int rrd_functions_find_by_name(RRDHOST *host, BUFFER *wb, const char *name, size
if(!(*item)) {
if(found)
return rrd_call_function_error(wb,
"The collector that registered this function, is not currently running.",
"The plugin that registered this feature, is not currently running.",
HTTP_RESP_SERVICE_UNAVAILABLE);
else
return rrd_call_function_error(wb,
"No collector is supplying this function on this host at this time.",
"This feature is not available on this host at this time.",
HTTP_RESP_NOT_FOUND);
}

Expand Down
2 changes: 1 addition & 1 deletion src/database/rrdfunctions.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ int rrd_function_run(RRDHOST *host, BUFFER *result_wb, int timeout_s,
rrd_function_result_callback_t result_cb, void *result_cb_data,
rrd_function_progress_cb_t progress_cb, void *progress_cb_data,
rrd_function_is_cancelled_cb_t is_cancelled_cb, void *is_cancelled_cb_data,
BUFFER *payload, const char *source, bool hidden);
BUFFER *payload, const char *source, bool allow_restricted);

bool rrd_function_available(RRDHOST *host, const char *function);

Expand Down
4 changes: 2 additions & 2 deletions src/libnetdata/json/json-c-parser-inline.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ int rrd_call_function_error(BUFFER *wb, const char *msg, int code) {

struct json_object *json_parse_function_payload_or_error(BUFFER *output, BUFFER *payload, int *code, json_parse_function_payload_t cb, void *cb_data) {
if(!payload || !buffer_strlen(payload)) {
*code = rrd_call_function_error(output, "No payload given", HTTP_RESP_BAD_REQUEST);
*code = rrd_call_function_error(output, "No payload given, but a payload is required for this feature.", HTTP_RESP_BAD_REQUEST);
return NULL;
}

struct json_tokener *tokener = json_tokener_new();
if (!tokener) {
*code = rrd_call_function_error(output, "Cannot initialize json parser", HTTP_RESP_INTERNAL_SERVER_ERROR);
*code = rrd_call_function_error(output, "Failed to initialize json parser.", HTTP_RESP_INTERNAL_SERVER_ERROR);
return NULL;
}

Expand Down
8 changes: 4 additions & 4 deletions src/plugins.d/pluginsd_functions.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ static void inflight_functions_insert_callback(const DICTIONARY_ITEM *item, void

pf->code = HTTP_RESP_SERVICE_UNAVAILABLE;
netdata_log_error("FUNCTION '%s': failed to send it to the plugin, error %zd", string2str(pf->function), ret);
rrd_call_function_error(pf->result_body_wb, "Failed to communicate with collector", pf->code);
rrd_call_function_error(pf->result_body_wb, "Failed to send this request to the plugin that offered it.", pf->code);
}
else {
pf->sent_successfully = true;
Expand All @@ -75,7 +75,7 @@ static bool inflight_functions_conflict_callback(const DICTIONARY_ITEM *item __m
struct inflight_function *pf = new_func;

netdata_log_error("PLUGINSD_PARSER: duplicate UUID on pending function '%s' detected. Ignoring the second one.", string2str(pf->function));
pf->code = rrd_call_function_error(pf->result_body_wb, "This request is already in progress", HTTP_RESP_BAD_REQUEST);
pf->code = rrd_call_function_error(pf->result_body_wb, "This transaction is already in progress.", HTTP_RESP_BAD_REQUEST);
pf->result.cb(pf->result_body_wb, pf->code, pf->result.data);
string_freez(pf->function);

Expand All @@ -94,7 +94,7 @@ static void inflight_functions_delete_callback(const DICTIONARY_ITEM *item __may
pf->sent_monotonic_ut - pf->started_monotonic_ut, now_realtime_usec() - pf->sent_monotonic_ut);

if(pf->code == HTTP_RESP_SERVICE_UNAVAILABLE && !buffer_strlen(pf->result_body_wb))
rrd_call_function_error(pf->result_body_wb, "The plugin exited while servicing this call.", pf->code);
rrd_call_function_error(pf->result_body_wb, "The plugin that was servicing this request, exited before responding.", pf->code);

pf->result.cb(pf->result_body_wb, pf->code, pf->result.data);

Expand Down Expand Up @@ -127,7 +127,7 @@ void pluginsd_inflight_functions_garbage_collect(PARSER *parser, usec_t now_ut)

if(!buffer_strlen(pf->result_body_wb) || pf->code == HTTP_RESP_OK)
pf->code = rrd_call_function_error(pf->result_body_wb,
"Timeout waiting for collector response.",
"Timeout waiting for a response.",
HTTP_RESP_GATEWAY_TIMEOUT);

dictionary_del(parser->inflight.functions, pf_dfe.name);
Expand Down
2 changes: 1 addition & 1 deletion src/streaming/sender_execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ static void execute_commands_function(struct sender_state *s, const char *comman

if(code != HTTP_RESP_OK) {
if (!buffer_strlen(wb))
rrd_call_function_error(wb, "Failed to route request to collector", code);
rrd_call_function_error(wb, "Failed to route this request to the plugin that offered it.", code);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/api/functions/function-bearer_get_token.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static bool bearer_parse_json_payload(json_object *jobj, const char *path, void
int function_bearer_get_token(BUFFER *wb, const char *function __maybe_unused, BUFFER *payload, const char *source) {
if(!request_source_is_cloud(source))
return rrd_call_function_error(
wb, "You cannot access this function from outside Netdata Cloud", HTTP_RESP_BAD_REQUEST);
wb, "Bearer tokens can only be provided via NC.", HTTP_RESP_BAD_REQUEST);

int code;
struct bearer_token_request rq = { 0 };
Expand Down
6 changes: 3 additions & 3 deletions src/web/api/v1/api_v1_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,12 @@ int api_v1_config(RRDHOST *host, struct web_client *w, char *url __maybe_unused)
else {
DYNCFG_CMDS c = dyncfg_cmds2id(action);
if(!id || !*id || !dyncfg_is_valid_id(id)) {
rrd_call_function_error(w->response.data, "invalid id given", HTTP_RESP_BAD_REQUEST);
rrd_call_function_error(w->response.data, "Invalid id", HTTP_RESP_BAD_REQUEST);
return HTTP_RESP_BAD_REQUEST;
}

if(c == DYNCFG_CMD_NONE) {
rrd_call_function_error(w->response.data, "invalid action given", HTTP_RESP_BAD_REQUEST);
rrd_call_function_error(w->response.data, "Invalid action", HTTP_RESP_BAD_REQUEST);
return HTTP_RESP_BAD_REQUEST;
}

Expand All @@ -68,7 +68,7 @@ int api_v1_config(RRDHOST *host, struct web_client *w, char *url __maybe_unused)
}

if(!add_name || !*add_name || !dyncfg_is_valid_id(add_name)) {
rrd_call_function_error(w->response.data, "invalid name given", HTTP_RESP_BAD_REQUEST);
rrd_call_function_error(w->response.data, "Invalid name", HTTP_RESP_BAD_REQUEST);
return HTTP_RESP_BAD_REQUEST;
}
snprintfz(cmd, sizeof(cmd), PLUGINSD_FUNCTION_CONFIG " %s %s %s", id, dyncfg_id2cmd_one(c), add_name);
Expand Down
4 changes: 2 additions & 2 deletions src/web/api/v2/api_v2_bearer.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ int api_v2_bearer_protection(RRDHOST *host __maybe_unused, struct web_client *w

int bearer_get_token_json_response(BUFFER *wb, RRDHOST *host, const char *claim_id, const char *machine_guid, const char *node_id, HTTP_USER_ROLE user_role, HTTP_ACCESS access, nd_uuid_t cloud_account_id, const char *client_name) {
if(!claim_id_matches_any(claim_id))
return rrd_call_function_error(wb, "The request is for a different claimed agent", HTTP_RESP_BAD_REQUEST);
return rrd_call_function_error(wb, "The request is for a different agent", HTTP_RESP_BAD_REQUEST);

if(!verify_host_uuids(host, machine_guid, node_id))
return rrd_call_function_error(wb, "The request is missing or not matching local UUIDs", HTTP_RESP_BAD_REQUEST);
return rrd_call_function_error(wb, "The request is missing or not matching local node UUIDs", HTTP_RESP_BAD_REQUEST);

nd_uuid_t uuid;
time_t expires_s = bearer_create_token(&uuid, user_role, access, cloud_account_id, client_name);
Expand Down
2 changes: 1 addition & 1 deletion src/web/api/v3/api_v3_settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ int api_v3_settings(RRDHOST *host, struct web_client *w, char *url) {
if(web_client_flags_check_auth(w) != WEB_CLIENT_FLAG_AUTH_BEARER && strcmp(file, "default") != 0)
return rrd_call_function_error(
w->response.data,
"Only the 'default' settings file is allowed for unauthenticated users",
"Only the 'default' settings file is allowed for anonymous users",
HTTP_RESP_BAD_REQUEST);

switch(w->mode) {
Expand Down

0 comments on commit a612572

Please sign in to comment.