账单作为可选开关

This commit is contained in:
yu.deng
2024-06-13 09:27:35 +08:00
parent ed717211aa
commit f719606948
15 changed files with 484 additions and 201 deletions

32
monitor/monitor.go Normal file
View File

@@ -0,0 +1,32 @@
package monitor
import "github.com/songquanpeng/one-api/relay/model"
type MonitorInstance interface {
Emit(ChannelId int, success bool)
ShouldDisableChannel(err *model.Error, statusCode int) bool
DisableChannel(channelId int, channelName string, reason string)
}
type defaultMonitor struct {
}
func NewMonitorInstance() MonitorInstance {
return &defaultMonitor{}
}
func (m *defaultMonitor) Emit(channelId int, success bool) {
if success {
metricSuccessChan <- channelId
} else {
metricFailChan <- channelId
}
}
func (m *defaultMonitor) ShouldDisableChannel(err *model.Error, statusCode int) bool {
return ShouldDisableChannel(err, statusCode)
}
func (m *defaultMonitor) DisableChannel(channelId int, channelName string, reason string) {
DisableChannel(channelId, channelName, reason)
}