Simplify the rrdhost_ingestion_status call (#19456)
Use a new simpler rrdhost_get_ingest_status
Stelios Fragkakis committed
Jan 22, 2025 at 01:57 UTC
b6b576e9dcaf45e5f5c98ac14cfc844e08b50385
2 files changed
+67
-3
src/database/rrdhost-status.c
+66
-3
@@ -97,9 +97,7 @@ static NETDATA_DOUBLE rrdhost_sender_replication_completion_unsafe(RRDHOST *host
97
}
98
99
RRDHOST_INGEST_STATUS rrdhost_ingestion_status(RRDHOST *host) {
100
- RRDHOST_STATUS status;
101
- rrdhost_status(host, now_realtime_sec(), &status);
102
- return status.ingest.status;
100
+ return rrdhost_get_ingest_status(host, now_realtime_sec());
101
}
102
103
int16_t rrdhost_ingestion_hops(RRDHOST *host) {
@@ -318,3 +316,68 @@ void rrdhost_status(RRDHOST *host, time_t now, RRDHOST_STATUS *s) {
316
else
317
s->health.status = RRDHOST_HEALTH_STATUS_DISABLED;
318
}
319
+
320
+
321
+// Minimal function to get the ingest status only
322
+RRDHOST_INGEST_STATUS rrdhost_get_ingest_status(RRDHOST *host, time_t now) {
323
+ RRDHOST_FLAGS flags = __atomic_load_n(&host->flags, __ATOMIC_RELAXED);
324
+ bool online = rrdhost_is_online(host);
325
+
326
+ // Initialize ingest status variables
327
+ RRDHOST_INGEST_STATUS ingest_status;
328
+ time_t ingest_since = MAX(host->stream.rcv.status.last_connected, host->stream.rcv.status.last_disconnected);
329
+ time_t db_last_time_s;
330
+
331
+ // Database state
332
+ time_t first_time_s, last_time_s;
333
+ rrdhost_retention(host, now, online, &first_time_s, &last_time_s);
334
+ db_last_time_s = last_time_s;
335
+
336
+ uint32_t metrics = __atomic_load_n(&host->rrdctx.metrics_count, __ATOMIC_RELAXED);
337
+ uint32_t instances = __atomic_load_n(&host->rrdctx.instances_count, __ATOMIC_RELAXED);
338
+ uint32_t contexts = __atomic_load_n(&host->rrdctx.contexts_count, __ATOMIC_RELAXED);
339
+
340
+ bool db_initializing = !first_time_s || !last_time_s || !metrics || !instances || !contexts ||
341
+ (flags & RRDHOST_FLAG_PENDING_CONTEXT_LOAD);
342
+
343
+ uint32_t collected_metrics = __atomic_load_n(&host->collected.metrics_count, __ATOMIC_RELAXED);
344
+
345
+ // Replication state, if set in progress due to zero collected metrics, no need to
346
+ // get the receiver lock
347
+ bool replication_in_progress = (!collected_metrics);
348
+ uint32_t replication_instances = 0;
349
+
350
+ if (!replication_in_progress) {
351
+ rrdhost_receiver_lock(host);
352
+ if (host->receiver && rrdhost_flag_check(host, RRDHOST_FLAG_COLLECTOR_ONLINE)) {
353
+ replication_instances = rrdhost_receiver_replicating_charts(host);
354
+ replication_in_progress = replication_instances > 0;
355
+ }
356
+ rrdhost_receiver_unlock(host);
357
+ }
358
+
359
+ // Compute ingest status
360
+ if (online) {
361
+ if (db_initializing) {
362
+ ingest_status = RRDHOST_INGEST_STATUS_INITIALIZING;
363
+ } else if (rrdhost_is_local(host)) {
364
+ ingest_status = RRDHOST_INGEST_STATUS_ONLINE;
365
+ ingest_since = netdata_start_time;
366
+ } else {
367
+ if (replication_in_progress || !collected_metrics) {
368
+ ingest_status = RRDHOST_INGEST_STATUS_REPLICATING;
369
+ } else {
370
+ ingest_status = RRDHOST_INGEST_STATUS_ONLINE;
371
+ }
372
+ }
373
+ } else {
374
+ if (!ingest_since) {
375
+ ingest_status = RRDHOST_INGEST_STATUS_ARCHIVED;
376
+ ingest_since = db_last_time_s;
377
+ } else {
378
+ ingest_status = RRDHOST_INGEST_STATUS_OFFLINE;
379
+ }
380
+ }
381
+
382
+ return ingest_status;
383
+}
src/database/rrdhost-status.h
+1
@@ -166,6 +166,7 @@ typedef struct rrdhost_status_t {
166
} RRDHOST_STATUS;
167
168
void rrdhost_status(RRDHOST *host, time_t now, RRDHOST_STATUS *s);
169
+RRDHOST_INGEST_STATUS rrdhost_get_ingest_status(RRDHOST *host, time_t now);
170
RRDHOST_INGEST_STATUS rrdhost_ingestion_status(RRDHOST *host);
171
int16_t rrdhost_ingestion_hops(RRDHOST *host);
172