MCPcopy
hub / github.com/BenedictKing/ccx / PersistenceStore

Interface PersistenceStore

backend-go/internal/metrics/persistence.go:8–44  ·  view source on GitHub ↗

PersistenceStore 持久化存储接口

Source from the content-addressed store, hash-verified

6
7// PersistenceStore 持久化存储接口
8type 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 的最后成功/失败时间
47type KeyLatestTimestamps struct {

Callers 24

recordFailureLockedMethod · 0.65
loadFromStoreMethod · 0.65
loadFromStoreMethod · 0.65
GetGlobalStatsHistoryFunction · 0.65
filterBucketsByURLsFunction · 0.65
GetGlobalStatsHistoryFunction · 0.65
filterModelBucketsByURLsFunction · 0.65
DeleteChannelMetricsMethod · 0.65

Implementers 2

SQLiteStorebackend-go/internal/metrics/sqlite_sto
fakePersistenceStorebackend-go/internal/handlers/channel_m

Calls

no outgoing calls

Tested by

no test coverage detected