Skip to content

Commit 0740c11

Browse files
feat: added routing engine label in logs and telemetry
1 parent 6328738 commit 0740c11

File tree

25 files changed

+324
-155
lines changed

25 files changed

+324
-155
lines changed

core/schemas/bifrost.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ const (
184184
BifrostContextKeyIsCustomProvider BifrostContextKey = "bifrost-is-custom-provider" // bool (set by bifrost - DO NOT SET THIS MANUALLY))
185185
BifrostContextKeyHTTPRequestType BifrostContextKey = "bifrost-http-request-type" // RequestType (set by bifrost - DO NOT SET THIS MANUALLY))
186186
BifrostContextKeyPassthroughExtraParams BifrostContextKey = "bifrost-passthrough-extra-params" // bool
187+
BifrostContextKeyRoutingEngineUsed BifrostContextKey = "bifrost-routing-engine-used" // string (set by bifrost - DO NOT SET THIS MANUALLY) - either "routing-rule", "governance" or "loadbalancing"
187188
)
188189

189190
// NOTE: for custom plugin implementation dealing with streaming short circuit,

docs/features/telemetry.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ Base Labels:
6262
- `method`: Request type (`chat`, `text`, `embedding`, `speech`, `transcription`)
6363
- `virtual_key_id`: Virtual key ID
6464
- `virtual_key_name`: Virtual key name
65+
- `routing_engine_used`: Routing engine used ("routing-rule", "governance", "loadbalancing")
6566
- `routing_rule_id`: Routing rule ID that matched the request
6667
- `routing_rule_name`: Routing rule name that matched the request
6768
- `selected_key_id`: Selected key ID

docs/openapi/paths/management/logging.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ logs:
4242
description: Comma-separated list of routing rule IDs to filter by
4343
schema:
4444
type: string
45+
- name: routing_engine_used
46+
in: query
47+
description: Comma-separated list of routing engines to filter by (routing-rule, governance, or loadbalancing)
48+
schema:
49+
type: string
4550
- name: start_time
4651
in: query
4752
description: Start time filter (RFC3339 format)
@@ -200,6 +205,11 @@ logs-stats:
200205
description: Comma-separated list of routing rule IDs to filter by
201206
schema:
202207
type: string
208+
- name: routing_engine_used
209+
in: query
210+
description: Comma-separated list of routing engines to filter by (routing-rule, governance, or loadbalancing)
211+
schema:
212+
type: string
203213
- name: start_time
204214
in: query
205215
description: Start time filter (RFC3339 format)

docs/openapi/schemas/management/logging.yaml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,16 @@ LogEntry:
3737
virtual_key_name:
3838
type: string
3939
nullable: true
40+
routing_engine_used:
41+
type: string
42+
description: The routing engine used for this request (routing-rule, governance, or loadbalancing)
43+
nullable: true
44+
routing_rule_id:
45+
type: string
46+
nullable: true
47+
routing_rule_name:
48+
type: string
49+
nullable: true
4050
stream:
4151
type: boolean
4252
raw_request:
@@ -320,6 +330,15 @@ SearchFilters:
320330
type: array
321331
items:
322332
type: string
333+
routing_rule_ids:
334+
type: array
335+
items:
336+
type: string
337+
routing_engine_used:
338+
type: array
339+
items:
340+
type: string
341+
description: Filter by routing engine (routing-rule, governance, or loadbalancing)
323342
start_time:
324343
type: string
325344
format: date-time
@@ -397,6 +416,16 @@ FilterDataResponse:
397416
type: array
398417
items:
399418
$ref: '../../schemas/management/governance.yaml#/VirtualKey'
419+
routing_rules:
420+
type: array
421+
items:
422+
$ref: '../../schemas/management/governance.yaml#/RoutingRule'
423+
description: Available routing rules for filtering
424+
routing_engines:
425+
type: array
426+
items:
427+
type: string
428+
description: Available routing engine types (routing-rule, governance, loadbalancing)
400429

