facets.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // SPDX-License-Identifier: GPL-3.0-or-later
  2. #ifndef FACETS_H
  3. #define FACETS_H 1
  4. #include "../libnetdata.h"
  5. #define FACET_VALUE_UNSET "-"
  6. #define FACET_VALUE_UNSAMPLED "[unsampled]"
  7. #define FACET_VALUE_ESTIMATED "[estimated]"
  8. typedef enum __attribute__((packed)) {
  9. FACETS_ANCHOR_DIRECTION_FORWARD,
  10. FACETS_ANCHOR_DIRECTION_BACKWARD,
  11. } FACETS_ANCHOR_DIRECTION;
  12. typedef enum __attribute__((packed)) {
  13. FACETS_TRANSFORM_VALUE,
  14. FACETS_TRANSFORM_HISTOGRAM,
  15. FACETS_TRANSFORM_FACET,
  16. FACETS_TRANSFORM_DATA,
  17. FACETS_TRANSFORM_FACET_SORT,
  18. } FACETS_TRANSFORMATION_SCOPE;
  19. typedef enum __attribute__((packed)) {
  20. FACET_KEY_OPTION_FACET = (1 << 0), // filterable values
  21. FACET_KEY_OPTION_NO_FACET = (1 << 1), // non-filterable value
  22. FACET_KEY_OPTION_NEVER_FACET = (1 << 2), // never enable this field as facet
  23. FACET_KEY_OPTION_STICKY = (1 << 3), // should be sticky in the table
  24. FACET_KEY_OPTION_VISIBLE = (1 << 4), // should be in the default table
  25. FACET_KEY_OPTION_FTS = (1 << 5), // the key is filterable by full text search (FTS)
  26. FACET_KEY_OPTION_MAIN_TEXT = (1 << 6), // full width and wrap
  27. FACET_KEY_OPTION_RICH_TEXT = (1 << 7),
  28. FACET_KEY_OPTION_REORDER = (1 << 8), // give the key a new order id on first encounter
  29. FACET_KEY_OPTION_TRANSFORM_VIEW = (1 << 9), // when registering the transformation, do it only at the view, not on all data
  30. FACET_KEY_OPTION_EXPANDED_FILTER = (1 << 10), // the presentation should have this filter expanded by default
  31. } FACET_KEY_OPTIONS;
  32. typedef enum __attribute__((packed)) {
  33. FACET_ROW_SEVERITY_DEBUG, // lowest - not important
  34. FACET_ROW_SEVERITY_NORMAL, // the default
  35. FACET_ROW_SEVERITY_NOTICE, // bold
  36. FACET_ROW_SEVERITY_WARNING, // yellow + bold
  37. FACET_ROW_SEVERITY_CRITICAL, // red + bold
  38. } FACET_ROW_SEVERITY;
  39. typedef struct facet_row_key_value {
  40. const char *tmp;
  41. uint32_t tmp_len;
  42. bool empty;
  43. BUFFER *wb;
  44. } FACET_ROW_KEY_VALUE;
  45. typedef struct facet_row {
  46. usec_t usec;
  47. DICTIONARY *dict;
  48. FACET_ROW_SEVERITY severity;
  49. struct facet_row *prev, *next;
  50. } FACET_ROW;
  51. typedef struct facets FACETS;
  52. typedef struct facet_key FACET_KEY;
  53. typedef void (*facets_key_transformer_t)(FACETS *facets __maybe_unused, BUFFER *wb, FACETS_TRANSFORMATION_SCOPE scope, void *data);
  54. typedef void (*facet_dynamic_row_t)(FACETS *facets, BUFFER *json_array, FACET_ROW_KEY_VALUE *rkv, FACET_ROW *row, void *data);
  55. typedef FACET_ROW_SEVERITY (*facet_row_severity_t)(FACETS *facets, FACET_ROW *row, void *data);
  56. FACET_KEY *facets_register_dynamic_key_name(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facet_dynamic_row_t cb, void *data);
  57. FACET_KEY *facets_register_key_name_transformation(FACETS *facets, const char *key, FACET_KEY_OPTIONS options, facets_key_transformer_t cb, void *data);
  58. void facets_register_row_severity(FACETS *facets, facet_row_severity_t cb, void *data);
  59. typedef enum __attribute__((packed)) {
  60. FACETS_OPTION_ALL_FACETS_VISIBLE = (1 << 0), // all facets should be visible by default in the table
  61. FACETS_OPTION_ALL_KEYS_FTS = (1 << 1), // all keys are searchable by full text search
  62. FACETS_OPTION_DONT_SEND_FACETS = (1 << 2), // "facets" object will not be included in the report
  63. FACETS_OPTION_DONT_SEND_HISTOGRAM = (1 << 3), // "histogram" object will not be included in the report
  64. FACETS_OPTION_DATA_ONLY = (1 << 4),
  65. FACETS_OPTION_DONT_SEND_EMPTY_VALUE_FACETS = (1 << 5), // empty facet values will not be included in the report
  66. FACETS_OPTION_SORT_FACETS_ALPHABETICALLY = (1 << 6),
  67. FACETS_OPTION_SHOW_DELTAS = (1 << 7),
  68. } FACETS_OPTIONS;
  69. FACETS *facets_create(uint32_t items_to_return, FACETS_OPTIONS options, const char *visible_keys, const char *facet_keys, const char *non_facet_keys);
  70. void facets_destroy(FACETS *facets);
  71. void facets_accepted_param(FACETS *facets, const char *param);
  72. void facets_rows_begin(FACETS *facets);
  73. bool facets_row_finished(FACETS *facets, usec_t usec);
  74. void facets_row_finished_unsampled(FACETS *facets, usec_t usec);
  75. void facets_update_estimations(FACETS *facets, usec_t from_ut, usec_t to_ut, size_t entries);
  76. size_t facets_histogram_slots(FACETS *facets);
  77. FACET_KEY *facets_register_key_name(FACETS *facets, const char *key, FACET_KEY_OPTIONS options);
  78. void facets_set_query(FACETS *facets, const char *query);
  79. void facets_set_items(FACETS *facets, uint32_t items);
  80. void facets_set_anchor(FACETS *facets, usec_t start_ut, usec_t stop_ut, FACETS_ANCHOR_DIRECTION direction);
  81. void facets_enable_slice_mode(FACETS *facets);
  82. bool facets_row_candidate_to_keep(FACETS *facets, usec_t usec);
  83. FACET_KEY *facets_register_facet_id(FACETS *facets, const char *key_id, FACET_KEY_OPTIONS options);
  84. void facets_register_facet_id_filter(FACETS *facets, const char *key_id, char *value_id, FACET_KEY_OPTIONS options);
  85. void facets_set_timeframe_and_histogram_by_id(FACETS *facets, const char *key_id, usec_t after_ut, usec_t before_ut);
  86. void facets_set_timeframe_and_histogram_by_name(FACETS *facets, const char *key_name, usec_t after_ut, usec_t before_ut);
  87. void facets_add_key_value(FACETS *facets, const char *key, const char *value);
  88. void facets_add_key_value_length(FACETS *facets, const char *key, size_t key_len, const char *value, size_t value_len);
  89. void facets_report(FACETS *facets, BUFFER *wb, DICTIONARY *used_hashes_registry);
  90. void facets_accepted_parameters_to_json_array(FACETS *facets, BUFFER *wb, bool with_keys);
  91. void facets_set_current_row_severity(FACETS *facets, FACET_ROW_SEVERITY severity);
  92. void facets_set_additional_options(FACETS *facets, FACETS_OPTIONS options);
  93. bool facets_key_name_is_filter(FACETS *facets, const char *key);
  94. bool facets_key_name_is_facet(FACETS *facets, const char *key);
  95. bool facets_key_name_value_length_is_selected(FACETS *facets, const char *key, size_t key_length, const char *value, size_t value_length);
  96. void facets_add_possible_value_name_to_key(FACETS *facets, const char *key, size_t key_length, const char *value, size_t value_length);
  97. void facets_sort_and_reorder_keys(FACETS *facets);
  98. usec_t facets_row_oldest_ut(FACETS *facets);
  99. usec_t facets_row_newest_ut(FACETS *facets);
  100. uint32_t facets_rows(FACETS *facets);
  101. void facets_table_config(BUFFER *wb);
  102. const char *facets_severity_to_string(FACET_ROW_SEVERITY severity);
  103. #endif