]> git.ipfire.org Git - thirdparty/collectd.git/commitdiff
open_telemetry_collector plugin: Enable gRPC reflection if available.
authorFlorian Forster <octo@collectd.org>
Thu, 1 Feb 2024 11:53:31 +0000 (12:53 +0100)
committerFlorian Forster <octo@collectd.org>
Tue, 20 Feb 2024 14:28:50 +0000 (15:28 +0100)
configure.ac
src/open_telemetry_collector.cc

index cadd9a986cf504402eed078acc1428e7585f8467..410580069189723bdb841306e11a04ed342ce8bf 100644 (file)
@@ -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++/ext/proto_server_reflection_plugin.h>]],
+        [[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"
index daeee9efd5ab6d5eb2577dcfd7f5af57e5391ca5..f70926e6153070f5e6662ee2ecbf9c941f79d56c 100644 (file)
@@ -37,6 +37,9 @@ extern "C" {
 #include <vector>
 
 #include <grpc++/grpc++.h>
+#if HAVE_GRPCPP_REFLECTION
+#include <grpc++/ext/proto_server_reflection_plugin.h>
+#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;