PersistenceStore 持久化存储接口
| 6 | |
| 7 | // PersistenceStore 持久化存储接口 |
| 8 | type PersistenceStore interface { |
| 9 | // AddRecord 添加记录到写入缓冲区(非阻塞) |
| 10 | AddRecord(record PersistentRecord) |
| 11 | |
| 12 | // LoadRecords 加载指定时间范围内的记录 |
| 13 | LoadRecords(since time.Time, apiType string) ([]PersistentRecord, error) |
| 14 | |
| 15 | // LoadLatestTimestamps 从全量历史记录中查询每个 key 的最后成功/失败时间 |
| 16 | // 用于启动时补全超出 24h 窗口的时间戳 |
| 17 | LoadLatestTimestamps(apiType string) (map[string]*KeyLatestTimestamps, error) |
| 18 | |
| 19 | // LoadCircuitStates 加载指定 API 类型的熔断状态 |
| 20 | LoadCircuitStates(apiType string) (map[string]*PersistentCircuitState, error) |
| 21 | |
| 22 | // UpsertCircuitState 写入或更新熔断状态 |
| 23 | UpsertCircuitState(state PersistentCircuitState) error |
| 24 | |
| 25 | // QueryAggregatedHistory 查询聚合历史数据(按时间桶分组) |
| 26 | // 用于 >24h 的长时间范围查询(1周/1月),内存中仅保留 24h |
| 27 | QueryAggregatedHistory(apiType string, since time.Time, intervalSeconds int64, metricsKey string, baseURL string) ([]AggregatedBucket, error) |
| 28 | |
| 29 | // QueryModelAggregatedHistory 查询按模型和时间桶分组的聚合历史数据。 |
| 30 | QueryModelAggregatedHistory(apiType string, since time.Time, intervalSeconds int64, metricsKey string, baseURL string) ([]ModelAggregatedBucket, error) |
| 31 | |
| 32 | // CleanupOldRecords 清理过期数据 |
| 33 | CleanupOldRecords(before time.Time) (int64, error) |
| 34 | |
| 35 | // DeleteRecordsByMetricsKeys 按 metrics_key 和 api_type 批量删除记录(用于删除渠道时清理数据) |
| 36 | // apiType: 接口类型(messages/responses/gemini),避免误删其他接口的数据 |
| 37 | DeleteRecordsByMetricsKeys(metricsKeys []string, apiType string) (int64, error) |
| 38 | |
| 39 | // DeleteCircuitStatesByMetricsKeys 按 metrics_key 和 api_type 批量删除熔断状态 |
| 40 | DeleteCircuitStatesByMetricsKeys(metricsKeys []string, apiType string) (int64, error) |
| 41 | |
| 42 | // Close 关闭存储(会先刷新缓冲区) |
| 43 | Close() error |
| 44 | } |
| 45 | |
| 46 | // KeyLatestTimestamps 每个 key 的最后成功/失败时间 |
| 47 | type KeyLatestTimestamps struct { |
no outgoing calls
no test coverage detected