From 440bd51e08fdfa2a4daa191fb68643456028a753 Mon Sep 17 00:00:00 2001 From: vkalintiris Date: Wed, 26 Jul 2023 15:30:49 +0300 Subject: Refactor RRD code. (#15423) * Storage engine. * Host indexes to rrdb * Move globals to rrdb * Move storage_tiers_backfill to rrdb * default_rrd_update_every to rrdb * default_rrd_history_entries to rrdb * gap_when_lost_iterations_above to rrdb * rrdset_free_obsolete_time_s to rrdb * libuv_worker_threads to rrdb * ieee754_doubles to rrdb * rrdhost_free_orphan_time_s to rrdb * rrd_rwlock to rrdb * localhost to rrdb * rm extern from func decls * mv rrd macro under rrd.h * default_rrdeng_page_cache_mb to rrdb * default_rrdeng_extent_cache_mb to rrdb * db_engine_journal_check to rrdb * default_rrdeng_disk_quota_mb to rrdb * default_multidb_disk_quota_mb to rrdb * multidb_ctx to rrdb * page_type_size to rrdb * tier_page_size to rrdb * No storage_engine_id in rrdim functions * storage_engine_id is provided by st * Update to fix merge conflict. * Update field name * Remove unnecessary macros from rrd.h * Rm unused type decls * Rm duplicate func decls * make internal function static * Make the rest of public dbengine funcs accept a storage_instance. * No more rrdengine_instance :) * rm rrdset_debug from rrd.h * Use rrdb to access globals in ML and ACLK Missed due to not having the submodules in the worktree. * rm total_number * rm RRDVAR_TYPE_TOTAL * rm unused inline * Rm names from typedef'd enums * rm unused header include * Move include * Rm unused header include * s/rrdhost_find_or_create/rrdhost_get_or_create/g * s/find_host_by_node_id/rrdhost_find_by_node_id/ Also, remove duplicate definition in rrdcontext.c * rm macro used only once * rm macro used only once * Reduce rrd.h api by moving funcs into a collector specific utils header * Remove unused func * Move parser specific function out of rrd.h * return storage_number instead of void pointer * move code related to rrd initialization out of rrdhost.c * Remove tier_grouping from rrdim_tier Saves 8 * storage_tiers bytes per dimension. * Fix rebase * s/rrd_update_every/update_every/ * Mark functions as static and constify args * Add license notes and file to build systems. * Remove remaining non-log/config mentions of memory mode * Move rrdlabels api to separate file. Also, move localhost functions that loads labels outside of database/ and into daemon/ * Remove function decl in rrd.h * merge rrdhost_cache_dir_for_rrdset_alloc into rrdset_cache_dir * Do not expose internal function from rrd.h * Rm NETDATA_RRD_INTERNALS Only one function decl is covered. We have more database internal functions that we currently expose for no good reason. These will be placed in a separate internal header in follow up PRs. * Add license note * Include libnetdata.h instead of aral.h * Use rrdb to access localhost * Fix builds without dbengine * Add header to build system files * Add rrdlabels.h to build systems * Move func def from rrd.h to rrdhost.c * Fix macos build * Rm non-existing function * Rebase master * Define buffer length macro in ad_charts. * Fix FreeBSD builds. * Mark functions static * Rm func decls without definitions * Rebase master * Rebase master * Properly initialize value of storage tiers. * Fix build after rebase. --- aclk/aclk.c | 36 +++++++++++++------------- aclk/aclk_capas.c | 6 ++--- aclk/aclk_proxy.c | 2 ++ aclk/aclk_proxy.h | 2 ++ aclk/aclk_query.c | 2 +- aclk/aclk_rrdhost_state.h | 2 ++ aclk/aclk_rx_msgs.c | 8 +++--- aclk/aclk_stats.c | 50 ++++++++++++++++++------------------ aclk/aclk_tx_msgs.c | 30 +++++++++++----------- aclk/aclk_util.c | 14 +++++----- aclk/schema-wrappers/node_info.cc | 2 ++ aclk/schema-wrappers/proto_2_json.cc | 2 ++ 12 files changed, 83 insertions(+), 73 deletions(-) (limited to 'aclk') diff --git a/aclk/aclk.c b/aclk/aclk.c index 312db076ff..59c3106dfa 100644 --- a/aclk/aclk.c +++ b/aclk/aclk.c @@ -913,15 +913,15 @@ void aclk_host_state_update(RRDHOST *host, int cmd) // node_id not found aclk_query_t create_query; create_query = aclk_query_new(REGISTER_NODE); - rrdhost_aclk_state_lock(localhost); + rrdhost_aclk_state_lock(rrdb.localhost); node_instance_creation_t node_instance_creation = { - .claim_id = localhost->aclk_state.claimed_id, + .claim_id = rrdb.localhost->aclk_state.claimed_id, .hops = host->system_info->hops, .hostname = rrdhost_hostname(host), .machine_guid = host->machine_guid}; create_query->data.bin_payload.payload = generate_node_instance_creation(&create_query->data.bin_payload.size, &node_instance_creation); - rrdhost_aclk_state_unlock(localhost); + rrdhost_aclk_state_unlock(rrdb.localhost); create_query->data.bin_payload.topic = ACLK_TOPICID_CREATE_NODE; create_query->data.bin_payload.msg_name = "CreateNodeInstance"; netdata_log_info("Registering host=%s, hops=%u", host->machine_guid, host->system_info->hops); @@ -942,10 +942,10 @@ void aclk_host_state_update(RRDHOST *host, int cmd) node_state_update.capabilities = aclk_get_agent_capas(); - rrdhost_aclk_state_lock(localhost); - node_state_update.claim_id = localhost->aclk_state.claimed_id; + rrdhost_aclk_state_lock(rrdb.localhost); + node_state_update.claim_id = rrdb.localhost->aclk_state.claimed_id; query->data.bin_payload.payload = generate_node_instance_connection(&query->data.bin_payload.size, &node_state_update); - rrdhost_aclk_state_unlock(localhost); + rrdhost_aclk_state_unlock(rrdb.localhost); netdata_log_info("Queuing status update for node=%s, live=%d, hops=%u",(char*)node_state_update.node_id, cmd, host->system_info->hops); @@ -986,10 +986,10 @@ void aclk_send_node_instances() } node_state_update.capabilities = aclk_get_node_instance_capas(host); - rrdhost_aclk_state_lock(localhost); - node_state_update.claim_id = localhost->aclk_state.claimed_id; + rrdhost_aclk_state_lock(rrdb.localhost); + node_state_update.claim_id = rrdb.localhost->aclk_state.claimed_id; query->data.bin_payload.payload = generate_node_instance_connection(&query->data.bin_payload.size, &node_state_update); - rrdhost_aclk_state_unlock(localhost); + rrdhost_aclk_state_unlock(rrdb.localhost); netdata_log_info("Queuing status update for node=%s, live=%d, hops=%d",(char*)node_state_update.node_id, list->live, list->hops); @@ -1010,10 +1010,10 @@ void aclk_send_node_instances() uuid_unparse_lower(list->host_id, (char*)node_instance_creation.machine_guid); create_query->data.bin_payload.topic = ACLK_TOPICID_CREATE_NODE; create_query->data.bin_payload.msg_name = "CreateNodeInstance"; - rrdhost_aclk_state_lock(localhost); - node_instance_creation.claim_id = localhost->aclk_state.claimed_id, + rrdhost_aclk_state_lock(rrdb.localhost); + node_instance_creation.claim_id = rrdb.localhost->aclk_state.claimed_id, create_query->data.bin_payload.payload = generate_node_instance_creation(&create_query->data.bin_payload.size, &node_instance_creation); - rrdhost_aclk_state_unlock(localhost); + rrdhost_aclk_state_unlock(rrdb.localhost); netdata_log_info("Queuing registration for host=%s, hops=%d",(char*)node_instance_creation.machine_guid, list->hops); freez((void *)node_instance_creation.machine_guid); @@ -1124,9 +1124,9 @@ char *aclk_state(void) buffer_sprintf(wb, "\n\tNode ID: %s\n", node_id); } - buffer_sprintf(wb, "\tStreaming Hops: %d\n\tRelationship: %s", host->system_info->hops, host == localhost ? "self" : "child"); + buffer_sprintf(wb, "\tStreaming Hops: %d\n\tRelationship: %s", host->system_info->hops, host == rrdb.localhost ? "self" : "child"); - if (host != localhost) + if (host != rrdb.localhost) buffer_sprintf(wb, "\n\tStreaming Connection Live: %s", host->receiver ? "true" : "false"); buffer_strcat(wb, "\n\tAlert Streaming Status:"); @@ -1270,10 +1270,10 @@ char *aclk_state_json(void) tmp = json_object_new_int(host->system_info->hops); json_object_object_add(nodeinstance, "streaming-hops", tmp); - tmp = json_object_new_string(host == localhost ? "self" : "child"); + tmp = json_object_new_string(host == rrdb.localhost ? "self" : "child"); json_object_object_add(nodeinstance, "relationship", tmp); - tmp = json_object_new_boolean((host->receiver || host == localhost)); + tmp = json_object_new_boolean((host->receiver || host == rrdb.localhost)); json_object_object_add(nodeinstance, "streaming-online", tmp); tmp = json_object_new_object(); @@ -1292,7 +1292,7 @@ char *aclk_state_json(void) } void add_aclk_host_labels(void) { - DICTIONARY *labels = localhost->rrdlabels; + DICTIONARY *labels = rrdb.localhost->rrdlabels; #ifdef ENABLE_ACLK rrdlabels_add(labels, "_aclk_available", "true", RRDLABEL_SRC_AUTO|RRDLABEL_SRC_ACLK); @@ -1324,5 +1324,5 @@ void aclk_queue_node_info(RRDHOST *host, bool immediate) { struct aclk_sync_host_config *wc = (struct aclk_sync_host_config *) host->aclk_sync_host_config; if (likely(wc)) - wc->node_info_send_time = (host == localhost || immediate) ? 1 : now_realtime_sec(); + wc->node_info_send_time = (host == rrdb.localhost || immediate) ? 1 : now_realtime_sec(); } diff --git a/aclk/aclk_capas.c b/aclk/aclk_capas.c index e8d85a2b9f..28c8825bce 100644 --- a/aclk/aclk_capas.c +++ b/aclk/aclk_capas.c @@ -21,19 +21,19 @@ const struct capability *aclk_get_agent_capas() { .name = NULL, .version = 0, .enabled = 0 } }; agent_capabilities[2].version = ml_capable() ? 1 : 0; - agent_capabilities[2].enabled = ml_enabled(localhost); + agent_capabilities[2].enabled = ml_enabled(rrdb.localhost); agent_capabilities[3].version = enable_metric_correlations ? metric_correlations_version : 0; agent_capabilities[3].enabled = enable_metric_correlations; - agent_capabilities[7].enabled = localhost->health.health_enabled; + agent_capabilities[7].enabled = rrdb.localhost->health.health_enabled; return agent_capabilities; } struct capability *aclk_get_node_instance_capas(RRDHOST *host) { - bool functions = (host == localhost || (host->receiver && stream_has_capability(host->receiver, STREAM_CAP_FUNCTIONS))); + bool functions = (host == rrdb.localhost || (host->receiver && stream_has_capability(host->receiver, STREAM_CAP_FUNCTIONS))); struct capability ni_caps[] = { { .name = "proto", .version = 1, .enabled = 1 }, diff --git a/aclk/aclk_proxy.c b/aclk/aclk_proxy.c index 4af46208f7..dd79f9061f 100644 --- a/aclk/aclk_proxy.c +++ b/aclk/aclk_proxy.c @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + #include "aclk_proxy.h" #include "daemon/common.h" diff --git a/aclk/aclk_proxy.h b/aclk/aclk_proxy.h index b4ceb7df84..e8fe2ae176 100644 --- a/aclk/aclk_proxy.h +++ b/aclk/aclk_proxy.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + #ifndef ACLK_PROXY_H #define ACLK_PROXY_H diff --git a/aclk/aclk_query.c b/aclk/aclk_query.c index 07d571be17..697e76118b 100644 --- a/aclk/aclk_query.c +++ b/aclk/aclk_query.c @@ -128,7 +128,7 @@ static int http_api_v2(struct aclk_query_thread *query_thr, aclk_query_t query) ACLK_STATS_UNLOCK; } - w->response.code = (short)web_client_api_request_with_node_selection(localhost, w, path); + w->response.code = (short)web_client_api_request_with_node_selection(rrdb.localhost, w, path); web_client_timeout_checkpoint_response_ready(w, &t); if(buffer_strlen(w->response.data) > ACLK_MAX_WEB_RESPONSE_SIZE) { diff --git a/aclk/aclk_rrdhost_state.h b/aclk/aclk_rrdhost_state.h index 5c8a2ddc94..ae7f548c90 100644 --- a/aclk/aclk_rrdhost_state.h +++ b/aclk/aclk_rrdhost_state.h @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + #ifndef ACLK_RRDHOST_STATE_H #define ACLK_RRDHOST_STATE_H diff --git a/aclk/aclk_rx_msgs.c b/aclk/aclk_rx_msgs.c index 84ade2b346..463db0e94a 100644 --- a/aclk/aclk_rx_msgs.c +++ b/aclk/aclk_rx_msgs.c @@ -279,7 +279,7 @@ int create_node_instance_result(const char *msg, size_t msg_len) RRDHOST *host = rrdhost_find_by_guid(res.machine_guid); if (likely(host)) { - if (host == localhost) { + if (host == rrdb.localhost) { node_state_update.live = 1; node_state_update.hops = 0; } else { @@ -289,10 +289,10 @@ int create_node_instance_result(const char *msg, size_t msg_len) node_state_update.capabilities = aclk_get_node_instance_capas(host); } - rrdhost_aclk_state_lock(localhost); - node_state_update.claim_id = localhost->aclk_state.claimed_id; + rrdhost_aclk_state_lock(rrdb.localhost); + node_state_update.claim_id = rrdb.localhost->aclk_state.claimed_id; query->data.bin_payload.payload = generate_node_instance_connection(&query->data.bin_payload.size, &node_state_update); - rrdhost_aclk_state_unlock(localhost); + rrdhost_aclk_state_unlock(rrdb.localhost); freez((void *)node_state_update.capabilities); diff --git a/aclk/aclk_stats.c b/aclk/aclk_stats.c index f4672882b7..03e9d95e25 100644 --- a/aclk/aclk_stats.c +++ b/aclk/aclk_stats.c @@ -38,7 +38,7 @@ static void aclk_stats_collect(struct aclk_metrics_per_sample *per_sample, struc if (unlikely(!st_aclkstats)) { st_aclkstats = rrdset_create_localhost( "netdata", "aclk_status", NULL, "aclk", NULL, "ACLK/Cloud connection status", - "connected", "netdata", "stats", 200000, localhost->rrd_update_every, RRDSET_TYPE_LINE); + "connected", "netdata", "stats", 200000, rrdb.localhost->update_every, RRDSET_TYPE_LINE); rd_online_status = rrddim_add(st_aclkstats, "online", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); } @@ -57,10 +57,10 @@ static void aclk_stats_query_queue(struct aclk_metrics_per_sample *per_sample) if (unlikely(!st_query_thread)) { st_query_thread = rrdset_create_localhost( "netdata", "aclk_query_per_second", NULL, "aclk", NULL, "ACLK Queries per second", "queries/s", - "netdata", "stats", 200001, localhost->rrd_update_every, RRDSET_TYPE_AREA); + "netdata", "stats", 200001, rrdb.localhost->update_every, RRDSET_TYPE_AREA); - rd_queued = rrddim_add(st_query_thread, "added", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE); - rd_dispatched = rrddim_add(st_query_thread, "dispatched", NULL, -1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE); + rd_queued = rrddim_add(st_query_thread, "added", NULL, 1, rrdb.localhost->update_every, RRD_ALGORITHM_ABSOLUTE); + rd_dispatched = rrddim_add(st_query_thread, "dispatched", NULL, -1, rrdb.localhost->update_every, RRD_ALGORITHM_ABSOLUTE); } rrddim_set_by_pointer(st_query_thread, rd_queued, per_sample->queries_queued); @@ -79,7 +79,7 @@ static void aclk_stats_latency(struct aclk_metrics_per_sample *per_sample) if (unlikely(!st)) { st = rrdset_create_localhost( "netdata", "aclk_latency_mqtt", NULL, "aclk", NULL, "ACLK Message Publish Latency", "ms", - "netdata", "stats", 200002, localhost->rrd_update_every, RRDSET_TYPE_LINE); + "netdata", "stats", 200002, rrdb.localhost->update_every, RRDSET_TYPE_LINE); rd_avg = rrddim_add(st, "avg", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rd_max = rrddim_add(st, "max", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); @@ -105,10 +105,10 @@ static void aclk_stats_cloud_req(struct aclk_metrics_per_sample *per_sample) if (unlikely(!st)) { st = rrdset_create_localhost( "netdata", "aclk_cloud_req", NULL, "aclk", NULL, "Requests received from cloud", "req/s", - "netdata", "stats", 200005, localhost->rrd_update_every, RRDSET_TYPE_STACKED); + "netdata", "stats", 200005, rrdb.localhost->update_every, RRDSET_TYPE_STACKED); - rd_rq_rcvd = rrddim_add(st, "received", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE); - rd_rq_err = rrddim_add(st, "malformed", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE); + rd_rq_rcvd = rrddim_add(st, "received", NULL, 1, rrdb.localhost->update_every, RRD_ALGORITHM_ABSOLUTE); + rd_rq_err = rrddim_add(st, "malformed", NULL, 1, rrdb.localhost->update_every, RRD_ALGORITHM_ABSOLUTE); } rrddim_set_by_pointer(st, rd_rq_rcvd, per_sample->cloud_req_recvd - per_sample->cloud_req_err); @@ -125,10 +125,10 @@ static void aclk_stats_cloud_req_type(struct aclk_metrics_per_sample *per_sample if (unlikely(!st)) { st = rrdset_create_localhost( "netdata", "aclk_processed_query_type", NULL, "aclk", NULL, "Query thread commands processed by their type", "cmd/s", - "netdata", "stats", 200006, localhost->rrd_update_every, RRDSET_TYPE_STACKED); + "netdata", "stats", 200006, rrdb.localhost->update_every, RRDSET_TYPE_STACKED); for (int i = 0; i < ACLK_QUERY_TYPE_COUNT; i++) - dims[i] = rrddim_add(st, aclk_query_get_name(i, 1), NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE); + dims[i] = rrddim_add(st, aclk_query_get_name(i, 1), NULL, 1, rrdb.localhost->update_every, RRD_ALGORITHM_ABSOLUTE); } @@ -167,10 +167,10 @@ static void aclk_stats_cloud_req_http_type(struct aclk_metrics_per_sample *per_s if (unlikely(!st)) { st = rrdset_create_localhost( "netdata", "aclk_cloud_req_http_type", NULL, "aclk", NULL, "Requests received from cloud via HTTP by their type", "req/s", - "netdata", "stats", 200007, localhost->rrd_update_every, RRDSET_TYPE_STACKED); + "netdata", "stats", 200007, rrdb.localhost->update_every, RRDSET_TYPE_STACKED); for (int i = 0; i < ACLK_STATS_CLOUD_HTTP_REQ_TYPE_CNT; i++) - rd_rq_types[i] = rrddim_add(st, cloud_req_http_type_names[i], NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE); + rd_rq_types[i] = rrddim_add(st, cloud_req_http_type_names[i], NULL, 1, rrdb.localhost->update_every, RRD_ALGORITHM_ABSOLUTE); } for (int i = 0; i < ACLK_STATS_CLOUD_HTTP_REQ_TYPE_CNT; i++) @@ -189,12 +189,12 @@ static void aclk_stats_query_threads(uint32_t *queries_per_thread) if (unlikely(!st)) { st = rrdset_create_localhost( "netdata", "aclk_query_threads", NULL, "aclk", NULL, "Queries Processed Per Thread", "req/s", - "netdata", "stats", 200009, localhost->rrd_update_every, RRDSET_TYPE_STACKED); + "netdata", "stats", 200009, rrdb.localhost->update_every, RRDSET_TYPE_STACKED); for (int i = 0; i < aclk_stats_cfg.query_thread_count; i++) { if (snprintfz(dim_name, MAX_DIM_NAME, "Query %d", i) < 0) netdata_log_error("snprintf encoding error"); - aclk_qt_data[i].dim = rrddim_add(st, dim_name, NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE); + aclk_qt_data[i].dim = rrddim_add(st, dim_name, NULL, 1, rrdb.localhost->update_every, RRD_ALGORITHM_ABSOLUTE); } } @@ -215,11 +215,11 @@ static void aclk_stats_query_time(struct aclk_metrics_per_sample *per_sample) if (unlikely(!st)) { st = rrdset_create_localhost( "netdata", "aclk_query_time", NULL, "aclk", NULL, "Time it took to process cloud requested DB queries", "us", - "netdata", "stats", 200008, localhost->rrd_update_every, RRDSET_TYPE_LINE); + "netdata", "stats", 200008, rrdb.localhost->update_every, RRDSET_TYPE_LINE); - rd_rq_avg = rrddim_add(st, "avg", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE); - rd_rq_max = rrddim_add(st, "max", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE); - rd_rq_total = rrddim_add(st, "total", NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE); + rd_rq_avg = rrddim_add(st, "avg", NULL, 1, rrdb.localhost->update_every, RRD_ALGORITHM_ABSOLUTE); + rd_rq_max = rrddim_add(st, "max", NULL, 1, rrdb.localhost->update_every, RRD_ALGORITHM_ABSOLUTE); + rd_rq_total = rrddim_add(st, "total", NULL, 1, rrdb.localhost->update_every, RRD_ALGORITHM_ABSOLUTE); } if(per_sample->cloud_q_process_count) @@ -240,10 +240,10 @@ static void aclk_stats_newproto_rx(uint32_t *rx_msgs_sample) if (unlikely(!st)) { st = rrdset_create_localhost( "netdata", "aclk_protobuf_rx_types", NULL, "aclk", NULL, "Received new cloud architecture messages by their type.", "msg/s", - "netdata", "stats", 200010, localhost->rrd_update_every, RRDSET_TYPE_STACKED); + "netdata", "stats", 200010, rrdb.localhost->update_every, RRDSET_TYPE_STACKED); for (unsigned int i = 0; i < aclk_stats_cfg.proto_hdl_cnt; i++) { - aclk_stats_cfg.rx_msg_dims[i] = rrddim_add(st, rx_handler_get_name(i), NULL, 1, localhost->rrd_update_every, RRD_ALGORITHM_ABSOLUTE); + aclk_stats_cfg.rx_msg_dims[i] = rrddim_add(st, rx_handler_get_name(i), NULL, 1, rrdb.localhost->update_every, RRD_ALGORITHM_ABSOLUTE); } } @@ -284,7 +284,7 @@ static void aclk_stats_mqtt_wss(struct mqtt_wss_stats *stats) if (unlikely(!st)) { st = rrdset_create_localhost( "netdata", "aclk_openssl_bytes", NULL, "aclk", NULL, "Received and Sent bytes.", "B/s", - "netdata", "stats", 200011, localhost->rrd_update_every, RRDSET_TYPE_STACKED); + "netdata", "stats", 200011, rrdb.localhost->update_every, RRDSET_TYPE_STACKED); rd_sent = rrddim_add(st, "sent", NULL, -1, 1, RRD_ALGORITHM_INCREMENTAL); rd_recvd = rrddim_add(st, "received", NULL, 1, 1, RRD_ALGORITHM_INCREMENTAL); @@ -293,7 +293,7 @@ static void aclk_stats_mqtt_wss(struct mqtt_wss_stats *stats) if (unlikely(!st_txbuf_perc)) { st_txbuf_perc = rrdset_create_localhost( "netdata", "aclk_mqtt_tx_perc", NULL, "aclk", NULL, "Actively used percentage of MQTT Tx Buffer,", "%", - "netdata", "stats", 200012, localhost->rrd_update_every, RRDSET_TYPE_LINE); + "netdata", "stats", 200012, rrdb.localhost->update_every, RRDSET_TYPE_LINE); rd_txbuf_perc = rrddim_add(st_txbuf_perc, "used", NULL, 1, 100, RRD_ALGORITHM_ABSOLUTE); } @@ -301,7 +301,7 @@ static void aclk_stats_mqtt_wss(struct mqtt_wss_stats *stats) if (unlikely(!st_txbuf)) { st_txbuf = rrdset_create_localhost( "netdata", "aclk_mqtt_tx_queue", NULL, "aclk", NULL, "State of transmit MQTT queue.", "B", - "netdata", "stats", 200013, localhost->rrd_update_every, RRDSET_TYPE_LINE); + "netdata", "stats", 200013, rrdb.localhost->update_every, RRDSET_TYPE_LINE); rd_tx_buffer_usable = rrddim_add(st_txbuf, "usable", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rd_tx_buffer_reclaimable = rrddim_add(st_txbuf, "reclaimable", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); @@ -313,7 +313,7 @@ static void aclk_stats_mqtt_wss(struct mqtt_wss_stats *stats) if (unlikely(!st_timing)) { st_timing = rrdset_create_localhost( "netdata", "aclk_mqtt_wss_time", NULL, "aclk", NULL, "Time spent handling MQTT, WSS, SSL and network communication.", "us", - "netdata", "stats", 200014, localhost->rrd_update_every, RRDSET_TYPE_STACKED); + "netdata", "stats", 200014, rrdb.localhost->update_every, RRDSET_TYPE_STACKED); rd_keepalive = rrddim_add(st_timing, "keep-alive", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); rd_read_socket = rrddim_add(st_timing, "socket_read_ssl", NULL, 1, 1, RRD_ALGORITHM_ABSOLUTE); @@ -379,7 +379,7 @@ void *aclk_stats_main_thread(void *ptr) heartbeat_t hb; heartbeat_init(&hb); - usec_t step_ut = localhost->rrd_update_every * USEC_PER_SEC; + usec_t step_ut = rrdb.localhost->update_every * USEC_PER_SEC; struct aclk_metrics_per_sample per_sample; struct aclk_metrics permanent; diff --git a/aclk/aclk_tx_msgs.c b/aclk/aclk_tx_msgs.c index 26e20dfb2c..03440aeeb0 100644 --- a/aclk/aclk_tx_msgs.c +++ b/aclk/aclk_tx_msgs.c @@ -218,19 +218,19 @@ uint16_t aclk_send_agent_connection_update(mqtt_wss_client client, int reachable .capabilities = aclk_get_agent_capas() }; - rrdhost_aclk_state_lock(localhost); - if (unlikely(!localhost->aclk_state.claimed_id)) { + rrdhost_aclk_state_lock(rrdb.localhost); + if (unlikely(!rrdb.localhost->aclk_state.claimed_id)) { netdata_log_error("Internal error. Should not come here if not claimed"); - rrdhost_aclk_state_unlock(localhost); + rrdhost_aclk_state_unlock(rrdb.localhost); return 0; } - if (localhost->aclk_state.prev_claimed_id) - conn.claim_id = localhost->aclk_state.prev_claimed_id; + if (rrdb.localhost->aclk_state.prev_claimed_id) + conn.claim_id = rrdb.localhost->aclk_state.prev_claimed_id; else - conn.claim_id = localhost->aclk_state.claimed_id; + conn.claim_id = rrdb.localhost->aclk_state.claimed_id; char *msg = generate_update_agent_connection(&len, &conn); - rrdhost_aclk_state_unlock(localhost); + rrdhost_aclk_state_unlock(rrdb.localhost); if (!msg) { netdata_log_error("Error generating agent::v1::UpdateAgentConnection payload"); @@ -238,9 +238,9 @@ uint16_t aclk_send_agent_connection_update(mqtt_wss_client client, int reachable } pid = aclk_send_bin_message_subtopic_pid(client, msg, len, ACLK_TOPICID_AGENT_CONN, "UpdateAgentConnection"); - if (localhost->aclk_state.prev_claimed_id) { - freez(localhost->aclk_state.prev_claimed_id); - localhost->aclk_state.prev_claimed_id = NULL; + if (rrdb.localhost->aclk_state.prev_claimed_id) { + freez(rrdb.localhost->aclk_state.prev_claimed_id); + rrdb.localhost->aclk_state.prev_claimed_id = NULL; } return pid; } @@ -253,16 +253,16 @@ char *aclk_generate_lwt(size_t *size) { .capabilities = NULL }; - rrdhost_aclk_state_lock(localhost); - if (unlikely(!localhost->aclk_state.claimed_id)) { + rrdhost_aclk_state_lock(rrdb.localhost); + if (unlikely(!rrdb.localhost->aclk_state.claimed_id)) { netdata_log_error("Internal error. Should not come here if not claimed"); - rrdhost_aclk_state_unlock(localhost); + rrdhost_aclk_state_unlock(rrdb.localhost); return NULL; } - conn.claim_id = localhost->aclk_state.claimed_id; + conn.claim_id = rrdb.localhost->aclk_state.claimed_id; char *msg = generate_update_agent_connection(size, &conn); - rrdhost_aclk_state_unlock(localhost); + rrdhost_aclk_state_unlock(rrdb.localhost); if (!msg) netdata_log_error("Error generating agent::v1::UpdateAgentConnection payload for LWT"); diff --git a/aclk/aclk_util.c b/aclk/aclk_util.c index 00920e0690..cf5ee7add3 100644 --- a/aclk/aclk_util.c +++ b/aclk/aclk_util.c @@ -183,20 +183,20 @@ static void topic_generate_final(struct aclk_topic *t) { if (!replace_tag) return; - rrdhost_aclk_state_lock(localhost); - if (unlikely(!localhost->aclk_state.claimed_id)) { + rrdhost_aclk_state_lock(rrdb.localhost); + if (unlikely(!rrdb.localhost->aclk_state.claimed_id)) { netdata_log_error("This should never be called if agent not claimed"); - rrdhost_aclk_state_unlock(localhost); + rrdhost_aclk_state_unlock(rrdb.localhost); return; } - t->topic = mallocz(strlen(t->topic_recvd) + 1 - strlen(CLAIM_ID_REPLACE_TAG) + strlen(localhost->aclk_state.claimed_id)); + t->topic = mallocz(strlen(t->topic_recvd) + 1 - strlen(CLAIM_ID_REPLACE_TAG) + strlen(rrdb.localhost->aclk_state.claimed_id)); memcpy(t->topic, t->topic_recvd, replace_tag - t->topic_recvd); dest = t->topic + (replace_tag - t->topic_recvd); - memcpy(dest, localhost->aclk_state.claimed_id, strlen(localhost->aclk_state.claimed_id)); - dest += strlen(localhost->aclk_state.claimed_id); - rrdhost_aclk_state_unlock(localhost); + memcpy(dest, rrdb.localhost->aclk_state.claimed_id, strlen(rrdb.localhost->aclk_state.claimed_id)); + dest += strlen(rrdb.localhost->aclk_state.claimed_id); + rrdhost_aclk_state_unlock(rrdb.localhost); replace_tag += strlen(CLAIM_ID_REPLACE_TAG); strcpy(dest, replace_tag); dest += strlen(replace_tag); diff --git a/aclk/schema-wrappers/node_info.cc b/aclk/schema-wrappers/node_info.cc index 5e321f6886..03f423bb93 100644 --- a/aclk/schema-wrappers/node_info.cc +++ b/aclk/schema-wrappers/node_info.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + #include "node_info.h" #include "proto/nodeinstance/info/v1/info.pb.h" diff --git a/aclk/schema-wrappers/proto_2_json.cc b/aclk/schema-wrappers/proto_2_json.cc index 8543965107..c67308fd24 100644 --- a/aclk/schema-wrappers/proto_2_json.cc +++ b/aclk/schema-wrappers/proto_2_json.cc @@ -1,3 +1,5 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + #include #include -- cgit v1.2.3