Skip to content

Commit 3080584

Browse files
general cleanup
Signed-off-by: Alexa Kreizinger <alexakreizinger@gmail.com>
1 parent e486ba5 commit 3080584

File tree

1 file changed

+98
-95
lines changed

1 file changed

+98
-95
lines changed

development/library_api.md

Lines changed: 98 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
# C Library API
1+
# C library API
22

3-
[Fluent Bit](http://fluentbit.io) library is written in C language and can be used from any C or C++ application. Before digging into the specification it is recommended to understand the workflow involved in the runtime.
3+
Fluent Bit is written in C and can be used from any C or C++ application.
44

55
## Workflow
66

7-
[Fluent Bit](http://fluentbit.io) runs as a service, meaning that the API exposed for developers provide interfaces to create and manage a context, specify inputs/outputs, set configuration parameters and set routing paths for the event/records. A typical usage of the library involves:
7+
Fluent Bit runs as a service, which means that the exposed API provides interfaces to create and manage contexts, specify inputs and outputs, set configuration parameters, and set routing paths for events or records. A typical usage of this library involves:
88

9-
* Create library instance/context and set properties.
10-
* Enable _input_ plugin\(s\) and set properties.
11-
* Enable _output_ plugin\(s\) and set properties.
12-
* Start the library runtime.
13-
* Optionally ingest records manually.
14-
* Stop the library runtime.
15-
* Destroy library instance/context.
9+
* Creating library instance and contexts and setting their properties.
10+
* Enabling input plugins and setting their properties.
11+
* Enabling output plugins and setting their properties.
12+
* Starting the library runtime.
13+
* Optionally ingesting records manually.
14+
* Stopping the library runtime.
15+
* Destroying library instances and contexts.
1616

17-
## Data Types
17+
## Data types
1818

19-
Starting from Fluent Bit v0.9, there is only one data type exposed by the library, by convention prefixed with **flb\_**.
19+
There is only one data type exposed by the library. By convention, this data type is prefixed with `flb_`.
2020

2121
| Type | Description |
2222
| :--- | :--- |
23-
| flb\_ctx\_t | Main library context. It aims to reference the context returned by _flb\_create\(\);_ |
23+
| `flb_ctx_t` | Main library context. This references the context returned by `flb_create();`. |
2424

25-
## API Reference
25+
## API reference
2626

27-
### Library Context Creation
27+
### Library context creation
2828

29-
As described earlier, the first step to use the library is to create a context of it, for the purpose the function **flb\_create\(\)** is used.
29+
Use the `flb_create()` function to create library context.
3030

31-
**Prototype**
31+
#### Prototype
3232

3333
```c
3434
flb_ctx_t *flb_create();
3535
```
3636

37-
**Return Value**
37+
#### Return value
3838

39-
On success, **flb\_create\(\)** returns the library context; on error, it returns NULL.
39+
On success, this function returns the library context. On error, it returns `NULL`.
4040

41-
**Usage**
41+
#### Usage
4242

4343
```c
4444
flb_ctx_t *ctx;
@@ -49,77 +49,79 @@ if (!ctx) {
4949
}
5050
```
5151

52-
### Set Service Properties
52+
### Set service properties
5353

54-
Using the **flb\_service\_set\(\)** function is possible to set context properties.
54+
Use the `flb_service_set()` function to set context properties.
5555

56-
**Prototype**
56+
#### Prototype
5757

5858
```c
5959
int flb_service_set(flb_ctx_t *ctx, ...);
6060
```
6161
62-
**Return Value**
62+
#### Return value
6363
64-
On success it returns 0; on error it returns a negative number.
64+
On success, this function returns `0`. On error, it returns a negative number.
6565
66-
**Usage**
66+
#### Usage
6767
68-
The **flb\_service\_set\(\)** allows to set one or more properties in a key/value string mode, e.g:
68+
This function sets one or more properties as a key/value string. For example:
6969
7070
```c
7171
int ret;
7272
7373
ret = flb_service_set(ctx, "Flush", "1", NULL);
7474
```
7575

76-
The above example specified the values for the properties **Flush** , note that the value is always a string \(char \*\) and once there is no more parameters a NULL argument must be added at the end of the list.
76+
This example specified the values for the property `Flush`. Its value is always a string (`char *`), and after all parameters are listed, you must add a `NULL` argument at the end of the list.
7777

78-
### Enable Input Plugin Instance
78+
### Enable input plugin instance
7979

80-
When built, [Fluent Bit](http://fluentbit.io) library contains a certain number of built-in _input_ plugins. In order to enable an _input_ plugin, the function **flb\_input**\(\) is used to create an instance of it.
80+
The Fluent Bit library contains several input plugins. To enable an input plugin, use the `flb_input()` function to create an instance of it.
8181

82-
> For plugins, an _instance_ means a context of the plugin enabled. You can create multiples instances of the same plugin.
82+
{% hint style="info" %}
83+
For plugins, an _instance_ means a context of the plugin enabled. You can create multiple instances of the same plugin.
84+
{% endhint %}
8385

84-
**Prototype**
86+
#### Prototype
8587

8688
```c
8789
int flb_input(flb_ctx_t *ctx, char *name, void *data);
8890
```
8991
90-
The argument **ctx** represents the library context created by **flb\_create\(\)**, then **name** is the name of the input plugin that is required to enable.
92+
The argument `ctx` represents the library context created by `flb_create()`, and `name` is the name of the input plugin to enable.
9193
92-
The third argument **data** can be used to pass a custom reference to the plugin instance, this is mostly used by custom or third party plugins, for generic plugins passing _NULL_ is OK.
94+
The argument `data` can be used to pass a custom reference to the plugin instance. This is mostly used by custom or third-party plugins. For generic plugins, it's okay to pass `NULL`.
9395
94-
**Return Value**
96+
#### Return value
9597
96-
On success, **flb\_input\(\)** returns an integer value &gt;= zero \(similar to a file descriptor\); on error, it returns a negative number.
98+
On success, this function returns an integer value greater than or equal to zero, similar to a file descriptor. On error, it returns a negative number.
9799
98-
**Usage**
100+
#### Usage
99101
100102
```c
101103
int in_ffd;
102104
103105
in_ffd = flb_input(ctx, "cpu", NULL);
104106
```
105107

106-
### Set Input Plugin Properties
108+
### Set input plugin properties
107109

108-
A plugin instance created through **flb\_input\(\)**, may provide some configuration properties. Using the **flb\_input\_set\(\)** function is possible to set these properties.
110+
A plugin instance created through `flb_input()` can include configuration properties. Use the `flb_input_set()` function to set these properties.
109111

110-
**Prototype**
112+
#### Prototype
111113

112114
```c
113115
int flb_input_set(flb_ctx_t *ctx, int in_ffd, ...);
114116
```
115117
116-
**Return Value**
118+
#### Return value
117119
118-
On success it returns 0; on error it returns a negative number.
120+
On success, this function returns `0`. On error, it returns a negative number.
119121
120-
**Usage**
122+
#### Usage
121123
122-
The **flb\_input\_set\(\)** allows to set one or more properties in a key/value string mode, e.g:
124+
This function sets one or more properties as a key/value string. For example:
123125
124126
```c
125127
int ret;
@@ -130,55 +132,57 @@ ret = flb_input_set(ctx, in_ffd,
130132
NULL);
131133
```
132134

133-
The argument **ctx** represents the library context created by **flb\_create\(\)**. The above example specified the values for the properties **tag** and **ssl**, note that the value is always a string \(char \*\) and once there is no more parameters a NULL argument must be added at the end of the list.
135+
The argument `ctx` represents the library context created by `flb_create()`. The previous example specified the values for the properties `tag` and `ssl`. Its value is always a string (`char *`), and after all parameters are listed, you must add a `NULL` argument at the end of the list.
134136

135-
The properties allowed per input plugin are specified on each specific plugin documentation.
137+
The properties allowed per input plugin are specified in the documentation for each plugin.
136138

137-
### Enable Output Plugin Instance
139+
### Enable output plugin instance
138140

139-
When built, [Fluent Bit](http://fluentbit.io) library contains a certain number of built-in _output_ plugins. In order to enable an _output_ plugin, the function **flb\_output**\(\) is used to create an instance of it.
141+
The Fluent Bit library contains several output plugins. To enable an output plugin, use the `flb_output()` function to create an instance of it.
140142

141-
> For plugins, an _instance_ means a context of the plugin enabled. You can create multiples instances of the same plugin.
143+
{% hint style="info" %}
144+
For plugins, an _instance_ means a context of the plugin enabled. You can create multiple instances of the same plugin.
145+
{% endhint %}
142146

143-
**Prototype**
147+
#### Prototype
144148

145149
```c
146150
int flb_output(flb_ctx_t *ctx, char *name, void *data);
147151
```
148152
149-
The argument **ctx** represents the library context created by **flb\_create\(\)**, then **name** is the name of the output plugin that is required to enable.
153+
The argument `ctx` represents the library context created by `flb_create()`, and `name` is the name of the output plugin to enable.
150154
151-
The third argument **data** can be used to pass a custom reference to the plugin instance, this is mostly used by custom or third party plugins, for generic plugins passing _NULL_ is OK.
155+
The argument `data` can be used to pass a custom reference to the plugin instance. This is mostly used by custom or third-party plugins. For generic plugins, it's okay to pass `NULL`.
152156
153-
**Return Value**
157+
#### Return value
154158
155-
On success, **flb\_output\(\)** returns the output plugin instance; on error, it returns a negative number.
159+
On success, this function returns the output plugin instance. On error, it returns a negative number.
156160
157-
**Usage**
161+
#### Usage
158162
159163
```c
160164
int out_ffd;
161165
162166
out_ffd = flb_output(ctx, "stdout", NULL);
163167
```
164168

165-
### Set Output Plugin Properties
169+
### Set output plugin properties
166170

167-
A plugin instance created through **flb\_output\(\)**, may provide some configuration properties. Using the **flb\_output\_set\(\)** function is possible to set these properties.
171+
A plugin instance created through `flb_output()` can include configuration properties. Use the `flb_output_set()` function to set these properties.
168172

169-
**Prototype**
173+
#### Prototype
170174

171175
```c
172176
int flb_output_set(flb_ctx_t *ctx, int out_ffd, ...);
173177
```
174178
175-
**Return Value**
179+
#### Return value
176180
177-
On success it returns an integer value &gt;= zero \(similar to a file descriptor\); on error it returns a negative number.
181+
On success, this function returns and integer value greater than or equal to zero, similar to a file descriptor. On error, it returns a negative number.
178182
179-
**Usage**
183+
#### Usage
180184
181-
The **flb\_output\_set\(\)** allows to set one or more properties in a key/value string mode, e.g:
185+
This function sets one or more properties as a key/value string. For example:
182186
183187
```c
184188
int ret;
@@ -189,99 +193,98 @@ ret = flb_output_set(ctx, out_ffd,
189193
NULL);
190194
```
191195

192-
The argument **ctx** represents the library context created by **flb\_create\(\)**. The above example specified the values for the properties **tag** and **ssl**, note that the value is always a string \(char \*\) and once there is no more parameters a NULL argument must be added at the end of the list.
196+
The argument `ctx` represents the library context created by `flb_create()`. The previous example specified the values for the properties `tag` and `ssl`. Its value is always a string (`char *`), and after all parameters are listed, you must add a `NULL` argument at the end of the list.
193197

194-
The properties allowed per output plugin are specified on each specific plugin documentation.
198+
The properties allowed per output plugin are specified in the documentation for each plugin.
195199

196-
## Start Fluent Bit Engine
200+
## Start Fluent Bit engine
197201

198-
Once the library context has been created and the input/output plugin instances are set, the next step is to start the engine. When started, the engine runs inside a new thread \(POSIX thread\) without blocking the caller application. To start the engine the function **flb\_start\(\)** is used.
202+
After you create the library context and set input and output plugin instances, use the `flb_start()` function to start the engine. After the engine has started, it runs inside a new thread (POSIX thread) without blocking the caller application.
199203

200-
**Prototype**
204+
### Prototype
201205

202206
```c
203207
int flb_start(flb_ctx_t *ctx);
204208
```
205209
206-
**Return Value**
210+
### Return value
207211
208-
On success it returns 0; on error it returns a negative number.
212+
On success, this function returns `0`. On error, it returns a negative number.
209213
210-
**Usage**
214+
### Usage
211215
212-
This simple call only needs as argument **ctx** which is the reference to the context created at the beginning with **flb\_create\(\)**:
216+
This function uses the `ctx` argument, which is a reference to the context created by `flb_create()`.
213217
214218
```c
215219
int ret;
216220
217221
ret = flb_start(ctx);
218222
```
219223

220-
## Stop Fluent Bit Engine
224+
## Stop Fluent Bit engine
221225

222-
To stop a running Fluent Bit engine, we provide the call **flb\_stop\(\)** for that purpose.
226+
To stop a running Fluent Bit engine, use `flb_stop()`.
223227

224-
**Prototype**
228+
### Prototype
225229

226230
```c
227231
int flb_stop(flb_ctx_t *ctx);
228232
```
229233
230-
The argument **ctx** is a reference to the context created at the beginning with **flb\_create\(\)** and previously started with **flb\_start\(\)**.
234+
The argument `ctx` is a reference to the context created by `flb_create()` and started by `flb_start()`.
231235
232-
When the call is invoked, the engine will wait a maximum of five seconds to flush buffers and release the resources in use. A stopped context can be re-started any time but without any data on it.
236+
When the call is invoked, the engine waits a maximum of five seconds to flush buffers and release any resources in use. A stopped context can be restarted at any time, but without any data on it.
233237
234-
**Return Value**
238+
### Return value
235239
236-
On success it returns 0; on error it returns a negative number.
240+
On success, this function returns `0`. On error, it returns a negative number.
237241
238-
**Usage**
242+
### Usage
239243
240244
```c
241245
int ret;
242246
243247
ret = flb_stop(ctx);
244248
```
245249

246-
## Destroy Library Context
250+
## Destroy library context
247251

248-
A library context must be destroyed after is not longer necessary, note that a previous **flb\_stop\(\)** call is mandatory. When destroyed all resources associated are released.
252+
You can destroy a library context after it's no longer necessary. A previous `flb_stop()` call is mandatory. After a library context is destroyed, all associated resources are released.
249253

250-
**Prototype**
254+
### Prototype
251255

252256
```c
253257
void flb_destroy(flb_ctx_t *ctx);
254258
```
255259
256-
The argument **ctx** is a reference to the context created at the beginning with **flb\_create\(\)**.
260+
The argument `ctx` is a reference to the context created by `flb_create()`.
257261
258-
**Return Value**
262+
### Return value
259263
260-
No return value.
264+
This function doesn't return a value.
261265
262-
**Usage**
266+
### Usage
263267
264268
```c
265269
flb_destroy(ctx);
266270
```
267271

268-
## Ingest Data Manually
272+
## Ingest data manually
269273

270-
There are some cases where the caller application may want to ingest data into Fluent Bit, for this purpose exists the function **flb\_lib\_push\(\)**.
274+
In some cases, the caller application might want to ingest data into Fluent Bit. You can use the `flb_lib_push()` function to do so.
271275

272-
**Prototype**
276+
### Prototype
273277

274278
```c
275279
int flb_lib_push(flb_ctx_t *ctx, int in_ffd, void *data, size_t len);
276280
```
277281
278-
The first argument is the context created previously through **flb\_create\(\)**. **in\_ffd** is the numeric reference of the input plugin \(for this case it should be an input of plugin **lib** type\), **data** is a reference to the message to be ingested and **len** the number of bytes to take from it.
282+
The first argument is the context created through `flb_create()`. The `in_ffd` argument is the numeric reference of the input plugin, which in this case is a `lib` input plugin. The `data` argument is a reference to the message to be ingested, and the `len` argument is the number of bytes to take from it.
279283
280-
**Return Value**
284+
### Return value
281285
282-
On success, it returns the number of bytes written; on error it returns -1.
286+
On success, this function returns the number of bytes written. On error, it returns `-1`.
283287
284-
**Usage**
285-
286-
For more details and an example about how to use this function properly please refer to the next section [Ingest Records Manually](ingest-records-manually.md).
288+
### Usage
287289
290+
For more information about how to use this function, including examples, see [Ingest Records Manually](ingest-records-manually.md).

0 commit comments

Comments
 (0)