Commit 8cf83c98 authored by erio's avatar erio
Browse files

feat(channel-monitor): aggregate history to daily rollups + soft delete

明细只保留 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 中复用平台主题色 + 倍率/专属倍率
(顺手优化)。
parent ba98243c
...@@ -23,6 +23,7 @@ import ( ...@@ -23,6 +23,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/authidentity" "github.com/Wei-Shaw/sub2api/ent/authidentity"
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel" "github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
"github.com/Wei-Shaw/sub2api/ent/channelmonitor" "github.com/Wei-Shaw/sub2api/ent/channelmonitor"
"github.com/Wei-Shaw/sub2api/ent/channelmonitordailyrollup"
"github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory" "github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory"
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule" "github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
"github.com/Wei-Shaw/sub2api/ent/group" "github.com/Wei-Shaw/sub2api/ent/group"
...@@ -72,6 +73,8 @@ type Client struct { ...@@ -72,6 +73,8 @@ type Client struct {
AuthIdentityChannel *AuthIdentityChannelClient AuthIdentityChannel *AuthIdentityChannelClient
// ChannelMonitor is the client for interacting with the ChannelMonitor builders. // ChannelMonitor is the client for interacting with the ChannelMonitor builders.
ChannelMonitor *ChannelMonitorClient ChannelMonitor *ChannelMonitorClient
// ChannelMonitorDailyRollup is the client for interacting with the ChannelMonitorDailyRollup builders.
ChannelMonitorDailyRollup *ChannelMonitorDailyRollupClient
// ChannelMonitorHistory is the client for interacting with the ChannelMonitorHistory builders. // ChannelMonitorHistory is the client for interacting with the ChannelMonitorHistory builders.
ChannelMonitorHistory *ChannelMonitorHistoryClient ChannelMonitorHistory *ChannelMonitorHistoryClient
// ErrorPassthroughRule is the client for interacting with the ErrorPassthroughRule builders. // ErrorPassthroughRule is the client for interacting with the ErrorPassthroughRule builders.
...@@ -139,6 +142,7 @@ func (c *Client) init() { ...@@ -139,6 +142,7 @@ func (c *Client) init() {
c.AuthIdentity = NewAuthIdentityClient(c.config) c.AuthIdentity = NewAuthIdentityClient(c.config)
c.AuthIdentityChannel = NewAuthIdentityChannelClient(c.config) c.AuthIdentityChannel = NewAuthIdentityChannelClient(c.config)
c.ChannelMonitor = NewChannelMonitorClient(c.config) c.ChannelMonitor = NewChannelMonitorClient(c.config)
c.ChannelMonitorDailyRollup = NewChannelMonitorDailyRollupClient(c.config)
c.ChannelMonitorHistory = NewChannelMonitorHistoryClient(c.config) c.ChannelMonitorHistory = NewChannelMonitorHistoryClient(c.config)
c.ErrorPassthroughRule = NewErrorPassthroughRuleClient(c.config) c.ErrorPassthroughRule = NewErrorPassthroughRuleClient(c.config)
c.Group = NewGroupClient(c.config) c.Group = NewGroupClient(c.config)
...@@ -263,6 +267,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) { ...@@ -263,6 +267,7 @@ func (c *Client) Tx(ctx context.Context) (*Tx, error) {
AuthIdentity: NewAuthIdentityClient(cfg), AuthIdentity: NewAuthIdentityClient(cfg),
AuthIdentityChannel: NewAuthIdentityChannelClient(cfg), AuthIdentityChannel: NewAuthIdentityChannelClient(cfg),
ChannelMonitor: NewChannelMonitorClient(cfg), ChannelMonitor: NewChannelMonitorClient(cfg),
ChannelMonitorDailyRollup: NewChannelMonitorDailyRollupClient(cfg),
ChannelMonitorHistory: NewChannelMonitorHistoryClient(cfg), ChannelMonitorHistory: NewChannelMonitorHistoryClient(cfg),
ErrorPassthroughRule: NewErrorPassthroughRuleClient(cfg), ErrorPassthroughRule: NewErrorPassthroughRuleClient(cfg),
Group: NewGroupClient(cfg), Group: NewGroupClient(cfg),
...@@ -314,6 +319,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error) ...@@ -314,6 +319,7 @@ func (c *Client) BeginTx(ctx context.Context, opts *sql.TxOptions) (*Tx, error)
AuthIdentity: NewAuthIdentityClient(cfg), AuthIdentity: NewAuthIdentityClient(cfg),
AuthIdentityChannel: NewAuthIdentityChannelClient(cfg), AuthIdentityChannel: NewAuthIdentityChannelClient(cfg),
ChannelMonitor: NewChannelMonitorClient(cfg), ChannelMonitor: NewChannelMonitorClient(cfg),
ChannelMonitorDailyRollup: NewChannelMonitorDailyRollupClient(cfg),
ChannelMonitorHistory: NewChannelMonitorHistoryClient(cfg), ChannelMonitorHistory: NewChannelMonitorHistoryClient(cfg),
ErrorPassthroughRule: NewErrorPassthroughRuleClient(cfg), ErrorPassthroughRule: NewErrorPassthroughRuleClient(cfg),
Group: NewGroupClient(cfg), Group: NewGroupClient(cfg),
...@@ -369,12 +375,12 @@ func (c *Client) Use(hooks ...Hook) { ...@@ -369,12 +375,12 @@ func (c *Client) Use(hooks ...Hook) {
for _, n := range []interface{ Use(...Hook) }{ for _, n := range []interface{ Use(...Hook) }{
c.APIKey, c.Account, c.AccountGroup, c.Announcement, c.AnnouncementRead, c.APIKey, c.Account, c.AccountGroup, c.Announcement, c.AnnouncementRead,
c.AuthIdentity, c.AuthIdentityChannel, c.ChannelMonitor, c.AuthIdentity, c.AuthIdentityChannel, c.ChannelMonitor,
c.ChannelMonitorHistory, c.ErrorPassthroughRule, c.Group, c.IdempotencyRecord, c.ChannelMonitorDailyRollup, c.ChannelMonitorHistory, c.ErrorPassthroughRule,
c.IdentityAdoptionDecision, c.PaymentAuditLog, c.PaymentOrder, c.Group, c.IdempotencyRecord, c.IdentityAdoptionDecision, c.PaymentAuditLog,
c.PaymentProviderInstance, c.PendingAuthSession, c.PromoCode, c.PromoCodeUsage, c.PaymentOrder, c.PaymentProviderInstance, c.PendingAuthSession, c.PromoCode,
c.Proxy, c.RedeemCode, c.SecuritySecret, c.Setting, c.SubscriptionPlan, c.PromoCodeUsage, c.Proxy, c.RedeemCode, c.SecuritySecret, c.Setting,
c.TLSFingerprintProfile, c.UsageCleanupTask, c.UsageLog, c.User, c.SubscriptionPlan, c.TLSFingerprintProfile, c.UsageCleanupTask, c.UsageLog,
c.UserAllowedGroup, c.UserAttributeDefinition, c.UserAttributeValue, c.User, c.UserAllowedGroup, c.UserAttributeDefinition, c.UserAttributeValue,
c.UserSubscription, c.UserSubscription,
} { } {
n.Use(hooks...) n.Use(hooks...)
...@@ -387,12 +393,12 @@ func (c *Client) Intercept(interceptors ...Interceptor) { ...@@ -387,12 +393,12 @@ func (c *Client) Intercept(interceptors ...Interceptor) {
for _, n := range []interface{ Intercept(...Interceptor) }{ for _, n := range []interface{ Intercept(...Interceptor) }{
c.APIKey, c.Account, c.AccountGroup, c.Announcement, c.AnnouncementRead, c.APIKey, c.Account, c.AccountGroup, c.Announcement, c.AnnouncementRead,
c.AuthIdentity, c.AuthIdentityChannel, c.ChannelMonitor, c.AuthIdentity, c.AuthIdentityChannel, c.ChannelMonitor,
c.ChannelMonitorHistory, c.ErrorPassthroughRule, c.Group, c.IdempotencyRecord, c.ChannelMonitorDailyRollup, c.ChannelMonitorHistory, c.ErrorPassthroughRule,
c.IdentityAdoptionDecision, c.PaymentAuditLog, c.PaymentOrder, c.Group, c.IdempotencyRecord, c.IdentityAdoptionDecision, c.PaymentAuditLog,
c.PaymentProviderInstance, c.PendingAuthSession, c.PromoCode, c.PromoCodeUsage, c.PaymentOrder, c.PaymentProviderInstance, c.PendingAuthSession, c.PromoCode,
c.Proxy, c.RedeemCode, c.SecuritySecret, c.Setting, c.SubscriptionPlan, c.PromoCodeUsage, c.Proxy, c.RedeemCode, c.SecuritySecret, c.Setting,
c.TLSFingerprintProfile, c.UsageCleanupTask, c.UsageLog, c.User, c.SubscriptionPlan, c.TLSFingerprintProfile, c.UsageCleanupTask, c.UsageLog,
c.UserAllowedGroup, c.UserAttributeDefinition, c.UserAttributeValue, c.User, c.UserAllowedGroup, c.UserAttributeDefinition, c.UserAttributeValue,
c.UserSubscription, c.UserSubscription,
} { } {
n.Intercept(interceptors...) n.Intercept(interceptors...)
...@@ -418,6 +424,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) { ...@@ -418,6 +424,8 @@ func (c *Client) Mutate(ctx context.Context, m Mutation) (Value, error) {
return c.AuthIdentityChannel.mutate(ctx, m) return c.AuthIdentityChannel.mutate(ctx, m)
case *ChannelMonitorMutation: case *ChannelMonitorMutation:
return c.ChannelMonitor.mutate(ctx, m) return c.ChannelMonitor.mutate(ctx, m)
case *ChannelMonitorDailyRollupMutation:
return c.ChannelMonitorDailyRollup.mutate(ctx, m)
case *ChannelMonitorHistoryMutation: case *ChannelMonitorHistoryMutation:
return c.ChannelMonitorHistory.mutate(ctx, m) return c.ChannelMonitorHistory.mutate(ctx, m)
case *ErrorPassthroughRuleMutation: case *ErrorPassthroughRuleMutation:
...@@ -1737,6 +1745,22 @@ func (c *ChannelMonitorClient) QueryHistory(_m *ChannelMonitor) *ChannelMonitorH ...@@ -1737,6 +1745,22 @@ func (c *ChannelMonitorClient) QueryHistory(_m *ChannelMonitor) *ChannelMonitorH
return query return query
} }
// QueryDailyRollups queries the daily_rollups edge of a ChannelMonitor.
func (c *ChannelMonitorClient) QueryDailyRollups(_m *ChannelMonitor) *ChannelMonitorDailyRollupQuery {
query := (&ChannelMonitorDailyRollupClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(channelmonitor.Table, channelmonitor.FieldID, id),
sqlgraph.To(channelmonitordailyrollup.Table, channelmonitordailyrollup.FieldID),
sqlgraph.Edge(sqlgraph.O2M, false, channelmonitor.DailyRollupsTable, channelmonitor.DailyRollupsColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks. // Hooks returns the client hooks.
func (c *ChannelMonitorClient) Hooks() []Hook { func (c *ChannelMonitorClient) Hooks() []Hook {
return c.hooks.ChannelMonitor return c.hooks.ChannelMonitor
...@@ -1762,6 +1786,157 @@ func (c *ChannelMonitorClient) mutate(ctx context.Context, m *ChannelMonitorMuta ...@@ -1762,6 +1786,157 @@ func (c *ChannelMonitorClient) mutate(ctx context.Context, m *ChannelMonitorMuta
} }
} }
// ChannelMonitorDailyRollupClient is a client for the ChannelMonitorDailyRollup schema.
type ChannelMonitorDailyRollupClient struct {
config
}
// NewChannelMonitorDailyRollupClient returns a client for the ChannelMonitorDailyRollup from the given config.
func NewChannelMonitorDailyRollupClient(c config) *ChannelMonitorDailyRollupClient {
return &ChannelMonitorDailyRollupClient{config: c}
}
// Use adds a list of mutation hooks to the hooks stack.
// A call to `Use(f, g, h)` equals to `channelmonitordailyrollup.Hooks(f(g(h())))`.
func (c *ChannelMonitorDailyRollupClient) Use(hooks ...Hook) {
c.hooks.ChannelMonitorDailyRollup = append(c.hooks.ChannelMonitorDailyRollup, hooks...)
}
// Intercept adds a list of query interceptors to the interceptors stack.
// A call to `Intercept(f, g, h)` equals to `channelmonitordailyrollup.Intercept(f(g(h())))`.
func (c *ChannelMonitorDailyRollupClient) Intercept(interceptors ...Interceptor) {
c.inters.ChannelMonitorDailyRollup = append(c.inters.ChannelMonitorDailyRollup, interceptors...)
}
// Create returns a builder for creating a ChannelMonitorDailyRollup entity.
func (c *ChannelMonitorDailyRollupClient) Create() *ChannelMonitorDailyRollupCreate {
mutation := newChannelMonitorDailyRollupMutation(c.config, OpCreate)
return &ChannelMonitorDailyRollupCreate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// CreateBulk returns a builder for creating a bulk of ChannelMonitorDailyRollup entities.
func (c *ChannelMonitorDailyRollupClient) CreateBulk(builders ...*ChannelMonitorDailyRollupCreate) *ChannelMonitorDailyRollupCreateBulk {
return &ChannelMonitorDailyRollupCreateBulk{config: c.config, builders: builders}
}
// MapCreateBulk creates a bulk creation builder from the given slice. For each item in the slice, the function creates
// a builder and applies setFunc on it.
func (c *ChannelMonitorDailyRollupClient) MapCreateBulk(slice any, setFunc func(*ChannelMonitorDailyRollupCreate, int)) *ChannelMonitorDailyRollupCreateBulk {
rv := reflect.ValueOf(slice)
if rv.Kind() != reflect.Slice {
return &ChannelMonitorDailyRollupCreateBulk{err: fmt.Errorf("calling to ChannelMonitorDailyRollupClient.MapCreateBulk with wrong type %T, need slice", slice)}
}
builders := make([]*ChannelMonitorDailyRollupCreate, rv.Len())
for i := 0; i < rv.Len(); i++ {
builders[i] = c.Create()
setFunc(builders[i], i)
}
return &ChannelMonitorDailyRollupCreateBulk{config: c.config, builders: builders}
}
// Update returns an update builder for ChannelMonitorDailyRollup.
func (c *ChannelMonitorDailyRollupClient) Update() *ChannelMonitorDailyRollupUpdate {
mutation := newChannelMonitorDailyRollupMutation(c.config, OpUpdate)
return &ChannelMonitorDailyRollupUpdate{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOne returns an update builder for the given entity.
func (c *ChannelMonitorDailyRollupClient) UpdateOne(_m *ChannelMonitorDailyRollup) *ChannelMonitorDailyRollupUpdateOne {
mutation := newChannelMonitorDailyRollupMutation(c.config, OpUpdateOne, withChannelMonitorDailyRollup(_m))
return &ChannelMonitorDailyRollupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// UpdateOneID returns an update builder for the given id.
func (c *ChannelMonitorDailyRollupClient) UpdateOneID(id int64) *ChannelMonitorDailyRollupUpdateOne {
mutation := newChannelMonitorDailyRollupMutation(c.config, OpUpdateOne, withChannelMonitorDailyRollupID(id))
return &ChannelMonitorDailyRollupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// Delete returns a delete builder for ChannelMonitorDailyRollup.
func (c *ChannelMonitorDailyRollupClient) Delete() *ChannelMonitorDailyRollupDelete {
mutation := newChannelMonitorDailyRollupMutation(c.config, OpDelete)
return &ChannelMonitorDailyRollupDelete{config: c.config, hooks: c.Hooks(), mutation: mutation}
}
// DeleteOne returns a builder for deleting the given entity.
func (c *ChannelMonitorDailyRollupClient) DeleteOne(_m *ChannelMonitorDailyRollup) *ChannelMonitorDailyRollupDeleteOne {
return c.DeleteOneID(_m.ID)
}
// DeleteOneID returns a builder for deleting the given entity by its id.
func (c *ChannelMonitorDailyRollupClient) DeleteOneID(id int64) *ChannelMonitorDailyRollupDeleteOne {
builder := c.Delete().Where(channelmonitordailyrollup.ID(id))
builder.mutation.id = &id
builder.mutation.op = OpDeleteOne
return &ChannelMonitorDailyRollupDeleteOne{builder}
}
// Query returns a query builder for ChannelMonitorDailyRollup.
func (c *ChannelMonitorDailyRollupClient) Query() *ChannelMonitorDailyRollupQuery {
return &ChannelMonitorDailyRollupQuery{
config: c.config,
ctx: &QueryContext{Type: TypeChannelMonitorDailyRollup},
inters: c.Interceptors(),
}
}
// Get returns a ChannelMonitorDailyRollup entity by its id.
func (c *ChannelMonitorDailyRollupClient) Get(ctx context.Context, id int64) (*ChannelMonitorDailyRollup, error) {
return c.Query().Where(channelmonitordailyrollup.ID(id)).Only(ctx)
}
// GetX is like Get, but panics if an error occurs.
func (c *ChannelMonitorDailyRollupClient) GetX(ctx context.Context, id int64) *ChannelMonitorDailyRollup {
obj, err := c.Get(ctx, id)
if err != nil {
panic(err)
}
return obj
}
// QueryMonitor queries the monitor edge of a ChannelMonitorDailyRollup.
func (c *ChannelMonitorDailyRollupClient) QueryMonitor(_m *ChannelMonitorDailyRollup) *ChannelMonitorQuery {
query := (&ChannelMonitorClient{config: c.config}).Query()
query.path = func(context.Context) (fromV *sql.Selector, _ error) {
id := _m.ID
step := sqlgraph.NewStep(
sqlgraph.From(channelmonitordailyrollup.Table, channelmonitordailyrollup.FieldID, id),
sqlgraph.To(channelmonitor.Table, channelmonitor.FieldID),
sqlgraph.Edge(sqlgraph.M2O, true, channelmonitordailyrollup.MonitorTable, channelmonitordailyrollup.MonitorColumn),
)
fromV = sqlgraph.Neighbors(_m.driver.Dialect(), step)
return fromV, nil
}
return query
}
// Hooks returns the client hooks.
func (c *ChannelMonitorDailyRollupClient) Hooks() []Hook {
hooks := c.hooks.ChannelMonitorDailyRollup
return append(hooks[:len(hooks):len(hooks)], channelmonitordailyrollup.Hooks[:]...)
}
// Interceptors returns the client interceptors.
func (c *ChannelMonitorDailyRollupClient) Interceptors() []Interceptor {
inters := c.inters.ChannelMonitorDailyRollup
return append(inters[:len(inters):len(inters)], channelmonitordailyrollup.Interceptors[:]...)
}
func (c *ChannelMonitorDailyRollupClient) mutate(ctx context.Context, m *ChannelMonitorDailyRollupMutation) (Value, error) {
switch m.Op() {
case OpCreate:
return (&ChannelMonitorDailyRollupCreate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdate:
return (&ChannelMonitorDailyRollupUpdate{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpUpdateOne:
return (&ChannelMonitorDailyRollupUpdateOne{config: c.config, hooks: c.Hooks(), mutation: m}).Save(ctx)
case OpDelete, OpDeleteOne:
return (&ChannelMonitorDailyRollupDelete{config: c.config, hooks: c.Hooks(), mutation: m}).Exec(ctx)
default:
return nil, fmt.Errorf("ent: unknown ChannelMonitorDailyRollup mutation op: %q", m.Op())
}
}
// ChannelMonitorHistoryClient is a client for the ChannelMonitorHistory schema. // ChannelMonitorHistoryClient is a client for the ChannelMonitorHistory schema.
type ChannelMonitorHistoryClient struct { type ChannelMonitorHistoryClient struct {
config config
...@@ -1888,12 +2063,14 @@ func (c *ChannelMonitorHistoryClient) QueryMonitor(_m *ChannelMonitorHistory) *C ...@@ -1888,12 +2063,14 @@ func (c *ChannelMonitorHistoryClient) QueryMonitor(_m *ChannelMonitorHistory) *C
// Hooks returns the client hooks. // Hooks returns the client hooks.
func (c *ChannelMonitorHistoryClient) Hooks() []Hook { func (c *ChannelMonitorHistoryClient) Hooks() []Hook {
return c.hooks.ChannelMonitorHistory hooks := c.hooks.ChannelMonitorHistory
return append(hooks[:len(hooks):len(hooks)], channelmonitorhistory.Hooks[:]...)
} }
// Interceptors returns the client interceptors. // Interceptors returns the client interceptors.
func (c *ChannelMonitorHistoryClient) Interceptors() []Interceptor { func (c *ChannelMonitorHistoryClient) Interceptors() []Interceptor {
return c.inters.ChannelMonitorHistory inters := c.inters.ChannelMonitorHistory
return append(inters[:len(inters):len(inters)], channelmonitorhistory.Interceptors[:]...)
} }
func (c *ChannelMonitorHistoryClient) mutate(ctx context.Context, m *ChannelMonitorHistoryMutation) (Value, error) { func (c *ChannelMonitorHistoryClient) mutate(ctx context.Context, m *ChannelMonitorHistoryMutation) (Value, error) {
...@@ -5671,23 +5848,23 @@ func (c *UserSubscriptionClient) mutate(ctx context.Context, m *UserSubscription ...@@ -5671,23 +5848,23 @@ func (c *UserSubscriptionClient) mutate(ctx context.Context, m *UserSubscription
type ( type (
hooks struct { hooks struct {
APIKey, Account, AccountGroup, Announcement, AnnouncementRead, AuthIdentity, APIKey, Account, AccountGroup, Announcement, AnnouncementRead, AuthIdentity,
AuthIdentityChannel, ChannelMonitor, ChannelMonitorHistory, AuthIdentityChannel, ChannelMonitor, ChannelMonitorDailyRollup,
ErrorPassthroughRule, Group, IdempotencyRecord, IdentityAdoptionDecision, ChannelMonitorHistory, ErrorPassthroughRule, Group, IdempotencyRecord,
PaymentAuditLog, PaymentOrder, PaymentProviderInstance, PendingAuthSession, IdentityAdoptionDecision, PaymentAuditLog, PaymentOrder,
PromoCode, PromoCodeUsage, Proxy, RedeemCode, SecuritySecret, Setting, PaymentProviderInstance, PendingAuthSession, PromoCode, PromoCodeUsage, Proxy,
SubscriptionPlan, TLSFingerprintProfile, UsageCleanupTask, UsageLog, User, RedeemCode, SecuritySecret, Setting, SubscriptionPlan, TLSFingerprintProfile,
UserAllowedGroup, UserAttributeDefinition, UserAttributeValue, UsageCleanupTask, UsageLog, User, UserAllowedGroup, UserAttributeDefinition,
UserSubscription []ent.Hook UserAttributeValue, UserSubscription []ent.Hook
} }
inters struct { inters struct {
APIKey, Account, AccountGroup, Announcement, AnnouncementRead, AuthIdentity, APIKey, Account, AccountGroup, Announcement, AnnouncementRead, AuthIdentity,
AuthIdentityChannel, ChannelMonitor, ChannelMonitorHistory, AuthIdentityChannel, ChannelMonitor, ChannelMonitorDailyRollup,
ErrorPassthroughRule, Group, IdempotencyRecord, IdentityAdoptionDecision, ChannelMonitorHistory, ErrorPassthroughRule, Group, IdempotencyRecord,
PaymentAuditLog, PaymentOrder, PaymentProviderInstance, PendingAuthSession, IdentityAdoptionDecision, PaymentAuditLog, PaymentOrder,
PromoCode, PromoCodeUsage, Proxy, RedeemCode, SecuritySecret, Setting, PaymentProviderInstance, PendingAuthSession, PromoCode, PromoCodeUsage, Proxy,
SubscriptionPlan, TLSFingerprintProfile, UsageCleanupTask, UsageLog, User, RedeemCode, SecuritySecret, Setting, SubscriptionPlan, TLSFingerprintProfile,
UserAllowedGroup, UserAttributeDefinition, UserAttributeValue, UsageCleanupTask, UsageLog, User, UserAllowedGroup, UserAttributeDefinition,
UserSubscription []ent.Interceptor UserAttributeValue, UserSubscription []ent.Interceptor
} }
) )
......
...@@ -20,6 +20,7 @@ import ( ...@@ -20,6 +20,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/authidentity" "github.com/Wei-Shaw/sub2api/ent/authidentity"
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel" "github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
"github.com/Wei-Shaw/sub2api/ent/channelmonitor" "github.com/Wei-Shaw/sub2api/ent/channelmonitor"
"github.com/Wei-Shaw/sub2api/ent/channelmonitordailyrollup"
"github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory" "github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory"
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule" "github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
"github.com/Wei-Shaw/sub2api/ent/group" "github.com/Wei-Shaw/sub2api/ent/group"
...@@ -112,6 +113,7 @@ func checkColumn(t, c string) error { ...@@ -112,6 +113,7 @@ func checkColumn(t, c string) error {
authidentity.Table: authidentity.ValidColumn, authidentity.Table: authidentity.ValidColumn,
authidentitychannel.Table: authidentitychannel.ValidColumn, authidentitychannel.Table: authidentitychannel.ValidColumn,
channelmonitor.Table: channelmonitor.ValidColumn, channelmonitor.Table: channelmonitor.ValidColumn,
channelmonitordailyrollup.Table: channelmonitordailyrollup.ValidColumn,
channelmonitorhistory.Table: channelmonitorhistory.ValidColumn, channelmonitorhistory.Table: channelmonitorhistory.ValidColumn,
errorpassthroughrule.Table: errorpassthroughrule.ValidColumn, errorpassthroughrule.Table: errorpassthroughrule.ValidColumn,
group.Table: group.ValidColumn, group.Table: group.ValidColumn,
......
...@@ -105,6 +105,18 @@ func (f ChannelMonitorFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Val ...@@ -105,6 +105,18 @@ func (f ChannelMonitorFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Val
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ChannelMonitorMutation", m) return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ChannelMonitorMutation", m)
} }
// The ChannelMonitorDailyRollupFunc type is an adapter to allow the use of ordinary
// function as ChannelMonitorDailyRollup mutator.
type ChannelMonitorDailyRollupFunc func(context.Context, *ent.ChannelMonitorDailyRollupMutation) (ent.Value, error)
// Mutate calls f(ctx, m).
func (f ChannelMonitorDailyRollupFunc) Mutate(ctx context.Context, m ent.Mutation) (ent.Value, error) {
if mv, ok := m.(*ent.ChannelMonitorDailyRollupMutation); ok {
return f(ctx, mv)
}
return nil, fmt.Errorf("unexpected mutation type %T. expect *ent.ChannelMonitorDailyRollupMutation", m)
}
// The ChannelMonitorHistoryFunc type is an adapter to allow the use of ordinary // The ChannelMonitorHistoryFunc type is an adapter to allow the use of ordinary
// function as ChannelMonitorHistory mutator. // function as ChannelMonitorHistory mutator.
type ChannelMonitorHistoryFunc func(context.Context, *ent.ChannelMonitorHistoryMutation) (ent.Value, error) type ChannelMonitorHistoryFunc func(context.Context, *ent.ChannelMonitorHistoryMutation) (ent.Value, error)
......
...@@ -16,6 +16,7 @@ import ( ...@@ -16,6 +16,7 @@ import (
"github.com/Wei-Shaw/sub2api/ent/authidentity" "github.com/Wei-Shaw/sub2api/ent/authidentity"
"github.com/Wei-Shaw/sub2api/ent/authidentitychannel" "github.com/Wei-Shaw/sub2api/ent/authidentitychannel"
"github.com/Wei-Shaw/sub2api/ent/channelmonitor" "github.com/Wei-Shaw/sub2api/ent/channelmonitor"
"github.com/Wei-Shaw/sub2api/ent/channelmonitordailyrollup"
"github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory" "github.com/Wei-Shaw/sub2api/ent/channelmonitorhistory"
"github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule" "github.com/Wei-Shaw/sub2api/ent/errorpassthroughrule"
"github.com/Wei-Shaw/sub2api/ent/group" "github.com/Wei-Shaw/sub2api/ent/group"
...@@ -315,6 +316,33 @@ func (f TraverseChannelMonitor) Traverse(ctx context.Context, q ent.Query) error ...@@ -315,6 +316,33 @@ func (f TraverseChannelMonitor) Traverse(ctx context.Context, q ent.Query) error
return fmt.Errorf("unexpected query type %T. expect *ent.ChannelMonitorQuery", q) return fmt.Errorf("unexpected query type %T. expect *ent.ChannelMonitorQuery", q)
} }
// The ChannelMonitorDailyRollupFunc type is an adapter to allow the use of ordinary function as a Querier.
type ChannelMonitorDailyRollupFunc func(context.Context, *ent.ChannelMonitorDailyRollupQuery) (ent.Value, error)
// Query calls f(ctx, q).
func (f ChannelMonitorDailyRollupFunc) Query(ctx context.Context, q ent.Query) (ent.Value, error) {
if q, ok := q.(*ent.ChannelMonitorDailyRollupQuery); ok {
return f(ctx, q)
}
return nil, fmt.Errorf("unexpected query type %T. expect *ent.ChannelMonitorDailyRollupQuery", q)
}
// The TraverseChannelMonitorDailyRollup type is an adapter to allow the use of ordinary function as Traverser.
type TraverseChannelMonitorDailyRollup func(context.Context, *ent.ChannelMonitorDailyRollupQuery) error
// Intercept is a dummy implementation of Intercept that returns the next Querier in the pipeline.
func (f TraverseChannelMonitorDailyRollup) Intercept(next ent.Querier) ent.Querier {
return next
}
// Traverse calls f(ctx, q).
func (f TraverseChannelMonitorDailyRollup) Traverse(ctx context.Context, q ent.Query) error {
if q, ok := q.(*ent.ChannelMonitorDailyRollupQuery); ok {
return f(ctx, q)
}
return fmt.Errorf("unexpected query type %T. expect *ent.ChannelMonitorDailyRollupQuery", q)
}
// The ChannelMonitorHistoryFunc type is an adapter to allow the use of ordinary function as a Querier. // The ChannelMonitorHistoryFunc type is an adapter to allow the use of ordinary function as a Querier.
type ChannelMonitorHistoryFunc func(context.Context, *ent.ChannelMonitorHistoryQuery) (ent.Value, error) type ChannelMonitorHistoryFunc func(context.Context, *ent.ChannelMonitorHistoryQuery) (ent.Value, error)
...@@ -982,6 +1010,8 @@ func NewQuery(q ent.Query) (Query, error) { ...@@ -982,6 +1010,8 @@ func NewQuery(q ent.Query) (Query, error) {
return &query[*ent.AuthIdentityChannelQuery, predicate.AuthIdentityChannel, authidentitychannel.OrderOption]{typ: ent.TypeAuthIdentityChannel, tq: q}, nil return &query[*ent.AuthIdentityChannelQuery, predicate.AuthIdentityChannel, authidentitychannel.OrderOption]{typ: ent.TypeAuthIdentityChannel, tq: q}, nil
case *ent.ChannelMonitorQuery: case *ent.ChannelMonitorQuery:
return &query[*ent.ChannelMonitorQuery, predicate.ChannelMonitor, channelmonitor.OrderOption]{typ: ent.TypeChannelMonitor, tq: q}, nil return &query[*ent.ChannelMonitorQuery, predicate.ChannelMonitor, channelmonitor.OrderOption]{typ: ent.TypeChannelMonitor, tq: q}, nil
case *ent.ChannelMonitorDailyRollupQuery:
return &query[*ent.ChannelMonitorDailyRollupQuery, predicate.ChannelMonitorDailyRollup, channelmonitordailyrollup.OrderOption]{typ: ent.TypeChannelMonitorDailyRollup, tq: q}, nil
case *ent.ChannelMonitorHistoryQuery: case *ent.ChannelMonitorHistoryQuery:
return &query[*ent.ChannelMonitorHistoryQuery, predicate.ChannelMonitorHistory, channelmonitorhistory.OrderOption]{typ: ent.TypeChannelMonitorHistory, tq: q}, nil return &query[*ent.ChannelMonitorHistoryQuery, predicate.ChannelMonitorHistory, channelmonitorhistory.OrderOption]{typ: ent.TypeChannelMonitorHistory, tq: q}, nil
case *ent.ErrorPassthroughRuleQuery: case *ent.ErrorPassthroughRuleQuery:
......
This diff is collapsed.
This diff is collapsed.
...@@ -30,6 +30,9 @@ type AuthIdentityChannel func(*sql.Selector) ...@@ -30,6 +30,9 @@ type AuthIdentityChannel func(*sql.Selector)
// ChannelMonitor is the predicate function for channelmonitor builders. // ChannelMonitor is the predicate function for channelmonitor builders.
type ChannelMonitor func(*sql.Selector) type ChannelMonitor func(*sql.Selector)
// ChannelMonitorDailyRollup is the predicate function for channelmonitordailyrollup builders.
type ChannelMonitorDailyRollup func(*sql.Selector)
// ChannelMonitorHistory is the predicate function for channelmonitorhistory builders. // ChannelMonitorHistory is the predicate function for channelmonitorhistory builders.
type ChannelMonitorHistory func(*sql.Selector) type ChannelMonitorHistory func(*sql.Selector)
......
This diff is collapsed.
...@@ -69,6 +69,8 @@ func (ChannelMonitor) Edges() []ent.Edge { ...@@ -69,6 +69,8 @@ func (ChannelMonitor) Edges() []ent.Edge {
return []ent.Edge{ return []ent.Edge{
edge.To("history", ChannelMonitorHistory.Type). edge.To("history", ChannelMonitorHistory.Type).
Annotations(entsql.OnDelete(entsql.Cascade)), Annotations(entsql.OnDelete(entsql.Cascade)),
edge.To("daily_rollups", ChannelMonitorDailyRollup.Type).
Annotations(entsql.OnDelete(entsql.Cascade)),
} }
} }
......
This diff is collapsed.
...@@ -9,10 +9,13 @@ import ( ...@@ -9,10 +9,13 @@ import (
"entgo.io/ent/schema/edge" "entgo.io/ent/schema/edge"
"entgo.io/ent/schema/field" "entgo.io/ent/schema/field"
"entgo.io/ent/schema/index" "entgo.io/ent/schema/index"
"github.com/Wei-Shaw/sub2api/ent/schema/mixins"
) )
// ChannelMonitorHistory holds the schema definition for the ChannelMonitorHistory entity. // ChannelMonitorHistory holds the schema definition for the ChannelMonitorHistory entity.
// 渠道监控历史:每次检测每个模型一行记录,由调度器写入,定期清理 30 天前的旧数据。 // 渠道监控历史:每次检测每个模型一行记录。明细只保留 1 天,超过 1 天的数据被聚合到
// channel_monitor_daily_rollups 后软删(deleted_at),由后续懒清理任务物理移除。
type ChannelMonitorHistory struct { type ChannelMonitorHistory struct {
ent.Schema ent.Schema
} }
...@@ -23,6 +26,12 @@ func (ChannelMonitorHistory) Annotations() []schema.Annotation { ...@@ -23,6 +26,12 @@ func (ChannelMonitorHistory) Annotations() []schema.Annotation {
} }
} }
func (ChannelMonitorHistory) Mixin() []ent.Mixin {
return []ent.Mixin{
mixins.SoftDeleteMixin{},
}
}
func (ChannelMonitorHistory) Fields() []ent.Field { func (ChannelMonitorHistory) Fields() []ent.Field {
return []ent.Field{ return []ent.Field{
field.Int64("monitor_id"), field.Int64("monitor_id"),
......
...@@ -30,6 +30,8 @@ type Tx struct { ...@@ -30,6 +30,8 @@ type Tx struct {
AuthIdentityChannel *AuthIdentityChannelClient AuthIdentityChannel *AuthIdentityChannelClient
// ChannelMonitor is the client for interacting with the ChannelMonitor builders. // ChannelMonitor is the client for interacting with the ChannelMonitor builders.
ChannelMonitor *ChannelMonitorClient ChannelMonitor *ChannelMonitorClient
// ChannelMonitorDailyRollup is the client for interacting with the ChannelMonitorDailyRollup builders.
ChannelMonitorDailyRollup *ChannelMonitorDailyRollupClient
// ChannelMonitorHistory is the client for interacting with the ChannelMonitorHistory builders. // ChannelMonitorHistory is the client for interacting with the ChannelMonitorHistory builders.
ChannelMonitorHistory *ChannelMonitorHistoryClient ChannelMonitorHistory *ChannelMonitorHistoryClient
// ErrorPassthroughRule is the client for interacting with the ErrorPassthroughRule builders. // ErrorPassthroughRule is the client for interacting with the ErrorPassthroughRule builders.
...@@ -217,6 +219,7 @@ func (tx *Tx) init() { ...@@ -217,6 +219,7 @@ func (tx *Tx) init() {
tx.AuthIdentity = NewAuthIdentityClient(tx.config) tx.AuthIdentity = NewAuthIdentityClient(tx.config)
tx.AuthIdentityChannel = NewAuthIdentityChannelClient(tx.config) tx.AuthIdentityChannel = NewAuthIdentityChannelClient(tx.config)
tx.ChannelMonitor = NewChannelMonitorClient(tx.config) tx.ChannelMonitor = NewChannelMonitorClient(tx.config)
tx.ChannelMonitorDailyRollup = NewChannelMonitorDailyRollupClient(tx.config)
tx.ChannelMonitorHistory = NewChannelMonitorHistoryClient(tx.config) tx.ChannelMonitorHistory = NewChannelMonitorHistoryClient(tx.config)
tx.ErrorPassthroughRule = NewErrorPassthroughRuleClient(tx.config) tx.ErrorPassthroughRule = NewErrorPassthroughRuleClient(tx.config)
tx.Group = NewGroupClient(tx.config) tx.Group = NewGroupClient(tx.config)
......
This diff is collapsed.
This diff is collapsed.
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment