明细只保留 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 中复用平台主题色 + 倍率/专属倍率 (顺手优化)。
175 lines
5.9 KiB
Go
175 lines
5.9 KiB
Go
// Code generated by ent, DO NOT EDIT.
|
|
|
|
package channelmonitorhistory
|
|
|
|
import (
|
|
"fmt"
|
|
"time"
|
|
|
|
"entgo.io/ent"
|
|
"entgo.io/ent/dialect/sql"
|
|
"entgo.io/ent/dialect/sql/sqlgraph"
|
|
)
|
|
|
|
const (
|
|
// Label holds the string label denoting the channelmonitorhistory type in the database.
|
|
Label = "channel_monitor_history"
|
|
// FieldID holds the string denoting the id field in the database.
|
|
FieldID = "id"
|
|
// FieldDeletedAt holds the string denoting the deleted_at field in the database.
|
|
FieldDeletedAt = "deleted_at"
|
|
// FieldMonitorID holds the string denoting the monitor_id field in the database.
|
|
FieldMonitorID = "monitor_id"
|
|
// FieldModel holds the string denoting the model field in the database.
|
|
FieldModel = "model"
|
|
// FieldStatus holds the string denoting the status field in the database.
|
|
FieldStatus = "status"
|
|
// FieldLatencyMs holds the string denoting the latency_ms field in the database.
|
|
FieldLatencyMs = "latency_ms"
|
|
// FieldPingLatencyMs holds the string denoting the ping_latency_ms field in the database.
|
|
FieldPingLatencyMs = "ping_latency_ms"
|
|
// FieldMessage holds the string denoting the message field in the database.
|
|
FieldMessage = "message"
|
|
// FieldCheckedAt holds the string denoting the checked_at field in the database.
|
|
FieldCheckedAt = "checked_at"
|
|
// EdgeMonitor holds the string denoting the monitor edge name in mutations.
|
|
EdgeMonitor = "monitor"
|
|
// Table holds the table name of the channelmonitorhistory in the database.
|
|
Table = "channel_monitor_histories"
|
|
// MonitorTable is the table that holds the monitor relation/edge.
|
|
MonitorTable = "channel_monitor_histories"
|
|
// MonitorInverseTable is the table name for the ChannelMonitor entity.
|
|
// It exists in this package in order to avoid circular dependency with the "channelmonitor" package.
|
|
MonitorInverseTable = "channel_monitors"
|
|
// MonitorColumn is the table column denoting the monitor relation/edge.
|
|
MonitorColumn = "monitor_id"
|
|
)
|
|
|
|
// Columns holds all SQL columns for channelmonitorhistory fields.
|
|
var Columns = []string{
|
|
FieldID,
|
|
FieldDeletedAt,
|
|
FieldMonitorID,
|
|
FieldModel,
|
|
FieldStatus,
|
|
FieldLatencyMs,
|
|
FieldPingLatencyMs,
|
|
FieldMessage,
|
|
FieldCheckedAt,
|
|
}
|
|
|
|
// ValidColumn reports if the column name is valid (part of the table columns).
|
|
func ValidColumn(column string) bool {
|
|
for i := range Columns {
|
|
if column == Columns[i] {
|
|
return true
|
|
}
|
|
}
|
|
return false
|
|
}
|
|
|
|
// Note that the variables below are initialized by the runtime
|
|
// package on the initialization of the application. Therefore,
|
|
// it should be imported in the main as follows:
|
|
//
|
|
// import _ "github.com/Wei-Shaw/sub2api/ent/runtime"
|
|
var (
|
|
Hooks [1]ent.Hook
|
|
Interceptors [1]ent.Interceptor
|
|
// ModelValidator is a validator for the "model" field. It is called by the builders before save.
|
|
ModelValidator func(string) error
|
|
// DefaultMessage holds the default value on creation for the "message" field.
|
|
DefaultMessage string
|
|
// MessageValidator is a validator for the "message" field. It is called by the builders before save.
|
|
MessageValidator func(string) error
|
|
// DefaultCheckedAt holds the default value on creation for the "checked_at" field.
|
|
DefaultCheckedAt func() time.Time
|
|
)
|
|
|
|
// Status defines the type for the "status" enum field.
|
|
type Status string
|
|
|
|
// Status values.
|
|
const (
|
|
StatusOperational Status = "operational"
|
|
StatusDegraded Status = "degraded"
|
|
StatusFailed Status = "failed"
|
|
StatusError Status = "error"
|
|
)
|
|
|
|
func (s Status) String() string {
|
|
return string(s)
|
|
}
|
|
|
|
// StatusValidator is a validator for the "status" field enum values. It is called by the builders before save.
|
|
func StatusValidator(s Status) error {
|
|
switch s {
|
|
case StatusOperational, StatusDegraded, StatusFailed, StatusError:
|
|
return nil
|
|
default:
|
|
return fmt.Errorf("channelmonitorhistory: invalid enum value for status field: %q", s)
|
|
}
|
|
}
|
|
|
|
// OrderOption defines the ordering options for the ChannelMonitorHistory queries.
|
|
type OrderOption func(*sql.Selector)
|
|
|
|
// ByID orders the results by the id field.
|
|
func ByID(opts ...sql.OrderTermOption) OrderOption {
|
|
return sql.OrderByField(FieldID, opts...).ToFunc()
|
|
}
|
|
|
|
// ByDeletedAt orders the results by the deleted_at field.
|
|
func ByDeletedAt(opts ...sql.OrderTermOption) OrderOption {
|
|
return sql.OrderByField(FieldDeletedAt, opts...).ToFunc()
|
|
}
|
|
|
|
// ByMonitorID orders the results by the monitor_id field.
|
|
func ByMonitorID(opts ...sql.OrderTermOption) OrderOption {
|
|
return sql.OrderByField(FieldMonitorID, opts...).ToFunc()
|
|
}
|
|
|
|
// ByModel orders the results by the model field.
|
|
func ByModel(opts ...sql.OrderTermOption) OrderOption {
|
|
return sql.OrderByField(FieldModel, opts...).ToFunc()
|
|
}
|
|
|
|
// ByStatus orders the results by the status field.
|
|
func ByStatus(opts ...sql.OrderTermOption) OrderOption {
|
|
return sql.OrderByField(FieldStatus, opts...).ToFunc()
|
|
}
|
|
|
|
// ByLatencyMs orders the results by the latency_ms field.
|
|
func ByLatencyMs(opts ...sql.OrderTermOption) OrderOption {
|
|
return sql.OrderByField(FieldLatencyMs, opts...).ToFunc()
|
|
}
|
|
|
|
// ByPingLatencyMs orders the results by the ping_latency_ms field.
|
|
func ByPingLatencyMs(opts ...sql.OrderTermOption) OrderOption {
|
|
return sql.OrderByField(FieldPingLatencyMs, opts...).ToFunc()
|
|
}
|
|
|
|
// ByMessage orders the results by the message field.
|
|
func ByMessage(opts ...sql.OrderTermOption) OrderOption {
|
|
return sql.OrderByField(FieldMessage, opts...).ToFunc()
|
|
}
|
|
|
|
// ByCheckedAt orders the results by the checked_at field.
|
|
func ByCheckedAt(opts ...sql.OrderTermOption) OrderOption {
|
|
return sql.OrderByField(FieldCheckedAt, opts...).ToFunc()
|
|
}
|
|
|
|
// ByMonitorField orders the results by monitor field.
|
|
func ByMonitorField(field string, opts ...sql.OrderTermOption) OrderOption {
|
|
return func(s *sql.Selector) {
|
|
sqlgraph.OrderByNeighborTerms(s, newMonitorStep(), sql.OrderByField(field, opts...))
|
|
}
|
|
}
|
|
func newMonitorStep() *sqlgraph.Step {
|
|
return sqlgraph.NewStep(
|
|
sqlgraph.From(Table, FieldID),
|
|
sqlgraph.To(MonitorInverseTable, FieldID),
|
|
sqlgraph.Edge(sqlgraph.M2O, true, MonitorTable, MonitorColumn),
|
|
)
|
|
}
|