Documentation
¶
Index ¶
- type ChannelDailyRequest
- type ChannelDailyResponse
- type GetRebuildJobRequest
- type Handler
- func (h *Handler) ChannelDaily(c *app.Context, req ChannelDailyRequest) (ChannelDailyResponse, error)
- func (h *Handler) GetRebuildJob(c *app.Context, req GetRebuildJobRequest) (RebuildJobView, error)
- func (h *Handler) Insights(c *app.Context, req InsightsRequest) (InsightsResponse, error)
- func (h *Handler) ListChannels(c *app.Context, req ListChannelsRequest) (api.PaginatedResponse[dao.ChannelBillingListItem], error)
- func (h *Handler) ListRebuildJobs(c *app.Context, _ api.EmptyRequest) (ListRebuildJobsResponse, error)
- func (h *Handler) ListTokens(c *app.Context, req ListTokensRequest) (api.PaginatedResponse[dao.TokenBillingListItem], error)
- func (h *Handler) Overview(c *app.Context, req OverviewRequest) (*dao.BillingOverview, error)
- func (h *Handler) Rebuild(c *app.Context, req RebuildRequest) (RebuildResponse, error)
- func (h *Handler) TokenDaily(c *app.Context, req TokenDailyRequest) (TokenDailyResponse, error)
- type InsightsRequest
- type InsightsResponse
- type ListChannelsRequest
- type ListRebuildJobsResponse
- type ListTokensRequest
- type OverviewRequest
- type RebuildJobView
- type RebuildRequest
- type RebuildResponse
- type TokenDailyRequest
- type TokenDailyResponse
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChannelDailyRequest ¶
type ChannelDailyResponse ¶
type ChannelDailyResponse struct {
Items []dao.ChannelBillingDailyItem `json:"items"`
}
type GetRebuildJobRequest ¶ added in v0.0.2
type GetRebuildJobRequest struct {
ID string `uri:"id" binding:"required"`
}
GetRebuildJobRequest is the URI-bound shape for GET /billing/rebuild/jobs/:id.
type Handler ¶
type Handler struct {
Runner *billing.RebuildRunner
Cache *dao.StatsCache
}
Handler bundles HTTP handlers for /admin/billing/*. Runner is the async rebuild scheduler; injected by master/server.go (T3.8). Nil-safe — when nil, async rebuild endpoints return InternalError.
func (*Handler) ChannelDaily ¶
func (h *Handler) ChannelDaily(c *app.Context, req ChannelDailyRequest) (ChannelDailyResponse, error)
func (*Handler) GetRebuildJob ¶ added in v0.0.2
func (h *Handler) GetRebuildJob(c *app.Context, req GetRebuildJobRequest) (RebuildJobView, error)
GetRebuildJob returns the current state of the named rebuild job. 404 if unknown (never submitted, gc'd after retain expiry, or lost to master restart — clients should retrigger).
func (*Handler) Insights ¶ added in v0.0.2
func (h *Handler) Insights(c *app.Context, req InsightsRequest) (InsightsResponse, error)
Insights 返回 billing 维度的两块洞察:
- cost_trend_stacked: 时间桶 × model_name 堆叠成本 (Phase 1 仅 stack=model);
- cache_saving: 缓存命中带来的 tokens / cost 节省概览。
stack 参数当前仅 model 生效; user/channel 等其它值会被静默回退为 model (Phase 1 是 admin 观测面板,等用户需要再开)。
窗口超过 ObsRange.Validate() 上限时返回 400 RangeOutOfBounds。
func (*Handler) ListChannels ¶
func (h *Handler) ListChannels(c *app.Context, req ListChannelsRequest) (api.PaginatedResponse[dao.ChannelBillingListItem], error)
func (*Handler) ListRebuildJobs ¶ added in v0.0.2
func (h *Handler) ListRebuildJobs(c *app.Context, _ api.EmptyRequest) (ListRebuildJobsResponse, error)
ListRebuildJobs returns running + retained terminal jobs (in arbitrary order — the runner stores them in a map).
func (*Handler) ListTokens ¶
func (h *Handler) ListTokens(c *app.Context, req ListTokensRequest) (api.PaginatedResponse[dao.TokenBillingListItem], error)
func (*Handler) Overview ¶
func (h *Handler) Overview(c *app.Context, req OverviewRequest) (*dao.BillingOverview, error)
func (*Handler) Rebuild ¶
func (h *Handler) Rebuild(c *app.Context, req RebuildRequest) (RebuildResponse, error)
Rebuild submits an async rebuild job after Runner.Submit fixes the actual request-log date list and progress denominator.
func (*Handler) TokenDaily ¶
func (h *Handler) TokenDaily(c *app.Context, req TokenDailyRequest) (TokenDailyResponse, error)
type InsightsRequest ¶ added in v0.0.2
type InsightsRequest struct {
Start int64 `form:"start"`
End int64 `form:"end"`
Gran string `form:"gran"`
Stack string `form:"stack"`
Model string `form:"model"`
UserID uint `form:"user_id"`
TokenID uint `form:"token_id"`
TopN int `form:"top_n"`
}
InsightsRequest 是 /v1/billing/insights 入参。 start/end 为 unix 秒, end 缺省 now, start 缺省 end-86400; gran 缺省 "day"; stack 缺省 "model" (Phase 1 仅支持 model, 其它值静默回退为 model)。
type InsightsResponse ¶ added in v0.0.2
type InsightsResponse struct {
Trend []dao.TimeBucket `json:"trend"`
CostTrendStacked dao.CostTrendStacked `json:"cost_trend_stacked"`
CacheSaving dao.CacheSaving `json:"cache_saving"`
}
InsightsResponse 是 /v1/billing/insights 返回。 Trend 是 cost/requests/tokens 的统一时间序列(tokens 含 cache, 且带 4 个 token 分量), 供前端 MetricTrendChart 切指标 + 按 token 类型拆;CostTrendStacked 是成本按 model 堆叠; CacheSaving 是缓存节省概览。
type ListChannelsRequest ¶
type ListRebuildJobsResponse ¶ added in v0.0.2
type ListRebuildJobsResponse struct {
Jobs []RebuildJobView `json:"jobs"`
}
ListRebuildJobsResponse holds all currently-tracked rebuild jobs.
type ListTokensRequest ¶
type OverviewRequest ¶
type RebuildJobView ¶ added in v0.0.2
type RebuildJobView struct {
ID string `json:"id"`
Status string `json:"status"`
DoneSlices int64 `json:"done_slices"`
TotalSlices int64 `json:"total_slices"`
ReplayedLogs int64 `json:"replayed_logs"`
StartedAt int64 `json:"started_at"`
FinishedAt int64 `json:"finished_at,omitempty"`
Error string `json:"error,omitempty"`
}
RebuildJobView is the wire shape for rebuild job GETs. Built from RebuildJob.Snapshot() so external reads are race-free.
type RebuildRequest ¶
type RebuildResponse ¶
type RebuildResponse struct {
JobID string `json:"job_id"`
TotalSlices int64 `json:"total_slices"`
}
RebuildResponse is the async submit ack. Clients should poll GET /admin/billing/rebuild/jobs/:id with the returned job_id for progress and final status.
type TokenDailyRequest ¶
type TokenDailyResponse ¶
type TokenDailyResponse struct {
Items []dao.TokenBillingDailyItem `json:"items"`
}