runtime

package
v1.13.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrPrometheusUnavailable = fmt.Errorf("prometheus unavailable")

ErrPrometheusUnavailable 表示 Prometheus 查询不可用。

View Source
var GlobalSubscriptionIndex = NewMemorySubscriptionIndex()

GlobalSubscriptionIndex 全进程默认订阅索引(多服务同进程共享)。

Functions

func ComponentGaugeQuery

func ComponentGaugeQuery(service string) (string, error)

ComponentGaugeQuery 查询服务组件 gauge。

func EventPublishRateQuery

func EventPublishRateQuery(window string) (string, error)

EventPublishRateQuery 事件发布速率。

func EventSubscriptionInfoQuery

func EventSubscriptionInfoQuery() string

EventSubscriptionInfoQuery 跨进程订阅事实。

func IsPrometheusMode

func IsPrometheusMode(mode string) bool

IsPrometheusMode 判断是否启用 Prometheus 查询。

func NormalizeMode

func NormalizeMode(mode string) string

NormalizeMode 将 RuntimeObservability.Mode 规范为 off|prometheus。

func NormalizeSubjectFamily

func NormalizeSubjectFamily(subject string) string

NormalizeSubjectFamily 将 Subject 归一为有界 family。

func ParseWindow

func ParseWindow(window string) (time.Duration, bool)

ParseWindow 解析允许的时间窗口。

func ServiceCallEdgeRateQuery

func ServiceCallEdgeRateQuery(window string) (string, error)

ServiceCallEdgeRateQuery 生成调用边速率查询。

func ServiceCallP95Query

func ServiceCallP95Query(service, window string) (string, error)

ServiceCallP95Query 生成目标服务调用 p95。

func ServiceCoreRateByResultQuery

func ServiceCoreRateByResultQuery(service, window string) (string, error)

ServiceCoreRateByResultQuery Core 入站按 result_class。

func ServiceHTTPP50Query

func ServiceHTTPP50Query(service, window string) (string, error)

ServiceHTTPP50Query HTTP 延迟 p50。

func ServiceHTTPP95Query

func ServiceHTTPP95Query(service, window string) (string, error)

ServiceHTTPP95Query HTTP 延迟 p95。

func ServiceHTTPP99Query

func ServiceHTTPP99Query(service, window string) (string, error)

ServiceHTTPP99Query HTTP 延迟 p99。

func ServiceHTTPRateByCodeQuery

func ServiceHTTPRateByCodeQuery(service, window string) (string, error)

ServiceHTTPRateByCodeQuery 按 code 分组的 HTTP 速率,用于错误率。

func ServiceHTTPRouteRateQuery

func ServiceHTTPRouteRateQuery(service, window string) (string, error)

ServiceHTTPRouteRateQuery HTTP 路径模板速率。

func ServiceLastSampleTimestampQuery

func ServiceLastSampleTimestampQuery(service string) (string, error)

ServiceLastSampleTimestampQuery 返回服务请求序列的最后样本时间(Unix 秒)。 使用 timestamp() 读取底层 counter 的最后采集时间,而不是 instant 表达式评估时间。

func ServiceRequestRateQuery

func ServiceRequestRateQuery(service, window string) (string, error)

ServiceRequestRateQuery 生成服务请求率 PromQL(HTTP + Core 入站合计优先 HTTP)。

func ServiceRouteRateQuery

func ServiceRouteRateQuery(service, window string) (string, error)

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 Config

type Config struct {
	Mode                 string
	CacheTTL             time.Duration
	MaxConcurrentQueries int
}

Config Aggregator 配置。

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

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"
	StateUnavailable  MetricState = "unavailable"
	StateNoTraffic    MetricState = "no_traffic"
	StateNotCollected MetricState = "not_collected"
)

func Freshness

func Freshness(window string, now time.Time, last *time.Time) MetricState

Freshness 根据窗口与最后采样时间判定是否 stale。 阈值:max(2×window, 30s)。

func MapQueryState

func MapQueryState(in QueryInput) MetricState

MapQueryState 将配置模式与查询错误映射为 MetricState。

func MergeStates

func MergeStates(states ...MetricState) MetricState

MergeStates 合并多个状态,取最差。

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。

func (*PromClient) Query

func (c *PromClient) Query(ctx context.Context, query string, ts time.Time) (Vector, error)

Query 执行 instant query。

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 QueryInput

type QueryInput struct {
	Mode string
	Err  error
}

QueryInput 描述一次指标查询的模式与错误。

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 Sample

type Sample struct {
	Timestamp time.Time
	Value     float64
	Metric    map[string]string
}

Sample 是一个时间点样本,可携带 Prometheus 指标标签。

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"`
	UnavailableInstances int         `json:"unavailable_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 全局拓扑响应。

type Vector

type Vector []Sample

Vector 是 instant query 结果。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL