@cryptotaxi247 / netdata-1 / commits / 8479be80c

Simplify parser README.md and add parser files to CMakeLists.txt (#14523)

Add parser in CMakeLists.txt Keep minimal documentation (overview) and refer to the actual code

Stelios Fragkakis committed Feb 14, 2023 at 19:48 UTC 8479be80c9ae1957b0e129c133f000e3460404f4
2 files changed +14 -148
CMakeLists.txt
+2 -6
@@ -512,6 +512,8 @@ set(LIBNETDATA_FILES
512 libnetdata/string/utf8.h
513 libnetdata/worker_utilization/worker_utilization.c
514 libnetdata/worker_utilization/worker_utilization.h
515 + libnetdata/parser/parser.h
516 + libnetdata/parser/parser.c
517 )
518
519 IF(ENABLE_PLUGIN_EBPF)
@@ -695,11 +697,6 @@ set(PLUGINSD_PLUGIN_FILES
697 collectors/plugins.d/pluginsd_parser.h
698 )
699
698 -set(PARSER_PLUGIN_FILES
699 - parser/parser.c
700 - parser/parser.h
701 - )
702 -
700 set(REGISTRY_PLUGIN_FILES
701 registry/registry.c
702 registry/registry.h
@@ -1077,7 +1074,6 @@ set(NETDATA_FILES
1074 ${WEB_PLUGIN_FILES}
1075 ${CLAIM_PLUGIN_FILES}
1076 ${SPAWN_PLUGIN_FILES}
1080 - ${PARSER_PLUGIN_FILES}
1077 )
1078
1079 set(NETDATACLI_FILES
libnetdata/parser/README.md
+12 -142
@@ -7,150 +7,20 @@ learn_topic_type: "References"
7 learn_rel_path: "Developers/Database"
8 -->
9
10 -
10 #### Introduction
11
13 -The parser will be used to process streaming and plugins input as well as metadata
14 -
15 -Usage
16 -
17 -1. Define a structure that will be used to share user state across calls
18 -1. Initialize the parser using `parser_init`
19 -2. Register keywords and associated callback function using `parser_add_keyword`
20 -3. Register actions on the keywords
21 -4. Start a loop until EOF
22 - 1. Fetch the next line using `parser_next`
23 - 2. Process the line using `parser_action`
24 - 1. The registered callbacks are executed to parse the input
25 - 2. The registered action for the callback is called for processing
26 -4. Release the parser using `parser_destroy`
27 -5. Release the user structure
28 -
29 -#### Functions
30 -
31 -TODO:
32 -
33 -##### parse_init(RRDHOST *host, void *user, void *input, int flags)
34 -
35 -Initialize an internal parser with the specified user defined data structure that will be shared across calls.
36 -
37 -Input
38 -- Host
39 - - The host this parser will be dealing with. For streaming with SSL enabled for this host
40 -- user
41 - - User defined structure that is passed in all the calls
42 -- input
43 - - Where the parser will get the input from
44 -- flags
45 - - flags to define processing on the input
46 -
47 -Output
48 -- A parser structure
49 -
50 -
51 -
52 -##### parse_push(PARSER *parser, char *line)
53 -
54 -Push a new line for processing
55 -
56 -Input
57 -
58 -- parser
59 - - The parser object as returned by the `parser_init`
60 -- line
61 - - The new line to process
62 -
63 -
64 -Output
65 -- The line will be injected into the stream and will be the next one to be processed
66 -
67 -Returns
68 -- 0 line added
69 -- 1 error detected
70 -
71 -
72 -##### parse_add_keyword(PARSER *parser, char *keyword, keyword_function callback_function)
73 -
74 -The function will add callbacks for keywords. The callback function is defined as
75 -
76 -`typedef PARSER_RC (*keyword_function)(char **, void *);`
77 -
78 -Input
79 -
80 -- parser
81 - - The parser object as returned by the `parser_init`
82 -- keyword
83 - - The keyword to register
84 -- keyword_function
85 - - The callback that will handle the keyword processing
86 - * The callback function should return one of the following
87 - * PARSER_RC_OK - Callback was successful (continue with other callbacks)
88 - * PARSER_RC_STOP - Stop processing callbacks (return OK)
89 - * PARSER_RC_ERROR - Callback failed, exit
90 -
91 -Output
92 -- The corresponding keyword and callback will be registered
93 -
94 -Returns
95 -- 0 maximum callbacks already registered for this keyword
96 -- > 0 which is the number of callbacks associated with this keyword.
97 -
98 -
99 -##### parser_next(PARSER *parser)
100 -Return the next item to parse
101 -
102 -Input
103 -- parser
104 - - The parser object as returned by the `parser_init`
105 -
106 -Output
107 -- The parser will store internally the next item to parse
108 -
109 -Returns
110 -- 0 Next item fetched successfully
111 -- 1 No more items to parse
112 -
113 -
114 -##### parser_action(PARSER *parser, char *input)
115 -Return the next item to parse
116 -
117 -Input
118 -- parser
119 - - The parser object as returned by the `parser_init`
120 -- input
121 - - Process the input specified instead of using the internal buffer
122 -
123 -Output
124 -- The current keyword will be processed by calling all the registered callbacks
125 -
126 -Returns
127 -- 0 Callbacks called successfully
128 -- 1 Failed
129 -
130 -
131 -##### parser_destroy(PARSER *parser)
132 -Cleanup a previously allocated parser
133 -
134 -Input
135 -- parser
136 - - The parser object as returned by the `parser_init`
137 -
138 -Output
139 -- The parser is deallocated
140 -
141 -Returns
142 -- none
143 -
12 +Generic parser that is used to register keywords and a corresponding function that will be executed when that
13 +keyword is encountered in the command stream (either from plugins or via streaming)
14
145 -##### parser_recover_input(PARSER *parser)
146 -Cleanup a previously allocated parser
15 +To use a parser do the following:
16
148 -Input
149 -- parser
150 - - The parser object as returned by the `parser_init`
151 -
152 -Output
153 -- The parser is deallocated
17 +1. Define a structure that will be used to share user state across calls (user defined `void *user`)
18 +2. Initialize the parser using `parser_init`
19 +3. Register keywords with their associated callback function using `parser_add_keyword`
20 +4. Start a loop for as long there is input (or parser_action returns error)
21 + 1. Fetch the next line using `parser_next` (if needed)
22 + 2. Process the line using `parser_action`
23 +5. Release the parser using `parser_destroy`
24 +6. Release the user structure
25
155 -Returns
156 -- none
26 +See examples in receiver.c / pluginsd_parser.c