Skip to content

Commit 60f1e63

Browse files
committed
Test MetricArgs
1 parent 667858e commit 60f1e63

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

include/triton/core/tritonserver.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2693,7 +2693,6 @@ TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricArgsDelete(
26932693
/// \param family The metric family to add this new metric to.
26942694
/// \param labels The array of labels to associate with this new metric.
26952695
/// \param label_count The number of labels.
2696-
/// bucket boundaries. For histogram only.
26972696
/// \return a TRITONSERVER_Error indicating success or failure.
26982697
TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricNew(
26992698
struct TRITONSERVER_Metric** metric,

src/metric_family.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ MetricFamily::Add(
104104
"Bucket boundaries not found in Metric args.");
105105
}
106106
if (args->kind() != TRITONSERVER_METRIC_KIND_HISTOGRAM) {
107-
throw std::invalid_argument(
108-
"Incorrect Metric args kind in histogram Metric constructor.");
107+
throw std::invalid_argument("Metric args not set to histogram kind.");
109108
}
110109
auto histogram_family_ptr =
111110
reinterpret_cast<prometheus::Family<prometheus::Histogram>*>(family_);

src/test/metrics_api_test.cc

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,67 @@ TEST_F(MetricsApiTest, TestHistogramEndToEnd)
479479
ASSERT_EQ(NumMetricMatches(server_, description), 0);
480480
}
481481

482+
// Test create a histogram metric without creating metric arguments
483+
TEST_F(MetricsApiTest, TestHistogramNoMetricArgs)
484+
{
485+
// Create metric family
486+
TRITONSERVER_MetricFamily* family;
487+
TRITONSERVER_MetricKind kind = TRITONSERVER_METRIC_KIND_HISTOGRAM;
488+
const char* name = "no_metric_args";
489+
const char* description = "no metric args description";
490+
FAIL_TEST_IF_ERR(
491+
TRITONSERVER_MetricFamilyNew(&family, kind, name, description),
492+
"Creating new metric family");
493+
494+
// MetricArgs not created
495+
TRITONSERVER_MetricArgs* args = nullptr;
496+
// Create metric
497+
std::vector<const TRITONSERVER_Parameter*> labels;
498+
TRITONSERVER_Metric* metric = nullptr;
499+
auto err = TRITONSERVER_MetricNewWithArgs(
500+
&metric, family, labels.data(), labels.size(), args);
501+
EXPECT_THAT(
502+
TRITONSERVER_ErrorMessage(err),
503+
HasSubstr("Bucket boundaries not found in Metric args"));
504+
505+
// Cleanup
506+
FAIL_TEST_IF_ERR(TRITONSERVER_MetricArgsDelete(args), "delete metric args");
507+
FAIL_TEST_IF_ERR(
508+
TRITONSERVER_MetricFamilyDelete(family), "delete metric family");
509+
}
510+
511+
// Test create a histogram metric without setting metric arguments
512+
TEST_F(MetricsApiTest, TestHistogramMetricArgsNotset)
513+
{
514+
// Create metric family
515+
TRITONSERVER_MetricFamily* family;
516+
TRITONSERVER_MetricKind kind = TRITONSERVER_METRIC_KIND_HISTOGRAM;
517+
const char* name = "metric_args_not_set";
518+
const char* description = "metric args not set description";
519+
FAIL_TEST_IF_ERR(
520+
TRITONSERVER_MetricFamilyNew(&family, kind, name, description),
521+
"Creating new metric family");
522+
523+
// Create metric args object without setting it
524+
TRITONSERVER_MetricArgs* args;
525+
FAIL_TEST_IF_ERR(
526+
TRITONSERVER_MetricArgsNew(&args), "Creating new metric args");
527+
528+
// Create metric
529+
std::vector<const TRITONSERVER_Parameter*> labels;
530+
TRITONSERVER_Metric* metric = nullptr;
531+
auto err = TRITONSERVER_MetricNewWithArgs(
532+
&metric, family, labels.data(), labels.size(), args);
533+
EXPECT_THAT(
534+
TRITONSERVER_ErrorMessage(err),
535+
HasSubstr("Metric args not set to histogram kind"));
536+
537+
// Cleanup
538+
FAIL_TEST_IF_ERR(TRITONSERVER_MetricArgsDelete(args), "delete metric args");
539+
FAIL_TEST_IF_ERR(
540+
TRITONSERVER_MetricFamilyDelete(family), "delete metric family");
541+
}
542+
482543
// Test that a duplicate metric family can't be added
483544
// with a conflicting type/kind
484545
TEST_F(MetricsApiTest, TestDupeMetricFamilyDiffKind)

0 commit comments

Comments
 (0)