Changeset 0.33.0 (#207)
Co-authored-by: Jeffrey Smith <jasafpro@gmail.com> Co-committed-by: Jeffrey Smith <jasafpro@gmail.com>
This commit is contained in:
@@ -12,27 +12,39 @@ import (
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"chat-switchboard/events"
|
||||
"chat-switchboard/metrics"
|
||||
"chat-switchboard/providers"
|
||||
"chat-switchboard/sandbox"
|
||||
"chat-switchboard/store"
|
||||
"chat-switchboard/tools"
|
||||
)
|
||||
|
||||
// recordHealthFn records provider health from standalone streaming functions.
|
||||
// recordHealthFn records provider health from standalone streaming functions
|
||||
// and updates Prometheus completion metrics (v0.33.0).
|
||||
func recordHealthFn(hr HealthRecorder, configID string, start time.Time, err error) {
|
||||
duration := time.Since(start)
|
||||
latencyMs := int(duration.Milliseconds())
|
||||
|
||||
if configID != "" {
|
||||
metrics.CompletionDuration.WithLabelValues(configID, "").Observe(duration.Seconds())
|
||||
}
|
||||
|
||||
if hr == nil || configID == "" {
|
||||
return
|
||||
}
|
||||
latencyMs := int(time.Since(start).Milliseconds())
|
||||
if err != nil {
|
||||
errMsg := err.Error()
|
||||
status := "error"
|
||||
if strings.Contains(errMsg, "HTTP 429") || strings.Contains(errMsg, "rate limit") || strings.Contains(errMsg, "Too Many Requests") {
|
||||
hr.RecordRateLimit(configID, latencyMs, errMsg)
|
||||
status = "rate_limited"
|
||||
} else {
|
||||
hr.RecordError(configID, latencyMs, errMsg)
|
||||
}
|
||||
metrics.CompletionsTotal.WithLabelValues(configID, "", status).Inc()
|
||||
} else {
|
||||
hr.RecordSuccess(configID, latencyMs)
|
||||
metrics.CompletionsTotal.WithLabelValues(configID, "", "success").Inc()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user