Skip to content

Commit 349daa6

Browse files
committed
Restore TRITONSERVER_MetricObserve
1 parent 60f1e63 commit 349daa6

File tree

5 files changed

+71
-11
lines changed

5 files changed

+71
-11
lines changed

include/triton/core/tritonserver.h

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,7 +2648,7 @@ TRITONSERVER_MetricFamilyDelete(struct TRITONSERVER_MetricFamily* family);
26482648

26492649
/// Get the TRITONSERVER_MetricKind of the metric family.
26502650
///
2651-
/// \param metric The metric family object to query.
2651+
/// \param family The metric family object to query.
26522652
/// \param kind Returns the TRITONSERVER_MetricKind of metric.
26532653
/// \return a TRITONSERVER_Error indicating success or failure.
26542654
TRITONSERVER_DECLSPEC struct TRITONSERVER_Error*
@@ -2664,10 +2664,12 @@ TRITONSERVER_GetMetricFamilyKind(
26642664
TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricArgsNew(
26652665
struct TRITONSERVER_MetricArgs** args);
26662666

2667-
/// Set metric args with prometheus histogram metric parameter.
2667+
/// Set metric args with histogram metric parameter.
26682668
///
26692669
/// \param args The metric args object to set.
2670-
/// \param buckets The array of bucket boundaries.
2670+
/// \param buckets The array of bucket boundaries for the expected range of
2671+
/// observed values.
2672+
///
26712673
/// \param buckets_count The number of bucket boundaries.
26722674
/// \return a TRITONSERVER_Error indicating success or failure.
26732675
TRITONSERVER_DECLSPEC struct TRITONSERVER_Error*
@@ -2732,10 +2734,9 @@ TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricDelete(
27322734
struct TRITONSERVER_Metric* metric);
27332735

27342736
/// Get the current value of a metric object.
2735-
/// Supports metrics of kind TRITONSERVER_METRIC_KIND_COUNTER,
2736-
/// TRITONSERVER_METRIC_KIND_GAUGE, TRITONSERVER_METRIC_KIND_HISTOGRAM, and
2737-
/// returns TRITONSERVER_ERROR_UNSUPPORTED for unsupported
2738-
/// TRITONSERVER_MetricKind.
2737+
/// Supports metrics of kind TRITONSERVER_METRIC_KIND_COUNTER
2738+
/// and TRITONSERVER_METRIC_KIND_GAUGE, and returns
2739+
/// TRITONSERVER_ERROR_UNSUPPORTED for unsupported TRITONSERVER_MetricKind.
27392740
///
27402741
/// \param metric The metric object to query.
27412742
/// \param value Returns the current value of the metric object.
@@ -2756,9 +2757,8 @@ TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricValue(
27562757
TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricIncrement(
27572758
struct TRITONSERVER_Metric* metric, double value);
27582759

2759-
/// Set the current value of metric to value or observe the value to metric.
2760-
/// Supports metrics of kind TRITONSERVER_METRIC_KIND_GAUGE and
2761-
/// TRITONSERVER_METRIC_KIND_HISTOGRAM. Returns
2760+
/// Set the current value of metric to value.
2761+
/// Supports metrics of kind TRITONSERVER_METRIC_KIND_GAUGE and returns
27622762
/// TRITONSERVER_ERROR_UNSUPPORTED for unsupported TRITONSERVER_MetricKind.
27632763
///
27642764
/// \param metric The metric object to update.
@@ -2767,6 +2767,16 @@ TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricIncrement(
27672767
TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricSet(
27682768
struct TRITONSERVER_Metric* metric, double value);
27692769

2770+
/// Sample an observation and count it to the appropriate bucket of a metric.
2771+
/// Supports metrics of kind TRITONSERVER_METRIC_KIND_HISTOGRAM and returns
2772+
/// TRITONSERVER_ERROR_UNSUPPORTED for unsupported TRITONSERVER_MetricKind.
2773+
///
2774+
/// \param metric The metric object to update.
2775+
/// \param value The amount for metric to sample observation.
2776+
/// \return a TRITONSERVER_Error indicating success or failure.
2777+
TRITONSERVER_DECLSPEC struct TRITONSERVER_Error* TRITONSERVER_MetricObserve(
2778+
struct TRITONSERVER_Metric* metric, double value);
2779+
27702780
/// Get the TRITONSERVER_MetricKind of metric of its corresponding family.
27712781
///
27722782
/// \param metric The metric object to query.

src/metric_family.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,6 +359,40 @@ Metric::Set(double value)
359359
gauge_ptr->Set(value);
360360
break;
361361
}
362+
case TRITONSERVER_METRIC_KIND_HISTOGRAM: {
363+
return TRITONSERVER_ErrorNew(
364+
TRITONSERVER_ERROR_UNSUPPORTED,
365+
"TRITONSERVER_METRIC_KIND_HISTOGRAM does not support Set");
366+
}
367+
default:
368+
return TRITONSERVER_ErrorNew(
369+
TRITONSERVER_ERROR_UNSUPPORTED,
370+
"Unsupported TRITONSERVER_MetricKind");
371+
}
372+
373+
return nullptr; // Success
374+
}
375+
376+
TRITONSERVER_Error*
377+
Metric::Observe(double value)
378+
{
379+
if (metric_ == nullptr) {
380+
return TRITONSERVER_ErrorNew(
381+
TRITONSERVER_ERROR_INTERNAL,
382+
"Could not set metric value. Metric has been invalidated.");
383+
}
384+
385+
switch (kind_) {
386+
case TRITONSERVER_METRIC_KIND_COUNTER: {
387+
return TRITONSERVER_ErrorNew(
388+
TRITONSERVER_ERROR_UNSUPPORTED,
389+
"TRITONSERVER_METRIC_KIND_COUNTER does not support Observe");
390+
}
391+
case TRITONSERVER_METRIC_KIND_GAUGE: {
392+
return TRITONSERVER_ErrorNew(
393+
TRITONSERVER_ERROR_UNSUPPORTED,
394+
"TRITONSERVER_METRIC_KIND_GAUGE does not support Observe");
395+
}
362396
case TRITONSERVER_METRIC_KIND_HISTOGRAM: {
363397
auto histogram_ptr = reinterpret_cast<prometheus::Histogram*>(metric_);
364398
histogram_ptr->Observe(value);

src/test/metrics_api_test.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ HistogramAPIHelper(
244244
double sum = 0.0;
245245
for (auto datum : data) {
246246
FAIL_TEST_IF_ERR(
247-
TRITONSERVER_MetricSet(metric, datum), "observe metric value");
247+
TRITONSERVER_MetricObserve(metric, datum), "observe metric value");
248248
sum += datum;
249249
}
250250
std::vector<std::uint64_t> cumulative_counts = {1, 1, 2, 2, 3, 3};

src/tritonserver.cc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3525,6 +3525,17 @@ TRITONSERVER_MetricSet(TRITONSERVER_Metric* metric, double value)
35253525
#endif // TRITON_ENABLE_METRICS
35263526
}
35273527

3528+
TRITONSERVER_Error*
3529+
TRITONSERVER_MetricObserve(TRITONSERVER_Metric* metric, double value)
3530+
{
3531+
#ifdef TRITON_ENABLE_METRICS
3532+
return reinterpret_cast<tc::Metric*>(metric)->Observe(value);
3533+
#else
3534+
return TRITONSERVER_ErrorNew(
3535+
TRITONSERVER_ERROR_UNSUPPORTED, "metrics not supported");
3536+
#endif // TRITON_ENABLE_METRICS
3537+
}
3538+
35283539
TRITONSERVER_Error*
35293540
TRITONSERVER_GetMetricKind(
35303541
TRITONSERVER_Metric* metric, TRITONSERVER_MetricKind* kind)

src/tritonserver_stub.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,6 +1105,11 @@ TRITONSERVER_MetricSet()
11051105
{
11061106
}
11071107

1108+
TRITONAPI_DECLSPEC void
1109+
TRITONSERVER_MetricObserve()
1110+
{
1111+
}
1112+
11081113
TRITONAPI_DECLSPEC void
11091114
TRITONSERVER_GetMetricKind()
11101115
{

0 commit comments

Comments
 (0)