Documentation
¶
Overview ¶
Package metric provides metric queries and subscription streams.
Resource inputs use the canonical resource/v2 Value without Struct conversion. ResourceData, Reference, or Route selects resource intent; opaque ResourceKey selectors and Params alone do not. Query automatically selects QueryResource for resource intent and never retries the legacy operation.
StreamMetrics accepts only nonresource frames. StreamResourceMetrics is an explicit mixed resource/nonresource lane: its wire-v2 opening handshake must succeed before a client publishes the stream. Every subsequent subscription and control frame uses wire version two. Resource references and access routes remain optional actual inputs, never synthesized from ordinary selectors.
QueryContext.Context and StreamContext.Context carry callback cancellation. Polling retains the complete resource input and Params for every query. StreamOutput.OperationError carries typed admission and transport failures; Error remains the native provider diagnostic field.
Index ¶
- Constants
- func RegisterMetricPluginServer(registrar grpc.ServiceRegistrar, server metricpb.MetricPluginServer)
- func RegisterPlugin(p *sdk.Plugin, opts PluginOpts) error
- func ValidFiniteUnit(unit string) bool
- func ValidateMetricDefinitionContract(d MetricDefinition) error
- func ValidateMetricDiscovery(r MetricDiscoveryRequest) error
- func ValidateMetricOwnerCatalog(c *MetricOwnerCatalog) error
- func ValidateMetricQueryContext(c MetricQueryContext) error
- func ValidateResourceMetricsCatalog(c *ResourceMetricsCatalog) error
- func ValidateResourceMetricsCatalogRequest(r ResourceMetricsCatalogRequest) error
- func ValidateResourceMetricsQuery(q ResourceMetricsQuery) error
- func ValidateResourceMetricsResponse(q ResourceMetricsQuery, r *ResourceMetricsResponse) error
- func ValidateStreamInput(input StreamInput) error
- type AggregateValue
- type ColorRange
- type CurrentValue
- type DataPoint
- type FiniteMetricDescriptor
- type FiniteQueryProvider
- type GetMetricOwnerCatalogFunc
- type Handler
- type Manager
- func (m *Manager) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)
- func (m *Manager) GetMetricOwnerCatalog(pc *types.PluginContext) (*MetricOwnerCatalog, error)
- func (m *Manager) GetResourceMetricsCatalog(pc *types.PluginContext, request ResourceMetricsCatalogRequest) (*ResourceMetricsCatalog, error)
- func (m *Manager) GetSupportedResources(_ *types.PluginContext) (*ProviderInfo, []Handler)
- func (m *Manager) Query(ctx *types.PluginContext, req QueryRequest) (*QueryResponse, error)
- func (m *Manager) QueryResource(ctx *types.PluginContext, req QueryRequest) (*QueryResponse, error)
- func (m *Manager) QueryResources(pc *types.PluginContext, q ResourceMetricsQuery) (*ResourceMetricsResponse, error)
- func (m *Manager) StreamMetrics(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
- func (m *Manager) StreamResourceMetrics(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
- type MetricBinding
- type MetricDataSource
- type MetricDefinition
- type MetricDefinitionOverride
- type MetricDescriptor
- type MetricDiscoveryProvider
- type MetricDiscoveryRequest
- type MetricDiscoveryResult
- type MetricFieldBinding
- type MetricFieldTransform
- type MetricOwnerCatalog
- type MetricOwnerCatalogProvider
- type MetricQueryContext
- type MetricResult
- type MetricScopeField
- type MetricShape
- type MetricSourceDefaults
- type MetricSourceRef
- type MetricStreamCommand
- type MetricUnit
- type MetricValidationIssue
- type MetricValidationResult
- type MetricViewSourceSelection
- type Plugin
- type PluginClient
- func (c *PluginClient) GetMetricOwnerCapabilities(ctx context.Context) (bool, error)
- func (c *PluginClient) GetMetricOwnerCatalog(pc *types.PluginContext) (*MetricOwnerCatalog, error)
- func (c *PluginClient) GetResourceMetricsCatalog(pc *types.PluginContext, request ResourceMetricsCatalogRequest) (*ResourceMetricsCatalog, error)
- func (c *PluginClient) GetSupportedResources(ctx *types.PluginContext) (*ProviderInfo, []Handler)
- func (c *PluginClient) Query(ctx *types.PluginContext, r QueryRequest) (*QueryResponse, error)
- func (c *PluginClient) QueryResource(ctx *types.PluginContext, r QueryRequest) (*QueryResponse, error)
- func (c *PluginClient) QueryResources(pc *types.PluginContext, q ResourceMetricsQuery) (*ResourceMetricsResponse, error)
- func (c *PluginClient) StreamMetrics(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
- func (c *PluginClient) StreamResourceMetrics(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
- type PluginOpts
- type PluginServer
- func (s *PluginServer) GetFiniteCapabilities(_ context.Context, _ *emptypb.Empty) (*metricpb.FiniteMetricCapabilities, error)
- func (s *PluginServer) GetMetricOwnerCatalog(ctx context.Context, _ *emptypb.Empty) (*metricpb.MetricOwnerCatalog, error)
- func (s *PluginServer) GetResourceMetricsCatalog(ctx context.Context, p *metricpb.ResourceMetricsCatalogRequest) (*metricpb.ResourceMetricsCatalog, error)
- func (s *PluginServer) GetSupportedResources(ctx context.Context, _ *emptypb.Empty) (*metricpb.GetSupportedMetricResourcesResponse, error)
- func (s *PluginServer) Query(ctx context.Context, p *metricpb.QueryMetricsRequest) (*metricpb.QueryMetricsResponse, error)
- func (s *PluginServer) QueryResource(ctx context.Context, p *metricpb.QueryMetricsRequest) (*metricpb.ResourceQueryMetricsResponse, error)
- func (s *PluginServer) QueryResources(ctx context.Context, p *metricpb.ResourceMetricsQuery) (*metricpb.ResourceMetricsResponse, error)
- func (s *PluginServer) StreamMetrics(stream metricpb.MetricPlugin_StreamMetricsServer) error
- func (s *PluginServer) StreamResourceMetrics(stream metricpb.MetricPlugin_StreamResourceMetricsServer) error
- type Provider
- type ProviderConfiguration
- type ProviderConnection
- type ProviderConnectionInput
- type ProviderInfo
- type QueryContext
- type QueryFunc
- type QueryRequest
- type QueryResourcesFunc
- type QueryResponse
- type ResourceMetricPoint
- type ResourceMetricResult
- type ResourceMetricTarget
- type ResourceMetricsCatalog
- type ResourceMetricsCatalogFunc
- type ResourceMetricsCatalogRequest
- type ResourceMetricsQuery
- type ResourceMetricsResponse
- type ResourceQueryProvider
- type ResourceStreamProvider
- type StreamContext
- type StreamFunc
- type StreamInput
- type StreamOutput
- type TimeSeries
Constants ¶
const ( MaxFiniteTargets = 256 MaxFiniteMetrics = 32 MaxFinitePoints = 10000 MaxFiniteRange = 31 * 24 * time.Hour )
Finite protocol bounds apply before dispatch and again before publication.
const ResourceWireVersion uint32 = 2
ResourceWireVersion identifies the lossless resource-aware metric protocol.
Variables ¶
This section is empty.
Functions ¶
func RegisterMetricPluginServer ¶ added in v0.9.0
func RegisterMetricPluginServer(registrar grpc.ServiceRegistrar, server metricpb.MetricPluginServer)
RegisterMetricPluginServer admits resource frames before generated protobuf decode.
func RegisterPlugin ¶
func RegisterPlugin( p *sdk.Plugin, opts PluginOpts, ) error
RegisterPlugin registers the metric capability with the plugin system.
func ValidFiniteUnit ¶ added in v0.16.0
ValidFiniteUnit accepts physical base units without inferring conversions.
func ValidateMetricDefinitionContract ¶ added in v0.16.0
func ValidateMetricDefinitionContract(d MetricDefinition) error
ValidateMetricDefinitionContract checks portable finite semantics, not a query language. A range-reuse declaration must name the range shape. Source providers additionally validate compilation and exact identity attribution.
func ValidateMetricDiscovery ¶ added in v0.16.0
func ValidateMetricDiscovery(r MetricDiscoveryRequest) error
func ValidateMetricOwnerCatalog ¶ added in v0.16.0
func ValidateMetricOwnerCatalog(c *MetricOwnerCatalog) error
ValidateMetricOwnerCatalog bounds owner metadata independently of source execution.
func ValidateMetricQueryContext ¶ added in v0.16.0
func ValidateMetricQueryContext(c MetricQueryContext) error
ValidateMetricQueryContext bounds host-provided mapping material before execution.
func ValidateResourceMetricsCatalog ¶ added in v0.16.0
func ValidateResourceMetricsCatalog(c *ResourceMetricsCatalog) error
ValidateResourceMetricsCatalog rejects unknown units/shapes, duplicate IDs and reuse declarations without their required shapes.
func ValidateResourceMetricsCatalogRequest ¶ added in v0.16.0
func ValidateResourceMetricsCatalogRequest(r ResourceMetricsCatalogRequest) error
ValidateResourceMetricsCatalogRequest validates exact source selection before I/O.
func ValidateResourceMetricsQuery ¶ added in v0.16.0
func ValidateResourceMetricsQuery(q ResourceMetricsQuery) error
ValidateResourceMetricsQuery checks finite domains, duplicate tokens and bounds. Dispatch additionally checks authority against the configured connection registry.
func ValidateResourceMetricsResponse ¶ added in v0.16.0
func ValidateResourceMetricsResponse(q ResourceMetricsQuery, r *ResourceMetricsResponse) error
ValidateResourceMetricsResponse rejects unknown/duplicate pairs and invalid data. Incomplete responses may omit pairs; they cannot claim Complete when pairs lack.
func ValidateStreamInput ¶ added in v0.9.0
func ValidateStreamInput(input StreamInput) error
ValidateStreamInput checks a frame before a host enqueues it on a shared stream.
Types ¶
type AggregateValue ¶
type AggregateValue struct {
MetricID string `json:"metric_id"`
Min float64 `json:"min"`
Max float64 `json:"max"`
Avg float64 `json:"avg"`
Sum float64 `json:"sum"`
P50 float64 `json:"p50"`
P90 float64 `json:"p90"`
P99 float64 `json:"p99"`
Count int64 `json:"count"`
Window time.Duration `json:"window"`
Labels map[string]string `json:"labels"`
}
AggregateValue represents aggregated metric data over a window.
func AggregateValueFromProto ¶
func AggregateValueFromProto(p *metricpb.AggregateValue) AggregateValue
AggregateValueFromProto shares labels and uses zero duration for a missing window.
func (*AggregateValue) ToProto ¶
func (a *AggregateValue) ToProto() *metricpb.AggregateValue
ToProto encodes the statistical window and shares the labels map.
type ColorRange ¶
type ColorRange struct {
Min float64 `json:"min"`
Max float64 `json:"max"`
Color string `json:"color"`
}
ColorRange defines a color to use for a range of metric values.
func ColorRangeFromProto ¶
func ColorRangeFromProto(p *metricpb.MetricColorRange) ColorRange
ColorRangeFromProto returns a zero range for nil input.
func (*ColorRange) ToProto ¶
func (c *ColorRange) ToProto() *metricpb.MetricColorRange
ToProto copies the range into a new wire message.
type CurrentValue ¶
type CurrentValue struct {
MetricID string `json:"metric_id"`
Value float64 `json:"value"`
Timestamp time.Time `json:"timestamp"`
Labels map[string]string `json:"labels"`
}
CurrentValue represents the current value of a metric.
func CurrentValueFromProto ¶
func CurrentValueFromProto(p *metricpb.CurrentValue) CurrentValue
CurrentValueFromProto shares labels and uses zero time for a missing timestamp.
func (*CurrentValue) ToProto ¶
func (c *CurrentValue) ToProto() *metricpb.CurrentValue
ToProto encodes the value and timestamp; the labels map remains shared.
type DataPoint ¶
type DataPoint struct {
Timestamp time.Time `json:"timestamp"`
Value float64 `json:"value"`
Labels map[string]string `json:"labels"`
}
DataPoint represents a single data point in a time series.
func DataPointFromProto ¶
DataPointFromProto decodes a sample and shares labels with the input. A missing timestamp yields the zero time.
type FiniteMetricDescriptor ¶ added in v0.16.0
type FiniteMetricDescriptor struct {
ID string `json:"id"`
Name string `json:"name"`
ResourceKey string `json:"resource_key"`
Unit string `json:"unit"`
Shapes []string `json:"shapes"`
Description string `json:"description"`
// Source overrides the catalog default for host-composed mixed-source lanes.
Source *MetricSourceRef `json:"source,omitempty"`
// RangeReuse is the provider's opt-in to coverage-aware range reuse. It
// requires the range shape; false or absent never permits reuse. Setting it
// guarantees that every ok range result for this metric is a pure point
// series: Points are pointwise evaluations on the grid StartTime+n*Step, and
// for the same query context and Step each point's value and presence do not
// depend on StartTime, EndTime or which other points were requested.
// Opted-in ok results leave Value and ObservedAt unset and Window zero;
// cross-bound assembly cannot transplant range-wide sample metadata.
// IdentityScope, Source and Dimensions must remain compatible. Non-ok and
// incomplete results establish no cross-bound coverage. Reuse does not imply
// current equivalence or immutable history: cache TTL still governs staleness.
// The descriptor, not an owner's MetricDefinition.RangeReuse declaration,
// is the opt-in, and a provider may decline that declaration.
RangeReuse bool `json:"range_reuse,omitempty"`
// RangeToCurrent separately allows the latest range point to represent a
// cached current sample. Both current and range shapes are required.
// The provider guarantees equivalent value semantics, unit, identity,
// source, dimensions and sampling window independent of range bounds/step.
// ObservedAt must be the actual source time associated with that last point,
// and Window its source sampling window, not range-wide metadata.
// Hosts still require a complete ok response, a numeric terminal point,
// known positive MaxSampleAge, fresh nonfuture source/evaluation times and
// an unexpired cache entry. A terminal gap never falls back to an older point.
// Point.Time does not establish source age and never replaces ObservedAt.
// Absence of this flag never permits range-to-current reuse.
RangeToCurrent bool `json:"range_to_current,omitempty"`
}
FiniteMetricDescriptor declares physical base units and supported evaluations. Units use ValidFiniteUnit; shapes are current or range, never legacy enum numbers.
type FiniteQueryProvider ¶ added in v0.16.0
type FiniteQueryProvider interface {
GetResourceMetricsCatalog(*types.PluginContext, ResourceMetricsCatalogRequest) (*ResourceMetricsCatalog, error)
QueryResources(*types.PluginContext, ResourceMetricsQuery) (*ResourceMetricsResponse, error)
}
FiniteQueryProvider is optional and independent of legacy Query/Stream. Implementations must honor cancellation and must not fabricate missing samples.
type GetMetricOwnerCatalogFunc ¶ added in v0.16.0
type GetMetricOwnerCatalogFunc func(*types.PluginContext) (*MetricOwnerCatalog, error)
type Handler ¶
type Handler struct {
Resource string `json:"resource"`
Metrics []MetricDescriptor `json:"metrics"`
}
Handler maps a resource key to its available metrics.
func HandlerFromProto ¶
func HandlerFromProto(p *metricpb.MetricHandler) Handler
HandlerFromProto decodes the available metrics; nil input yields an empty handler.
func (*Handler) ToProto ¶
func (h *Handler) ToProto() *metricpb.MetricHandler
ToProto copies the handler and its metric descriptors into wire messages.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager manages metric queries and streams within a plugin process.
func NewManager ¶
func NewManager( log logging.Logger, sp settings.Provider, providerInfo ProviderInfo, handlers map[string]Handler, queryFunc QueryFunc, streamFunc StreamFunc, ) *Manager
NewManager creates a process-local manager. A nil logger disables logging. Bind the connection provider before starting concurrent queries or streams.
func (*Manager) BindConnectionContextProvider ¶ added in v0.9.0
func (m *Manager) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)
BindConnectionContextProvider installs the sole configured native registry during capability setup, before any stream or query starts.
func (*Manager) GetMetricOwnerCatalog ¶ added in v0.16.0
func (m *Manager) GetMetricOwnerCatalog(pc *types.PluginContext) (*MetricOwnerCatalog, error)
func (*Manager) GetResourceMetricsCatalog ¶ added in v0.16.0
func (m *Manager) GetResourceMetricsCatalog(pc *types.PluginContext, request ResourceMetricsCatalogRequest) (*ResourceMetricsCatalog, error)
GetResourceMetricsCatalog resolves metadata under the selected source lease. Unconfigured finite callbacks return UNSUPPORTED, never a legacy fallback.
func (*Manager) GetSupportedResources ¶
func (m *Manager) GetSupportedResources(_ *types.PluginContext) (*ProviderInfo, []Handler)
GetSupportedResources returns provider metadata and an unordered handler snapshot.
func (*Manager) Query ¶
func (m *Manager) Query(ctx *types.PluginContext, req QueryRequest) (*QueryResponse, error)
Query runs a non-resource query; resource intent requires QueryResource.
func (*Manager) QueryResource ¶ added in v0.9.0
func (m *Manager) QueryResource(ctx *types.PluginContext, req QueryRequest) (*QueryResponse, error)
QueryResource validates resource input before leasing its configured connection.
func (*Manager) QueryResources ¶ added in v0.16.0
func (m *Manager) QueryResources(pc *types.PluginContext, q ResourceMetricsQuery) (*ResourceMetricsResponse, error)
QueryResources holds the configured source lease through execution. Native targets additionally retain their catalog/connection leases; external targets arrive through the host's owner admission and bounded public projection. Source authority comes from configured provider and the selected context, not input.
func (*Manager) StreamMetrics ¶
func (m *Manager) StreamMetrics(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
StreamMetrics starts an owner-isolated non-resource lane until cancellation or input closure.
func (*Manager) StreamResourceMetrics ¶ added in v0.9.0
func (m *Manager) StreamResourceMetrics(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
StreamResourceMetrics leases the selected connection for the lane's lifetime. Cancellation stops native work and prevents further delivery.
type MetricBinding ¶ added in v0.16.0
type MetricBinding struct {
ID string `json:"id"`
Signal string `json:"signal"`
ResourcePluginID string `json:"resource_plugin_id"`
ResourceConnectionID string `json:"resource_connection_id"`
Source MetricSourceRef `json:"source"`
Policy string `json:"policy"`
PublicScope map[string]string `json:"public_scope"`
Overrides []MetricDefinitionOverride `json:"overrides"`
Revision string `json:"revision"`
}
MetricBinding stores source configuration independently of presentation preferences. Resource owner authority never comes from the selected source connection.
type MetricDataSource ¶ added in v0.16.0
type MetricDefinition ¶ added in v0.16.0
type MetricDefinition struct {
ID string `json:"id"`
Name string `json:"name"`
ResourceKeys []string `json:"resource_keys"`
Unit string `json:"unit"`
Semantics string `json:"semantics"`
Dimensions []string `json:"dimensions"`
SupportedShapes []string `json:"supported_shapes"`
QueryLanguage string `json:"query_language"`
Query string `json:"query"`
FieldBindings []MetricFieldBinding `json:"field_bindings"`
IdentityLabels []string `json:"identity_labels"`
Reducer string `json:"reducer"`
BatchStrategy string `json:"batch_strategy"`
Revision string `json:"revision"`
Native bool `json:"native"`
// RangeReuse is the owner's declaration that this authored definition meets
// the FiniteMetricDescriptor.RangeReuse guarantee. It requires the range
// shape. It is not an opt-in: the provider's descriptor decides and may
// decline, and a host clears the declaration unless the effective definition
// is exactly the owner-authored one.
RangeReuse bool `json:"range_reuse,omitempty"`
}
MetricDefinition combines stable semantics with an explicitly selected source mapping. Units and shapes use the same physical vocabulary as FiniteMetricDescriptor.
type MetricDefinitionOverride ¶ added in v0.16.0
type MetricDefinitionOverride struct {
MetricID string `json:"metric_id"`
Source *MetricSourceRef `json:"source,omitempty"`
Query *string `json:"query,omitempty"`
FieldBindings *[]MetricFieldBinding `json:"field_bindings,omitempty"`
IdentityLabels *[]string `json:"identity_labels,omitempty"`
Reducer *string `json:"reducer,omitempty"`
BatchStrategy *string `json:"batch_strategy,omitempty"`
Revision string `json:"revision"`
}
MetricDefinitionOverride is sparse. Nil inherits; removing the override resets it.
type MetricDescriptor ¶
type MetricDescriptor struct {
ID string `json:"id"`
Name string `json:"name"`
Unit MetricUnit `json:"unit"`
Icon string `json:"icon"`
ColorRanges []ColorRange `json:"color_ranges"`
FormatString string `json:"format_string"`
SupportedShapes []MetricShape `json:"supported_shapes"`
ChartGroup string `json:"chart_group"`
}
MetricDescriptor describes a single metric.
func MetricDescriptorFromProto ¶
func MetricDescriptorFromProto(p *metricpb.MetricDescriptor) MetricDescriptor
MetricDescriptorFromProto decodes descriptor slices; nil input yields zero metadata.
func (*MetricDescriptor) ToProto ¶
func (d *MetricDescriptor) ToProto() *metricpb.MetricDescriptor
ToProto copies descriptor slices into a new wire message.
type MetricDiscoveryProvider ¶ added in v0.16.0
type MetricDiscoveryProvider interface {
DiscoverMetricLabels(*types.PluginContext, MetricDiscoveryRequest) (*MetricDiscoveryResult, error)
}
type MetricDiscoveryRequest ¶ added in v0.16.0
type MetricDiscoveryRequest struct {
Source MetricSourceRef `json:"source"`
MetricName string `json:"metric_name"`
LabelName string `json:"label_name"`
Matchers map[string]string `json:"matchers"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Limit int `json:"limit"`
}
MetricDiscoveryRequest permits bounded exact-match discovery, not arbitrary selectors.
type MetricDiscoveryResult ¶ added in v0.16.0
type MetricFieldBinding ¶ added in v0.16.0
type MetricFieldBinding struct {
Field string `json:"field"`
Label string `json:"label"`
Source string `json:"source"`
Required bool `json:"required"`
Transform MetricFieldTransform `json:"transform,omitempty"`
ResourcePath string `json:"resource_path,omitempty"`
}
MetricFieldBinding binds an approved owner scalar or public scope to a source label. ResourcePath is an RFC6901 scalar pointer; only the host may populate PublicData.
type MetricFieldTransform ¶ added in v0.16.0
type MetricFieldTransform string
MetricFieldTransform is a bounded, deterministic public identity transform.
const ( MetricTransformIdentity MetricFieldTransform = "identity" MetricTransformLowercase MetricFieldTransform = "lowercase" MetricTransformUppercase MetricFieldTransform = "uppercase" )
type MetricOwnerCatalog ¶ added in v0.16.0
type MetricOwnerCatalog struct {
Definitions []MetricDefinition `json:"definitions"`
ScopeFields []MetricScopeField `json:"scope_fields"`
}
MetricOwnerCatalog exposes owner-authored definitions and public scope metadata.
type MetricOwnerCatalogProvider ¶ added in v0.16.0
type MetricOwnerCatalogProvider interface {
GetMetricOwnerCatalog(*types.PluginContext) (*MetricOwnerCatalog, error)
}
MetricOwnerCatalogProvider is independent of finite execution and legacy metrics.
type MetricQueryContext ¶ added in v0.16.0
type MetricQueryContext struct {
Definitions []MetricDefinition `json:"definitions"`
PublicScope map[string]string `json:"public_scope"`
MappingRevision string `json:"mapping_revision"`
ProjectionRevision string `json:"projection_revision,omitempty"`
}
MetricQueryContext is host-resolved mapping state, not caller resource authority. MappingRevision fences source configuration; ProjectionRevision fences approved fields.
type MetricResult ¶
type MetricResult struct {
TimeSeries *TimeSeries `json:"time_series,omitempty"`
CurrentValue *CurrentValue `json:"current_value,omitempty"`
AggregateValue *AggregateValue `json:"aggregate_value,omitempty"`
}
MetricResult wraps one of the possible metric result types.
func MetricResultFromProto ¶
func MetricResultFromProto(p *metricpb.MetricResult) MetricResult
MetricResultFromProto decodes the selected wire variant; absent variants yield zero.
func (*MetricResult) ToProto ¶
func (r *MetricResult) ToProto() *metricpb.MetricResult
ToProto encodes the first present result in series, current, aggregate order.
type MetricScopeField ¶ added in v0.16.0
type MetricScopeField struct {
Key string `json:"key"`
Name string `json:"name"`
Description string `json:"description"`
}
MetricScopeField describes one owner-approved public scope entry.
type MetricShape ¶
type MetricShape int
MetricShape indicates the type of metric data.
const ( // ShapeCurrent requests the latest value. ShapeCurrent MetricShape = 0 // ShapeTimeseries requests timestamped samples. ShapeTimeseries MetricShape = 1 // ShapeAggregate requests a statistical window. ShapeAggregate MetricShape = 2 )
func MetricShapeFromProto ¶
func MetricShapeFromProto(p metricpb.MetricShape) MetricShape
MetricShapeFromProto preserves every int32 wire shape, including unknown values.
func (MetricShape) ToProto ¶
func (s MetricShape) ToProto() metricpb.MetricShape
ToProto converts the shape to the int32 wire enum. Out-of-range ints truncate.
type MetricSourceDefaults ¶ added in v0.16.0
type MetricSourceDefaults struct {
Source *MetricSourceRef `json:"source,omitempty"`
Revision string `json:"revision"`
}
MetricSourceDefaults is a profile default. A nil Source resets to native inheritance.
type MetricSourceRef ¶ added in v0.16.0
type MetricSourceRef struct {
PluginID string `json:"plugin_id"`
ConnectionID string `json:"connection_id"`
DatasourceUID string `json:"datasource_uid"`
DatasourceKind string `json:"datasource_kind"`
Native bool `json:"native,omitempty"`
}
MetricSourceRef identifies the selected source, not the resource owner. Native sources have no datasource kind or UID.
type MetricStreamCommand ¶
type MetricStreamCommand int
MetricStreamCommand represents a command for the metric stream.
const ( // StreamCommandSubscribe starts a subscription within its owning lane. StreamCommandSubscribe MetricStreamCommand = 0 // StreamCommandUnsubscribe retires a subscription within its owning lane. StreamCommandUnsubscribe MetricStreamCommand = 1 // StreamCommandClose retires the addressed subscription, not other lanes. StreamCommandClose MetricStreamCommand = 2 )
func MetricStreamCommandFromProto ¶
func MetricStreamCommandFromProto(p metricpb.MetricStreamCommand) MetricStreamCommand
MetricStreamCommandFromProto preserves unknown wire commands for validation.
func (MetricStreamCommand) ToProto ¶
func (c MetricStreamCommand) ToProto() metricpb.MetricStreamCommand
ToProto converts the command to the int32 wire enum. Out-of-range ints truncate.
type MetricUnit ¶
type MetricUnit int
MetricUnit represents the unit of a metric value.
const ( // UnitNone denotes a dimensionless value. UnitNone MetricUnit = 0 // UnitBytes measures bytes. UnitBytes MetricUnit = 1 // UnitKB measures kilobytes. UnitKB MetricUnit = 2 // UnitMB measures megabytes. UnitMB MetricUnit = 3 // UnitGB measures gigabytes. UnitGB MetricUnit = 4 // UnitPercentage measures percentages. UnitPercentage MetricUnit = 5 // UnitMillis measures milliseconds. UnitMillis MetricUnit = 6 // UnitSeconds measures seconds. UnitSeconds MetricUnit = 7 // UnitCount measures discrete occurrences. UnitCount MetricUnit = 8 // UnitOpsPerSec measures operations per second. UnitOpsPerSec MetricUnit = 9 // UnitBytesPerSec measures byte throughput. UnitBytesPerSec MetricUnit = 10 // UnitMillicores measures thousandths of a CPU core. UnitMillicores MetricUnit = 11 // UnitCores measures CPU cores. UnitCores MetricUnit = 12 )
func MetricUnitFromProto ¶
func MetricUnitFromProto(p metricpb.MetricUnit) MetricUnit
MetricUnitFromProto preserves every int32 wire unit, including unknown values.
func (MetricUnit) ToProto ¶
func (u MetricUnit) ToProto() metricpb.MetricUnit
ToProto converts the unit to the int32 wire enum. Out-of-range ints truncate.
type MetricValidationIssue ¶ added in v0.16.0
type MetricValidationResult ¶ added in v0.16.0
type MetricValidationResult struct {
Valid bool `json:"valid"`
Issues []MetricValidationIssue `json:"issues"`
}
type MetricViewSourceSelection ¶ added in v0.16.0
type MetricViewSourceSelection struct {
OwnerPluginID string `json:"owner_plugin_id"`
OwnerConnectionID string `json:"owner_connection_id"`
ResourceKey string `json:"resource_key"`
Mode string `json:"mode"`
Source *MetricSourceRef `json:"source,omitempty"`
Revision string `json:"revision"`
}
MetricViewSourceSelection is profile-durable source configuration for one owner connection and resource view, independent of presentation preferences. Mode is inherit, native, or external. Only external carries Source.
type Plugin ¶
Plugin implements the hashicorp go-plugin interfaces for metric capability.
func (*Plugin) BindConnectionContextProvider ¶ added in v0.9.0
func (p *Plugin) BindConnectionContextProvider(provider resourcev2.ConnectionContextProvider)
BindConnectionContextProvider forwards registry binding to implementations that accept it. Call during setup, before serving requests.
func (*Plugin) GRPCClient ¶
func (p *Plugin) GRPCClient( _ context.Context, _ *plugin.GRPCBroker, c *grpc.ClientConn, ) (any, error)
GRPCClient creates a client backed by the supplied connection; the caller owns that connection.
func (*Plugin) GRPCServer ¶
GRPCServer registers the metric service on the supplied server.
type PluginClient ¶
type PluginClient struct {
// contains filtered or unexported fields
}
PluginClient forwards metric queries and streams to a remote plugin.
func (*PluginClient) GetMetricOwnerCapabilities ¶ added in v0.16.0
func (c *PluginClient) GetMetricOwnerCapabilities(ctx context.Context) (bool, error)
GetMetricOwnerCapabilities probes owner support without requiring finite execution.
func (*PluginClient) GetMetricOwnerCatalog ¶ added in v0.16.0
func (c *PluginClient) GetMetricOwnerCatalog(pc *types.PluginContext) (*MetricOwnerCatalog, error)
func (*PluginClient) GetResourceMetricsCatalog ¶ added in v0.16.0
func (c *PluginClient) GetResourceMetricsCatalog(pc *types.PluginContext, request ResourceMetricsCatalogRequest) (*ResourceMetricsCatalog, error)
GetResourceMetricsCatalog negotiates finite support; old processes return UNSUPPORTED.
func (*PluginClient) GetSupportedResources ¶
func (c *PluginClient) GetSupportedResources(ctx *types.PluginContext) (*ProviderInfo, []Handler)
GetSupportedResources returns the remote provider and its resource handlers.
func (*PluginClient) Query ¶
func (c *PluginClient) Query(ctx *types.PluginContext, r QueryRequest) (*QueryResponse, error)
Query selects the legacy or resource-aware RPC from the request's intent.
func (*PluginClient) QueryResource ¶ added in v0.9.0
func (c *PluginClient) QueryResource(ctx *types.PluginContext, r QueryRequest) (*QueryResponse, error)
QueryResource validates resource intent and requires resource-aware response admission.
func (*PluginClient) QueryResources ¶ added in v0.16.0
func (c *PluginClient) QueryResources(pc *types.PluginContext, q ResourceMetricsQuery) (*ResourceMetricsResponse, error)
QueryResources makes one typed batch RPC, never a per-resource fallback loop.
func (*PluginClient) StreamMetrics ¶
func (c *PluginClient) StreamMetrics(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
StreamMetrics opens a legacy metric stream bound to ctx.
func (*PluginClient) StreamResourceMetrics ¶ added in v0.9.0
func (c *PluginClient) StreamResourceMetrics(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
StreamResourceMetrics waits for remote readiness before forwarding resource frames.
type PluginOpts ¶
type PluginOpts struct {
// ProviderInfo describes this metric provider.
ProviderInfo ProviderInfo `json:"provider_info"`
// Handlers maps resource keys to their metric handlers.
// For example: "core::v1::Pod" -> Handler
Handlers map[string]Handler `json:"handlers"`
// QueryFunc is the function that queries metrics from the provider.
QueryFunc QueryFunc `json:"-"`
// StreamFunc is the optional function that streams metrics. If nil,
// the SDK will poll QueryFunc at the requested interval.
StreamFunc StreamFunc `json:"-"`
// ResourceMetricsCatalogFunc and QueryResourcesFunc enable finite execution.
// Both must be set together; legacy callbacks remain independently optional.
ResourceMetricsCatalogFunc ResourceMetricsCatalogFunc `json:"-"`
QueryResourcesFunc QueryResourcesFunc `json:"-"`
GetMetricOwnerCatalogFunc GetMetricOwnerCatalogFunc `json:"-"`
}
PluginOpts contains the options for the metric plugin.
type PluginServer ¶
type PluginServer struct{ Impl any }
PluginServer adapts metric provider calls to the gRPC transport.
func (*PluginServer) GetFiniteCapabilities ¶ added in v0.16.0
func (s *PluginServer) GetFiniteCapabilities(_ context.Context, _ *emptypb.Empty) (*metricpb.FiniteMetricCapabilities, error)
GetFiniteCapabilities negotiates the typed finite protocol without legacy calls.
func (*PluginServer) GetMetricOwnerCatalog ¶ added in v0.16.0
func (s *PluginServer) GetMetricOwnerCatalog(ctx context.Context, _ *emptypb.Empty) (*metricpb.MetricOwnerCatalog, error)
func (*PluginServer) GetResourceMetricsCatalog ¶ added in v0.16.0
func (s *PluginServer) GetResourceMetricsCatalog(ctx context.Context, p *metricpb.ResourceMetricsCatalogRequest) (*metricpb.ResourceMetricsCatalog, error)
func (*PluginServer) GetSupportedResources ¶
func (s *PluginServer) GetSupportedResources( ctx context.Context, _ *emptypb.Empty, ) (*metricpb.GetSupportedMetricResourcesResponse, error)
GetSupportedResources exposes the provider's resource handlers.
func (*PluginServer) Query ¶
func (s *PluginServer) Query( ctx context.Context, p *metricpb.QueryMetricsRequest, ) (*metricpb.QueryMetricsResponse, error)
Query decodes a legacy query and preserves provider error classification.
func (*PluginServer) QueryResource ¶ added in v0.9.0
func (s *PluginServer) QueryResource( ctx context.Context, p *metricpb.QueryMetricsRequest, ) (*metricpb.ResourceQueryMetricsResponse, error)
QueryResource admits resource-aware input before invoking the provider.
func (*PluginServer) QueryResources ¶ added in v0.16.0
func (s *PluginServer) QueryResources(ctx context.Context, p *metricpb.ResourceMetricsQuery) (*metricpb.ResourceMetricsResponse, error)
func (*PluginServer) StreamMetrics ¶
func (s *PluginServer) StreamMetrics(stream metricpb.MetricPlugin_StreamMetricsServer) error
StreamMetrics serves a legacy metric stream until completion or cancellation.
func (*PluginServer) StreamResourceMetrics ¶ added in v0.9.0
func (s *PluginServer) StreamResourceMetrics(stream metricpb.MetricPlugin_StreamResourceMetricsServer) error
StreamResourceMetrics validates the open frame and acknowledges provider readiness.
type Provider ¶
type Provider interface {
GetSupportedResources(ctx *types.PluginContext) (*ProviderInfo, []Handler)
Query(ctx *types.PluginContext, req QueryRequest) (*QueryResponse, error)
StreamMetrics(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
}
Provider is the interface satisfied by the plugin server and client to provide metric querying functionality.
type ProviderConfiguration ¶ added in v0.16.0
type ProviderConfiguration interface {
GetProviderConnections(*types.PluginContext) ([]ProviderConnection, error)
SaveProviderConnection(*types.PluginContext, ProviderConnectionInput) (*ProviderConnection, error)
DeleteProviderConnection(*types.PluginContext, string) error
GetDataSources(*types.PluginContext, MetricSourceRef) ([]MetricDataSource, error)
TestProviderConnection(*types.PluginContext, string) (*MetricValidationResult, error)
ValidateMetricDefinition(*types.PluginContext, MetricSourceRef, MetricDefinition) (*MetricValidationResult, error)
}
ProviderConfiguration runs only inside the trusted provider boundary.
type ProviderConnection ¶ added in v0.16.0
type ProviderConnection struct {
ID string `json:"id"`
Name string `json:"name"`
PluginID string `json:"plugin_id"`
Kind string `json:"kind"`
URL string `json:"url"`
HasCredentials bool `json:"has_credentials"`
PublicConfig map[string]string `json:"public_config"`
}
ProviderConnection contains public configuration only; no operation returns secrets.
type ProviderConnectionInput ¶ added in v0.16.0
type ProviderConnectionInput struct {
Connection ProviderConnection `json:"connection"`
Credential *string `json:"credential,omitempty"`
}
ProviderConnectionInput accepts a write-only secret: nil preserves, empty clears.
type ProviderInfo ¶
type ProviderInfo struct {
ID string `json:"id"`
Name string `json:"name"`
Icon string `json:"icon"`
Description string `json:"description"`
}
ProviderInfo describes a metric provider.
func ProviderInfoFromProto ¶
func ProviderInfoFromProto(p *metricpb.MetricProviderInfo) ProviderInfo
ProviderInfoFromProto returns zero metadata for nil input.
func (*ProviderInfo) ToProto ¶
func (p *ProviderInfo) ToProto() *metricpb.MetricProviderInfo
ToProto encodes provider metadata into a new wire message.
type QueryContext ¶
type QueryContext struct {
context.Context `json:"-"`
PluginID string
ConnectionID string
Connection *types.Connection
}
QueryContext provides context for metric queries. Wraps the plugin context plus connection information passed via gRPC metadata.
type QueryFunc ¶
type QueryFunc func(ctx *QueryContext, req QueryRequest) (*QueryResponse, error)
QueryFunc queries metrics for a resource.
type QueryRequest ¶
type QueryRequest struct {
ResourceKey string `json:"resource_key"`
ResourceID string `json:"resource_id"`
ResourceNamespace string `json:"resource_namespace"`
ResourceData *resourcev2.Value `json:"resource_data,omitempty"`
Reference *resourcev2.ResourceReference `json:"reference,omitempty"`
Route *resourcev2.AccessRoute `json:"route,omitempty"`
MetricIDs []string `json:"metric_ids"`
Shape MetricShape `json:"shape"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Step time.Duration `json:"step"`
Params map[string]string `json:"params"`
}
QueryRequest is the Go-side representation of a metric query.
func (QueryRequest) HasResourceIntent ¶ added in v0.9.0
func (r QueryRequest) HasResourceIntent() bool
HasResourceIntent reports whether the request needs the resource-aware protocol.
func (*QueryRequest) UnmarshalJSON ¶ added in v0.9.0
func (r *QueryRequest) UnmarshalJSON(data []byte) error
UnmarshalJSON admits exact field names and validates lossless resource input.
type QueryResourcesFunc ¶ added in v0.16.0
type QueryResourcesFunc func(*types.PluginContext, ResourceMetricsQuery) (*ResourceMetricsResponse, error)
QueryResourcesFunc receives the source-owned leased connection context. All target admissions remain leased until the callback returns.
type QueryResponse ¶
type QueryResponse struct {
Success bool `json:"success"`
Results []MetricResult `json:"results"`
Error string `json:"error"`
}
QueryResponse is the Go-side representation of a metric query response.
func QueryResponseFromProto ¶
func QueryResponseFromProto(p *metricpb.QueryMetricsResponse) *QueryResponse
QueryResponseFromProto decodes results; nil input produces an unsuccessful empty response.
func (*QueryResponse) ToProto ¶
func (r *QueryResponse) ToProto() *metricpb.QueryMetricsResponse
ToProto copies result containers; nested label maps remain shared.
type ResourceMetricPoint ¶ added in v0.16.0
ResourceMetricPoint carries an evaluation timestamp and a physical base-unit value. It does not establish the age of the underlying source sample. A nil Value is a gap, never zero. NaN and infinity are invalid.
type ResourceMetricResult ¶ added in v0.16.0
type ResourceMetricResult struct {
ResourceToken string `json:"resource_token"`
MetricID string `json:"metric_id"`
Status string `json:"status"`
Value *float64 `json:"value"`
Points []ResourceMetricPoint `json:"points"`
Dimensions map[string]string `json:"dimensions"`
ObservedAt *time.Time `json:"observed_at"`
Window time.Duration `json:"window"`
// IdentityScope describes source attribution, not host cache fencing.
// \"incarnation\" means source verified UID; \"name\" means name-only attribution.
IdentityScope string `json:"identity_scope"`
Message string `json:"message"`
// Source is exact provenance. The host fills external and mixed-source results.
// A single owner-native lane may omit this redundant field; use its catalog
// source. Consumers resolve result, descriptor, then catalog source.
Source *MetricSourceRef `json:"source,omitempty"`
}
ResourceMetricResult reports one target/metric evaluation. ObservedAt and Window come from the source; absence must never be replaced by receipt time. Non-ok statuses carry no numeric data. Missing is not a zero-valued sample.
type ResourceMetricTarget ¶ added in v0.16.0
type ResourceMetricTarget struct {
Token string `json:"token"`
Reference resourcev2.ResourceReference `json:"reference"`
Route resourcev2.AccessRoute `json:"route"`
// PublicData contains only host-approved scalar fields from owner observations.
// Providers must never interpret this projection as resource authority.
PublicData map[string]string `json:"public_data,omitempty"`
}
ResourceMetricTarget binds a caller correlation token to an admitted reference. Token does not confer authority. Route must match the selected connection.
type ResourceMetricsCatalog ¶ added in v0.16.0
type ResourceMetricsCatalog struct {
Source MetricSourceRef `json:"source"`
Metrics []FiniteMetricDescriptor `json:"metrics"`
MaxTargets int `json:"max_targets"`
// MaxSampleAge is the source's live-data age policy, not cache TTL.
// Zero leaves freshness unknown. Range completeness is independent of live age.
MaxSampleAge time.Duration `json:"max_sample_age"`
}
ResourceMetricsCatalog is authoritative for source units, shapes and batch size.
type ResourceMetricsCatalogFunc ¶ added in v0.16.0
type ResourceMetricsCatalogFunc func(*types.PluginContext, ResourceMetricsCatalogRequest) (*ResourceMetricsCatalog, error)
ResourceMetricsCatalogFunc returns descriptors for one canonical resource key.
type ResourceMetricsCatalogRequest ¶ added in v0.16.0
type ResourceMetricsCatalogRequest struct {
Source MetricSourceRef `json:"source"`
ResourceKey string `json:"resource_key"`
Context MetricQueryContext `json:"context"`
}
ResourceMetricsCatalogRequest names the exact source whose mappings are requested.
type ResourceMetricsQuery ¶ added in v0.16.0
type ResourceMetricsQuery struct {
Source MetricSourceRef `json:"source"`
Targets []ResourceMetricTarget `json:"targets"`
MetricIDs []string `json:"metric_ids"`
Shape string `json:"shape"`
StartTime time.Time `json:"start_time"`
EndTime time.Time `json:"end_time"`
Step time.Duration `json:"step"`
Context MetricQueryContext `json:"context"`
}
ResourceMetricsQuery evaluates every requested target/metric pair once. Current forbids range fields. Range requires ordered times and positive Step.
type ResourceMetricsResponse ¶ added in v0.16.0
type ResourceMetricsResponse struct {
Results []ResourceMetricResult `json:"results"`
Complete bool `json:"complete"`
Warnings []string `json:"warnings"`
}
ResourceMetricsResponse separates completeness from individual result status. Complete requires exactly one result for every requested target/metric pair.
type ResourceQueryProvider ¶ added in v0.9.0
type ResourceQueryProvider interface {
QueryResource(*types.PluginContext, QueryRequest) (*QueryResponse, error)
}
ResourceQueryProvider accepts lossless resource queries on the explicit v2 RPC.
type ResourceStreamProvider ¶ added in v0.9.0
type ResourceStreamProvider interface {
StreamResourceMetrics(context.Context, chan StreamInput) (chan StreamOutput, error)
}
ResourceStreamProvider accepts mixed resource and nonresource v2 frames.
type StreamContext ¶
type StreamContext struct {
context.Context `json:"-"`
PluginID string
ConnectionID string
Connection *types.Connection
}
StreamContext provides context for metric streams.
type StreamFunc ¶
type StreamFunc func(ctx *StreamContext, in chan StreamInput) (chan StreamOutput, error)
StreamFunc streams metrics for subscriptions. If nil, the SDK polls QueryFunc.
type StreamInput ¶
type StreamInput struct {
SubscriptionID string `json:"subscription_id"`
Command MetricStreamCommand `json:"command"`
ResourceKey string `json:"resource_key"`
ResourceID string `json:"resource_id"`
ResourceNamespace string `json:"resource_namespace"`
ResourceData *resourcev2.Value `json:"resource_data,omitempty"`
Reference *resourcev2.ResourceReference `json:"reference,omitempty"`
Route *resourcev2.AccessRoute `json:"route,omitempty"`
MetricIDs []string `json:"metric_ids"`
Interval time.Duration `json:"interval"`
Params map[string]string `json:"params"`
CatalogRevision string `json:"catalog_revision,omitempty"`
}
StreamInput is a control message for the metric stream.
func (StreamInput) HasResourceIntent ¶ added in v0.9.0
func (r StreamInput) HasResourceIntent() bool
HasResourceIntent reports whether the stream frame carries resource-aware input.
func (*StreamInput) UnmarshalJSON ¶ added in v0.9.0
func (r *StreamInput) UnmarshalJSON(data []byte) error
UnmarshalJSON validates stream metadata, catalog pins, and resource values.
type StreamOutput ¶
type StreamOutput struct {
SubscriptionID string `json:"subscription_id"`
Results []MetricResult `json:"results"`
Timestamp time.Time `json:"timestamp"`
Error string `json:"error"`
OperationError *resourcev2.ResourceOperationError `json:"operation_error,omitempty"`
}
StreamOutput is a metric data push from the stream.
type TimeSeries ¶
type TimeSeries struct {
MetricID string `json:"metric_id"`
DataPoints []DataPoint `json:"data_points"`
Labels map[string]string `json:"labels"`
}
TimeSeries represents a series of data points for a metric.
func TimeSeriesFromProto ¶
func TimeSeriesFromProto(p *metricpb.TimeSeries) TimeSeries
TimeSeriesFromProto decodes samples and shares label maps with the wire input.
func (*TimeSeries) ToProto ¶
func (t *TimeSeries) ToProto() *metricpb.TimeSeries
ToProto allocates sample messages and shares their label maps with the result.