Skip to content

Conversation

JeffLuoo
Copy link
Owner

@JeffLuoo JeffLuoo commented Jun 17, 2020

One feature of stackdriver output plugin in fluentd is that we will provide more information on log name for the stream of the log. This feature is missing in fluent bit and this patch will add this feature.


Enter [N/A] in the box, if an item is not applicable to your change.

Testing
Before we can approve your change; please submit the following in a comment:

  • Example configuration file for the change
  • Debug log output from testing the change
  • Attached Valgrind output that shows no leaks or memory corruption was found

Documentation

  • Documentation required for this feature

Fluent Bit is licensed under Apache 2.0, by submitting this pull request I understand that this code will be released under the terms of that license.

@JeffLuoo JeffLuoo requested review from courageJ and erain June 17, 2020 20:49
@JeffLuoo
Copy link
Owner Author

JeffLuoo commented Jun 17, 2020

Example configuration file for the change

fluent-bit.conf

[SERVICE]
    Flush        1
    Daemon       Off
    Log_Level    debug
    Parsers_File myparser.conf

[INPUT]
    Name            tail
    Tag             k8s_container.test
    Parser          JSON
    Path            /home/jeffluoo/fluentbit/testContainer.json

[OUTPUT]
    Name stackdriver
    Match k8s_container.*
    resource k8s_container
    k8s_cluster_name k8s_cluster_name_test
    k8s_cluster_location k8s_cluster_location_test

[FILTER]
    Name record_modifier
    Match k8s_container.*
    Record logging.googleapis.com/local_resource_id k8s_container.namespace_name_test.podt_name_test.container_name_test

myparser.conf

[PARSER]
   Name  JSON
   Format  json

/home/jeffluoo/fluentbit/testContainer.json

{"stream":"stderr","time":"2019-03-09T13:52:36.806411254Z","log":"test Log Message","kubernetes":{"labels":{"controller-revision-hash":"foorbarr","pod-template-generation":"1","app":"logging-availability-test"},"namespace_name":"test-components","docker_id":"testDockerId","container_name":"logging-test","pod_name":"logging-availability-test-v8gwl","annotations":{"prometheus.io\/path":"\/","prometheus.io\/scrape":"true"},"host":"gke-test-host","pod_id":"test-pod-id"}}

@JeffLuoo
Copy link
Owner Author

Debug log output from testing the change

fluent-bit/build$ ./bin/fluent-bit -c ../conf/fluent-bit.conf 
Fluent Bit v1.5.0
* Copyright (C) 2019-2020 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2020/06/17 16:53:33] [ info] Configuration:
[2020/06/17 16:53:33] [ info]  flush time     | 1.000000 seconds
[2020/06/17 16:53:33] [ info]  grace          | 5 seconds
[2020/06/17 16:53:33] [ info]  daemon         | 0
[2020/06/17 16:53:33] [ info] ___________
[2020/06/17 16:53:33] [ info]  inputs:
[2020/06/17 16:53:33] [ info]      tail
[2020/06/17 16:53:33] [ info] ___________
[2020/06/17 16:53:33] [ info]  filters:
[2020/06/17 16:53:33] [ info]      record_modifier.0
[2020/06/17 16:53:33] [ info] ___________
[2020/06/17 16:53:33] [ info]  outputs:
[2020/06/17 16:53:33] [ info]      stackdriver.0
[2020/06/17 16:53:33] [ info] ___________
[2020/06/17 16:53:33] [ info]  collectors:
[2020/06/17 16:53:33] [debug] [storage] [cio stream] new stream registered: tail.0
[2020/06/17 16:53:33] [ info] [storage] version=1.0.4, initializing...
[2020/06/17 16:53:33] [ info] [storage] in-memory
[2020/06/17 16:53:33] [ info] [storage] normal synchronization mode, checksum disabled, max_chunks_up=128
[2020/06/17 16:53:33] [ info] [engine] started (pid=8112)
[2020/06/17 16:53:33] [debug] [engine] coroutine stack size: 24576 bytes (24.0K)
[2020/06/17 16:53:33] [debug] [input:tail:tail.0] inotify watch fd=19
[2020/06/17 16:53:33] [debug] [input:tail:tail.0] scanning path /home/jeffluoo/fluentbit/testContainer.json
[2020/06/17 16:53:33] [debug] [input:tail:tail.0] inode=1366402 appended as /home/jeffluoo/fluentbit/testContainer.json
[2020/06/17 16:53:33] [debug] [input:tail:tail.0] scan_glob add(): /home/jeffluoo/fluentbit/testContainer.json, inode 1366402
[2020/06/17 16:53:33] [ info] [oauth2] HTTP Status=200
[2020/06/17 16:53:33] [ info] [oauth2] access token from 'www.googleapis.com:443' retrieved
[2020/06/17 16:53:33] [debug] [router] match rule tail.0:stackdriver.0
[2020/06/17 16:53:33] [ info] [sp] stream processor started
[2020/06/17 16:53:33] [debug] [input:tail:tail.0] inode=1366402 file=/home/jeffluoo/fluentbit/testContainer.json promote to TAIL_EVENT
[2020/06/17 16:53:33] [ info] inotify_fs_add(): inode=1366402 watch_fd=1 name=/home/jeffluoo/fluentbit/testContainer.json
[2020/06/17 16:53:34] [debug] [task] created task=0x55f594cb1030 id=0 OK
[2020/06/17 16:53:34] [debug] [output:stackdriver:stackdriver.0] HTTP Status=200
[2020/06/17 16:53:34] [debug] [upstream] KA connection #30 to logging.googleapis.com:443 is now available
[2020/06/17 16:53:34] [debug] [task] destroy task=0x55f594cb1030 (task_id=0)
^C[engine] caught signal (SIGINT)
[2020/06/17 16:53:39] [ info] [input] pausing tail.0
[2020/06/17 16:53:39] [debug] [input:tail:tail.0] inode=1366402 removing file name /home/jeffluoo/fluentbit/testContainer.json
[2020/06/17 16:53:39] [ info] inotify_fs_remove(): inode=1366402 watch_fd=1