401430
DeleteLogsRequest:
402431
type: object

framework/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
- feat: add base_model support to model catalog for cross-provider model matching
22
- feat: add GetBaseModelName, IsSameModel, and GetDistinctBaseModelNames methods to ModelCatalog for resolving model aliases and checking model equivalence
33
- feat: add database migration for base_model column on model pricing table
4+
- feat: add database migration for routing_engine_used column on logs table

framework/logstore/migrations.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ func triggerMigrations(ctx context.Context, db *gorm.DB) error {
6161
if err := migrationAddVirtualKeyColumnsToMCPToolLogs(ctx, db); err != nil {
6262
return err
6363
}
64+
if err := migrationAddRoutingEngineUsedColumn(ctx, db); err != nil {
65+
return err
66+
}
6467
return nil
6568
}
6669

@@ -985,3 +988,36 @@ func migrationAddVirtualKeyColumnsToMCPToolLogs(ctx context.Context, db *gorm.DB
985988
}
986989
return nil
987990
}
991+
992+
func migrationAddRoutingEngineUsedColumn(ctx context.Context, db *gorm.DB) error {
993+
opts := *migrator.DefaultOptions
994+
opts.UseTransaction = true
995+
m := migrator.New(db, &opts, []*migrator.Migration{{
996+
ID: "logs_add_routing_engine_used_column",
997+
Migrate: func(tx *gorm.DB) error {
998+
tx = tx.WithContext(ctx)
999+
migrator := tx.Migrator()
1000+
if !migrator.HasColumn(&Log{}, "routing_engine_used") {
1001+
if err := migrator.AddColumn(&Log{}, "routing_engine_used"); err != nil {
1002+
return err
1003+
}
1004+
}
1005+
return nil
1006+
},
1007+
Rollback: func(tx *gorm.DB) error {
1008+
tx = tx.WithContext(ctx)
1009+
migrator := tx.Migrator()
1010+
if migrator.HasColumn(&Log{}, "routing_engine_used") {
1011+
if err := migrator.DropColumn(&Log{}, "routing_engine_used"); err != nil {
1012+
return err
1013+
}
1014+
}
1015+
return nil
1016+
},
1017+
}})
1018+
err := m.Migrate()
1019+
if err != nil {
1020+
return fmt.Errorf("error while adding routing engine used column: %s", err.Error())
1021+
}
1022+
return nil
1023+
}

framework/logstore/rdb.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ func (s *RDBLogStore) applyFilters(baseQuery *gorm.DB, filters SearchFilters) *g
6464
if len(filters.RoutingRuleIDs) > 0 {
6565
baseQuery = baseQuery.Where("routing_rule_id IN ?", filters.RoutingRuleIDs)
6666
}
67+
if len(filters.RoutingEngineUsed) > 0 {
68+
baseQuery = baseQuery.Where("routing_engine_used IN ?", filters.RoutingEngineUsed)
69+
}
6770
if filters.StartTime != nil {
6871
baseQuery = baseQuery.Where("timestamp >= ?", *filters.StartTime)
6972
}

