| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_STREAM_CAPABILITIES_H |
| 4 | #define NETDATA_STREAM_CAPABILITIES_H |
| 5 | |
| 6 | #include "libnetdata/libnetdata.h" |
| 7 | |
| 8 | // ---------------------------------------------------------------------------- |
| 9 | // obsolete versions - do not use anymore |
| 10 | |
| 11 | #define STREAM_OLD_VERSION_CLAIM 3 |
| 12 | #define STREAM_OLD_VERSION_CLABELS 4 |
| 13 | #define STREAM_OLD_VERSION_LZ4 5 |
| 14 | |
| 15 | // ---------------------------------------------------------------------------- |
| 16 | // capabilities negotiation |
| 17 | |
| 18 | typedef enum { |
| 19 | STREAM_CAP_NONE = 0, |
| 20 | |
| 21 | // do not use the first 3 bits |
| 22 | // they used to be versions 1, 2 and 3 |
| 23 | // before we introduce capabilities |
| 24 | |
| 25 | STREAM_CAP_V1 = (1 << 3), // v1 = the oldest protocol |
| 26 | STREAM_CAP_V2 = (1 << 4), // v2 = the second version of the protocol (with host labels) |
| 27 | STREAM_CAP_VN = (1 << 5), // version negotiation supported (for versions 3, 4, 5 of the protocol) |
| 28 | // v3 = claiming supported |
| 29 | // v4 = chart labels supported |
| 30 | // v5 = lz4 compression supported |
| 31 | STREAM_CAP_VCAPS = (1 << 6), // capabilities negotiation supported |
| 32 | STREAM_CAP_HLABELS = (1 << 7), // host labels supported |
| 33 | STREAM_CAP_CLAIM = (1 << 8), // claiming supported |
| 34 | STREAM_CAP_CLABELS = (1 << 9), // chart labels supported |
| 35 | STREAM_CAP_LZ4 = (1 << 10), // lz4 compression supported |
| 36 | STREAM_CAP_FUNCTIONS = (1 << 11), // plugin functions supported |
| 37 | STREAM_CAP_REPLICATION = (1 << 12), // replication supported |
| 38 | STREAM_CAP_BINARY = (1 << 13), // streaming supports binary data |
| 39 | STREAM_CAP_INTERPOLATED = (1 << 14), // streaming supports interpolated streaming of values |
| 40 | STREAM_CAP_IEEE754 = (1 << 15), // streaming supports binary/hex transfer of double values |
| 41 | STREAM_CAP_DATA_WITH_ML = (1 << 16), // leave this unused for as long as possible - NOT USED, BUT KEEP IT |
| 42 | // STREAM_CAP_DYNCFG = (1 << 17), // leave this unused for as long as possible |
| 43 | STREAM_CAP_SLOTS = (1 << 18), // the sender can appoint a unique slot for each chart |
| 44 | STREAM_CAP_ZSTD = (1 << 19), // ZSTD compression supported |
| 45 | STREAM_CAP_GZIP = (1 << 20), // GZIP compression supported |
| 46 | STREAM_CAP_BROTLI = (1 << 21), // BROTLI compression supported |
| 47 | STREAM_CAP_PROGRESS = (1 << 22), // Functions PROGRESS support |
| 48 | STREAM_CAP_DYNCFG = (1 << 23), // support for DYNCFG |
| 49 | STREAM_CAP_NODE_ID = (1 << 24), // support for sending NODE_ID back to the child |
| 50 | STREAM_CAP_PATHS = (1 << 25), // support for sending PATHS upstream and downstream |
| 51 | STREAM_CAP_ML_MODELS = (1 << 26), // support for sending MODELS upstream |
| 52 | STREAM_CAP_FLOAT_BASELINE = (1 << 27), // support float baselines for dimensions |
| 53 | |
| 54 | STREAM_CAP_INVALID = (1 << 30), // used as an invalid value for capabilities when this is set |
| 55 | // this must be signed int, so don't use the last bit |
| 56 | // needed for negotiating errors between parent and child |
| 57 | } STREAM_CAPABILITIES; |
| 58 | |
| 59 | #define STREAM_CAP_ALWAYS_DISABLED (STREAM_CAP_DATA_WITH_ML) |
| 60 | |
| 61 | #ifdef ENABLE_LZ4 |
| 62 | #define STREAM_CAP_LZ4_AVAILABLE STREAM_CAP_LZ4 |
| 63 | #else |
| 64 | #define STREAM_CAP_LZ4_AVAILABLE 0 |
| 65 | #endif // ENABLE_LZ4 |
| 66 | |
| 67 | #ifdef ENABLE_ZSTD |
| 68 | #define STREAM_CAP_ZSTD_AVAILABLE STREAM_CAP_ZSTD |
| 69 | #else |
| 70 | #define STREAM_CAP_ZSTD_AVAILABLE 0 |
| 71 | #endif // ENABLE_ZSTD |
| 72 | |
| 73 | #ifdef ENABLE_BROTLI |
| 74 | #define STREAM_CAP_BROTLI_AVAILABLE STREAM_CAP_BROTLI |
| 75 | #else |
| 76 | #define STREAM_CAP_BROTLI_AVAILABLE 0 |
| 77 | #endif // ENABLE_BROTLI |
| 78 | |
| 79 | #define STREAM_CAP_COMPRESSIONS_AVAILABLE (STREAM_CAP_LZ4_AVAILABLE|STREAM_CAP_ZSTD_AVAILABLE|STREAM_CAP_BROTLI_AVAILABLE|STREAM_CAP_GZIP) |
| 80 | |
| 81 | #define stream_has_capability(rpt, capability) ((rpt) && ((rpt)->capabilities & (capability)) == (capability)) |
| 82 | |
| 83 | static inline bool stream_has_more_than_one_capability_of(STREAM_CAPABILITIES caps, STREAM_CAPABILITIES mask) { |
| 84 | STREAM_CAPABILITIES common = (STREAM_CAPABILITIES)(caps & mask); |
| 85 | return (common & (common - 1)) != 0 && common != 0; |
| 86 | } |
| 87 | |
| 88 | struct sender_state; |
| 89 | struct receiver_state; |
| 90 | struct rrdhost; |
| 91 | |
| 92 | STREAM_CAPABILITIES stream_capabilities_parse_one(const char *str); |
| 93 | |
| 94 | void stream_capabilities_to_string(BUFFER *wb, STREAM_CAPABILITIES caps); |
| 95 | void stream_capabilities_to_json_array(BUFFER *wb, STREAM_CAPABILITIES caps, const char *key); |
| 96 | void log_receiver_capabilities(struct receiver_state *rpt); |
| 97 | void log_sender_capabilities(struct sender_state *s); |
| 98 | STREAM_CAPABILITIES convert_stream_version_to_capabilities(int32_t version, struct rrdhost *host, bool sender); |
| 99 | int32_t stream_capabilities_to_vn(uint32_t caps); |
| 100 | STREAM_CAPABILITIES stream_our_capabilities(struct rrdhost *host, bool sender); |
| 101 | |
| 102 | void check_local_streaming_capabilities(void); |
| 103 | |
| 104 | #endif //NETDATA_STREAM_CAPABILITIES_H |