Documentation
¶
Index ¶
- func RegisterPlugin(p *sdk.Plugin, opts PluginOpts) error
- type AggregateValue
- type ColorRange
- type CurrentValue
- type DataPoint
- type Handler
- type Manager
- type MetricDescriptor
- type MetricResult
- type MetricShape
- type MetricStreamCommand
- type MetricUnit
- type Plugin
- type PluginClient
- func (c *PluginClient) GetSupportedResources(ctx *types.PluginContext) (*ProviderInfo, []Handler)
- func (c *PluginClient) Query(ctx *types.PluginContext, req QueryRequest) (*QueryResponse, error)
- func (c *PluginClient) StreamMetrics(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
- type PluginOpts
- type PluginServer
- func (s *PluginServer) GetSupportedResources(ctx context.Context, _ *emptypb.Empty) (*metricpb.GetSupportedMetricResourcesResponse, error)
- func (s *PluginServer) Query(ctx context.Context, in *metricpb.QueryMetricsRequest) (*metricpb.QueryMetricsResponse, error)
- func (s *PluginServer) StreamMetrics(stream metricpb.MetricPlugin_StreamMetricsServer) error
- type Provider
- type ProviderInfo
- type QueryContext
- type QueryFunc
- type QueryRequest
- type QueryResponse
- type StreamContext
- type StreamFunc
- type StreamInput
- type StreamOutput
- type TimeSeries
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RegisterPlugin ¶
func RegisterPlugin( p *sdk.Plugin, opts PluginOpts, ) error
RegisterPlugin registers the metric capability with the plugin system.
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
func (*AggregateValue) ToProto ¶
func (a *AggregateValue) ToProto() *metricpb.AggregateValue
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
func (*ColorRange) ToProto ¶
func (c *ColorRange) ToProto() *metricpb.MetricColorRange
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
func (*CurrentValue) ToProto ¶
func (c *CurrentValue) ToProto() *metricpb.CurrentValue
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 ¶
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
func (*Handler) ToProto ¶
func (h *Handler) ToProto() *metricpb.MetricHandler
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
func (*Manager) GetSupportedResources ¶
func (m *Manager) GetSupportedResources(_ *types.PluginContext) (*ProviderInfo, []Handler)
func (*Manager) Query ¶
func (m *Manager) Query(ctx *types.PluginContext, req QueryRequest) (*QueryResponse, error)
func (*Manager) StreamMetrics ¶
func (m *Manager) StreamMetrics(ctx context.Context, in chan StreamInput) (chan StreamOutput, error)
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
func (*MetricDescriptor) ToProto ¶
func (d *MetricDescriptor) ToProto() *metricpb.MetricDescriptor
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
func (*MetricResult) ToProto ¶
func (r *MetricResult) ToProto() *metricpb.MetricResult
type MetricShape ¶
type MetricShape int
MetricShape indicates the type of metric data.
const ( ShapeCurrent MetricShape = 0 ShapeTimeseries MetricShape = 1 ShapeAggregate MetricShape = 2 )
func MetricShapeFromProto ¶
func MetricShapeFromProto(p metricpb.MetricShape) MetricShape
func (MetricShape) ToProto ¶
func (s MetricShape) ToProto() metricpb.MetricShape
type MetricStreamCommand ¶
type MetricStreamCommand int
MetricStreamCommand represents a command for the metric stream.
const ( StreamCommandSubscribe MetricStreamCommand = 0 StreamCommandUnsubscribe MetricStreamCommand = 1 StreamCommandClose MetricStreamCommand = 2 )
func MetricStreamCommandFromProto ¶
func MetricStreamCommandFromProto(p metricpb.MetricStreamCommand) MetricStreamCommand
func (MetricStreamCommand) ToProto ¶
func (c MetricStreamCommand) ToProto() metricpb.MetricStreamCommand
type MetricUnit ¶
type MetricUnit int
MetricUnit represents the unit of a metric value.
const ( UnitNone MetricUnit = 0 UnitBytes MetricUnit = 1 UnitKB MetricUnit = 2 UnitMB MetricUnit = 3 UnitGB MetricUnit = 4 UnitPercentage MetricUnit = 5 UnitMillis MetricUnit = 6 UnitSeconds MetricUnit = 7 UnitCount MetricUnit = 8 UnitOpsPerSec MetricUnit = 9 UnitBytesPerSec MetricUnit = 10 UnitMillicores MetricUnit = 11 UnitCores MetricUnit = 12 )
func MetricUnitFromProto ¶
func MetricUnitFromProto(p metricpb.MetricUnit) MetricUnit
func (MetricUnit) ToProto ¶
func (u MetricUnit) ToProto() metricpb.MetricUnit
type Plugin ¶
Plugin implements the hashicorp go-plugin interfaces for metric capability.
func (*Plugin) GRPCClient ¶
func (p *Plugin) GRPCClient( _ context.Context, _ *plugin.GRPCBroker, c *grpc.ClientConn, ) (interface{}, error)
func (*Plugin) GRPCServer ¶
type PluginClient ¶
type PluginClient struct {
// contains filtered or unexported fields
}
func (*PluginClient) GetSupportedResources ¶
func (c *PluginClient) GetSupportedResources(ctx *types.PluginContext) (*ProviderInfo, []Handler)
func (*PluginClient) Query ¶
func (c *PluginClient) Query( ctx *types.PluginContext, req QueryRequest, ) (*QueryResponse, error)
func (*PluginClient) StreamMetrics ¶
func (c *PluginClient) StreamMetrics( ctx context.Context, in chan StreamInput, ) (chan StreamOutput, error)
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:"-"`
}
PluginOpts contains the options for the metric plugin.
type PluginServer ¶
type PluginServer struct {
Impl Provider
}
func (*PluginServer) GetSupportedResources ¶
func (s *PluginServer) GetSupportedResources( ctx context.Context, _ *emptypb.Empty, ) (*metricpb.GetSupportedMetricResourcesResponse, error)
func (*PluginServer) Query ¶
func (s *PluginServer) Query( ctx context.Context, in *metricpb.QueryMetricsRequest, ) (*metricpb.QueryMetricsResponse, error)
func (*PluginServer) StreamMetrics ¶
func (s *PluginServer) StreamMetrics(stream metricpb.MetricPlugin_StreamMetricsServer) error
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 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
func (*ProviderInfo) ToProto ¶
func (p *ProviderInfo) ToProto() *metricpb.MetricProviderInfo
type QueryContext ¶
type QueryContext struct {
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 map[string]interface{} `json:"resource_data"`
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.
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
func (*QueryResponse) ToProto ¶
func (r *QueryResponse) ToProto() *metricpb.QueryMetricsResponse
type StreamContext ¶
type StreamContext struct {
PluginID string
}
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 map[string]interface{} `json:"resource_data"`
MetricIDs []string `json:"metric_ids"`
Interval time.Duration `json:"interval"`
}
StreamInput is a control message for the metric stream.
type StreamOutput ¶
type StreamOutput struct {
SubscriptionID string `json:"subscription_id"`
Results []MetricResult `json:"results"`
Timestamp time.Time `json:"timestamp"`
Error string `json:"error"`
}
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
func (*TimeSeries) ToProto ¶
func (t *TimeSeries) ToProto() *metricpb.TimeSeries