@cryptotaxi247 / netdata-1 / commits / 7b3308390

SUBSTRING simple patterns fix (#16264)

* when in substring matches, do not expect an asterisk at the end of the pattern * fix substring matches in simple patterns; allow negative searches in facets

Costa Tsaousis committed Oct 24, 2023 at 00:14 UTC 7b3308390ab501efeaaf2a32eb7cccadaa2bbc3e
2 files changed +28 -7
libnetdata/facets/facets.c
+20 -7
@@ -307,7 +307,8 @@ struct facets {
307
308 struct {
309 FACET_ROW_SEVERITY severity;
310 - size_t keys_matched_by_query; // the number of fields matched the full text search (per row)
310 + size_t keys_matched_by_query_positive; // the number of fields matched the full text search (per row)
311 + size_t keys_matched_by_query_negative; // the number of fields matched the full text search (per row)
312 } current_row;
313
314 struct {
@@ -1583,8 +1584,18 @@ static inline void facets_key_check_value(FACETS *facets, FACET_KEY *k) {
1584 if(facets->query && !facet_key_value_empty(k) && ((k->options & FACET_KEY_OPTION_FTS) || facets->options & FACETS_OPTION_ALL_KEYS_FTS)) {
1585 facets->operations.fts.searches++;
1586 facets_key_value_copy_to_buffer(k);
1586 - if(simple_pattern_matches(facets->query, buffer_tostring(k->current_value.b)))
1587 - facets->current_row.keys_matched_by_query++;
1587 + switch(simple_pattern_matches_extract(facets->query, buffer_tostring(k->current_value.b), NULL, 0)) {
1588 + case SP_MATCHED_POSITIVE:
1589 + facets->current_row.keys_matched_by_query_positive++;
1590 + break;
1591 +
1592 + case SP_MATCHED_NEGATIVE:
1593 + facets->current_row.keys_matched_by_query_negative++;
1594 + break;
1595 +
1596 + case SP_NOT_MATCHED:
1597 + break;
1598 + }
1599 }
1600
1601 if(k->values.enabled)
@@ -1844,7 +1855,8 @@ static void facets_reset_keys_with_value_and_row(FACETS *facets) {
1855 }
1856
1857 facets->current_row.severity = FACET_ROW_SEVERITY_NORMAL;
1847 - facets->current_row.keys_matched_by_query = 0;
1858 + facets->current_row.keys_matched_by_query_positive = 0;
1859 + facets->current_row.keys_matched_by_query_negative = 0;
1860 facets->keys_in_row.used = 0;
1861 }
1862
@@ -1862,9 +1874,10 @@ void facets_rows_begin(FACETS *facets) {
1874 bool facets_row_finished(FACETS *facets, usec_t usec) {
1875 facets->operations.rows.evaluated++;
1876
1865 - if(unlikely((facets->query && facets->keys_filtered_by_query && !facets->current_row.keys_matched_by_query) ||
1866 - (facets->timeframe.before_ut && usec > facets->timeframe.before_ut) ||
1867 - (facets->timeframe.after_ut && usec < facets->timeframe.after_ut))) {
1877 + if(unlikely((facets->query && facets->keys_filtered_by_query &&
1878 + (!facets->current_row.keys_matched_by_query_positive || facets->current_row.keys_matched_by_query_negative)) ||
1879 + (facets->timeframe.before_ut && usec > facets->timeframe.before_ut) ||
1880 + (facets->timeframe.after_ut && usec < facets->timeframe.after_ut))) {
1881 // this row is not useful
1882 // 1. not matched by full text search, or
1883 // 2. not in our timeframe
libnetdata/simple_pattern/simple_pattern.c
+8
@@ -144,6 +144,14 @@ SIMPLE_PATTERN *simple_pattern_create(const char *list, const char *separators,
144 m->negative = negative;
145 m->case_sensitive = case_sensitive;
146
147 + if(default_mode == SIMPLE_PATTERN_SUBSTRING) {
148 + m->mode = SIMPLE_PATTERN_SUBSTRING;
149 +
150 + struct simple_pattern *tm = m;
151 + for(tm = m; tm->child ; tm = tm->child) ;
152 + tm->mode = SIMPLE_PATTERN_SUBSTRING;
153 + }
154 +
155 // link it at the end
156 if(unlikely(!root))
157 root = last = m;