@JeffLuoo
Copy link
Owner Author

Attached Valgrind output that shows no leaks or memory corruption was found

$ valgrind ./bin/fluent-bit -c ../conf/fluent-bit.conf 
==8119== Memcheck, a memory error detector
==8119== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==8119== Using Valgrind-3.14.0 and LibVEX; rerun with -h for copyright info
==8119== Command: ./bin/fluent-bit -c ../conf/testContainer.conf
==8119== 
Fluent Bit v1.5.0
* Copyright (C) 2019-2020 The Fluent Bit Authors
* Copyright (C) 2015-2018 Treasure Data
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2020/06/17 16:56:00] [ info] Configuration:
[2020/06/17 16:56:00] [ info]  flush time     | 1.000000 seconds
[2020/06/17 16:56:00] [ info]  grace          | 5 seconds
[2020/06/17 16:56:00] [ info]  daemon         | 0
[2020/06/17 16:56:00] [ info] ___________
[2020/06/17 16:56:00] [ info]  inputs:
[2020/06/17 16:56:00] [ info]      tail
[2020/06/17 16:56:00] [ info] ___________
[2020/06/17 16:56:00] [ info]  filters:
[2020/06/17 16:56:00] [ info]      record_modifier.0
[2020/06/17 16:56:00] [ info] ___________
[2020/06/17 16:56:00] [ info]  outputs:
[2020/06/17 16:56:00] [ info]      stackdriver.0
[2020/06/17 16:56:00] [ info] ___________
[2020/06/17 16:56:00] [ info]  collectors:
[2020/06/17 16:56:00] [debug] [storage] [cio stream] new stream registered: tail.0
[2020/06/17 16:56:00] [ info] [storage] version=1.0.4, initializing...
[2020/06/17 16:56:00] [ info] [storage] in-memory
[2020/06/17 16:56:00] [ info] [storage] normal synchronization mode, checksum disabled, max_chunks_up=128
[2020/06/17 16:56:00] [ info] [engine] started (pid=8119)
[2020/06/17 16:56:00] [debug] [engine] coroutine stack size: 24576 bytes (24.0K)
[2020/06/17 16:56:00] [debug] [input:tail:tail.0] inotify watch fd=19
[2020/06/17 16:56:00] [debug] [input:tail:tail.0] scanning path /home/jeffluoo/fluentbit/testContainer.json
[2020/06/17 16:56:00] [debug] [input:tail:tail.0] inode=1366402 appended as /home/jeffluoo/fluentbit/testContainer.json
[2020/06/17 16:56:00] [debug] [input:tail:tail.0] scan_glob add(): /home/jeffluoo/fluentbit/testContainer.json, inode 1366402
[2020/06/17 16:56:02] [ info] [oauth2] HTTP Status=200
[2020/06/17 16:56:02] [ info] [oauth2] access token from 'www.googleapis.com:443' retrieved
[2020/06/17 16:56:02] [debug] [router] match rule tail.0:stackdriver.0
[2020/06/17 16:56:02] [ info] [sp] stream processor started
[2020/06/17 16:56:02] [debug] [input:tail:tail.0] inode=1366402 file=/home/jeffluoo/fluentbit/testContainer.json promote to TAIL_EVENT
[2020/06/17 16:56:02] [ info] inotify_fs_add(): inode=1366402 watch_fd=1 name=/home/jeffluoo/fluentbit/testContainer.json
==8119== Warning: client switching stacks?  SP change: 0x1ffefffd18 --> 0x6171e80
==8119==          to suppress, use: --max-stackframe=137319997080 or greater
==8119== Warning: client switching stacks?  SP change: 0x6171df8 --> 0x1ffefffd18
==8119==          to suppress, use: --max-stackframe=137319997216 or greater
==8119== Warning: client switching stacks?  SP change: 0x1ffefffd18 --> 0x6171df8
==8119==          to suppress, use: --max-stackframe=137319997216 or greater
==8119==          further instances of this message will not be shown.
[2020/06/17 16:56:03] [debug] [task] created task=0x616ba50 id=0 OK
[2020/06/17 16:56:04] [debug] [output:stackdriver:stackdriver.0] HTTP Status=200
[2020/06/17 16:56:04] [debug] [upstream] KA connection #30 to logging.googleapis.com:443 is now available
[2020/06/17 16:56:04] [debug] [task] destroy task=0x616ba50 (task_id=0)
^C[engine] caught signal (SIGINT)
[2020/06/17 16:56:08] [ info] [input] pausing tail.0
[2020/06/17 16:56:08] [debug] [input:tail:tail.0] inode=1366402 removing file name /home/jeffluoo/fluentbit/testContainer.json
[2020/06/17 16:56:08] [ info] inotify_fs_remove(): inode=1366402 watch_fd=1
==8119== 
==8119== HEAP SUMMARY:
==8119==     in use at exit: 0 bytes in 0 blocks
==8119==   total heap usage: 83,237 allocs, 83,237 frees, 10,251,382 bytes allocated
==8119== 
==8119== All heap blocks were freed -- no leaks are possible
==8119== 
==8119== For counts of detected and suppressed errors, rerun with: -v
==8119== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