framework/logstore/tables.go

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,24 @@ const (
3030

3131
// SearchFilters represents the available filters for log searches
3232
type SearchFilters struct {
33-
Providers []string `json:"providers,omitempty"`
34-
Models []string `json:"models,omitempty"`
35-
Status []string `json:"status,omitempty"`
36-
Objects []string `json:"objects,omitempty"` // For filtering by request type (chat.completion, text.completion, embedding)
37-
SelectedKeyIDs []string `json:"selected_key_ids,omitempty"`
38-
VirtualKeyIDs []string `json:"virtual_key_ids,omitempty"`
39-
RoutingRuleIDs []string `json:"routing_rule_ids,omitempty"`
40-
StartTime *time.Time `json:"start_time,omitempty"`
41-
EndTime *time.Time `json:"end_time,omitempty"`
42-
MinLatency *float64 `json:"min_latency,omitempty"`
43-
MaxLatency *float64 `json:"max_latency,omitempty"`
44-
MinTokens *int `json:"min_tokens,omitempty"`
45-
MaxTokens *int `json:"max_tokens,omitempty"`
46-
MinCost *float64 `json:"min_cost,omitempty"`
47-
MaxCost *float64 `json:"max_cost,omitempty"`
48-
MissingCostOnly bool `json:"missing_cost_only,omitempty"`
49-
ContentSearch string `json:"content_search,omitempty"`
33+
Providers []string `json:"providers,omitempty"`
34+
Models []string `json:"models,omitempty"`
35+
Status []string `json:"status,omitempty"`
36+
Objects []string `json:"objects,omitempty"` // For filtering by request type (chat.completion, text.completion, embedding)
37+
SelectedKeyIDs []string `json:"selected_key_ids,omitempty"`
38+
VirtualKeyIDs []string `json:"virtual_key_ids,omitempty"`
39+
RoutingRuleIDs []string `json:"routing_rule_ids,omitempty"`
40+
RoutingEngineUsed []string `json:"routing_engine_used,omitempty"` // For filtering by routing engine (routing-rule, governance, loadbalancing)
41+
StartTime *time.Time `json:"start_time,omitempty"`
42+
EndTime *time.Time `json:"end_time,omitempty"`
43+
MinLatency *float64 `json:"min_latency,omitempty"`
44+
MaxLatency *float64 `json:"max_latency,omitempty"`
45+
MinTokens *int `json:"min_tokens,omitempty"`
46+
MaxTokens *int `json:"max_tokens,omitempty"`
47+
MinCost *float64 `json:"min_cost,omitempty"`
48+
MaxCost *float64 `json:"max_cost,omitempty"`
49+
MissingCostOnly bool `json:"missing_cost_only,omitempty"`
50+
ContentSearch string `json:"content_search,omitempty"`
5051
}
5152

5253
// PaginationOptions represents pagination parameters
@@ -89,6 +90,7 @@ type Log struct {
8990
SelectedKeyName string `gorm:"type:varchar(255)" json:"selected_key_name"`
9091
VirtualKeyID *string `gorm:"type:varchar(255);index:idx_logs_virtual_key_id" json:"virtual_key_id"`
9192
VirtualKeyName *string `gorm:"type:varchar(255)" json:"virtual_key_name"`
93+
RoutingEngineUsed *string `gorm:"type:varchar(255);index:idx_logs_routing_engine_used" json:"routing_engine_used"`
9294
RoutingRuleID *string `gorm:"type:varchar(255);index:idx_logs_routing_rule_id" json:"routing_rule_id"`
9395
RoutingRuleName *string `gorm:"type:varchar(255)" json:"routing_rule_name"`
9496
InputHistory string `gorm:"type:text" json:"-"` // JSON serialized []schemas.ChatMessage

plugins/governance/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,7 @@ func (p *GovernancePlugin) loadBalanceProvider(ctx *schemas.BifrostContext, req
529529
// Update the model field in the request body
530530
body["model"] = string(selectedProvider) + "/" + refinedModel
531531
}
532+
ctx.SetValue(schemas.BifrostContextKeyRoutingEngineUsed, "governance")
532533

533534
// Check if fallbacks field is already present
534535
_, hasFallbacks := body["fallbacks"]
@@ -650,6 +651,7 @@ func (p *GovernancePlugin) applyRoutingRules(ctx *schemas.BifrostContext, req *s
650651
// For regular requests, update in body
651652
body["model"] = decision.Provider + "/" + decision.Model
652653
}
654+
ctx.SetValue(schemas.BifrostContextKeyRoutingEngineUsed, "routing-rule")
653655

654656
// Add fallbacks if present
655657
if len(decision.Fallbacks) > 0 {

plugins/logging/changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
- feat: add routing engine used to log entries

0 commit comments

Comments
 (0)