diff --git a/.build/Dockerfile b/.build/Dockerfile new file mode 100644 index 0000000..5be5df5 --- /dev/null +++ b/.build/Dockerfile @@ -0,0 +1,22 @@ +ARG TAG=ubuntu18 + +FROM neogenie/iqlogger_builder:$TAG + +ARG VERSION +ARG TAG +ARG ARCH +ARG UBUNTU + +ARG CI_PIPELINE_ID +ARG CI_COMMIT_REF_NAME +ARG CI_COMMIT_MESSAGE +ARG CI_COMMIT_SHA +ARG CI_USER + +ADD . /iqlogger +WORKDIR iqlogger + +RUN .build/${TAG}.sh + +RUN cp iqlogger .build_deb/${TAG}/usr/local/bin/ +RUN bash .build_deb/create-deb.sh \ No newline at end of file diff --git a/.build/build-16.sh b/.build/ubuntu16.sh similarity index 100% rename from .build/build-16.sh rename to .build/ubuntu16.sh diff --git a/.build/build-18.sh b/.build/ubuntu18.sh similarity index 100% rename from .build/build-18.sh rename to .build/ubuntu18.sh diff --git a/.build_deb/create-deb.sh b/.build_deb/create-deb.sh new file mode 100644 index 0000000..0b98dc5 --- /dev/null +++ b/.build_deb/create-deb.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +rm .build_deb/${TAG}/var/log/iqlogger/.gitkeep +rm .build_deb/${TAG}/var/lib/iqlogger/.gitkeep +rm .build_deb/${TAG}/usr/local/bin/.gitkeep +cd .build_deb/${TAG} +fpm -s dir -t deb -a ${ARCH} -n iqlogger -v ${VERSION}-${UBUNTU} -m neogenie@yandex.ru \ + -d libtbb2 -d zlib1g \ + --pre-install ../pre-install.sh \ + --after-install ../post-install.sh \ + --vendor neogenie@yandex.ru \ + --config-files etc/iqlogger \ + etc/ usr/ var/ diff --git a/.build_deb/create_deb_16.sh b/.build_deb/create_deb_16.sh deleted file mode 100644 index 3eb9573..0000000 --- a/.build_deb/create_deb_16.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -VERSION=`cat version` - -rm .build_deb/ubuntu-16/var/log/iqlogger/.gitkeep -rm .build_deb/ubuntu-16/var/lib/iqlogger/.gitkeep -rm .build_deb/ubuntu-16/usr/local/bin/.gitkeep -cd .build_deb/ubuntu-16 -fpm -s dir -t deb -a amd64 -n iqlogger -v ${VERSION}-xenial -m sergey.tarasov@iqoption.com \ - -d libtbb2 -d zlib1g \ - --pre-install ../pre-install.sh \ - --after-install ../post-install.sh \ - --vendor noc@iqoption.com \ - --config-files etc/iqlogger \ - etc/ usr/ var/ diff --git a/.build_deb/create_deb_18.sh b/.build_deb/create_deb_18.sh deleted file mode 100644 index 11b19fa..0000000 --- a/.build_deb/create_deb_18.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -VERSION=`cat version` - -rm .build_deb/ubuntu-18/var/log/iqlogger/.gitkeep -rm .build_deb/ubuntu-18/var/lib/iqlogger/.gitkeep -rm .build_deb/ubuntu-18/usr/local/bin/.gitkeep -cd .build_deb/ubuntu-18 -fpm -s dir -t deb -a amd64 -n iqlogger -v ${VERSION}-bionic -m sergey.tarasov@iqoption.com \ - -d libtbb2 -d zlib1g \ - --pre-install ../pre-install.sh \ - --after-install ../post-install.sh \ - --vendor noc@iqoption.com \ - --config-files etc/iqlogger \ - etc/ usr/ var/ diff --git a/.build_deb/ubuntu-16/etc/iqlogger/iqlogger.json b/.build_deb/ubuntu16/etc/iqlogger/iqlogger.json similarity index 100% rename from .build_deb/ubuntu-16/etc/iqlogger/iqlogger.json rename to .build_deb/ubuntu16/etc/iqlogger/iqlogger.json diff --git a/.build_deb/ubuntu-16/etc/iqlogger/processor.js b/.build_deb/ubuntu16/etc/iqlogger/processor.js similarity index 100% rename from .build_deb/ubuntu-16/etc/iqlogger/processor.js rename to .build_deb/ubuntu16/etc/iqlogger/processor.js diff --git a/.build_deb/ubuntu-16/etc/systemd/system/iqlogger.service b/.build_deb/ubuntu16/etc/systemd/system/iqlogger.service similarity index 100% rename from .build_deb/ubuntu-16/etc/systemd/system/iqlogger.service rename to .build_deb/ubuntu16/etc/systemd/system/iqlogger.service diff --git a/.build_deb/ubuntu-16/usr/local/bin/.gitkeep b/.build_deb/ubuntu16/usr/local/bin/.gitkeep similarity index 100% rename from .build_deb/ubuntu-16/usr/local/bin/.gitkeep rename to .build_deb/ubuntu16/usr/local/bin/.gitkeep diff --git a/.build_deb/ubuntu-16/var/lib/iqlogger/.gitkeep b/.build_deb/ubuntu16/var/lib/iqlogger/.gitkeep similarity index 100% rename from .build_deb/ubuntu-16/var/lib/iqlogger/.gitkeep rename to .build_deb/ubuntu16/var/lib/iqlogger/.gitkeep diff --git a/.build_deb/ubuntu-16/var/log/iqlogger/.gitkeep b/.build_deb/ubuntu16/var/log/iqlogger/.gitkeep similarity index 100% rename from .build_deb/ubuntu-16/var/log/iqlogger/.gitkeep rename to .build_deb/ubuntu16/var/log/iqlogger/.gitkeep diff --git a/.build_deb/ubuntu-18/etc/iqlogger/iqlogger.json b/.build_deb/ubuntu18/etc/iqlogger/iqlogger.json similarity index 100% rename from .build_deb/ubuntu-18/etc/iqlogger/iqlogger.json rename to .build_deb/ubuntu18/etc/iqlogger/iqlogger.json diff --git a/.build_deb/ubuntu-18/etc/iqlogger/processor.js b/.build_deb/ubuntu18/etc/iqlogger/processor.js similarity index 100% rename from .build_deb/ubuntu-18/etc/iqlogger/processor.js rename to .build_deb/ubuntu18/etc/iqlogger/processor.js diff --git a/.build_deb/ubuntu-18/etc/systemd/system/iqlogger.service b/.build_deb/ubuntu18/etc/systemd/system/iqlogger.service similarity index 100% rename from .build_deb/ubuntu-18/etc/systemd/system/iqlogger.service rename to .build_deb/ubuntu18/etc/systemd/system/iqlogger.service diff --git a/.build_deb/ubuntu-18/usr/local/bin/.gitkeep b/.build_deb/ubuntu18/usr/local/bin/.gitkeep similarity index 100% rename from .build_deb/ubuntu-18/usr/local/bin/.gitkeep rename to .build_deb/ubuntu18/usr/local/bin/.gitkeep diff --git a/.build_deb/ubuntu-18/var/lib/iqlogger/.gitkeep b/.build_deb/ubuntu18/var/lib/iqlogger/.gitkeep similarity index 100% rename from .build_deb/ubuntu-18/var/lib/iqlogger/.gitkeep rename to .build_deb/ubuntu18/var/lib/iqlogger/.gitkeep diff --git a/.build_deb/ubuntu-18/var/log/iqlogger/.gitkeep b/.build_deb/ubuntu18/var/log/iqlogger/.gitkeep similarity index 100% rename from .build_deb/ubuntu-18/var/log/iqlogger/.gitkeep rename to .build_deb/ubuntu18/var/log/iqlogger/.gitkeep diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e393171 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,46 @@ +os: linux +dist: xenial +language: shell + +services: + - docker + +jobs: + include: + - env: + - TAG=ubuntu16 + - ARCH=amd64 + - UBUNTU=xenial + - env: + - TAG=ubuntu18 + - ARCH=amd64 + - UBUNTU=bionic + +script: + - echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin; + - export VERSION=`cat ./version` + - chmod +x .build/ubuntu16.sh + - chmod +x .build/ubuntu18.sh + - docker build -t builder --build-arg VERSION="$VERSION" --build-arg TAG="$TAG" --build-arg ARCH="$ARCH" --build-arg UBUNTU="$UBUNTU" --build-arg CI_PIPELINE_ID="$TRAVIS_BUILD_NUMBER" --build-arg CI_COMMIT_REF_NAME="$TRAVIS_BRANCH" --build-arg CI_COMMIT_SHA="$TRAVIS_COMMIT" --build-arg CI_COMMIT_MESSAGE="$TRAVIS_COMMIT_MESSAGE" --build-arg CI_USER="$USER" -f .build/Dockerfile . + - docker create --name builder builder + - mkdir -p ${TRAVIS_BUILD_DIR}/build + - docker cp builder:/iqlogger/iqlogger ${TRAVIS_BUILD_DIR}/build/ + - docker cp builder:/iqlogger/.build_deb/${TAG}/iqlogger_$VERSION-${UBUNTU}_$ARCH.deb ${TRAVIS_BUILD_DIR}/build/ + - docker rm builder + - ls -alh ${TRAVIS_BUILD_DIR}/build + - cp ${TRAVIS_BUILD_DIR}/build/iqlogger .docker/usr/local/bin/; + - if [[ "$TAG" == "ubuntu18" ]]; then + docker build -t ${DOCKER_REPOSITORY}:$VERSION .docker; + docker push ${DOCKER_REPOSITORY}:$VERSION; + docker tag ${DOCKER_REPOSITORY}:$VERSION ${DOCKER_REPOSITORY}:latest; + docker push ${DOCKER_REPOSITORY}:latest; + fi + +deploy: + provider: releases + api_key: "$GITHUB_TOKEN" + file_glob: true + file: ${TRAVIS_BUILD_DIR}/build/*.deb + skip_cleanup: true + on: + tags: true \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 01c8944..4ec8afe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,6 +31,39 @@ configure_file ( "${PROJECT_BINARY_DIR}/src/Version.h" ) +if (DEFINED ENV{CI_PIPELINE_ID}) + set(BUILD_ID "$ENV{CI_PIPELINE_ID}") +else () + set(BUILD_ID "undefined") +endif () +message("Build id: ${BUILD_ID}") + +if (DEFINED ENV{CI_COMMIT_REF_NAME}) + set(BUILD_COMMIT "$ENV{CI_COMMIT_SHA} ($ENV{CI_COMMIT_MESSAGE})") + set(GIT_VERSION "$ENV{CI_COMMIT_REF_NAME}") +else () + set(BUILD_COMMIT "undefined (undefined)") + execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_VERSION + OUTPUT_STRIP_TRAILING_WHITESPACE + ) +endif () +message("Build commit: ${BUILD_COMMIT}") +message("Git version: ${GIT_VERSION}") + +string(TIMESTAMP BUILD_DATE_TIME "%Y-%m-%d %H:%M:%S UTC" UTC) + +if (DEFINED ENV{CI_USER}) + set(BUILD_USER "$ENV{CI_USER}") +else () + set(BUILD_USER "undefined") +endif () + +message("Build date: ${BUILD_DATE_TIME}") +message("Build user: ${BUILD_USER}") + configure_file ( "${PROJECT_SOURCE_DIR}/src/config/Config.h.in" "${PROJECT_BINARY_DIR}/src/config/Config.h" @@ -38,14 +71,24 @@ configure_file ( set(Boost_USE_STATIC_LIBS ON) set(Boost_USE_MULTITHREADED ON) -set(Boost_USE_STATIC_RUNTIME ON) -find_package(Boost COMPONENTS system iostreams program_options REQUIRED) +find_package(Boost COMPONENTS system iostreams program_options regex REQUIRED) if(NOT Boost_FOUND) message(FATAL "Boost not found!") endif() +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang") + set(CPP_FILESYSTEM_LIB "c++fs") +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CPP_FILESYSTEM_LIB "stdc++fs") + set(EC_STATIC_GLIBC ON) +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Intel") + message(FATAL "Intel is not supported!") +elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC") + message(FATAL "MS Visual Studio is not supported!") +endif() + include_directories("${PROJECT_SOURCE_DIR}/src") include_directories(${Boost_INCLUDE_DIRS}) @@ -80,7 +123,7 @@ add_executable(${PROJECT_NAME} src/main.cpp src/formats/gelf/GelfMessage.cpp ) -set(IQLOGGER_LIBS "${IQLOGGER_INPUT_LIBRARIES}${IQLOGGER_OUTPUT_LIBRARIES}${IQLOGGER_STATS_LIBRARIES};${Boost_LIBRARIES};tbb;pthread;z;stdc++fs") +set(IQLOGGER_LIBS "${IQLOGGER_INPUT_LIBRARIES}${IQLOGGER_OUTPUT_LIBRARIES}${IQLOGGER_STATS_LIBRARIES};${Boost_LIBRARIES};${CPP_FILESYSTEM_LIB};tbb;pthread;z;") if(IQLOGGER_WITH_PROCESSOR) message("Processor detected") diff --git a/README.md b/README.md index 3626bd7..e88c6bd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,9 @@ IQ Logger ======================= +[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0) +[![Build Status](https://travis-ci.org/iqoption/iqlogger.svg?branch=master)](https://travis-ci.org/iqoption/iqlogger) + **IQLogger** - высокопроизводительное легковесное решение для сбора, процессинга, транспорта и балансировки логов из любых источников, включая: - логи своих приложений diff --git a/src/inputs/Record.h b/src/inputs/Record.h index bad095c..74b642b 100644 --- a/src/inputs/Record.h +++ b/src/inputs/Record.h @@ -47,7 +47,7 @@ namespace iqlogger::inputs { public: - template ::value>> + template >> explicit Record(RecordDataT&& data) : m_data(std::move(data)) { TRACE("inputs::Record::Record()"); @@ -55,8 +55,9 @@ namespace iqlogger::inputs { template < class U, - typename = std::enable_if_t>::value>, - typename = std::enable_if_t::value> + typename ST = typename T::SourceT, + typename = std::enable_if_t>>, + typename = std::enable_if_t> > explicit Record(RecordDataT&& data, U&& source) : m_data(std::move(data)), m_source(std::forward(source)) { diff --git a/src/inputs/gelf/tcp/Server.h b/src/inputs/gelf/tcp/Server.h index 0aaf005..e69e02a 100644 --- a/src/inputs/gelf/tcp/Server.h +++ b/src/inputs/gelf/tcp/Server.h @@ -114,7 +114,8 @@ namespace iqlogger::inputs::gelf::tcp { public: explicit Server(RecordQueuePtr queuePtr, boost::asio::io_service &io_service, short port) - : m_acceptor(io_service, tcp::endpoint(tcp::v4(), port)), + : m_io_service(io_service), + m_acceptor(io_service, tcp::endpoint(tcp::v4(), port)), m_queuePtr(queuePtr) { start_accept(); @@ -128,7 +129,7 @@ namespace iqlogger::inputs::gelf::tcp { void start_accept() { tcp_connection::pointer new_connection = - tcp_connection::create(m_acceptor.get_io_service(), m_queuePtr); + tcp_connection::create(m_io_service, m_queuePtr); auto handler = [this, new_connection](const boost::system::error_code &error) { handle_accept(new_connection, error); @@ -152,6 +153,7 @@ namespace iqlogger::inputs::gelf::tcp { start_accept(); } + boost::asio::io_service &m_io_service; tcp::acceptor m_acceptor; RecordQueuePtr m_queuePtr; }; diff --git a/src/inputs/json/tcp/Server.h b/src/inputs/json/tcp/Server.h index 0191d73..1438549 100644 --- a/src/inputs/json/tcp/Server.h +++ b/src/inputs/json/tcp/Server.h @@ -114,7 +114,8 @@ namespace iqlogger::inputs::json::tcp { public: explicit Server(RecordQueuePtr queuePtr, boost::asio::io_service &io_service, short port) - : m_acceptor(io_service, tcp::endpoint(tcp::v4(), port)), + : m_io_service(io_service), + m_acceptor(io_service, tcp::endpoint(tcp::v4(), port)), m_queuePtr(queuePtr) { start_accept(); @@ -128,7 +129,7 @@ namespace iqlogger::inputs::json::tcp { void start_accept() { tcp_connection::pointer new_connection = - tcp_connection::create(m_acceptor.get_io_service(), m_queuePtr); + tcp_connection::create(m_io_service, m_queuePtr); auto handler = [this, new_connection](const boost::system::error_code &error) { handle_accept(new_connection, error); @@ -152,6 +153,7 @@ namespace iqlogger::inputs::json::tcp { start_accept(); } + boost::asio::io_service &m_io_service; tcp::acceptor m_acceptor; RecordQueuePtr m_queuePtr; }; diff --git a/src/outputs/gelf/tcp/GelfOutput.cpp b/src/outputs/gelf/tcp/GelfOutput.cpp index 6c7d4fd..dcab992 100644 --- a/src/outputs/gelf/tcp/GelfOutput.cpp +++ b/src/outputs/gelf/tcp/GelfOutput.cpp @@ -75,11 +75,11 @@ GelfOutput::GelfOutput(config::DestinationConfig destinationConfig, metrics::ato } }; - auto connect = [&socket, &error, upstream, port = m_port, &run]() { + auto connect = [this, &socket, &error, upstream, port = m_port, &run]() { DEBUG("Connect to " << upstream << ":" << port); - boost::asio::ip::tcp::resolver resolver(socket.get_io_service()); + boost::asio::ip::tcp::resolver resolver(m_io_service); try {