Skip to content

Commit cdc534f

Browse files
committed
development: update API usage
Signed-off-by: Eduardo Silva <eduardo@treasure-data.com>
1 parent 83ae55a commit cdc534f

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

development/ingest_records_manually.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ The following C code snippet shows how to insert a few JSON records into a runni
3131
int main()
3232
{
3333
int ret;
34+
int in_ffd;
35+
int out_ffd;
3436
flb_ctx_t *ctx;
35-
flb_input_t *in;
36-
flb_output_t *out;
3737

3838
/* Create library context */
3939
ctx = flb_create();
@@ -42,15 +42,15 @@ int main()
4242
}
4343

4444
/* Enable the input plugin for manual data ingestion */
45-
in = flb_input(ctx, "lib", NULL);
46-
if (!in) {
45+
in_ffd = flb_input(ctx, "lib", NULL);
46+
if (in_ffd == -1) {
4747
flb_destroy(ctx);
4848
return -1;
4949
}
5050

5151
/* Enable output plugin 'stdout' (print records to the standard output) */
52-
out = flb_output(ctx, "stdout", NULL);
53-
if (!out) {
52+
out_ffd = flb_output(ctx, "stdout", NULL);
53+
if (out_ffd == -1) {
5454
flb_destroy(ctx);
5555
return -1;
5656
}
@@ -63,8 +63,8 @@ int main()
6363
}
6464

6565
/* Ingest data manually */
66-
flb_lib_push(in, JSON_1, sizeof(JSON_1) - 1);
67-
flb_lib_push(in, JSON_2, sizeof(JSON_2) - 1);
66+
flb_lib_push(ctx, in_ffd, JSON_1, sizeof(JSON_1) - 1);
67+
flb_lib_push(ctx, in_ffd, JSON_2, sizeof(JSON_2) - 1);
6868

6969
/* Stop the engine (5 seconds to flush remaining data) */
7070
flb_stop(ctx);

development/library_api.md

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,21 @@
77
[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:
88

99
- Create library instance/context.
10-
- Enable _input_ plugin(s) instances and set properties.
11-
- Enable _output_ plugin(s) instances and set properties.
10+
- Enable _input_ plugin(s) and set properties.
11+
- Enable _output_ plugin(s) and set properties.
1212
- Start the library runtime.
1313
- Optionally ingest records manually.
1414
- Stop the library runtime.
1515
- Destroy library instance/context.
1616

1717
## Data Types
1818

19-
There are three main data types exposed by the library. All of them including further functions are prefixed with __flb\___. The following table describes them:
19+
Starting from Fluent Bit v0.9, there is only one data type exposed by the library, by convention prefixed with __flb\___.
2020

2121

2222
| Type | Description |
2323
|--------------|----------------------|
2424
| flb_ctx_t | Main library context. It aims to reference the context returned by _flb\_create();_|
25-
| flb_input_t | Reference an enabled _input_ plugin instance. Used to store the output of _flb\_input(...);_ function. |
26-
| flb_output_t | Reference an enabled _output_ plugin instance. Used to store the output of _flb\_output(...);_ function. |
2725

2826
## API Reference
2927

@@ -62,7 +60,7 @@ When built, [Fluent Bit](http://fluentbit.io) library contains a certain number
6260
__Prototype__
6361

6462
```C
65-
flb_input_t *flb_input(flb_ctx_t *ctx, char *name, void *data);
63+
int flb_input(flb_ctx_t *ctx, char *name, void *data);
6664
```
6765
6866
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.
@@ -71,14 +69,14 @@ The third argument __data__ can be used to pass a custom reference to the plugin
7169
7270
__Return Value__
7371
74-
On success, __flb_input()__ returns the input plugin instance; on error, it returns NULL.
72+
On success, __flb_input()__ returns an integer value >= zero (similar to a file descriptor); on error, it returns NULL.
7573
7674
__Usage__
7775
7876
```C
79-
flb_input_t *in;
77+
int in_ffd;
8078
81-
in = flb_input(ctx, "cpu", NULL);
79+
in_ffd = flb_input(ctx, "cpu", NULL);
8280
```
8381

8482
### Set Input Plugin Properties
@@ -88,7 +86,7 @@ A plugin instance created through __flb_input()__, may provide some configuratio
8886
__Prototype__
8987

9088
```C
91-
int flb_input_set(flb_input_t *in, ...);
89+
int flb_input_set(flb_ctx_t *ctx, int in_ffd, ...);
9290
```
9391
9492
__Return Value__
@@ -102,13 +100,13 @@ The __flb_input_set()__ allow to set one or more properties in a key/value strin
102100
```C
103101
int ret;
104102
105-
ret = flb_input_set(in,
103+
ret = flb_input_set(ctx, in_ffd,
106104
"tag", "my_records",
107105
"ssl", "false",
108106
NULL);
109107
```
110108

111-
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.
109+
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.
112110

113111
The properties allowed per input plugin are specified on each specific plugin documentation.
114112

@@ -121,7 +119,7 @@ When built, [Fluent Bit](http://fluentbit.io) library contains a certain number
121119
__Prototype__
122120

123121
```C
124-
flb_output_t *flb_output(flb_ctx_t *ctx, char *name, void *data);
122+
int flb_output(flb_ctx_t *ctx, char *name, void *data);
125123
```
126124
127125
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.
@@ -135,9 +133,9 @@ On success, __flb_output()__ returns the output plugin instance; on error, it re
135133
__Usage__
136134
137135
```C
138-
flb_output_t *out;
136+
int out_ffd;
139137
140-
out = flb_output(ctx, "stdout", NULL);
138+
out_ffd = flb_output(ctx, "stdout", NULL);
141139
```
142140

143141
### Set Output Plugin Properties
@@ -147,12 +145,12 @@ A plugin instance created through __flb_output()__, may provide some configurati
147145
__Prototype__
148146

149147
```C
150-
int flb_output_set(flb_output_t *in, ...);
148+
int flb_output_set(flb_ctx_t *ctx, int out_ffd, ...);
151149
```
152150
153151
__Return Value__
154152
155-
On success it returns 0; on error it returns a negative number.
153+
On success it returns an integer value >= zero (similar to a file descriptor); on error it returns a negative number.
156154
157155
__Usage__
158156
@@ -161,13 +159,13 @@ The __flb_output_set()__ allow to set one or more properties in a key/value stri
161159
```C
162160
int ret;
163161
164-
ret = flb_output_set(in,
165-
"tag", "my_records",
166-
"ssl", "false",
167-
NULL);
162+
ret = flb_output_set(ctx, out_ffd,
163+
"tag", "my_records",
164+
"ssl", "false",
165+
NULL);
168166
```
169167

170-
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.
168+
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.
171169

172170
The properties allowed per output plugin are specified on each specific plugin documentation.
173171

@@ -250,10 +248,10 @@ There are some cases where the caller application may want to ingest data into F
250248
__Prototype__
251249

252250
```C
253-
int flb_lib_push(flb_input_t *input, void *data, size_t len);
251+
int flb_lib_push(flb_ctx_t *ctx, int in_ffd, void *data, size_t len);
254252
```
255253
256-
The first argument __input__ is a reference to an input instance of the __lib__ plugin, __data__ is a reference to the message to be ingested and __len__ the number of bytes to take from it.
254+
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.
257255
258256
__Return Value__
259257

0 commit comments

Comments
 (0)