-
Notifications
You must be signed in to change notification settings - Fork 863
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metrics cache integration with C++ backend
- Loading branch information
Naman Nandan
committed
Nov 29, 2022
1 parent
f21518d
commit 0ade963
Showing
20 changed files
with
233 additions
and
22 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
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
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,29 @@ | ||
#include "src/utils/metrics/registry.hh" | ||
|
||
namespace torchserve { | ||
std::shared_ptr<MetricsCache> MetricsRegistry::metrics_cache = nullptr; | ||
|
||
void MetricsRegistry::Initialize(const std::string& metrics_config_file_path, | ||
const MetricsContext& metrics_context) { | ||
try { | ||
std::shared_ptr<MetricsConfigurationHandler> metrics_config_handler = | ||
std::make_shared<YAMLMetricsConfigurationHandler>(); | ||
metrics_config_handler->LoadConfiguration(metrics_config_file_path, | ||
metrics_context); | ||
metrics_cache = std::make_shared<LogMetricsCache>(); | ||
metrics_cache->Initialize(*metrics_config_handler); | ||
} catch (...) { | ||
metrics_cache = nullptr; | ||
throw; | ||
} | ||
} | ||
|
||
std::shared_ptr<MetricsCache>& MetricsRegistry::GetMetricsCacheInstance() { | ||
if (metrics_cache == nullptr) { | ||
throw std::runtime_error( | ||
"Metrics cache not initialized in metrics registry"); | ||
} | ||
|
||
return metrics_cache; | ||
} | ||
} // namespace torchserve |
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,21 @@ | ||
#ifndef TS_CPP_UTILS_METRICS_REGISTRY_HH_ | ||
#define TS_CPP_UTILS_METRICS_REGISTRY_HH_ | ||
|
||
#include <stdexcept> | ||
|
||
#include "src/utils/metrics/log_metrics_cache.hh" | ||
#include "src/utils/metrics/yaml_config.hh" | ||
|
||
namespace torchserve { | ||
class MetricsRegistry { | ||
public: | ||
static void Initialize(const std::string& metrics_config_file_path, | ||
const MetricsContext& metrics_context); | ||
static std::shared_ptr<MetricsCache>& GetMetricsCacheInstance(); | ||
|
||
private: | ||
static std::shared_ptr<MetricsCache> metrics_cache; | ||
}; | ||
} // namespace torchserve | ||
|
||
#endif // TS_CPP_UTILS_METRICS_REGISTRY_HH_ |
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,9 @@ | ||
dimensions: | ||
- &model_name "ModelName" | ||
- &level "Level" | ||
|
||
model_metrics: | ||
gauge: | ||
- name: HandlerTime | ||
unit: ms | ||
dimensions: [*model_name, *level] |
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,36 @@ | ||
#include "src/utils/metrics/registry.hh" | ||
|
||
#include <gmock/gmock.h> | ||
#include <gtest/gtest.h> | ||
|
||
#include <stdexcept> | ||
|
||
namespace torchserve { | ||
TEST(RegistryTest, TestValidConfigFile) { | ||
MetricsRegistry::Initialize("test/resources/metrics/valid_config.yaml", | ||
MetricsContext::BACKEND); | ||
ASSERT_THAT(MetricsRegistry::GetMetricsCacheInstance(), | ||
::testing::A<std::shared_ptr<MetricsCache>>()); | ||
} | ||
|
||
TEST(RegistryTest, TestInvalidConfigFile) { | ||
ASSERT_THROW( | ||
MetricsRegistry::Initialize( | ||
"test/resources/metrics/invalid_config_duplicate_dimension.yaml", | ||
MetricsContext::BACKEND), | ||
std::invalid_argument); | ||
ASSERT_THROW(MetricsRegistry::GetMetricsCacheInstance(), std::runtime_error); | ||
} | ||
|
||
TEST(RegistryTest, TestReInitialize) { | ||
MetricsRegistry::Initialize("test/resources/metrics/valid_config.yaml", | ||
MetricsContext::BACKEND); | ||
ASSERT_THAT(MetricsRegistry::GetMetricsCacheInstance(), | ||
::testing::A<std::shared_ptr<MetricsCache>>()); | ||
|
||
MetricsRegistry::Initialize("test/resources/metrics/default_config.yaml", | ||
MetricsContext::BACKEND); | ||
ASSERT_THAT(MetricsRegistry::GetMetricsCacheInstance(), | ||
::testing::A<std::shared_ptr<MetricsCache>>()); | ||
} | ||
} // namespace torchserve |
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.