diff --git a/README.md b/README.md index 7e67e19..4bcac91 100644 --- a/README.md +++ b/README.md @@ -2,8 +2,8 @@ # Spectator-cpp -This implements a basic [Spectator](https://github.com/Netflix/spectator) library for instrumenting CPP applications. It -consists of a thin client designed to send metrics through [spectatord](https://github.com/Netflix-Skunkworks/spectatord). +This implements a basic [Spectator](https://github.com/Netflix/spectator) library for instrumenting CPP applications. +It consists of a thin client designed to send metrics through [spectatord](https://github.com/Netflix-Skunkworks/spectatord). ## High-Volume Publishing diff --git a/libs/README.md b/libs/README.md index 95ab922..ed429d5 100644 --- a/libs/README.md +++ b/libs/README.md @@ -1,6 +1,7 @@ # Spectator-CPP Libraries -This directory contains all the core libraries that make up the Spectator-CPP framework. These modular components work together to build the implementation of the main Spectator Registry interface. +This directory contains all the core libraries that make up the Spectator-CPP framework. These modular components work +together to build the implementation of the main Spectator Registry interface. ## Library Overview @@ -10,12 +11,14 @@ This directory contains all the core libraries that make up the Spectator-CPP fr | `logger` | Logging facilities used throughout the framework | | `meter` | Core metrics implementations including counters, gauges, timers, and meter identification | | `utils` | Utility classes and helpers including singleton patterns | -| `writer` | Output writers for metrics data (file, memory, UDP, Unix Domain Socket) | +| `writer` | Output writers for metrics data (Memory, UDP, Unix Domain Socket) | ## Usage -Each library subfolder contains additional documentation describing its specific API and usage examples. See the main project README for complete integration instructions. +Each library subfolder contains additional documentation describing its specific API and usage examples. See the main +project README for complete integration instructions. ## Dependencies -Most libraries have minimal external dependencies, though some writers may require specific system capabilities for networking. \ No newline at end of file +Most libraries have minimal external dependencies, though some writers may require specific system capabilities for +networking. \ No newline at end of file diff --git a/libs/config/README.md b/libs/config/README.md index d6e53255..e4836a6 100644 --- a/libs/config/README.md +++ b/libs/config/README.md @@ -2,10 +2,11 @@ ## Overview -The `Config` class serves as the configuration object for the Registry class, which manages how metrics are sent to SpectatorD. -The `Config` constructor takes two parameters. The first parameter is required and is a `WriterConfig` object. This object defines -how metrics will be sent to `SpectatorD`. The second parameter `extraTags` is an unordered map of strings allowing you to provide additional tags to -all of your metrics. Extra tags are additional key-value pairs attached to all metrics and will be merged with environment-derived tags. +The `Config` class serves as the configuration object for the Registry class, which manages how metrics are sent to +SpectatorD. The `Config` constructor takes two parameters. The first parameter is required and is a `WriterConfig` +object. This object defines how metrics will be sent to `SpectatorD`. The second parameter `extraTags` is an +unordered map of strings allowing you to provide additional tags to all of your metrics. Extra tags are additional +key-value pairs attached to all metrics and will be merged with environment-derived tags. ## Usage @@ -31,11 +32,12 @@ Config config(WriterConfig(WriterTypes::Memory), tags); ## Environment Variables -If the following environment variables are set and not empty, there key and value will also be read and applied to your tags +If the following environment variables are set and not empty, there key and value will also be read and applied to +your tags - `TITUS_CONTAINER_NAME`: Set the `nf.container` tag automatically - `TITUS_PROCESS_NAME`: Set the `nf.process` tag automatically ### Warning -If the environment variable `SPECTATOR_OUTPUT_LOCATION` is set this will override the value specified in the `WriterConfig` -read the `WriterConfig` readme.md for more details. \ No newline at end of file +If the environment variable `SPECTATOR_OUTPUT_LOCATION` is set this will override the value specified in the +`WriterConfig` read the `WriterConfig` readme.md for more details. \ No newline at end of file diff --git a/libs/meter/meter_types/include/age_gauge.h b/libs/meter/meter_types/include/age_gauge.h index 6f52a90..08b286d 100644 --- a/libs/meter/meter_types/include/age_gauge.h +++ b/libs/meter/meter_types/include/age_gauge.h @@ -19,7 +19,7 @@ class AgeGauge final : public Meter Writer::GetInstance().Write(line); } - void Set(const int& seconds) const + void Set(const double& seconds) const { auto line = this->ConstructLine(seconds); Writer::GetInstance().Write(line); diff --git a/libs/meter/meter_types/include/dist_summary.h b/libs/meter/meter_types/include/dist_summary.h index 4448d6e..2f4fd83 100644 --- a/libs/meter/meter_types/include/dist_summary.h +++ b/libs/meter/meter_types/include/dist_summary.h @@ -13,7 +13,7 @@ class DistributionSummary final : public Meter public: explicit DistributionSummary(const MeterId& meter_id) : Meter(meter_id, DisTRIBUTION_SUMMARY_TYPE_SYMBOL) {} - void Record(const int& amount) const + void Record(const double& amount) const { if (amount >= 0) { diff --git a/libs/meter/meter_types/include/percentile_dist_summary.h b/libs/meter/meter_types/include/percentile_dist_summary.h index b269d22..6af6530 100644 --- a/libs/meter/meter_types/include/percentile_dist_summary.h +++ b/libs/meter/meter_types/include/percentile_dist_summary.h @@ -4,6 +4,7 @@ #include #include +#include #include static constexpr auto PERCENTILE_DISTRIBUTION_SUMMARY_TYPE_SYMBOL = "D"; @@ -16,7 +17,7 @@ class PercentileDistributionSummary final : public Meter { } - void Record(const int& amount) const + void Record(const int64_t& amount) const { if (amount >= 0) { diff --git a/libs/meter/meter_types/test/test_age_gauge.cpp b/libs/meter/meter_types/test/test_age_gauge.cpp index 18e19be..0f75552 100644 --- a/libs/meter/meter_types/test/test_age_gauge.cpp +++ b/libs/meter/meter_types/test/test_age_gauge.cpp @@ -26,5 +26,5 @@ TEST_F(AgeGaugeTest, Set) AgeGauge g(tid); EXPECT_TRUE(writer->IsEmpty()); g.Set(10); - EXPECT_EQ("A:age_gauge:10\n", writer->LastLine()); + EXPECT_EQ("A:age_gauge:10.000000\n", writer->LastLine()); } \ No newline at end of file diff --git a/libs/meter/meter_types/test/test_dist_summary.cpp b/libs/meter/meter_types/test/test_dist_summary.cpp index 04810bc..69fa7b5 100644 --- a/libs/meter/meter_types/test/test_dist_summary.cpp +++ b/libs/meter/meter_types/test/test_dist_summary.cpp @@ -17,7 +17,7 @@ TEST_F(DistSummaryTest, record) EXPECT_TRUE(writer->IsEmpty()); ds.Record(42); - EXPECT_EQ("d:dist_summary:42\n", writer->LastLine()); + EXPECT_EQ("d:dist_summary:42.000000\n", writer->LastLine()); } TEST_F(DistSummaryTest, recordNegative) @@ -39,5 +39,5 @@ TEST_F(DistSummaryTest, recordZero) EXPECT_TRUE(writer->IsEmpty()); ds.Record(0); - EXPECT_EQ("d:dist_summary:0\n", writer->LastLine()); + EXPECT_EQ("d:dist_summary:0.000000\n", writer->LastLine()); } \ No newline at end of file diff --git a/libs/writer/README.md b/libs/writer/README.md index fd20412..1967124 100644 --- a/libs/writer/README.md +++ b/libs/writer/README.md @@ -1,6 +1,7 @@ # Writer Module -The Writer module provides a flexible system for metric data output in the Spectator C++ library. It consists of several components that handle different aspects of data writing. +The Writer module provides a flexible system for metric data output in the Spectator C++ library. It consists of +several components that handle different aspects of data writing. ## Components @@ -36,7 +37,8 @@ This component handles configuration of writers: WriterConfig config(WriterTypes::UDP); // Or with a URL-style location - WriterConfig config("udp://192.168.1.100:8125"); + const std::string unixUrl = std::string(WriterTypes::UnixURL) + "/var/run/custom/socket.sock"; + const WriterConfig config(unixUrl); // Environment variable overrides any provided value // SPECTATOR_OUTPUT_LOCATION=unix:///custom/path/socket.sock @@ -72,7 +74,8 @@ These components work together to provide a flexible metric output system: ```cpp // Create a configuration -WriterConfig writerConfig("udp://localhost:8125"); +const std::string udpUrl = std::string(WriterTypes::UDPURL) + "192.168.1.100:8125"; +const WriterConfig writerConfig(udpUrl); // Create a configuration object with the writer config Config config(writerConfig); diff --git a/spectator/test_registry.cpp b/spectator/test_registry.cpp index 65909f5..610bab4 100644 --- a/spectator/test_registry.cpp +++ b/spectator/test_registry.cpp @@ -31,10 +31,10 @@ TEST(RegistryTest, AgeGauge) EXPECT_TRUE(memoryWriter->IsEmpty()); g1.Set(1); - EXPECT_EQ("A:age_gauge:1\n", memoryWriter->LastLine()); + EXPECT_EQ("A:age_gauge:1.000000\n", memoryWriter->LastLine()); g2.Set(2); - EXPECT_EQ("A:age_gauge,my-tags=bar:2\n", memoryWriter->LastLine()); + EXPECT_EQ("A:age_gauge,my-tags=bar:2.000000\n", memoryWriter->LastLine()); } TEST(RegistryTest, AgeGaugeWithId) @@ -47,7 +47,7 @@ TEST(RegistryTest, AgeGaugeWithId) EXPECT_TRUE(memoryWriter->IsEmpty()); g.Set(0); - EXPECT_EQ("A:age_gauge,extra-tags=foo,my-tags=bar:0\n", + EXPECT_EQ("A:age_gauge,extra-tags=foo,my-tags=bar:0.000000\n", ParseProtocolLine(memoryWriter->LastLine()).value().to_string()); } @@ -109,7 +109,7 @@ TEST(RegistryTest, DistributionSummary) EXPECT_TRUE(memoryWriter->IsEmpty()); d.Record(42); - EXPECT_EQ("d:distribution_summary:42\n", memoryWriter->LastLine()); + EXPECT_EQ("d:distribution_summary:42.000000\n", memoryWriter->LastLine()); } TEST(RegistryTest, DistributionSummaryWithId) @@ -122,7 +122,7 @@ TEST(RegistryTest, DistributionSummaryWithId) EXPECT_TRUE(memoryWriter->IsEmpty()); d.Record(42); - EXPECT_EQ("d:distribution_summary,extra-tags=foo,my-tags=bar:42\n", + EXPECT_EQ("d:distribution_summary,extra-tags=foo,my-tags=bar:42.000000\n", ParseProtocolLine(memoryWriter->LastLine()).value().to_string()); }