|
| 1 | +/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
| 2 | + |
| 3 | +/* Fluent Bit |
| 4 | + * ========== |
| 5 | + * Copyright (C) 2025 The Fluent Bit Authors |
| 6 | + * |
| 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | + * you may not use this file except in compliance with the License. |
| 9 | + * You may obtain a copy of the License at |
| 10 | + * |
| 11 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | + * |
| 13 | + * Unless required by applicable law or agreed to in writing, software |
| 14 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | + * See the License for the specific language governing permissions and |
| 17 | + * limitations under the License. |
| 18 | + */ |
| 19 | + |
| 20 | +#ifndef FLB_TDA_H |
| 21 | +#define FLB_TDA_H |
| 22 | + |
| 23 | +#include <fluent-bit/ripser/flb_ripser_wrapper.h> |
| 24 | +#include <cmetrics/cmetrics.h> |
| 25 | +#include <cmetrics/cmt_map.h> |
| 26 | +#include <cfl/cfl_sds.h> |
| 27 | + |
| 28 | +struct tda_window; |
| 29 | +struct tda_proc_ctx; |
| 30 | + |
| 31 | +/* time-series samples (aggregated metrics snapshot) */ |
| 32 | +struct tda_sample { |
| 33 | + uint64_t ts; |
| 34 | + double values[]; |
| 35 | +}; |
| 36 | + |
| 37 | +struct tda_group { |
| 38 | + cfl_sds_t ns; |
| 39 | + cfl_sds_t subsystem; |
| 40 | + int index; /* 0 .. feature_dim-1 */ |
| 41 | +}; |
| 42 | + |
| 43 | +struct tda_window { |
| 44 | + lwrb_t rb; |
| 45 | + uint8_t *buf; |
| 46 | + size_t sample_size; /* sizeof(uint64_t) + feature_dim * sizeof(double) */ |
| 47 | + int feature_dim; |
| 48 | +}; |
| 49 | + |
| 50 | +/* processor context */ |
| 51 | +struct tda_proc_ctx { |
| 52 | + struct tda_window *window; |
| 53 | + int window_size; /* max number of samples in window */ |
| 54 | + int min_points; /* minimum samples before running ripser */ |
| 55 | + |
| 56 | + int feature_dim; /* # of (ns,subsystem) groups */ |
| 57 | + struct flb_hash_table *groups; /* key="ns.subsystem" -> struct tda_group* */ |
| 58 | + struct tda_group **group_list; /* for safe free() */ |
| 59 | + |
| 60 | + /* delay embedding parameters */ |
| 61 | + int embed_dim; /* m: number of delays (1 = no embedding) */ |
| 62 | + int embed_delay; /* tau: delay in samples */ |
| 63 | + |
| 64 | + /* exposed betti-number gauges (created lazily) */ |
| 65 | + struct cmt_gauge *g_betti0; |
| 66 | + struct cmt_gauge *g_betti1; |
| 67 | + struct cmt_gauge *g_betti2; |
| 68 | + |
| 69 | + /* for counter → rate conversion */ |
| 70 | + double *last_vec; /* last raw snapshot for each feature_dim */ |
| 71 | + uint64_t last_ts; /* last snapshot timestamp (nanoseconds) */ |
| 72 | + |
| 73 | + struct flb_processor_instance *ins; |
| 74 | +}; |
| 75 | + |
| 76 | +#endif /* FLB_TDA_H */ |
0 commit comments