@cryptotaxi247 / netdata-1 / commits / 63289c53f

Integrate OpenTelemetry collector build into build system. (#19702)

* Fix Go version requirement detection to not have external deps. Instead of relying on a UNIX-like environment with the `grep` and `cut` commands, perform the required data extraction using CMake code. This makes it more portable, but also should speed things up a tiny bit because it doesn’t require invoking external commands. * Preliminary integration of the new otel-collector into the build. Adding `-DENABLE_PLUGIN_OTEL=On` to CMake options will enable building the plugin and installing it. Currently disabled by default, and does not include packaging integration yet. The plugin itself can be built independently of the primary build system but using the same build infrastructure that is used to build it as part of the regular build by using CMake in the src/go/otel-collector directory. * Minor cleanup. * Fix build prefix. * Restructure to not use a sub-project.

Austin S. Hemmelgarn committed Mar 11, 2025 at 07:27 UTC 63289c53fe5313b565b3fb07262004c5c6de283e
4 files changed +96 -11
CMakeLists.txt
+14 -1
@@ -169,6 +169,7 @@ mark_as_advanced(ENABLE_DASHBOARD)
169
170 # Data collection plugins
171 option(ENABLE_PLUGIN_GO "Enable metric collectors written in Go" ${DEFAULT_FEATURE_STATE})
172 +option(ENABLE_PLUGIN_OTEL "Enable metrics collection via OpenTelemetry collector" False)
173 option(ENABLE_PLUGIN_PYTHON "Enable metric collectors written in Python" ${DEFAULT_FEATURE_STATE})
174
175 cmake_dependent_option(ENABLE_PLUGIN_APPS "Enable per-process resource usage monitoring" ${DEFAULT_FEATURE_STATE} "OS_LINUX OR OS_FREEBSD OR OS_MACOS OR OS_WINDOWS" False)
@@ -303,7 +304,7 @@ if(ENABLE_JEMALLOC)
304 endif()
305 endif()
306
306 -if(ENABLE_PLUGIN_GO)
307 +if(ENABLE_PLUGIN_GO OR ENABLE_PLUGIN_OTEL)
308 include(NetdataGoTools)
309
310 find_min_go_version("${CMAKE_SOURCE_DIR}/src/go")
@@ -3053,6 +3054,18 @@ if(ENABLE_PLUGIN_GO)
3054 DESTINATION usr/libexec/netdata/plugins.d)
3055 endif()
3056
3057 +#
3058 +# Handle OTel Collector plugin
3059 +#
3060 +
3061 +if(ENABLE_PLUGIN_OTEL)
3062 + include(${CMAKE_SOURCE_DIR}/src/go/otel-collector/CMakeLists.txt)
3063 +
3064 + install(PROGRAMS ${CMAKE_BINARY_DIR}/otel-collector/otelcol.plugin
3065 + COMPONENT plugin-otelcol
3066 + DESTINATION usr/libexec/netdata/plugins.d)
3067 +endif()
3068 +
3069 #
3070 # Generate config file
3071 #
packaging/cmake/Modules/NetdataGoTools.cmake
+3 -10
@@ -49,9 +49,6 @@ endmacro()
49 # All files found will be checked for a `go` directive, and the
50 # MIN_GO_VERSION variable will be set to the highest version
51 # number found among these directives.
52 -#
53 -# Only works on UNIX-like systems, because it has to process the go.mod
54 -# files in ways that CMake can't do on it's own.
52 function(find_min_go_version src_tree)
53 message(STATUS "Determining minimum required version of Go for this build")
54
@@ -61,14 +58,10 @@ function(find_min_go_version src_tree)
58
59 foreach(f IN ITEMS ${go_mod_files})
60 message(VERBOSE "Checking Go version specified in ${f}")
64 - execute_process(
65 - COMMAND grep -E "^go .*$" ${f}
66 - COMMAND cut -f 2 -d " "
67 - RESULT_VARIABLE version_check_result
68 - OUTPUT_VARIABLE go_mod_version
69 - )
61 + file(STRINGS "${f}" match_line REGEX "^go .*$")
62
71 - if(version_check_result EQUAL 0)
63 + if(match_line)
64 + list(GET match_line 0 go_mod_version)
65 string(REGEX MATCH "([0-9]+\\.[0-9]+(\\.[0-9]+)?)" go_mod_version "${go_mod_version}")
66
67 if(go_mod_version VERSION_GREATER result)
src/go/otel-collector/CMakeLists.txt new
+58
@@ -0,0 +1,58 @@
1 +# SPDX-License-Identifier: GPL-3.0-or-later
2 +
3 +function(_handle_otel)
4 + if(CMAKE_BUILD_TYPE STREQUAL Debug)
5 + set(DEBUG_BUILD True)
6 + else()
7 + set(DEBUG_BUILD False)
8 + endif()
9 +
10 + message(STATUS "Generating OpenTelemetry Collector Builder configuration")
11 + configure_file("${CMAKE_CURRENT_SOURCE_DIR}/release-config.yaml.in"
12 + "${CMAKE_BINARY_DIR}/otel-build-config.yaml"
13 + @ONLY)
14 + message(STATUS "Generating OpenTelemetry Collector Builder configuration -- Done")
15 +
16 + message(STATUS "Fetching OpenTelemetry Collector Builder")
17 + set(OLD_GOBIN $ENV{GOBIN})
18 + set(ENV{GOBIN} ${CMAKE_BINARY_DIR}/bin)
19 + execute_process(
20 + COMMAND ${GO_EXECUTABLE} install go.opentelemetry.io/collector/cmd/builder@latest
21 + RESULT_VARIABLE otel_builder_install
22 + )
23 + set(ENV{GOBIN} ${OLD_GOBIN})
24 +
25 + if(otel_builder_install)
26 + message(FATAL_ERROR "Fetching OpenTelemetry Collector Builder --Failed")
27 + else()
28 + message(STATUS "Fetching OpenTelemetry Collector Builder -- Success")
29 + endif()
30 +
31 + set(DIRS "exporter/journaldexporter")
32 + set(otelcol_deps "")
33 +
34 + foreach(dir IN LISTS DIRS)
35 + file(GLOB_RECURSE deps CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/*.go")
36 + list(APPEND otelcol_deps "${deps}")
37 + list(APPEND otelcol_deps
38 + "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/go.mod"
39 + "${CMAKE_CURRENT_SOURCE_DIR}/${dir}/go.sum"
40 + )
41 + endforeach()
42 +
43 + add_custom_command(
44 + OUTPUT otel-collector/otelcol.plugin
45 + COMMAND ${CMAKE_BINARY_DIR}/bin/builder --config=${CMAKE_BINARY_DIR}/otel-build-config.yaml
46 + DEPENDS ${otelcol_deps}
47 + COMMENT "Building otelcol.plugin"
48 + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
49 + VERBATIM
50 + )
51 +
52 + add_custom_target(
53 + plugin-otelcol ALL
54 + DEPENDS otel-collector/otelcol.plugin
55 + )
56 +endfunction()
57 +
58 +handle_otel()
src/go/otel-collector/release-config.yaml.in new
+21
@@ -0,0 +1,21 @@
1 +dist:
2 + name: otelcol.plugin
3 + module: github.com/netdata/netdata/otel-collector
4 + description: OpenTelemetry Collector Distribution built for Netdata
5 + output_path: @CMAKE_BINARY_DIR@/otel-collector
6 + version: @NETDATA_VERSION_STRING@
7 + go: @GO_EXECUTABLE@
8 + debug_compilation: @DEBUG_BUILD@
9 +
10 +receivers:
11 + - gomod: go.opentelemetry.io/collector/receiver/otlpreceiver v0.120.0
12 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/receiver/filelogreceiver v0.120.0
13 +
14 +exporters:
15 + - gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.120.0
16 + - gomod: github.com/open-telemetry/opentelemetry-collector-contrib/exporter/fileexporter v0.120.0
17 + - gomod: go.opentelemetry.io/collector/exporter/otlpexporter v0.120.0
18 + - gomod: github.com/netdata/netdata/otel-collector/exporter/journaldexporter v0.0.0
19 +
20 +replaces:
21 + - github.com/netdata/netdata/otel-collector/exporter/journaldexporter => @CMAKE_CURRENT_SOURCE_DIR@/exporter/journaldexporter