From 1eb5b6c2ce15d32fa3f1511f3a1847d342ea63a4 Mon Sep 17 00:00:00 2001 From: Adam Wegrzynek Date: Wed, 20 Feb 2019 15:49:32 +0100 Subject: [PATCH] Drop HTTP transport (#124) * Drop HTTP transport * Use Ubunty xenial in travis --- .travis.yml | 19 ++++----- CMakeLists.txt | 5 +-- README.md | 4 +- cmake/FindCURL.cmake | 67 -------------------------------- src/Backends/InfluxDB.cxx | 10 ----- src/Backends/InfluxDB.h | 7 +--- src/MonitoringFactory.cxx | 4 -- src/Transports/HTTP.cxx | 70 ---------------------------------- src/Transports/HTTP.h | 59 ---------------------------- test/testMonitoringFactory.cxx | 4 +- 10 files changed, 16 insertions(+), 233 deletions(-) delete mode 100644 cmake/FindCURL.cmake delete mode 100644 src/Transports/HTTP.cxx delete mode 100644 src/Transports/HTTP.h diff --git a/.travis.yml b/.travis.yml index f5ffb1e0d..2b299ec5f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ sudo: required language: cpp -dist: trusty matrix: allow_failures: - os: linux @@ -15,6 +14,7 @@ matrix: osx_image: xcode10 env: TOOL=test - os: linux + dist: xenial env: TOOL=test addons: apt: @@ -24,11 +24,12 @@ matrix: - gcc-8 - g++-8 - cmake - - libboost-system1.55-dev - - libboost-filesystem1.55-dev - - libboost-test1.55-dev - - libboost-program-options1.55-dev + - libboost-system1.58-dev + - libboost-filesystem1.58-dev + - libboost-test1.58-dev + - libboost-program-options1.58-dev - os: linux + dist: xenial env: TOOL=coverage addons: apt: @@ -44,10 +45,10 @@ matrix: - doxygen-latex - doxygen-gui - graphviz - - libboost-system1.55-dev - - libboost-filesystem1.55-dev - - libboost-test1.55-dev - - libboost-program-options1.55-dev + - libboost-system1.58-dev + - libboost-filesystem1.58-dev + - libboost-test1.58-dev + - libboost-program-options1.58-dev branches: only: - dev diff --git a/CMakeLists.txt b/CMakeLists.txt index 1af69016e..7c3d914ff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -53,7 +53,6 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") find_package(Boost REQUIRED COMPONENTS unit_test_framework program_options system filesystem) find_package(Git QUIET) find_package(ApMon MODULE) -find_package(CURL REQUIRED MODULE) #################################### @@ -77,7 +76,6 @@ set(SRCS src/MonitoringFactory.cxx src/Transports/UDP.cxx src/Transports/TCP.cxx - src/Transports/HTTP.cxx src/Transports/Unix.cxx src/Exceptions/MonitoringException.cxx ) @@ -86,7 +84,7 @@ set(SRCS message(STATUS "Backends") message(STATUS " Compiling StdCout backend") message(STATUS " Compiling Flume UDP/JSON backend") -message(STATUS " Compiling InfluxDB HTTP and UDP backend") +message(STATUS " Compiling InfluxDB backend with Unix socket and UDP transport") # Create library add_library(Monitoring SHARED ${SRCS} $<$:src/Backends/ApMonBackend.cxx>) @@ -104,7 +102,6 @@ target_link_libraries(Monitoring Boost::boost PRIVATE Boost::system - CURL::CURL $<$:ApMon::ApMon> ) diff --git a/README.md b/README.md index 2e912f057..7f8ce0c16 100644 --- a/README.md +++ b/README.md @@ -67,11 +67,11 @@ See table below to find out how to create `URI` for each backend: | Backend name | Transport | URI backend[-protocol] | URI query | Default verbosity | | ------------ |:-----------:|:----------------------:|:----------:| -----------------:| -| InfluxDB | HTTP | `influxdb-http` | `?db=` | `info` | +| No-op | - | `no-op` | | - | | InfluxDB | UDP | `influxdb-udp` | - | `info` | | InfluxDB | Unix socket | `influxdb-unix` | - | `info` | | ApMon | UDP | `apmon` | - | `info` | -| StdOut | - | `stdout`, `infologger` | - | `debug` | +| StdOut | - | `stdout`, `infologger` | [Prefix] | `debug` | | Flume | UDP | `flume` | - | `info` | ##### StdCout output format diff --git a/cmake/FindCURL.cmake b/cmake/FindCURL.cmake deleted file mode 100644 index c102f36b5..000000000 --- a/cmake/FindCURL.cmake +++ /dev/null @@ -1,67 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# FindCURL -# -------- -# -# Find curl -# -# IMPORTED Targets -# ^^^^^^^^^^^^^^^^ -# -# This module defines :prop_tgt:`IMPORTED` target ``CURL::CURL``, if -# curl has been found. -# -# Find the native CURL headers and libraries. -# -# :: -# -# CURL_INCLUDE_DIRS - where to find curl/curl.h, etc. -# CURL_LIBRARIES - List of libraries when using curl. -# CURL_FOUND - True if curl found. -# CURL_VERSION_STRING - the version of curl found (since CMake 2.8.8) - -# Look for the header file. -find_path(CURL_INCLUDE_DIR NAMES curl/curl.h) -mark_as_advanced(CURL_INCLUDE_DIR) - -# Look for the library (sorted from most current/relevant entry to least). -find_library(CURL_LIBRARY NAMES - curl - # Windows MSVC prebuilts: - curllib - libcurl_imp - curllib_static - # Windows older "Win32 - MSVC" prebuilts (libcurl.lib, e.g. libcurl-7.15.5-win32-msvc.zip): - libcurl -) -mark_as_advanced(CURL_LIBRARY) - -if(CURL_INCLUDE_DIR) - foreach(_curl_version_header curlver.h curl.h) - if(EXISTS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}") - file(STRINGS "${CURL_INCLUDE_DIR}/curl/${_curl_version_header}" curl_version_str REGEX "^#define[\t ]+LIBCURL_VERSION[\t ]+\".*\"") - - string(REGEX REPLACE "^#define[\t ]+LIBCURL_VERSION[\t ]+\"([^\"]*)\".*" "\\1" CURL_VERSION_STRING "${curl_version_str}") - unset(curl_version_str) - break() - endif() - endforeach() -endif() - -include(FindPackageHandleStandardArgs) -FIND_PACKAGE_HANDLE_STANDARD_ARGS(CURL - REQUIRED_VARS CURL_LIBRARY CURL_INCLUDE_DIR - VERSION_VAR CURL_VERSION_STRING) - -if(CURL_FOUND) - set(CURL_LIBRARIES ${CURL_LIBRARY}) - set(CURL_INCLUDE_DIRS ${CURL_INCLUDE_DIR}) - - if(NOT TARGET CURL::CURL) - add_library(CURL::CURL UNKNOWN IMPORTED) - set_target_properties(CURL::CURL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${CURL_INCLUDE_DIRS}") - set_property(TARGET CURL::CURL APPEND PROPERTY IMPORTED_LOCATION "${CURL_LIBRARY}") - endif() -endif() diff --git a/src/Backends/InfluxDB.cxx b/src/Backends/InfluxDB.cxx index fe687c9d2..60a8fd78b 100644 --- a/src/Backends/InfluxDB.cxx +++ b/src/Backends/InfluxDB.cxx @@ -7,7 +7,6 @@ #include #include #include "../Transports/UDP.h" -#include "../Transports/HTTP.h" #include "../Transports/Unix.h" #include "../Exceptions/MonitoringException.h" @@ -27,15 +26,6 @@ InfluxDB::InfluxDB(const std::string& host, unsigned int port) : << " ("<< host << ":" << port << ")" << MonLogger::End(); } -InfluxDB::InfluxDB(const std::string& host, unsigned int port, const std::string& search) -{ - mTransport = std::make_unique( - "http://" + host + ":" + std::to_string(port) + "/write?" + search - ); - MonLogger::Get() << "InfluxDB/HTTP backend initialized" << " (" << "http://" << host - << ":" << std::to_string(port) << "/write?" << search << ")" << MonLogger::End(); -} - InfluxDB::InfluxDB(const std::string& socketPath) : mTransport(std::make_unique(socketPath)) { diff --git a/src/Backends/InfluxDB.h b/src/Backends/InfluxDB.h index bdff100ac..88baa2359 100644 --- a/src/Backends/InfluxDB.h +++ b/src/Backends/InfluxDB.h @@ -32,12 +32,7 @@ class InfluxDB final : public Backend /// \param port InfluxDB UDP endpoint port number InfluxDB(const std::string& host, unsigned int port); - /// Constructor for HTTP transport - /// \param host InfluxDB HTTP endpoint hostname - /// \param port InfluxDB HTTP endpoint port number - /// \param path Query search providing database name - InfluxDB(const std::string& host, unsigned int port, const std::string& search); - + /// Constructor for Unix socket transport InfluxDB(const std::string& socketPath); /// Default destructor diff --git a/src/MonitoringFactory.cxx b/src/MonitoringFactory.cxx index 43c84c502..d67eab188 100644 --- a/src/MonitoringFactory.cxx +++ b/src/MonitoringFactory.cxx @@ -49,9 +49,6 @@ std::unique_ptr getInfluxDb(http::url uri) { if (uri.protocol == "udp") { return std::make_unique(uri.host, uri.port); } - if (uri.protocol == "http") { - return std::make_unique(uri.host, uri.port, uri.search); - } if (uri.protocol == "unix") { std::string path = uri.path;; auto found = std::find_if(begin(verbosities), end(verbosities), @@ -99,7 +96,6 @@ std::unique_ptr MonitoringFactory::GetBackend(std::string& url) { {"infologger", getStdOut}, {"stdout", getStdOut}, {"influxdb-udp", getInfluxDb}, - {"influxdb-http", getInfluxDb}, {"influxdb-unix", getInfluxDb}, {"apmon", getApMon}, {"flume", getFlume}, diff --git a/src/Transports/HTTP.cxx b/src/Transports/HTTP.cxx deleted file mode 100644 index de6efbea9..000000000 --- a/src/Transports/HTTP.cxx +++ /dev/null @@ -1,70 +0,0 @@ -/// -/// \file HTTP.cxx -/// \author Adam Wegrzynek -/// - -#include "HTTP.h" -#include "../MonLogger.h" -#include "../Exceptions/MonitoringException.h" -#include -#include - -namespace o2 -{ -/// ALICE O2 Monitoring system -namespace monitoring -{ -/// Monitoring transports -namespace transports -{ - -HTTP::HTTP(const std::string& url) : - curlHandle(initCurl(url), &HTTP::deleteCurl) -{ -} - -CURL* HTTP::initCurl(std::string url) -{ - CURLcode globalInitResult = curl_global_init(CURL_GLOBAL_ALL); - if (globalInitResult != CURLE_OK) { - throw MonitoringException("cURL init", curl_easy_strerror(globalInitResult)); - } - - CURL *curl = curl_easy_init(); - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0); - curl_easy_setopt(curl, CURLOPT_CONNECTTIMEOUT, 10); - curl_easy_setopt(curl, CURLOPT_TIMEOUT, 10); - curl_easy_setopt(curl, CURLOPT_POST, 1); - curl_easy_setopt(curl, CURLOPT_TCP_KEEPIDLE, 120L); - curl_easy_setopt(curl, CURLOPT_TCP_KEEPINTVL, 60L); - FILE *devnull = fopen("/dev/null", "w+"); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, devnull); - return curl; -} - -void HTTP::deleteCurl(CURL * curl) -{ - curl_easy_cleanup(curl); - curl_global_cleanup(); -} - -void HTTP::send(std::string&& post) -{ - CURLcode response; - long responseCode; - curl_easy_setopt(curlHandle.get(), CURLOPT_POSTFIELDS, post.c_str()); - curl_easy_setopt(curlHandle.get(), CURLOPT_POSTFIELDSIZE, (long) post.length()); - response = curl_easy_perform(curlHandle.get()); - curl_easy_getinfo(curlHandle.get(), CURLINFO_RESPONSE_CODE, &responseCode); - if (response != CURLE_OK) { - MonLogger::Get() << "HTTP Tranport " << curl_easy_strerror(response) << MonLogger::End(); - } - if (responseCode < 200 || responseCode > 206) { - MonLogger::Get() << "HTTP Transport: Response code : " << std::to_string(responseCode) << MonLogger::End(); - } -} - -} // namespace transports -} // namespace monitoring -} // namespace o2 diff --git a/src/Transports/HTTP.h b/src/Transports/HTTP.h deleted file mode 100644 index 60be959a3..000000000 --- a/src/Transports/HTTP.h +++ /dev/null @@ -1,59 +0,0 @@ -/// -/// \file HTTP.h -/// \author Adam Wegrzynek -/// - -#ifndef ALICEO2_MONITORING_TRANSPORTS_HTTP_H -#define ALICEO2_MONITORING_TRANSPORTS_HTTP_H - -#include "TransportInterface.h" - -#include -#include -#include - -namespace o2 -{ -/// ALICE O2 Monitoring system -namespace monitoring -{ -/// Monitoring transports -namespace transports -{ - -/// \brief HTTP POST transport for Monitoring backends -/// -/// Allows to push string formatted metrics as HTTP POST requests via cURL -class HTTP : public TransportInterface -{ - public: - /// Constructor - /// \param url URL of HTTP server endpoint - HTTP(const std::string& url); - - /// Default destructor - ~HTTP() = default; - - /// Sends metric via HTTP POST - /// \param post r-value reference string formatted metric - void send(std::string&& post); - - private: - /// Custom deleter of CURL object - /// \param curl CURL handle - static void deleteCurl(CURL * curl); - - /// Initilizes CURL and all common options - /// \param url URL to InfluxDB - /// \return CURL handle - CURL* initCurl(std::string url); - - /// CURL smart pointer with custom deleter - std::unique_ptr curlHandle; -}; - -} // namespace transports -} // namespace monitoring -} // namespace o2 - -#endif // ALICEO2_MONITORING_TRANSPORTS_HTTP_H diff --git a/test/testMonitoringFactory.cxx b/test/testMonitoringFactory.cxx index 0a843d24e..6079e44d4 100644 --- a/test/testMonitoringFactory.cxx +++ b/test/testMonitoringFactory.cxx @@ -28,8 +28,8 @@ BOOST_AUTO_TEST_CASE(verbosity) auto influxDebug = Monitoring::GetBackend(influxDebugUrl); BOOST_CHECK_EQUAL(static_cast::type>(influxDebug->getVerbosity()), 2); - std::string influxHttpUrl = "influxdb-http://127.0.0.1:1234/?db=test"; - auto influxHttp = Monitoring::GetBackend(influxHttpUrl); + std::string influxUnixUrl = "influxdb-unix://127.0.0.1:1234/?db=test"; + auto influxHttp = Monitoring::GetBackend(influxUnixUrl); std::string ilProdUrl = "stdout:///info"; auto ilProd = Monitoring::GetBackend(ilProdUrl);