Skip to content

Commit 2118762

Browse files
Structure for negative filter logstorage (#557)
Add 2 optional fields for excluded applications and contexts Store value of these fields from config file Filter message base on excluded applications and contexts Logstorage does not support both multiple excluded applications and contexts Check applications and contexts from message, if they existed in excluded list the message will be not stored in logstorage buffer Unit test update for negative filter + Add test suites for new functions + Add test cases for modification in current implementation + Update bash script for offline logstorage test Update documentation to introduce negative filter + Add sequence diagram for negative filter + Add activity datagram for negative filter + Write description for negative filter in logstorage documentation + Write guideline for using negative filtern Improvement for negative filter unit test + Add strncmp for checking success id storing process + Add comments for calloc functions to initialize config pointer Initialize pointers in test suites + Add 3 more test scenarios for negative filter + Set unused excluded_apid/ctids fields to NULL Signed-off-by: LUU QUANG MINH <[email protected]> Co-authored-by: Le Tin <[email protected]>
1 parent 86fb853 commit 2118762

File tree

6 files changed

+460
-13
lines changed

6 files changed

+460
-13
lines changed

doc/dlt_offline_logstorage.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,56 @@ the clients are able to update any log level to user contexts.
336336

337337
By setting ```MaintainLogstorageLogLevel=ON``` or ```MaintainLogstorageLogLevel=1```
338338
or not set, the logstorage will maintain its log level as the highest priority.
339+
340+
## Logstorage Negative Filter
341+
342+
The DLT Logstorage also provides negative filter feature, which allows filtering
343+
unwanted Application or Context.
344+
345+
The following strategies are implemented:
346+
- Exclude a pair of Application and Context
347+
348+
```
349+
[FILTER1]
350+
...
351+
ExcludedLogAppName=LOG
352+
ExcludedContextName=TEST
353+
```
354+
- Exclude single Application or list of Applications
355+
356+
```
357+
[FILTER1]
358+
...
359+
ExcludedLogAppName=LOG
360+
361+
[FILTER2]
362+
...
363+
ExcludedLogAppName=LOG1,LOG2,LOG3
364+
```
365+
- Exclude single Context or list of Contexts
366+
367+
```
368+
[FILTER1]
369+
...
370+
ExcludedContextName=TEST
371+
372+
[FILTER2]
373+
...
374+
ExcludedContextName=TEST1,TEST2,TEST3
375+
```
376+
377+
Note :
378+
379+
DLT offline logstorage does not support multiple Application and multiple Context filter.
380+
The following configuration is not supported and the behavior will be undefinded:
381+
```
382+
[FILTER1]
383+
...
384+
LogAppName=LOG1,LOG2,LOG3
385+
ContextName=TEST1,TEST2,TEST3
386+
387+
[FILTER2]
388+
...
389+
ExcludedLogAppName=LOG1,LOG2,LOG3
390+
ExcludedContextName=TEST1,TEST2,TEST3
391+
```

src/offlinelogstorage/dlt_offline_logstorage.c

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,16 @@ DLT_STATIC void dlt_logstorage_filter_config_free(DltLogStorageFilterConfig *dat
5656
data->ctids = NULL;
5757
}
5858

59+
if (data->excluded_apids) {
60+
free(data->excluded_apids);
61+
data->excluded_apids = NULL;
62+
}
63+
64+
if (data->excluded_ctids) {
65+
free(data->excluded_ctids);
66+
data->excluded_ctids = NULL;
67+
}
68+
5969
if (data->file_name) {
6070
free(data->file_name);
6171
data->file_name = NULL;
@@ -162,6 +172,12 @@ DLT_STATIC int dlt_logstorage_list_add_config(DltLogStorageFilterConfig *data,
162172
if (data->ctids != NULL)
163173
(*listdata)->ctids = strdup(data->ctids);
164174

175+
if (data->excluded_apids != NULL)
176+
(*listdata)->excluded_apids = strdup(data->excluded_apids);
177+
178+
if (data->excluded_ctids != NULL)
179+
(*listdata)->excluded_ctids = strdup(data->excluded_ctids);
180+
165181
if (data->file_name != NULL)
166182
(*listdata)->file_name = strdup(data->file_name);
167183

@@ -529,6 +545,45 @@ DLT_STATIC int dlt_logstorage_get_keys_list(char *ids, char *sep, char **list,
529545
return 0;
530546
}
531547

548+
DLT_STATIC bool dlt_logstorage_check_excluded_ids(char *id, char *delim, char *excluded_ids)
549+
{
550+
char *token = NULL;
551+
char *tmp_token = NULL;
552+
char *ids_local = NULL;
553+
554+
if ((id == NULL) || (delim == NULL) || (excluded_ids == NULL)) {
555+
dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
556+
return false;
557+
}
558+
559+
ids_local = strdup(excluded_ids);
560+
561+
if (ids_local == NULL) {
562+
dlt_vlog(LOG_ERR, "%s: Cannot duplicate string.\n", __func__);
563+
return false;
564+
}
565+
566+
token = strtok_r(ids_local, delim, &tmp_token);
567+
568+
if (token == NULL) {
569+
dlt_vlog(LOG_ERR, "%s: %s could not be parsed.\n", __func__, ids_local);
570+
free(ids_local);
571+
return false;
572+
}
573+
574+
while (token != NULL) {
575+
if(strncmp(id, token, DLT_ID_SIZE) == 0) {
576+
free(ids_local);
577+
return true;
578+
}
579+
580+
token = strtok_r(NULL, delim, &tmp_token);
581+
}
582+
583+
free(ids_local);
584+
return false;
585+
}
586+
532587
/**
533588
* dlt_logstorage_create_keys_only_ctid
534589
*
@@ -969,6 +1024,28 @@ DLT_STATIC int dlt_logstorage_check_ctids(DltLogStorageFilterConfig *config,
9691024
return dlt_logstorage_read_list_of_names(&config->ctids, (const char*)value);
9701025
}
9711026

1027+
DLT_STATIC int dlt_logstorage_store_config_excluded_apids(DltLogStorageFilterConfig *config,
1028+
char *value)
1029+
{
1030+
if ((config == NULL) || (value == NULL)) {
1031+
dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
1032+
return -1;
1033+
}
1034+
1035+
return dlt_logstorage_read_list_of_names(&config->excluded_apids, value);
1036+
}
1037+
1038+
DLT_STATIC int dlt_logstorage_store_config_excluded_ctids(DltLogStorageFilterConfig *config,
1039+
char *value)
1040+
{
1041+
if ((config == NULL) || (value == NULL)) {
1042+
dlt_vlog(LOG_ERR, "%s: Invalid parameters\n", __func__);
1043+
return -1;
1044+
}
1045+
1046+
return dlt_logstorage_read_list_of_names(&config->excluded_ctids, (const char*)value);
1047+
}
1048+
9721049
DLT_STATIC int dlt_logstorage_set_loglevel(int *log_level,
9731050
int value)
9741051
{
@@ -1327,6 +1404,16 @@ DLT_STATIC DltLogstorageFilterConf
13271404
.func = dlt_logstorage_check_ctids,
13281405
.is_opt = 1
13291406
},
1407+
[DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = {
1408+
.key = "ExcludedLogAppName",
1409+
.func = dlt_logstorage_store_config_excluded_apids,
1410+
.is_opt = 1
1411+
},
1412+
[DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = {
1413+
.key = "ExcludedContextName",
1414+
.func = dlt_logstorage_store_config_excluded_ctids,
1415+
.is_opt = 1
1416+
},
13301417
[DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = {
13311418
.key = "LogLevel",
13321419
.func = dlt_logstorage_check_loglevel,
@@ -1397,6 +1484,16 @@ DLT_STATIC DltLogstorageFilterConf
13971484
.func = dlt_logstorage_check_ctids,
13981485
.is_opt = 0
13991486
},
1487+
[DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = {
1488+
.key = NULL,
1489+
.func = dlt_logstorage_store_config_excluded_apids,
1490+
.is_opt = 1
1491+
},
1492+
[DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = {
1493+
.key = NULL,
1494+
.func = dlt_logstorage_store_config_excluded_ctids,
1495+
.is_opt = 1
1496+
},
14001497
[DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = {
14011498
.key = NULL,
14021499
.func = dlt_logstorage_check_loglevel,
@@ -1466,6 +1563,16 @@ DLT_STATIC DltLogstorageFilterConf
14661563
.func = dlt_logstorage_check_ctids,
14671564
.is_opt = 0
14681565
},
1566+
[DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME] = {
1567+
.key = NULL,
1568+
.func = dlt_logstorage_store_config_excluded_apids,
1569+
.is_opt = 1
1570+
},
1571+
[DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME] = {
1572+
.key = NULL,
1573+
.func = dlt_logstorage_store_config_excluded_ctids,
1574+
.is_opt = 1
1575+
},
14691576
[DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL] = {
14701577
.key = "LogLevel",
14711578
.func = dlt_logstorage_check_loglevel,
@@ -1685,6 +1792,16 @@ DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle,
16851792
tmp_data.ctids = NULL;
16861793
}
16871794

1795+
if (tmp_data.excluded_apids != NULL) {
1796+
free(tmp_data.excluded_apids);
1797+
tmp_data.excluded_apids = NULL;
1798+
}
1799+
1800+
if (tmp_data.excluded_ctids != NULL) {
1801+
free(tmp_data.excluded_ctids);
1802+
tmp_data.excluded_ctids = NULL;
1803+
}
1804+
16881805
if (tmp_data.file_name != NULL) {
16891806
free(tmp_data.file_name);
16901807
tmp_data.file_name = NULL;
@@ -1704,6 +1821,11 @@ DLT_STATIC int dlt_daemon_offline_setup_filter_properties(DltLogStorage *handle,
17041821
}
17051822
}
17061823

1824+
if(dlt_logstorage_count_ids(tmp_data.excluded_apids) > 1 && dlt_logstorage_count_ids(tmp_data.excluded_ctids) > 1) {
1825+
dlt_vlog(LOG_WARNING, "%s: Logstorage does not support both multiple excluded applications and contexts\n", __func__);
1826+
return DLT_OFFLINE_LOGSTORAGE_FILTER_ERROR;
1827+
}
1828+
17071829
/* filter configuration is valid */
17081830
ret = dlt_logstorage_setup_table(handle, &tmp_data);
17091831

@@ -2339,6 +2461,33 @@ DLT_STATIC int dlt_logstorage_filter(DltLogStorage *handle,
23392461
"%s: ECUID does not match (Requested=%s, config[%d]=%s). Set the config to NULL and continue the filter loop\n",
23402462
__func__, ecuid, i, config[i]->ecuid);
23412463
config[i] = NULL;
2464+
continue;
2465+
}
2466+
}
2467+
2468+
if(config[i]->excluded_apids != NULL && config[i]->excluded_ctids != NULL) {
2469+
/* Filter on excluded application and context */
2470+
if(apid != NULL && ctid != NULL && dlt_logstorage_check_excluded_ids(apid, ",", config[i]->excluded_apids)
2471+
&& dlt_logstorage_check_excluded_ids(ctid, ",", config[i]->excluded_ctids)) {
2472+
dlt_vlog(LOG_DEBUG, "%s: %s matches with [%s] and %s matches with [%s]. Set the config to NULL and continue the filter loop\n",
2473+
__func__, apid, config[i]->excluded_apids, ctid, config[i]->excluded_ctids);
2474+
config[i] = NULL;
2475+
}
2476+
}
2477+
else if(config[i]->excluded_apids == NULL) {
2478+
/* Only filter on excluded contexts */
2479+
if(ctid != NULL && config[i]->excluded_ctids != NULL && dlt_logstorage_check_excluded_ids(ctid, ",", config[i]->excluded_ctids)) {
2480+
dlt_vlog(LOG_DEBUG, "%s: %s matches with [%s]. Set the config to NULL and continue the filter loop\n",
2481+
__func__, ctid, config[i]->excluded_ctids);
2482+
config[i] = NULL;
2483+
}
2484+
}
2485+
else if(config[i]->excluded_ctids == NULL) {
2486+
/* Only filter on excluded applications */
2487+
if(apid != NULL && config[i]->excluded_apids != NULL && dlt_logstorage_check_excluded_ids(apid, ",", config[i]->excluded_apids)) {
2488+
dlt_vlog(LOG_DEBUG, "%s: %s matches with [%s]. Set the config to NULL and continue the filter loop\n",
2489+
__func__, apid, config[i]->excluded_apids);
2490+
config[i] = NULL;
23422491
}
23432492
}
23442493
}

