diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2023-08-25 09:43:06 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-25 09:43:06 +0300 |
commit | b194954ff59488b1f86dbc81a08532817170048f (patch) | |
tree | 63034a5c6433d827ecd4c6f08a0933a6cbcc14c1 /libnetdata | |
parent | 05a83fed3db898e6bf6c5215b79d65b4d1ee758b (diff) |
allow any field to be a facet (#15880)
Diffstat (limited to 'libnetdata')
-rw-r--r-- | libnetdata/facets/facets.c | 25 | ||||
-rw-r--r-- | libnetdata/facets/facets.h | 9 |
2 files changed, 21 insertions, 13 deletions
diff --git a/libnetdata/facets/facets.c b/libnetdata/facets/facets.c index eb20bf25d9..ea5831873a 100644 --- a/libnetdata/facets/facets.c +++ b/libnetdata/facets/facets.c @@ -841,7 +841,7 @@ void facets_accepted_param(FACETS *facets, const char *param) { dictionary_set(facets->accepted_params, param, NULL, 0); } -inline FACET_KEY *facets_register_key(FACETS *facets, const char *key, FACET_KEY_OPTIONS options) { +inline FACET_KEY *facets_register_key_name(FACETS *facets, const char *key, FACET_KEY_OPTIONS options) { FACET_KEY tk = { .name = key, .options = options, @@ -852,15 +852,15 @@ inline FACET_KEY *facets_register_key(FACETS *facets, const char *key, FACET_KEY return dictionary_set(facets->keys, hash, &tk, sizeof(tk)); } -inline FACET_KEY *facets_register_key_transformation(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facets_key_transformer_t cb, void *data) { - FACET_KEY *k = facets_register_key(facets, key, options); +inline FACET_KEY *facets_register_key_name_transformation(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facets_key_transformer_t cb, void *data) { + FACET_KEY *k = facets_register_key_name(facets, key, options); k->transform.cb = cb; k->transform.data = data; return k; } -inline FACET_KEY *facets_register_dynamic_key(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facet_dynamic_row_t cb, void *data) { - FACET_KEY *k = facets_register_key(facets, key, options); +inline FACET_KEY *facets_register_dynamic_key_name(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facet_dynamic_row_t cb, void *data) { + FACET_KEY *k = facets_register_key_name(facets, key, options); k->dynamic.cb = cb; k->dynamic.data = data; return k; @@ -881,17 +881,24 @@ void facets_set_anchor(FACETS *facets, usec_t anchor) { facets->anchor = anchor; } -void facets_register_facet_filter(FACETS *facets, const char *key_id, char *value_ids, FACET_KEY_OPTIONS options) { +inline FACET_KEY *facets_register_facet_id(FACETS *facets, const char *key_id, FACET_KEY_OPTIONS options) { FACET_KEY tk = { .options = options, + .default_selected_for_values = true, }; FACET_KEY *k = dictionary_set(facets->keys, key_id, &tk, sizeof(tk)); - k->default_selected_for_values = false; k->options |= FACET_KEY_OPTION_FACET; k->options &= ~FACET_KEY_OPTION_NO_FACET; facet_key_late_init(facets, k); + return k; +} + +void facets_register_facet_id_filter(FACETS *facets, const char *key_id, char *value_ids, FACET_KEY_OPTIONS options) { + FACET_KEY *k = facets_register_facet_id(facets, key_id, options); + k->default_selected_for_values = false; + FACET_VALUE tv = { .selected = true, }; @@ -935,7 +942,7 @@ static inline void facets_check_value(FACETS *facets __maybe_unused, FACET_KEY * } void facets_add_key_value(FACETS *facets, const char *key, const char *value) { - FACET_KEY *k = facets_register_key(facets, key, 0); + FACET_KEY *k = facets_register_key_name(facets, key, 0); buffer_flush(k->current_value.b); buffer_strcat(k->current_value.b, value); k->current_value.updated = true; @@ -944,7 +951,7 @@ void facets_add_key_value(FACETS *facets, const char *key, const char *value) { } void facets_add_key_value_length(FACETS *facets, const char *key, const char *value, size_t value_len) { - FACET_KEY *k = facets_register_key(facets, key, 0); + FACET_KEY *k = facets_register_key_name(facets, key, 0); buffer_flush(k->current_value.b); buffer_strncat(k->current_value.b, value, value_len); k->current_value.updated = true; diff --git a/libnetdata/facets/facets.h b/libnetdata/facets/facets.h index 0943083f59..2933a020fb 100644 --- a/libnetdata/facets/facets.h +++ b/libnetdata/facets/facets.h @@ -34,8 +34,8 @@ void facets_string_hash(const char *src, size_t len, char *out); typedef void (*facets_key_transformer_t)(FACETS *facets __maybe_unused, BUFFER *wb, void *data); typedef void (*facet_dynamic_row_t)(FACETS *facets, BUFFER *json_array, FACET_ROW_KEY_VALUE *rkv, FACET_ROW *row, void *data); -FACET_KEY *facets_register_dynamic_key(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facet_dynamic_row_t cb, void *data); -FACET_KEY *facets_register_key_transformation(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facets_key_transformer_t cb, void *data); +FACET_KEY *facets_register_dynamic_key_name(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facet_dynamic_row_t cb, void *data); +FACET_KEY *facets_register_key_name_transformation(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facets_key_transformer_t cb, void *data); typedef enum __attribute__((packed)) { FACETS_OPTION_ALL_FACETS_VISIBLE = (1 << 0), // all facets, should be visible by default in the table @@ -50,11 +50,12 @@ void facets_accepted_param(FACETS *facets, const char *param); void facets_rows_begin(FACETS *facets); void facets_row_finished(FACETS *facets, usec_t usec); -FACET_KEY *facets_register_key(FACETS *facets, const char *param, FACET_KEY_OPTIONS options); +FACET_KEY *facets_register_key_name(FACETS *facets, const char *key, FACET_KEY_OPTIONS options); void facets_set_query(FACETS *facets, const char *query); void facets_set_items(FACETS *facets, uint32_t items); void facets_set_anchor(FACETS *facets, usec_t anchor); -void facets_register_facet_filter(FACETS *facets, const char *key_id, char *value_ids, FACET_KEY_OPTIONS options); +FACET_KEY *facets_register_facet_id(FACETS *facets, const char *key_id, FACET_KEY_OPTIONS options); +void facets_register_facet_id_filter(FACETS *facets, const char *key_id, char *value_ids, FACET_KEY_OPTIONS options); void facets_set_histogram(FACETS *facets, const char *chart, usec_t after_ut, usec_t before_ut); void facets_add_key_value(FACETS *facets, const char *key, const char *value); |