Skip to content

Commit 15374f0

Browse files
add unknown const
Signed-off-by: Jintao Zhang <[email protected]>
1 parent f5fb694 commit 15374f0

File tree

3 files changed

+27
-20
lines changed

3 files changed

+27
-20
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package consts
2+
3+
// UnknownLabel is a canonical fallback label value used across the codebase
4+
// when a more specific value (e.g., model, category, reason) is not available.
5+
const UnknownLabel = "unknown"

src/semantic-router/pkg/extproc/reason_mode_selector.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"strings"
77

88
"github.com/vllm-project/semantic-router/src/semantic-router/pkg/config"
9+
"github.com/vllm-project/semantic-router/src/semantic-router/pkg/consts"
910
"github.com/vllm-project/semantic-router/src/semantic-router/pkg/metrics"
1011
"github.com/vllm-project/semantic-router/src/semantic-router/pkg/observability"
1112
"github.com/vllm-project/semantic-router/src/semantic-router/pkg/utils/entropy"
@@ -132,7 +133,7 @@ func (r *OpenAIRouter) setReasoningModeToRequestBody(requestBody []byte, enabled
132133
}
133134

134135
// Determine model for kwargs and logging
135-
model := "unknown"
136+
model := consts.UnknownLabel
136137
if modelValue, ok := requestMap["model"]; ok {
137138
if modelStr, ok := modelValue.(string); ok {
138139
model = modelStr
@@ -191,7 +192,7 @@ func (r *OpenAIRouter) setReasoningModeToRequestBody(requestBody []byte, enabled
191192
// Record metrics for template usage and effort when enabled
192193
if enabled {
193194
familyConfig := r.getModelReasoningFamily(model)
194-
modelFamily := "unknown"
195+
modelFamily := consts.UnknownLabel
195196
templateParam := "reasoning_effort" // default fallback
196197

197198
if familyConfig != nil {

src/semantic-router/pkg/metrics/metrics.go

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"github.com/prometheus/client_golang/prometheus/promauto"
1010

1111
"github.com/vllm-project/semantic-router/src/semantic-router/pkg/config"
12+
"github.com/vllm-project/semantic-router/src/semantic-router/pkg/consts"
1213
)
1314

1415
// Minimal fallback bucket configurations - used only when configuration is completely missing
@@ -384,18 +385,18 @@ var (
384385
// RecordModelRequest increments the counter for requests to a specific model
385386
func RecordModelRequest(model string) {
386387
if model == "" {
387-
model = "unknown"
388+
model = consts.UnknownLabel
388389
}
389390
ModelRequests.WithLabelValues(model).Inc()
390391
}
391392

392393
// RecordRequestError increments request error counters labeled by model and normalized reason
393394
func RecordRequestError(model, reason string) {
394395
if model == "" {
395-
model = "unknown"
396+
model = consts.UnknownLabel
396397
}
397398
if reason == "" {
398-
reason = "unknown"
399+
reason = consts.UnknownLabel
399400
}
400401
// Normalize a few common variants to canonical reasons
401402
switch reason {
@@ -435,10 +436,10 @@ func RecordModelCost(model string, currency string, amount float64) {
435436
// RecordRoutingReasonCode increments the counter for a routing decision reason code and model
436437
func RecordRoutingReasonCode(reasonCode, model string) {
437438
if reasonCode == "" {
438-
reasonCode = "unknown"
439+
reasonCode = consts.UnknownLabel
439440
}
440441
if model == "" {
441-
model = "unknown"
442+
model = consts.UnknownLabel
442443
}
443444
RoutingReasonCodes.WithLabelValues(reasonCode, model).Inc()
444445
}
@@ -453,7 +454,7 @@ func RecordModelTokensDetailed(model string, promptTokens, completionTokens floa
453454

454455
// Also record per-request histograms for visibility into distribution
455456
if model == "" {
456-
model = "unknown"
457+
model = consts.UnknownLabel
457458
}
458459
PromptTokensPerRequest.WithLabelValues(model).Observe(promptTokens)
459460
CompletionTokensPerRequest.WithLabelValues(model).Observe(completionTokens)
@@ -470,7 +471,7 @@ func RecordModelTTFT(model string, seconds float64) {
470471
return
471472
}
472473
if model == "" {
473-
model = "unknown"
474+
model = consts.UnknownLabel
474475
}
475476
ModelTTFT.WithLabelValues(model).Observe(seconds)
476477
}
@@ -481,7 +482,7 @@ func RecordModelTPOT(model string, secondsPerToken float64) {
481482
return
482483
}
483484
if model == "" {
484-
model = "unknown"
485+
model = consts.UnknownLabel
485486
}
486487
ModelTPOT.WithLabelValues(model).Observe(secondsPerToken)
487488
}
@@ -515,7 +516,7 @@ func UpdateCacheEntries(backend string, count int) {
515516
// RecordCategoryClassification increments the counter for a specific category classification
516517
func RecordCategoryClassification(category string) {
517518
if category == "" {
518-
category = "unknown"
519+
category = consts.UnknownLabel
519520
}
520521
CategoryClassificationsCount.WithLabelValues(category).Inc()
521522
}
@@ -575,7 +576,7 @@ func GetBatchSizeRange(size int) string {
575576
}
576577

577578
// Fallback for unexpected cases
578-
return "unknown"
579+
return consts.UnknownLabel
579580
}
580581

581582
// GetBatchSizeRangeFromBuckets generates range labels based on size buckets
@@ -756,7 +757,7 @@ func RecordReasoningDecision(category, model string, enabled bool, effort string
756757
// RecordReasoningTemplateUsage records usage of a model-family-specific template parameter
757758
func RecordReasoningTemplateUsage(family, param string) {
758759
if family == "" {
759-
family = "unknown"
760+
family = consts.UnknownLabel
760761
}
761762
if param == "" {
762763
param = "none"
@@ -767,7 +768,7 @@ func RecordReasoningTemplateUsage(family, param string) {
767768
// RecordReasoningEffortUsage records the effort usage by model family
768769
func RecordReasoningEffortUsage(family, effort string) {
769770
if family == "" {
770-
family = "unknown"
771+
family = consts.UnknownLabel
771772
}
772773
if effort == "" {
773774
effort = "unspecified"
@@ -778,7 +779,7 @@ func RecordReasoningEffortUsage(family, effort string) {
778779
// RecordEntropyClassificationDecision records an entropy-based classification decision
779780
func RecordEntropyClassificationDecision(uncertaintyLevel string, reasoningEnabled bool, decisionReason string, topCategory string) {
780781
if uncertaintyLevel == "" {
781-
uncertaintyLevel = "unknown"
782+
uncertaintyLevel = consts.UnknownLabel
782783
}
783784
if decisionReason == "" {
784785
decisionReason = "unspecified"
@@ -798,7 +799,7 @@ func RecordEntropyClassificationDecision(uncertaintyLevel string, reasoningEnabl
798799
// RecordEntropyValue records the entropy value for a classification
799800
func RecordEntropyValue(category string, classificationType string, entropyValue float64) {
800801
if category == "" {
801-
category = "unknown"
802+
category = consts.UnknownLabel
802803
}
803804
if classificationType == "" {
804805
classificationType = "standard"
@@ -810,7 +811,7 @@ func RecordEntropyValue(category string, classificationType string, entropyValue
810811
// RecordClassificationConfidence records the confidence score from classification
811812
func RecordClassificationConfidence(category string, classificationMethod string, confidence float64) {
812813
if category == "" {
813-
category = "unknown"
814+
category = consts.UnknownLabel
814815
}
815816
if classificationMethod == "" {
816817
classificationMethod = "traditional"
@@ -827,10 +828,10 @@ func RecordEntropyClassificationLatency(seconds float64) {
827828
// RecordProbabilityDistributionQuality records quality checks for probability distributions
828829
func RecordProbabilityDistributionQuality(qualityCheck string, status string) {
829830
if qualityCheck == "" {
830-
qualityCheck = "unknown"
831+
qualityCheck = consts.UnknownLabel
831832
}
832833
if status == "" {
833-
status = "unknown"
834+
status = consts.UnknownLabel
834835
}
835836

836837
ProbabilityDistributionQuality.WithLabelValues(qualityCheck, status).Inc()
@@ -839,7 +840,7 @@ func RecordProbabilityDistributionQuality(qualityCheck string, status string) {
839840
// RecordEntropyFallback records when entropy-based routing falls back to traditional methods
840841
func RecordEntropyFallback(fallbackReason string, fallbackStrategy string) {
841842
if fallbackReason == "" {
842-
fallbackReason = "unknown"
843+
fallbackReason = consts.UnknownLabel
843844
}
844845
if fallbackStrategy == "" {
845846
fallbackStrategy = "unspecified"

0 commit comments

Comments
 (0)