Documentation
¶
Index ¶
- Variables
- func ComponentGaugeQuery(service string) (string, error)
- func EventPublishRateQuery(window string) (string, error)
- func EventSubscriptionInfoQuery() string
- func IsPrometheusMode(mode string) bool
- func NormalizeMode(mode string) string
- func NormalizeSubjectFamily(subject string) string
- func ParseWindow(window string) (time.Duration, bool)
- func ServiceCallEdgeRateQuery(window string) (string, error)
- func ServiceCallP95Query(service, window string) (string, error)
- func ServiceCoreRateByResultQuery(service, window string) (string, error)
- func ServiceHTTPP50Query(service, window string) (string, error)
- func ServiceHTTPP95Query(service, window string) (string, error)
- func ServiceHTTPP99Query(service, window string) (string, error)
- func ServiceHTTPRateByCodeQuery(service, window string) (string, error)
- func ServiceHTTPRouteRateQuery(service, window string) (string, error)
- func ServiceLastSampleTimestampQuery(service string) (string, error)
- func ServiceRequestRateQuery(service, window string) (string, error)
- func ServiceRouteRateQuery(service, window string) (string, error)
- type Aggregator
- func (a *Aggregator) KnownService(ctx context.Context, service string) bool
- func (a *Aggregator) ServiceDetail(ctx context.Context, window, service string) (*ServiceDetailResponse, error)
- func (a *Aggregator) SetSubscriptions(idx SubscriptionIndex)
- func (a *Aggregator) Topology(ctx context.Context, window string) (*TopologyResponse, error)
- type ClusterView
- type ComponentSnapshot
- type Config
- type InstanceMetrics
- type MemorySubscriptionIndex
- func (m *MemorySubscriptionIndex) List(context.Context) ([]SubscriptionEdge, error)
- func (m *MemorySubscriptionIndex) Register(targetService, subject, eventType string, reliable bool) func()
- func (m *MemorySubscriptionIndex) ResetForTest()
- func (m *MemorySubscriptionIndex) Unregister(targetService, subjectFamily, eventType string, reliable bool)
- type MetricState
- type MetricValue
- type PromClient
- type PromQuerier
- type ProviderClusterView
- type QueryInput
- type RouteMetrics
- type RuntimeWarning
- type Sample
- type ServiceDetailResponse
- type ServiceEdge
- type ServiceNode
- type SubscriptionEdge
- type SubscriptionIndex
- type TopologyResponse
- type Vector
Constants ¶
This section is empty.
Variables ¶
ErrPrometheusUnavailable 表示 Prometheus 查询不可用。
var GlobalSubscriptionIndex = NewMemorySubscriptionIndex()
GlobalSubscriptionIndex 全进程默认订阅索引(多服务同进程共享)。
Functions ¶
func ComponentGaugeQuery ¶
ComponentGaugeQuery 查询服务组件 gauge。
func EventPublishRateQuery ¶
EventPublishRateQuery 事件发布速率。
func EventSubscriptionInfoQuery ¶
func EventSubscriptionInfoQuery() string
EventSubscriptionInfoQuery 跨进程订阅事实。
func IsPrometheusMode ¶
IsPrometheusMode 判断是否启用 Prometheus 查询。
func NormalizeMode ¶
NormalizeMode 将 RuntimeObservability.Mode 规范为 off|prometheus。
func NormalizeSubjectFamily ¶
NormalizeSubjectFamily 将 Subject 归一为有界 family。
func ServiceCallEdgeRateQuery ¶
ServiceCallEdgeRateQuery 生成调用边速率查询。
func ServiceCallP95Query ¶
ServiceCallP95Query 生成目标服务调用 p95。
func ServiceCoreRateByResultQuery ¶
ServiceCoreRateByResultQuery Core 入站按 result_class。
func ServiceHTTPP50Query ¶
ServiceHTTPP50Query HTTP 延迟 p50。
func ServiceHTTPP95Query ¶
ServiceHTTPP95Query HTTP 延迟 p95。
func ServiceHTTPP99Query ¶
ServiceHTTPP99Query HTTP 延迟 p99。
func ServiceHTTPRateByCodeQuery ¶
ServiceHTTPRateByCodeQuery 按 code 分组的 HTTP 速率,用于错误率。
func ServiceHTTPRouteRateQuery ¶
ServiceHTTPRouteRateQuery HTTP 路径模板速率。
func ServiceLastSampleTimestampQuery ¶
ServiceLastSampleTimestampQuery 返回服务请求序列的最后样本时间(Unix 秒)。 使用 timestamp() 读取底层 counter 的最后采集时间,而不是 instant 表达式评估时间。
func ServiceRequestRateQuery ¶
ServiceRequestRateQuery 生成服务请求率 PromQL(HTTP + Core 入站合计优先 HTTP)。
func ServiceRouteRateQuery ¶
ServiceRouteRateQuery 生成服务内路由速率(Core gRPC 入站)。
Types ¶
type Aggregator ¶
type Aggregator struct {
// contains filtered or unexported fields
}
Aggregator 合并集群拓扑与 Prometheus 指标。
func NewAggregator ¶
func NewAggregator(cluster ClusterView, prom PromQuerier, cfg Config) *Aggregator
NewAggregator 创建聚合器。
func (*Aggregator) KnownService ¶
func (a *Aggregator) KnownService(ctx context.Context, service string) bool
KnownService 判断服务是否在集群视图中。
func (*Aggregator) ServiceDetail ¶
func (a *Aggregator) ServiceDetail(ctx context.Context, window, service string) (*ServiceDetailResponse, error)
ServiceDetail 构建服务详情。
func (*Aggregator) SetSubscriptions ¶
func (a *Aggregator) SetSubscriptions(idx SubscriptionIndex)
SetSubscriptions 设置异步边订阅索引。
func (*Aggregator) Topology ¶
func (a *Aggregator) Topology(ctx context.Context, window string) (*TopologyResponse, error)
Topology 构建全局拓扑。
type ClusterView ¶
type ClusterView interface {
List(ctx context.Context, serviceName string, statuses ...cluster.NodeStatus) ([]*cluster.NodeInfo, error)
ListServices(ctx context.Context) ([]string, error)
}
ClusterView 抽象集群拓扑读取。
type ComponentSnapshot ¶
type ComponentSnapshot struct {
Component string `json:"component"`
State MetricState `json:"state"`
Gauges map[string]*float64 `json:"gauges,omitempty"`
}
ComponentSnapshot 服务内部组件。
type InstanceMetrics ¶
type InstanceMetrics struct {
InstanceID string `json:"instance_id"`
Status string `json:"status"`
RequestRate MetricValue `json:"request_rate"`
P95Ms MetricValue `json:"p95_ms"`
State MetricState `json:"state"`
}
InstanceMetrics 实例分布。
type MemorySubscriptionIndex ¶
type MemorySubscriptionIndex struct {
// contains filtered or unexported fields
}
MemorySubscriptionIndex 进程内订阅注册表,并同步导出 Prometheus 指标供跨进程查询。
func NewMemorySubscriptionIndex ¶
func NewMemorySubscriptionIndex() *MemorySubscriptionIndex
NewMemorySubscriptionIndex 创建空索引。
func (*MemorySubscriptionIndex) List ¶
func (m *MemorySubscriptionIndex) List(context.Context) ([]SubscriptionEdge, error)
List 返回当前本进程订阅边。
func (*MemorySubscriptionIndex) Register ¶
func (m *MemorySubscriptionIndex) Register(targetService, subject, eventType string, reliable bool) func()
Register 登记一条已验证的业务订阅,返回幂等注销函数。
func (*MemorySubscriptionIndex) ResetForTest ¶
func (m *MemorySubscriptionIndex) ResetForTest()
ResetForTest 清空索引。
func (*MemorySubscriptionIndex) Unregister ¶
func (m *MemorySubscriptionIndex) Unregister(targetService, subjectFamily, eventType string, reliable bool)
Unregister 取消订阅;引用归零后删除本地边与 Prom 样本。
type MetricState ¶
type MetricState string
MetricState 统一指标状态。
const ( StateOK MetricState = "ok" StatePartial MetricState = "partial" StateStale MetricState = "stale" StateNoTraffic MetricState = "no_traffic" StateNotCollected MetricState = "not_collected" )
func MapQueryState ¶
func MapQueryState(in QueryInput) MetricState
MapQueryState 将配置模式与查询错误映射为 MetricState。
type MetricValue ¶
type MetricValue struct {
Value *float64 `json:"value"`
State MetricState `json:"state"`
LastSample *time.Time `json:"last_sample,omitempty"`
CoverageSec *float64 `json:"coverage_sec,omitempty"`
}
MetricValue 表示可空数值 + 状态。
func NullMetric ¶
func NullMetric(state MetricState) MetricValue
NullMetric 构造 null + state 的 MetricValue。
func ValueMetric ¶
func ValueMetric(v float64, state MetricState) MetricValue
ValueMetric 构造有值的 MetricValue。
type PromClient ¶
type PromClient struct {
// contains filtered or unexported fields
}
PromClient Prometheus HTTP API 客户端。
func NewPromClient ¶
func NewPromClient(baseURL string, timeout time.Duration) *PromClient
NewPromClient 创建客户端。baseURL 如 http://prometheus:9090。
type PromQuerier ¶
type PromQuerier interface {
Query(ctx context.Context, query string, ts time.Time) (Vector, error)
}
PromQuerier 可测试的 Prometheus 查询接口。
type ProviderClusterView ¶
type ProviderClusterView struct {
Provider cluster.ClusterRegistry
}
ProviderClusterView 将 ClusterProvider 适配为 Aggregator 所需视图。
func (ProviderClusterView) List ¶
func (v ProviderClusterView) List(ctx context.Context, serviceName string, statuses ...cluster.NodeStatus) ([]*cluster.NodeInfo, error)
List 委托 Provider.List。
func (ProviderClusterView) ListServices ¶
func (v ProviderClusterView) ListServices(ctx context.Context) ([]string, error)
ListServices 通过 List("", ) 收集唯一服务名。
type RouteMetrics ¶
type RouteMetrics struct {
Route string `json:"route"`
Method string `json:"method,omitempty"`
RequestRate MetricValue `json:"request_rate"`
ErrorRate MetricValue `json:"error_rate"`
P50Ms MetricValue `json:"p50_ms"`
P95Ms MetricValue `json:"p95_ms"`
P99Ms MetricValue `json:"p99_ms"`
State MetricState `json:"state"`
}
RouteMetrics 服务内路由指标。
type RuntimeWarning ¶
type RuntimeWarning struct {
Code string `json:"code"`
Message string `json:"message"`
Scope string `json:"scope,omitempty"`
}
RuntimeWarning 安全可展示的告警。
type ServiceDetailResponse ¶
type ServiceDetailResponse struct {
GeneratedAt time.Time `json:"generated_at"`
Window string `json:"window"`
Service ServiceNode `json:"service"`
Routes []RouteMetrics `json:"routes"`
Instances []InstanceMetrics `json:"instances"`
Components []ComponentSnapshot `json:"components"`
Warnings []RuntimeWarning `json:"warnings"`
}
ServiceDetailResponse 服务详情。
type ServiceEdge ¶
type ServiceEdge struct {
Source string `json:"source"`
Target string `json:"target"`
Kind string `json:"kind"` // sync|async
Protocol string `json:"protocol,omitempty"`
SubjectFamily string `json:"subject_family,omitempty"`
RequestRate MetricValue `json:"request_rate"`
ErrorRate MetricValue `json:"error_rate"`
P95Ms MetricValue `json:"p95_ms"`
State MetricState `json:"state"`
}
ServiceEdge 同步/异步调用边。
type ServiceNode ¶
type ServiceNode struct {
Service string `json:"service"`
RegisteredInstances int `json:"registered_instances"`
RunningInstances int `json:"running_instances"`
RequestRate MetricValue `json:"request_rate"`
ErrorRate MetricValue `json:"error_rate"`
P50Ms MetricValue `json:"p50_ms"`
P95Ms MetricValue `json:"p95_ms"`
P99Ms MetricValue `json:"p99_ms"`
State MetricState `json:"state"`
}
ServiceNode 全局图服务节点。
type SubscriptionEdge ¶
type SubscriptionEdge struct {
SourceSubjectFamily string
EventType string
TargetService string
Reliable bool
}
SubscriptionEdge 异步边元数据。
type SubscriptionIndex ¶
type SubscriptionIndex interface {
List(ctx context.Context) ([]SubscriptionEdge, error)
}
SubscriptionIndex 只读订阅索引。
type TopologyResponse ¶
type TopologyResponse struct {
GeneratedAt time.Time `json:"generated_at"`
Window string `json:"window"`
Status MetricState `json:"status"`
Services []ServiceNode `json:"services"`
Edges []ServiceEdge `json:"edges"`
Warnings []RuntimeWarning `json:"warnings"`
}
TopologyResponse 全局拓扑响应。