From: Florian Forster Date: Thu, 1 Feb 2024 11:53:31 +0000 (+0100) Subject: open_telemetry_collector plugin: Enable gRPC reflection if available. X-Git-Tag: collectd-6.0.0.rc3~4^2~10 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a07173ef9ef0fb78d01a50e8732817841b4c43e9;p=thirdparty%2Fcollectd.git open_telemetry_collector plugin: Enable gRPC reflection if available. --- diff --git a/configure.ac b/configure.ac index cadd9a986..410580069 100644 --- a/configure.ac +++ b/configure.ac @@ -2880,6 +2880,37 @@ if test "x$with_libgrpcpp" = "xyes"; then AC_LANG_POP(C++) fi +if test "x$with_libgrpcpp" = "xyes"; then + AC_MSG_CHECKING([for grpc++_reflection]) + AC_LANG_PUSH(C++) + SAVE_CPPFLAGS="$CPPFLAGS" + SAVE_LDFLAGS="$LDFLAGS" + SAVE_LIBS="$LIBS" + CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS $CPPFLAGS" + LDFLAGS="$with_libgrpcpp_ldflags" + LIBS="-lgrpc++_reflection $GRPCPP_LIBS" + AC_LINK_IFELSE( + [ + AC_LANG_PROGRAM( + [[#include ]], + [[grpc::reflection::InitProtoReflectionServerBuilderPlugin();]] + ) + ], + [ + AC_MSG_RESULT([yes]) + GRPCPP_LIBS="$LIBS" + AC_DEFINE([HAVE_GRPCPP_REFLECTION], [1], [Define if the grpc++_reflection library is available.]) + ], + [ + AC_MSG_RESULT([no]) + ] + ) + CPPFLAGS="$SAVE_CPPFLAGS" + LDFLAGS="$SAVE_LDFLAGS" + LIBS="$SAVE_LIBS" + AC_LANG_POP(C++) +fi + BUILD_WITH_LIBGRPCPP_CPPFLAGS="-std=c++11 $with_libgrpcpp_cppflags $GRPCPP_CFLAGS" BUILD_WITH_LIBGRPCPP_LDFLAGS="$with_libgrpcpp_ldflags" BUILD_WITH_LIBGRPCPP_LIBS="$GRPCPP_LIBS" diff --git a/src/open_telemetry_collector.cc b/src/open_telemetry_collector.cc index daeee9efd..f70926e61 100644 --- a/src/open_telemetry_collector.cc +++ b/src/open_telemetry_collector.cc @@ -37,6 +37,9 @@ extern "C" { #include #include +#if HAVE_GRPCPP_REFLECTION +#include +#endif #include "opentelemetry/proto/collector/metrics/v1/metrics_service.grpc.pb.h" #include "opentelemetry/proto/collector/metrics/v1/metrics_service.pb.h" @@ -370,6 +373,9 @@ public: class CollectorServer final { public: void Start() { +#if HAVE_GRPCPP_REFLECTION + grpc::reflection::InitProtoReflectionServerBuilderPlugin(); +#endif auto auth = grpc::InsecureServerCredentials(); grpc::ServerBuilder builder;