@@ -358,13 +358,36 @@ Metric::Increment(const double& value)
358
358
void
359
359
Metric::SetValue (const double & value)
360
360
{
361
+ // SetValue and Observe share the same C API TRITONSERVER_MetricSet.
362
+ // Throws if SetValue is called by a histogram metric.
363
+ TRITONSERVER_MetricKind kind;
364
+ THROW_IF_TRITON_ERROR (TRITONSERVER_GetMetricKind (
365
+ reinterpret_cast <TRITONSERVER_Metric*>(metric_address_), &kind));
366
+ if (kind == TRITONSERVER_METRIC_KIND_HISTOGRAM) {
367
+ throw PythonBackendException (
368
+ " TRITONSERVER_METRIC_KIND_HISTOGRAM does not support SetValue" );
369
+ }
370
+
361
371
auto triton_metric = reinterpret_cast <TRITONSERVER_Metric*>(metric_address_);
362
372
THROW_IF_TRITON_ERROR (TRITONSERVER_MetricSet (triton_metric, value));
363
373
}
364
374
365
375
void
366
376
Metric::Observe (const double & value)
367
377
{
378
+ // SetValue and Observe share the same C API TRITONSERVER_MetricSet.
379
+ // Throws if Observe is called by a non-histogram metric.
380
+ TRITONSERVER_MetricKind kind;
381
+ THROW_IF_TRITON_ERROR (TRITONSERVER_GetMetricKind (
382
+ reinterpret_cast <TRITONSERVER_Metric*>(metric_address_), &kind));
383
+ if (kind == TRITONSERVER_METRIC_KIND_COUNTER) {
384
+ throw PythonBackendException (
385
+ " TRITONSERVER_METRIC_KIND_COUNTER does not support Observe" );
386
+ } else if (kind == TRITONSERVER_METRIC_KIND_GAUGE) {
387
+ throw PythonBackendException (
388
+ " TRITONSERVER_METRIC_KIND_GAUGE does not support Observe" );
389
+ }
390
+
368
391
auto triton_metric = reinterpret_cast <TRITONSERVER_Metric*>(metric_address_);
369
392
THROW_IF_TRITON_ERROR (TRITONSERVER_MetricSet (triton_metric, value));
370
393
}
0 commit comments