@JeffLuoo JeffLuoo changed the base branch from feature/k8s_container to master June 23, 2020 20:29
@JeffLuoo JeffLuoo changed the base branch from master to feature/k8s_container June 23, 2020 20:30
@JeffLuoo JeffLuoo force-pushed the feature/modify_tag_value branch from c31f2bb to 9b24ad2 Compare June 23, 2020 20:33
@JeffLuoo JeffLuoo requested a review from erain June 23, 2020 20:35
@JeffLuoo JeffLuoo force-pushed the feature/k8s_container branch 5 times, most recently from 0680c24 to 7f663f2 Compare June 26, 2020 21:57
@JeffLuoo JeffLuoo force-pushed the feature/k8s_container branch from 7f663f2 to d88101d Compare July 8, 2020 20:17
@JeffLuoo JeffLuoo force-pushed the feature/k8s_container branch from 6419928 to a111c08 Compare August 5, 2020 18:34
@JeffLuoo JeffLuoo force-pushed the feature/k8s_container branch from a111c08 to 2e451c8 Compare August 13, 2020 20:47
@JeffLuoo JeffLuoo force-pushed the feature/k8s_container branch from b9cac4e to 94dae4e Compare August 26, 2020 16:43
@github-actions
Copy link

This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.

@github-actions github-actions bot added the Stale label Mar 10, 2021
JeffLuoo pushed a commit that referenced this pull request Jun 16, 2021
output_thread patch #1 : pipe creation is platform dependent, in unixes it's
achieved through the pipe syscall but in windows it's a socket pair created
through libevent which means instead of read/write we need to use recv/send
which was already abstracted through flb_pipe_(r/w).

output_thread patch #2 : in windows the SOCKET data type is defined as an
UINT_PTR which means in 64 bit operating systems it's an 8 byte number
instead of 4. libevent abstracts this through the evutil_socket_t data type
which in turn is abstracted using the flb_pipefd_t data type in fluent bit.

The problem comes to play when calling mk_event_channel_create which
receives 2 int pointers to return both pipe endpoints. This means there
are 2 possible bugs (one of which was happening and the other is not
really a concern I think) :

Since mk_event_channel_create was only modifying the low part of the elements
in the ch_parent_events array and the structure was not zeroed when allocated,
the high parts of those 64 bit members contained garbage which caused any
winsock calls to return error 10038 (not a socket). That's the reason why I
added a memset call in line 421.

There is still a possible issue with mk_event_channel_create which we should
fix by moving our platform dependent data type to mk_lib and defining our
flb local data types to those if need be (for consistency).

Signed-off-by: Leonardo Alminana <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants