Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

in_opentelemetry: fix memory leak #8293

Merged
merged 1 commit into from
Dec 18, 2023
Merged

Conversation

nokute78
Copy link
Collaborator

This patch is to fix following valgrind error.
The resource should be freed by opentelemetry__proto__collector__logs__v1__export_logs_service_request__free_unpacked.

==149281== 
==149281== HEAP SUMMARY:
==149281==     in use at exit: 688 bytes in 21 blocks
==149281==   total heap usage: 1,611 allocs, 1,590 frees, 1,258,568 bytes allocated
==149281== 
==149281== 688 (40 direct, 648 indirect) bytes in 1 blocks are definitely lost in loss record 9 of 9
==149281==    at 0x4848899: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==149281==    by 0x9893BC: system_alloc (protobuf-c.c:154)
==149281==    by 0x98940C: do_alloc (protobuf-c.c:167)
==149281==    by 0x98E30C: protobuf_c_message_unpack (protobuf-c.c:3063)
==149281==    by 0x9926B3: opentelemetry__proto__collector__logs__v1__export_logs_service_request__unpack (logs_service.pb-c.c:43)
==149281==    by 0x4BF436: binary_payload_to_msgpack (opentelemetry_prot.c:410)
==149281==    by 0x4C1922: process_payload_logs (opentelemetry_prot.c:1339)
==149281==    by 0x4C2406: opentelemetry_prot_handle (opentelemetry_prot.c:1647)
==149281==    by 0x4B942E: opentelemetry_conn_event (http_conn.c:99)
==149281==    by 0x244C82: flb_engine_start (flb_engine.c:1009)
==149281==    by 0x1DE9F4: flb_lib_worker (flb_lib.c:638)
==149281==    by 0x4FF4AC2: start_thread (pthread_create.c:442)
==149281== 
==149281== LEAK SUMMARY:
==149281==    definitely lost: 40 bytes in 1 blocks
==149281==    indirectly lost: 648 bytes in 20 blocks
==149281==      possibly lost: 0 bytes in 0 blocks
==149281==    still reachable: 0 bytes in 0 blocks
==149281==         suppressed: 0 bytes in 0 blocks
==149281== 
==149281== For lists of detected and suppressed errors, rerun with: -s
==149281== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)

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

If this is a change to packaging of containers or native binaries then please confirm it works for all targets.

  • [N/A] Run local packaging test showing all targets (including any new ones) build.
  • [N/A] Set ok-package-test label to test for all targets (requires maintainer to do).

Documentation

  • [N/A] Documentation required for this feature

Backporting

  • [] Backport to latest stable release.

Configuration

[INPUT]
    Name opentelemetry
    Port 4318

[OUTPUT]
    Name stdout

Debug/Valgrind output

  1. Run fluent-bit
  2. Send logs using telemetrygen logs --otlp-http --otlp-insecure --telemetry-attributes "key=\"value\""

Note: I installed telemetrygen using following command.

go install github.com/open-telemetry/opentelemetry-collector-contrib/cmd/telemetrygen@latest
$ valgrind --leak-check=full bin/fluent-bit -c otel.cfg 
==146487== Memcheck, a memory error detector
==146487== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==146487== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==146487== Command: bin/fluent-bit -c otel.cfg
==146487== 
Fluent Bit v2.2.1
* Copyright (C) 2015-2023 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2023/12/17 11:51:01] [ info] [fluent bit] version=2.2.1, commit=2389f44ee4, pid=146487
[2023/12/17 11:51:02] [ info] [storage] ver=1.2.0, type=memory, sync=normal, checksum=off, max_chunks_up=128
[2023/12/17 11:51:02] [ info] [cmetrics] version=0.6.5
[2023/12/17 11:51:02] [ info] [ctraces ] version=0.3.1
[2023/12/17 11:51:02] [ info] [input:opentelemetry:opentelemetry.0] initializing
[2023/12/17 11:51:02] [ info] [input:opentelemetry:opentelemetry.0] storage_strategy='memory' (memory only)
[2023/12/17 11:51:02] [ info] [input:opentelemetry:opentelemetry.0] listening on 0.0.0.0:4318
[2023/12/17 11:51:02] [ info] [output:stdout:stdout.0] worker #0 started
[2023/12/17 11:51:02] [ info] [sp] stream processor started
[0] v1_logs: [[1702781469.874892154, {"app"=>"server", "value"=>"value"}], {"message"=>"the message"}]
^C[2023/12/17 11:51:11] [engine] caught signal (SIGINT)
[2023/12/17 11:51:11] [ warn] [engine] service will shutdown in max 5 seconds
[2023/12/17 11:51:12] [ info] [engine] service has stopped (0 pending tasks)
[2023/12/17 11:51:12] [ info] [output:stdout:stdout.0] thread worker #0 stopping...
[2023/12/17 11:51:12] [ info] [output:stdout:stdout.0] thread worker #0 stopped
==146487== 
==146487== HEAP SUMMARY:
==146487==     in use at exit: 0 bytes in 0 blocks
==146487==   total heap usage: 1,630 allocs, 1,630 frees, 1,414,216 bytes allocated
==146487== 
==146487== All heap blocks were freed -- no leaks are possible
==146487== 
==146487== For lists of detected and suppressed errors, rerun with: -s
==146487== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

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.

@edsiper
Copy link
Member

edsiper commented Dec 17, 2023

thanks @nokute78

please adjust the commit prefix to in_opentelemetry: ...

Signed-off-by: Takahiro Yamashita <[email protected]>
@nokute78 nokute78 changed the title in_otel: fix memory leak in_opentelemetry: fix memory leak Dec 18, 2023
@nokute78
Copy link
Collaborator Author

@edsiper I fixed commit message.

@edsiper edsiper merged commit ca7bb0d into fluent:master Dec 18, 2023
42 of 43 checks passed
@edsiper
Copy link
Member

edsiper commented Dec 18, 2023

thank you

@nokute78 nokute78 deleted the fix_in_otel_leak branch December 22, 2023 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants