| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_SQLITE_ACLK_H |
| 4 | #define NETDATA_SQLITE_ACLK_H |
| 5 | |
| 6 | #define ACLK_MAX_ALERT_UPDATES "50" |
| 7 | #define ACLK_SYNC_QUERY_SIZE 512 |
| 8 | |
| 9 | static inline int uuid_parse_fix(char *in, nd_uuid_t uuid) |
| 10 | { |
| 11 | in[8] = '-'; |
| 12 | in[13] = '-'; |
| 13 | in[18] = '-'; |
| 14 | in[23] = '-'; |
| 15 | return uuid_parse(in, uuid); |
| 16 | } |
| 17 | |
| 18 | enum aclk_database_opcode { |
| 19 | ACLK_DATABASE_NOOP = 0, |
| 20 | ACLK_DATABASE_NODE_STATE, |
| 21 | ACLK_DATABASE_PUSH_ALERT_CONFIG, |
| 22 | ACLK_DATABASE_NODE_UNREGISTER, |
| 23 | ACLK_MQTT_WSS_CLIENT_SET, |
| 24 | ACLK_MQTT_WSS_CLIENT_RESET, |
| 25 | ACLK_CANCEL_NODE_UPDATE_TIMER, |
| 26 | ACLK_QUEUE_NODE_INFO, |
| 27 | ACLK_QUERY_EXECUTE, |
| 28 | ACLK_QUERY_BATCH_ADD, |
| 29 | ACLK_QUERY_BATCH_EXECUTE, |
| 30 | ACLK_SYNC_SHUTDOWN, |
| 31 | |
| 32 | // leave this last |
| 33 | // we need it to check for worker utilization |
| 34 | ACLK_MAX_ENUMERATIONS_DEFINED |
| 35 | }; |
| 36 | |
| 37 | typedef struct aclk_sync_cfg_t { |
| 38 | RRDHOST *host; |
| 39 | uv_timer_t timer; |
| 40 | bool timer_initialized; |
| 41 | |
| 42 | // pending context checkpoint - saved when deferred during context load or post-processing |
| 43 | // protected by pending_ctx_spinlock (accessed from ACLK query thread and context worker thread) |
| 44 | SPINLOCK pending_ctx_spinlock; |
| 45 | uint64_t pending_ctx_generation; |
| 46 | bool pending_ctx_checkpoint; |
| 47 | char *pending_ctx_claim_id; |
| 48 | char *pending_ctx_node_id; |
| 49 | uint64_t pending_ctx_version_hash; |
| 50 | time_t pending_ctx_saved_monotonic_s; |
| 51 | |
| 52 | int8_t send_snapshot; |
| 53 | bool stream_alerts; |
| 54 | int alert_count; |
| 55 | int snapshot_count; |
| 56 | int checkpoint_count; |
| 57 | time_t node_info_send_time; |
| 58 | time_t node_collectors_send; |
| 59 | char node_id[UUID_STR_LEN]; |
| 60 | } aclk_sync_cfg_t; |
| 61 | |
| 62 | void create_aclk_config(RRDHOST *host, nd_uuid_t *host_uuid, nd_uuid_t *node_id); |
| 63 | void destroy_aclk_config(RRDHOST *host); |
| 64 | void aclk_synchronization_init(void); |
| 65 | void aclk_synchronization_shutdown(void); |
| 66 | void aclk_push_alert_config(const char *node_id, const char *config_hash); |
| 67 | void schedule_node_state_update(RRDHOST *host, uint64_t delay); |
| 68 | void unregister_node(const char *machine_guid); |
| 69 | void aclk_queue_node_info(RRDHOST *host, bool immediate); |
| 70 | |
| 71 | #endif //NETDATA_SQLITE_ACLK_H |