@@ -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
484545TEST_F (MetricsApiTest, TestDupeMetricFamilyDiffKind)
0 commit comments