diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..87c0807 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,40 @@ +name: Build + +on: + pull_request: + push: + branches: + - main + +jobs: + build: + if: ${{ github.repository == 'Netflix/spectator-cpp' }} + runs-on: ubuntu-latest + env: + CC: "gcc-11" + CXX: "g++-11" + LANG: "en_US.UTF-8" + steps: + - uses: actions/checkout@v2 + + - name: Bazel Cache + uses: actions/cache@v3 + with: + path: ~/.cache/bazel + key: ${{ runner.os }}-bazel + + - name: Install System Dependencies + run: | + curl -fsSL https://bazel.build/bazel-release.pub.gpg | gpg --dearmor > bazel.gpg + sudo mv bazel.gpg /etc/apt/trusted.gpg.d/ + echo "deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8" | sudo tee /etc/apt/sources.list.d/bazel.list + sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test + sudo apt-get update && sudo apt-get install -y bazel binutils-dev g++-11 + + - name: Build spectator-cpp + run: | + bazel --output_user_root=~/.cache/bazel --batch build --config asan spectator_test spectator + + - name: Test spectator-cpp + run: | + GTEST_COLOR=1 ./bazel-bin/spectator_test diff --git a/.gitignore b/.gitignore index c4ecf75..54b6549 100644 --- a/.gitignore +++ b/.gitignore @@ -1,16 +1,5 @@ -CMakeCache.txt -CMakeFiles/ -CTestTestfile.cmake -Makefile -cmake_install.cmake -bazel-* -build-* -node_modules/ -npm-debug.log -.newt.netflix_environment.sh -cmake-build-* -logs/ +.clwb/ .idea/ .vscode/ -.clwb -compile_commands.json +bazel-* +build-* diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index de8b72e..0000000 --- a/.travis.yml +++ /dev/null @@ -1,32 +0,0 @@ -language: cpp -dist: bionic -script: ./run-build.sh - -addons: - apt: - sources: - - sourceline: 'deb [arch=amd64] https://storage.googleapis.com/bazel-apt stable jdk1.8' - key_url: 'https://bazel.build/bazel-release.pub.gpg' - - sourceline: 'deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-11 main' - key_url: 'https://apt.llvm.org/llvm-snapshot.gpg.key' - - sourceline: 'ppa:ubuntu-toolchain-r/test' - packages: - - bazel-3.5.0 - - clang-11 - - g++-10 - - binutils-dev - - lcov - -matrix: - include: - - os: linux - compiler: clang - env: CC='clang' CXX='clang++' - -env: - global: - - LANG="en_US.UTF-8" - -cache: - directories: - - $HOME/.cache/bazel diff --git a/README.md b/README.md index dc3ed0b..d4763d6 100644 --- a/README.md +++ b/README.md @@ -1,17 +1,14 @@ -[![Build Status](https://travis-ci.org/Netflix/spectator-cpp.svg?branch=master)](https://travis-ci.org/Netflix/spectator-cpp) +[![Build](https://github.com/Netflix/spectator-cpp/actions/workflows/build.yml/badge.svg)](https://github.com/Netflix/spectator-cpp/actions/workflows/build.yml) # Spectator-cpp -> :warning: Experimental - -Simple library for instructing code to record dimensional time series. It -sends all activity to a -[spectatord](https://github.com/Netflix-Skunkworks/spectatord) sidecar. +Simple library for instructing code to record dimensional time series. It sends all activity to +a [spectatord](https://github.com/Netflix-Skunkworks/spectatord) sidecar. ## Description -This implements a basic [Spectator](https://github.com/Netflix/spectator) library -for instrumenting C++ applications, sending all metric activity to a sidecar. +This implements a basic [Spectator](https://github.com/Netflix/spectator) library for instrumenting +C++ applications, sending all metric activity to a sidecar. ## Instrumenting Code @@ -44,13 +41,13 @@ class Server { // do some work and obtain a response... Response res{200, 64}; - // Update the counter id with dimensions based on the request. The - // counter will then be looked up in the registry which should be - // fairly cheap, such as lookup of id object in a map - // However, it is more expensive than having a local variable set - // to the counter. - auto cnt_id = request_count_id_->WithTag("country", request.country) - ->WithTag("status", std::to_string(res.status)); + // Update the Counter id with dimensions, based on information in the request. The Counter + // will be looked up in the Registry, which is a fairly cheap operation, about the same as + // the lookup of an id object in a map. However, it is more expensive than having a local + // variable set to the Counter. + auto cnt_id = request_count_id_ + ->WithTag("country", request.country) + ->WithTag("status", std::to_string(res.status)); registry_->GetCounter(std::move(cnt_id))->Increment(); request_latency_->Record(std::chrono::steady_clock::now() - start); response_size_->Record(res.size); @@ -65,7 +62,6 @@ class Server { }; Request get_next_request() { - //... return Request{"US"}; } @@ -82,6 +78,5 @@ int main() { auto req = get_next_request(); server.Handle(req); } - } ``` diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..22e3435 --- /dev/null +++ b/build.sh @@ -0,0 +1,4 @@ +#!/bin/bash + +bazel --output_user_root=$HOME/.cache/bazel --batch build --config asan spectator_test spectator +GTEST_COLOR=1 ./bazel-bin/spectator_test diff --git a/codecov.yml b/codecov.yml deleted file mode 100644 index 765e05d..0000000 --- a/codecov.yml +++ /dev/null @@ -1,7 +0,0 @@ -comment: - layout: "reach, diff, flags, files" - behavior: default - require_changes: false # if true: only post the comment if coverage changes - require_base: no # [yes :: must have a base report to post] - require_head: yes # [yes :: must have a head report to post] - branches: null diff --git a/create-lcov-report.sh b/create-lcov-report.sh deleted file mode 100755 index a299e5c..0000000 --- a/create-lcov-report.sh +++ /dev/null @@ -1,12 +0,0 @@ -# Creating report -set -ex -if [ x$TRAVIS_BUILD_DIR != x ]; then - cd $TRAVIS_BUILD_DIR -fi -echo $PWD -# capture coverage info -lcov --directory . --capture --output-file coverage.info -# filter out system, cmake-build, tests and 3rd-party code from our test coverage -lcov --remove coverage.info '/usr/*' '*/usr/*' '*_test*' --output-file coverage.info -# print report to stdout for debugging -lcov --list coverage.info diff --git a/run-build.sh b/run-build.sh deleted file mode 100755 index da304e6..0000000 --- a/run-build.sh +++ /dev/null @@ -1,5 +0,0 @@ -#!/bin/bash - -bazel-3.5.0 --output_user_root=$HOME/.cache/bazel --batch build --config asan spectator_test spectator -./bazel-bin/spectator_test - diff --git a/spectator/publisher.cc b/spectator/publisher.cc index 26d3140..13c8879 100644 --- a/spectator/publisher.cc +++ b/spectator/publisher.cc @@ -21,7 +21,7 @@ SpectatordPublisher::SpectatordPublisher(absl::string_view endpoint, setup_udp(endpoint.substr(pos)); } else if (endpoint != "disabled") { logger_->warn( - "Unknown endpoint: {}. Expecting: 'unix:/path/to/socket'" + "Unknown endpoint: '{}'. Expecting: 'unix:/path/to/socket'" " or 'udp:hostname:port' - Will not send metrics", std::string(endpoint)); setup_nop_sender();