| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef FACETS_H |
| 4 | #define FACETS_H 1 |
| 5 | |
| 6 | #include "../libnetdata.h" |
| 7 | |
| 8 | #define FACET_VALUE_UNSET "-" |
| 9 | #define FACET_VALUE_UNSAMPLED "[unsampled]" |
| 10 | #define FACET_VALUE_ESTIMATED "[estimated]" |
| 11 | |
| 12 | typedef enum __attribute__((packed)) { |
| 13 | FACETS_ANCHOR_DIRECTION_FORWARD, |
| 14 | FACETS_ANCHOR_DIRECTION_BACKWARD, |
| 15 | } FACETS_ANCHOR_DIRECTION; |
| 16 | |
| 17 | typedef enum __attribute__((packed)) { |
| 18 | FACETS_TRANSFORM_VALUE, |
| 19 | FACETS_TRANSFORM_HISTOGRAM, |
| 20 | FACETS_TRANSFORM_FACET, |
| 21 | FACETS_TRANSFORM_DATA, |
| 22 | FACETS_TRANSFORM_FACET_SORT, |
| 23 | } FACETS_TRANSFORMATION_SCOPE; |
| 24 | |
| 25 | typedef enum __attribute__((packed)) { |
| 26 | FACET_KEY_OPTION_NONE = 0, |
| 27 | FACET_KEY_OPTION_FACET = (1 << 0), // filterable values |
| 28 | FACET_KEY_OPTION_NO_FACET = (1 << 1), // non-filterable value |
| 29 | FACET_KEY_OPTION_NEVER_FACET = (1 << 2), // never enable this field as facet |
| 30 | FACET_KEY_OPTION_STICKY = (1 << 3), // should be sticky in the table |
| 31 | FACET_KEY_OPTION_VISIBLE = (1 << 4), // should be in the default table |
| 32 | FACET_KEY_OPTION_FTS = (1 << 5), // the key is filterable by full text search (FTS) |
| 33 | FACET_KEY_OPTION_MAIN_TEXT = (1 << 6), // full width and wrap |
| 34 | FACET_KEY_OPTION_RICH_TEXT = (1 << 7), |
| 35 | FACET_KEY_OPTION_REORDER = (1 << 8), // give the key a new order id on first encounter |
| 36 | FACET_KEY_OPTION_REORDER_DONE = (1 << 9), // done re-ordering for this field |
| 37 | FACET_KEY_OPTION_TRANSFORM_VIEW = (1 << 10), // when registering the transformation, do it only at the view, not on all data |
| 38 | FACET_KEY_OPTION_EXPANDED_FILTER = (1 << 11), // the presentation should have this filter expanded by default |
| 39 | FACET_KEY_OPTION_PRETTY_XML = (1 << 12), // instruct the UI to parse this as an XML document |
| 40 | FACET_KEY_OPTION_HIDDEN = (1 << 13), // do not include this field in the response |
| 41 | FACET_KEY_OPTION_FILTER_ONLY = (1 << 14), // the key is filterable, but not to be exposed as facet |
| 42 | } FACET_KEY_OPTIONS; |
| 43 | |
| 44 | typedef enum __attribute__((packed)) { |
| 45 | FACET_ROW_SEVERITY_DEBUG, // lowest - not important |
| 46 | FACET_ROW_SEVERITY_NORMAL, // the default |
| 47 | FACET_ROW_SEVERITY_NOTICE, // bold |
| 48 | FACET_ROW_SEVERITY_WARNING, // yellow + bold |
| 49 | FACET_ROW_SEVERITY_CRITICAL, // red + bold |
| 50 | } FACET_ROW_SEVERITY; |
| 51 | |
| 52 | typedef struct facet_row_key_value { |
| 53 | const char *tmp; |
| 54 | uint32_t tmp_len; |
| 55 | bool empty; |
| 56 | BUFFER *wb; |
| 57 | } FACET_ROW_KEY_VALUE; |
| 58 | |
| 59 | typedef struct facet_row_bin_data { |
| 60 | void (*cleanup_cb)(void *data); |
| 61 | void *data; |
| 62 | } FACET_ROW_BIN_DATA; |
| 63 | |
| 64 | #define FACET_ROW_BIN_DATA_EMPTY (FACET_ROW_BIN_DATA){.data = NULL, .cleanup_cb = NULL} |
| 65 | |
| 66 | typedef struct facet_row { |
| 67 | usec_t usec; |
| 68 | DICTIONARY *dict; |
| 69 | FACET_ROW_SEVERITY severity; |
| 70 | FACET_ROW_BIN_DATA bin_data; |
| 71 | struct facet_row *prev, *next; |
| 72 | } FACET_ROW; |
| 73 | |
| 74 | typedef struct facets FACETS; |
| 75 | typedef struct facet_key FACET_KEY; |
| 76 | |
| 77 | typedef void (*facets_key_transformer_t)(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope, void *data); |
| 78 | typedef void (*facet_dynamic_row_t)(FACETS *facets, BUFFER *json_array, FACET_ROW_KEY_VALUE *rkv, FACET_ROW *row, void *data); |
| 79 | typedef FACET_ROW_SEVERITY (*facet_row_severity_t)(FACETS *facets, FACET_ROW *row, void *data); |
| 80 | FACET_KEY *facets_register_dynamic_key_name(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facet_dynamic_row_t cb, void *data); |
| 81 | FACET_KEY *facets_register_key_name_transformation(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facets_key_transformer_t cb, void *data); |
| 82 | void facets_register_row_severity(FACETS *facets, facet_row_severity_t cb, void *data); |
| 83 | |
| 84 | typedef enum __attribute__((packed)) { |
| 85 | FACETS_OPTION_ALL_FACETS_VISIBLE = (1 << 0), // all facets should be visible by default in the table |
| 86 | FACETS_OPTION_ALL_KEYS_FTS = (1 << 1), // all keys are searchable by full text search |
| 87 | FACETS_OPTION_DONT_SEND_FACETS = (1 << 2), // "facets" object will not be included in the report |
| 88 | FACETS_OPTION_DONT_SEND_HISTOGRAM = (1 << 3), // "histogram" object will not be included in the report |
| 89 | FACETS_OPTION_DATA_ONLY = (1 << 4), |
| 90 | FACETS_OPTION_DONT_SEND_EMPTY_VALUE_FACETS = (1 << 5), // empty facet values will not be included in the report |
| 91 | FACETS_OPTION_SORT_FACETS_ALPHABETICALLY = (1 << 6), |
| 92 | FACETS_OPTION_SHOW_DELTAS = (1 << 7), |
| 93 | FACETS_OPTION_HASH_IDS = (1 << 8), // when set, the id of the facets, keys and values will be their hash |
| 94 | } FACETS_OPTIONS; |
| 95 | |
| 96 | FACETS *facets_create(uint32_t items_to_return, FACETS_OPTIONS options, const char *visible_keys, const char *facet_keys, const char *non_facet_keys); |
| 97 | void facets_destroy(FACETS *facets); |
| 98 | |
| 99 | void facets_accepted_param(FACETS *facets, const char *param); |
| 100 | |
| 101 | void facets_rows_begin(FACETS *facets); |
| 102 | bool facets_row_finished(FACETS *facets, usec_t usec); |
| 103 | |
| 104 | void facets_row_finished_unsampled(FACETS *facets, usec_t usec); |
| 105 | void facets_update_estimations(FACETS *facets, usec_t from_ut, usec_t to_ut, size_t entries); |
| 106 | size_t facets_histogram_slots(FACETS *facets); |
| 107 | |
| 108 | FACET_KEY *facets_register_key_name(FACETS *facets, const char *key, FACET_KEY_OPTIONS options); |
| 109 | void facets_set_query(FACETS *facets, const char *query); |
| 110 | void facets_set_items(FACETS *facets, uint32_t items); |
| 111 | void facets_set_anchor(FACETS *facets, usec_t start_ut, usec_t stop_ut, FACETS_ANCHOR_DIRECTION direction); |
| 112 | void facets_enable_slice_mode(FACETS *facets); |
| 113 | bool facets_row_candidate_to_keep(FACETS *facets, usec_t usec); |
| 114 | |
| 115 | void facets_reset_and_disable_all_facets(FACETS *facets); |
| 116 | |
| 117 | FACET_KEY *facets_register_facet(FACETS *facets, const char *name, FACET_KEY_OPTIONS options); |
| 118 | FACET_KEY *facets_register_facet_id(FACETS *facets, const char *key_id, FACET_KEY_OPTIONS options); |
| 119 | |
| 120 | void facets_register_facet_filter(FACETS *facets, const char *key, const char *value, FACET_KEY_OPTIONS options); |
| 121 | void facets_register_facet_filter_id(FACETS *facets, const char *key_id, const char *value_id, FACET_KEY_OPTIONS options); |
| 122 | |
| 123 | void facets_set_timeframe_and_histogram_by_id(FACETS *facets, const char *key_id, usec_t after_ut, usec_t before_ut); |
| 124 | void facets_set_timeframe_and_histogram_by_name(FACETS *facets, const char *key_name, usec_t after_ut, usec_t before_ut); |
| 125 | |
| 126 | void facets_add_key_value(FACETS *facets, const char *key, const char *value); |
| 127 | void facets_add_key_value_length(FACETS *facets, const char *key, size_t key_len, const char *value, size_t value_len); |
| 128 | |
| 129 | void facets_report(FACETS *facets, BUFFER *wb, DICTIONARY *used_hashes_registry); |
| 130 | void facets_accepted_parameters_to_json_array(FACETS *facets, BUFFER *wb, bool with_keys); |
| 131 | void facets_set_current_row_severity(FACETS *facets, FACET_ROW_SEVERITY severity); |
| 132 | void facets_set_additional_options(FACETS *facets, FACETS_OPTIONS options); |
| 133 | |
| 134 | bool facets_key_name_is_filter(FACETS *facets, const char *key); |
| 135 | bool facets_key_name_is_facet(FACETS *facets, const char *key); |
| 136 | bool facets_key_name_value_length_is_selected(FACETS *facets, const char *key, size_t key_length, const char *value, size_t value_length); |
| 137 | void facets_add_possible_value_name_to_key(FACETS *facets, const char *key, size_t key_length, const char *value, size_t value_length); |
| 138 | |
| 139 | void facets_sort_and_reorder_keys(FACETS *facets); |
| 140 | usec_t facets_row_oldest_ut(FACETS *facets); |
| 141 | usec_t facets_row_newest_ut(FACETS *facets); |
| 142 | uint32_t facets_rows(FACETS *facets); |
| 143 | |
| 144 | void facets_table_config(FACETS *facets, BUFFER *wb); |
| 145 | |
| 146 | const char *facets_severity_to_string(FACET_ROW_SEVERITY severity); |
| 147 | |
| 148 | typedef bool (*facets_foreach_selected_value_in_key_t)(FACETS *facets, size_t id, const char *key, const char *value, void *data); |
| 149 | bool facets_foreach_selected_value_in_key(FACETS *facets, const char *key, size_t key_length, DICTIONARY *used_hashes_registry, facets_foreach_selected_value_in_key_t cb, void *data); |
| 150 | |
| 151 | void facets_row_bin_data_set(FACETS *facets, void (*cleanup_cb)(void *data), void *data); |
| 152 | void *facets_row_bin_data_get(FACETS *facets __maybe_unused, FACET_ROW *row); |
| 153 | |
| 154 | void facets_use_hashes_for_ids(FACETS *facets, bool set); |
| 155 | |
| 156 | #endif |