明细只保留 1 天,超过 1 天聚合到新表 channel_monitor_daily_rollups(按 monitor_id/model/bucket_date 维度),聚合保留 30 天。两张表都用 SoftDeleteMixin 软删除(DELETE 自动改为 UPDATE deleted_at = NOW())。 聚合 + 清理任务由 OpsCleanupService 的 cron 统一调度,与运维监控的清理共享 schedule(默认 0 2 * * *)和 leader lock。ChannelMonitorRunner 的 cleanupLoop 被移除,只保留 dueCheckLoop。 读取路径 ComputeAvailability* 改为 UNION 明细(今天 deleted_at IS NULL)+ 聚合(过去 windowDays 天 deleted_at IS NULL),SUM(ok)/SUM(total) 自然加权 计算可用率,AVG latency 用 SUM(sum_latency_ms)/SUM(count_latency)。 watermark 表 channel_monitor_aggregation_watermark 单行(id=1),记录 last_aggregated_date,重启后从该日期 +1 继续聚合,首次为 nil 则从 today - 30d 开始回填,单次最多 35 天上限避免长事务。 raw SQL 的 ListLatestPerModel / ListLatestForMonitorIDs / ListRecentHistoryForMonitors 都补上 deleted_at IS NULL 过滤(SoftDeleteMixin interceptor 只对 ent query 生效)。 bump version to 0.1.114.28 GroupBadge 在 MonitorKeyPickerDialog 中复用平台主题色 + 倍率/专属倍率 (顺手优化)。
222 lines
8.2 KiB
Go
222 lines
8.2 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package ent
|
|
|
|
import (
|
|
"fmt"
|
|
"strings"
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"github.com/Wei-Shaw/sub2api/ent/channelmonitor"
|
|
"github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory"
|
|
)
|
|
|
|
// ChannelMonitorHistory is the model entity for the ChannelMonitorHistory schema.
|
|
type ChannelMonitorHistory struct {
|
|
config `json:"-"`
|
|
// ID of the ent.
|
|
ID int64 `json:"id,omitempty"`
|
|
// DeletedAt holds the value of the "deleted_at" field.
|
|
DeletedAt *time.Time `json:"deleted_at,omitempty"`
|
|
// MonitorID holds the value of the "monitor_id" field.
|
|
MonitorID int64 `json:"monitor_id,omitempty"`
|
|
// Model holds the value of the "model" field.
|
|
Model string `json:"model,omitempty"`
|
|
// Status holds the value of the "status" field.
|
|
Status channelmonitorhistory.Status `json:"status,omitempty"`
|
|
// LatencyMs holds the value of the "latency_ms" field.
|
|
LatencyMs *int `json:"latency_ms,omitempty"`
|
|
// PingLatencyMs holds the value of the "ping_latency_ms" field.
|
|
PingLatencyMs *int `json:"ping_latency_ms,omitempty"`
|
|
// Message holds the value of the "message" field.
|
|
Message string `json:"message,omitempty"`
|
|
// CheckedAt holds the value of the "checked_at" field.
|
|
CheckedAt time.Time `json:"checked_at,omitempty"`
|
|
// Edges holds the relations/edges for other nodes in the graph.
|
|
// The values are being populated by the ChannelMonitorHistoryQuery when eager-loading is set.
|
|
Edges ChannelMonitorHistoryEdges `json:"edges"`
|
|
selectValues sql.SelectValues
|
|
}
|
|
|
|
// ChannelMonitorHistoryEdges holds the relations/edges for other nodes in the graph.
|
|
type ChannelMonitorHistoryEdges struct {
|
|
// Monitor holds the value of the monitor edge.
|
|
Monitor *ChannelMonitor `json:"monitor,omitempty"`
|
|
// loadedTypes holds the information for reporting if a
|
|
// type was loaded (or requested) in eager-loading or not.
|
|
loadedTypes [1]bool
|
|
}
|
|
|
|
// MonitorOrErr returns the Monitor value or an error if the edge
|
|
// was not loaded in eager-loading, or loaded but was not found.
|
|
func (e ChannelMonitorHistoryEdges) MonitorOrErr() (*ChannelMonitor, error) {
|
|
if e.Monitor != nil {
|
|
return e.Monitor, nil
|
|
} else if e.loadedTypes[0] {
|
|
return nil, &NotFoundError{label: channelmonitor.Label}
|
|
}
|
|
return nil, &NotLoadedError{edge: "monitor"}
|
|
}
|
|
|
|
// scanValues returns the types for scanning values from sql.Rows.
|
|
func (*ChannelMonitorHistory) scanValues(columns []string) ([]any, error) {
|
|
values := make([]any, len(columns))
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case channelmonitorhistory.FieldID, channelmonitorhistory.FieldMonitorID, channelmonitorhistory.FieldLatencyMs, channelmonitorhistory.FieldPingLatencyMs:
|
|
values[i] = new(sql.NullInt64)
|
|
case channelmonitorhistory.FieldModel, channelmonitorhistory.FieldStatus, channelmonitorhistory.FieldMessage:
|
|
values[i] = new(sql.NullString)
|
|
case channelmonitorhistory.FieldDeletedAt, channelmonitorhistory.FieldCheckedAt:
|
|
values[i] = new(sql.NullTime)
|
|
default:
|
|
values[i] = new(sql.UnknownType)
|
|
}
|
|
}
|
|
return values, nil
|
|
}
|
|
|
|
// assignValues assigns the values that were returned from sql.Rows (after scanning)
|
|
// to the ChannelMonitorHistory fields.
|
|
func (_m *ChannelMonitorHistory) assignValues(columns []string, values []any) error {
|
|
if m, n := len(values), len(columns); m < n {
|
|
return fmt.Errorf("mismatch number of scan values: %d != %d", m, n)
|
|
}
|
|
for i := range columns {
|
|
switch columns[i] {
|
|
case channelmonitorhistory.FieldID:
|
|
value, ok := values[i].(*sql.NullInt64)
|
|
if !ok {
|
|
return fmt.Errorf("unexpected type %T for field id", value)
|
|
}
|
|
_m.ID = int64(value.Int64)
|
|
case channelmonitorhistory.FieldDeletedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field deleted_at", values[i])
|
|
} else if value.Valid {
|
|
_m.DeletedAt = new(time.Time)
|
|
*_m.DeletedAt = value.Time
|
|
}
|
|
case channelmonitorhistory.FieldMonitorID:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field monitor_id", values[i])
|
|
} else if value.Valid {
|
|
_m.MonitorID = value.Int64
|
|
}
|
|
case channelmonitorhistory.FieldModel:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field model", values[i])
|
|
} else if value.Valid {
|
|
_m.Model = value.String
|
|
}
|
|
case channelmonitorhistory.FieldStatus:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field status", values[i])
|
|
} else if value.Valid {
|
|
_m.Status = channelmonitorhistory.Status(value.String)
|
|
}
|
|
case channelmonitorhistory.FieldLatencyMs:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field latency_ms", values[i])
|
|
} else if value.Valid {
|
|
_m.LatencyMs = new(int)
|
|
*_m.LatencyMs = int(value.Int64)
|
|
}
|
|
case channelmonitorhistory.FieldPingLatencyMs:
|
|
if value, ok := values[i].(*sql.NullInt64); !ok {
|
|
return fmt.Errorf("unexpected type %T for field ping_latency_ms", values[i])
|
|
} else if value.Valid {
|
|
_m.PingLatencyMs = new(int)
|
|
*_m.PingLatencyMs = int(value.Int64)
|
|
}
|
|
case channelmonitorhistory.FieldMessage:
|
|
if value, ok := values[i].(*sql.NullString); !ok {
|
|
return fmt.Errorf("unexpected type %T for field message", values[i])
|
|
} else if value.Valid {
|
|
_m.Message = value.String
|
|
}
|
|
case channelmonitorhistory.FieldCheckedAt:
|
|
if value, ok := values[i].(*sql.NullTime); !ok {
|
|
return fmt.Errorf("unexpected type %T for field checked_at", values[i])
|
|
} else if value.Valid {
|
|
_m.CheckedAt = value.Time
|
|
}
|
|
default:
|
|
_m.selectValues.Set(columns[i], values[i])
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// Value returns the ent.Value that was dynamically selected and assigned to the ChannelMonitorHistory.
|
|
// This includes values selected through modifiers, order, etc.
|
|
func (_m *ChannelMonitorHistory) Value(name string) (ent.Value, error) {
|
|
return _m.selectValues.Get(name)
|
|
}
|
|
|
|
// QueryMonitor queries the "monitor" edge of the ChannelMonitorHistory entity.
|
|
func (_m *ChannelMonitorHistory) QueryMonitor() *ChannelMonitorQuery {
|
|
return NewChannelMonitorHistoryClient(_m.config).QueryMonitor(_m)
|
|
}
|
|
|
|
// Update returns a builder for updating this ChannelMonitorHistory.
|
|
// Note that you need to call ChannelMonitorHistory.Unwrap() before calling this method if this ChannelMonitorHistory
|
|
// was returned from a transaction, and the transaction was committed or rolled back.
|
|
func (_m *ChannelMonitorHistory) Update() *ChannelMonitorHistoryUpdateOne {
|
|
return NewChannelMonitorHistoryClient(_m.config).UpdateOne(_m)
|
|
}
|
|
|
|
// Unwrap unwraps the ChannelMonitorHistory entity that was returned from a transaction after it was closed,
|
|
// so that all future queries will be executed through the driver which created the transaction.
|
|
func (_m *ChannelMonitorHistory) Unwrap() *ChannelMonitorHistory {
|
|
_tx, ok := _m.config.driver.(*txDriver)
|
|
if !ok {
|
|
panic("ent: ChannelMonitorHistory is not a transactional entity")
|
|
}
|
|
_m.config.driver = _tx.drv
|
|
return _m
|
|
}
|
|
|
|
// String implements the fmt.Stringer.
|
|
func (_m *ChannelMonitorHistory) String() string {
|
|
var builder strings.Builder
|
|
builder.WriteString("ChannelMonitorHistory(")
|
|
builder.WriteString(fmt.Sprintf("id=%v, ", _m.ID))
|
|
if v := _m.DeletedAt; v != nil {
|
|
builder.WriteString("deleted_at=")
|
|
builder.WriteString(v.Format(time.ANSIC))
|
|
}
|
|
builder.WriteString(", ")
|
|
builder.WriteString("monitor_id=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.MonitorID))
|
|
builder.WriteString(", ")
|
|
builder.WriteString("model=")
|
|
builder.WriteString(_m.Model)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("status=")
|
|
builder.WriteString(fmt.Sprintf("%v", _m.Status))
|
|
builder.WriteString(", ")
|
|
if v := _m.LatencyMs; v != nil {
|
|
builder.WriteString("latency_ms=")
|
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
|
}
|
|
builder.WriteString(", ")
|
|
if v := _m.PingLatencyMs; v != nil {
|
|
builder.WriteString("ping_latency_ms=")
|
|
builder.WriteString(fmt.Sprintf("%v", *v))
|
|
}
|
|
builder.WriteString(", ")
|
|
builder.WriteString("message=")
|
|
builder.WriteString(_m.Message)
|
|
builder.WriteString(", ")
|
|
builder.WriteString("checked_at=")
|
|
builder.WriteString(_m.CheckedAt.Format(time.ANSIC))
|
|
builder.WriteByte(')')
|
|
return builder.String()
|
|
}
|
|
|
|
// ChannelMonitorHistories is a parsable slice of ChannelMonitorHistory.
|
|
type ChannelMonitorHistories []*ChannelMonitorHistory
|