forked from cancecen/spectator-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
replace invalid characters in ids (Netflix#106)
It is easy enough to break the spectatord line protocol, if any of the control characters (`:,=`) are inserted in unexpected places. Since metric names and tags are often programmatically generated, we want to only construct id strings which are valid.
- Loading branch information
1 parent
8d9ab60
commit 1bdddd5
Showing
16 changed files
with
275 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,3 +3,4 @@ | |
.vscode/ | ||
bazel-* | ||
build-* | ||
spectator/valid_chars.inc |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
cmake_minimum_required(VERSION 3.13) | ||
|
||
project(spectator-cpp) | ||
|
||
set(CMAKE_CXX_STANDARD 17) | ||
set(CMAKE_CXX_STANDARD_REQUIRED True) | ||
|
||
add_compile_options(-fno-omit-frame-pointer "$<$<CONFIG:Debug>:-fsanitize=address>") | ||
add_link_options(-fno-omit-frame-pointer "$<$<CONFIG:Debug>:-fsanitize=address>") | ||
|
||
include(CTest) | ||
include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) | ||
conan_basic_setup() | ||
|
||
#-- spectator_test test executable | ||
file(GLOB spectator_test_source_files | ||
"spectator/*_test.cc" | ||
"spectator/test_*.cc" | ||
"spectator/test_*.h" | ||
) | ||
add_executable(spectator_test ${spectator_test_source_files}) | ||
target_link_libraries(spectator_test spectator ${CONAN_LIBS}) | ||
add_test( | ||
NAME spectator_test | ||
COMMAND spectator_test | ||
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} | ||
) | ||
|
||
#-- spectator library | ||
add_library(spectator | ||
"spectator/logger.cc" | ||
"spectator/publisher.cc" | ||
"spectator/config.h" | ||
"spectator/id.h" | ||
"spectator/logger.h" | ||
"spectator/measurement.h" | ||
"spectator/meter_type.h" | ||
"spectator/publisher.h" | ||
"spectator/registry.h" | ||
"spectator/stateful_meters.h" | ||
"spectator/stateless_meters.h" | ||
"spectator/valid_chars.inc" | ||
) | ||
target_link_libraries(spectator ${CONAN_LIBS}) | ||
target_link_options(spectator PRIVATE "$<$<CONFIG:Release>:-static-libstdc++>") | ||
|
||
#-- generator tools | ||
add_executable(gen_valid_chars "tools/gen_valid_chars.cc") | ||
|
||
#-- file generators, must exist where the outputs are referenced | ||
add_custom_command( | ||
OUTPUT "spectator/valid_chars.inc" | ||
COMMAND "${CMAKE_BINARY_DIR}/bin/gen_valid_chars" > "${CMAKE_SOURCE_DIR}/spectator/valid_chars.inc" | ||
DEPENDS gen_valid_chars | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include "stateless_meters.h" | ||
#include "test_publisher.h" | ||
#include <gtest/gtest.h> | ||
|
||
namespace { | ||
|
||
using spectator::Id; | ||
using spectator::MonotonicCounterUint; | ||
using spectator::Tags; | ||
using spectator::TestPublisher; | ||
|
||
TEST(MonotonicCounterUint, Set) { | ||
TestPublisher publisher; | ||
auto id = std::make_shared<Id>("ctr", Tags{}); | ||
auto id2 = std::make_shared<Id>("ctr2", Tags{{"key", "val"}}); | ||
MonotonicCounterUint<TestPublisher> c{id, &publisher}; | ||
MonotonicCounterUint<TestPublisher> c2{id2, &publisher}; | ||
|
||
c.Set(42); | ||
c2.Set(2); | ||
c.Set(-1); | ||
std::vector<std::string> expected = {"U:ctr:42", "U:ctr2,key=val:2", "U:ctr:18446744073709551615"}; | ||
EXPECT_EQ(publisher.SentMessages(), expected); | ||
} | ||
|
||
TEST(MonotonicCounterUint, InvalidTags) { | ||
TestPublisher publisher; | ||
// test with a single tag, because tags order is not guaranteed in a flat_hash_map | ||
auto id = std::make_shared<Id>("test`!@#$%^&*()-=~_+[]{}\\|;:'\",<.>/?foo", | ||
Tags{{"tag1,:=", "value1,:="}}); | ||
MonotonicCounterUint c{id, &publisher}; | ||
EXPECT_EQ("U:test______^____-_~______________.___foo,tag1___=value1___:", c.GetPrefix()); | ||
} | ||
} // namespace |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.