src/offlinelogstorage/dlt_offline_logstorage.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,8 @@ struct DltLogStorageFilterConfig
171171
/* filter section */
172172
char *apids; /* Application IDs configured for filter */
173173
char *ctids; /* Context IDs configured for filter */
174+
char *excluded_apids; /* Excluded Application IDs configured for filter */
175+
char *excluded_ctids; /* Excluded Context IDs configured for filter */
174176
int log_level; /* Log level number configured for filter */
175177
int reset_log_level; /* reset Log level to be sent on disconnect */
176178
char *file_name; /* File name for log storage configured for filter */
@@ -265,6 +267,8 @@ typedef struct {
265267
typedef enum {
266268
DLT_LOGSTORAGE_FILTER_CONF_LOGAPPNAME = 0,
267269
DLT_LOGSTORAGE_FILTER_CONF_CONTEXTNAME,
270+
DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_LOGAPPNAME,
271+
DLT_LOGSTORAGE_FILTER_CONF_EXCLUDED_CONTEXTNAME,
268272
DLT_LOGSTORAGE_FILTER_CONF_LOGLEVEL,
269273
DLT_LOGSTORAGE_FILTER_CONF_RESET_LOGLEVEL,
270274
DLT_LOGSTORAGE_FILTER_CONF_FILE,

src/offlinelogstorage/dlt_offline_logstorage_internal.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,12 @@ DLT_STATIC int dlt_logstorage_check_apids(DltLogStorageFilterConfig *config, cha
7676

7777
DLT_STATIC int dlt_logstorage_check_ctids(DltLogStorageFilterConfig *config, char *value);
7878

79+
DLT_STATIC int dlt_logstorage_store_config_excluded_apids(DltLogStorageFilterConfig *config, char *value);
80+
81+
DLT_STATIC int dlt_logstorage_store_config_excluded_ctids(DltLogStorageFilterConfig *config, char *value);
82+
83+
DLT_STATIC bool dlt_logstorage_check_excluded_ids(char *id, char *delim, char *excluded_ids);
84+
7985
DLT_STATIC int dlt_logstorage_check_loglevel(DltLogStorageFilterConfig *config, char *value);
8086

8187
DLT_STATIC int dlt_logstorage_check_gzip_compression(DltLogStorageFilterConfig *config, char *value);

0 commit comments

Comments
 (0)