Documentation ¶
Index ¶
- Constants
- func NewExternalMetricNotFoundError(metricName string) *apierr.StatusError
- func NewLabelNotAllowedError(label string) *apierr.StatusError
- func NewMetricNotFoundError(resource schema.GroupResource, metricName string) *apierr.StatusError
- func NewMetricNotFoundForError(resource schema.GroupResource, metricName string, resourceName string) *apierr.StatusError
- func NewNoSuchMetricError(metricName string, err error) *apierr.StatusError
- func NewOperationNotSupportedError(operation string) *apierr.StatusError
- type NodeResult
- type PodResult
- type QueryBuilder
- func (qb QueryBuilder) AsContainerType() QueryBuilder
- func (qb QueryBuilder) Build() (*stackdriver.ProjectsTimeSeriesListCall, error)
- func (qb QueryBuilder) WithMetricKind(metricKind string) QueryBuilder
- func (qb QueryBuilder) WithMetricSelector(metricSelector labels.Selector) QueryBuilder
- func (qb QueryBuilder) WithMetricValueType(metricValueType string) QueryBuilder
- func (qb QueryBuilder) WithNamespace(namespace string) QueryBuilder
- func (qb QueryBuilder) WithNodeNames(nodeNames []string) QueryBuilder
- func (qb QueryBuilder) WithNodes(nodes *v1.NodeList) QueryBuilder
- func (qb QueryBuilder) WithPodNames(podNames []string) QueryBuilder
- func (qb QueryBuilder) WithPods(pods *v1.PodList) QueryBuilder
- type Translator
- func (t *Translator) CheckMetricUniquenessForPod(response *stackdriver.ListTimeSeriesResponse, metricName string) error
- func (t *Translator) GetCoreContainerMetricFromResponse(response *stackdriver.ListTimeSeriesResponse) (map[string]map[string]resource.Quantity, map[string]api.TimeInfo, error)
- func (t *Translator) GetCoreNodeMetricFromResponse(response *stackdriver.ListTimeSeriesResponse) (map[string]resource.Quantity, map[string]api.TimeInfo, error)
- func (t *Translator) GetExternalMetricProject(metricSelector labels.Selector) (string, error)
- func (t *Translator) GetExternalMetricRequest(metricName, metricKind, metricValueType string, metricSelector labels.Selector) (*stackdriver.ProjectsTimeSeriesListCall, error)
- func (t *Translator) GetMetricKind(metricName string, metricSelector labels.Selector) (string, string, error)
- func (t *Translator) GetMetricsFromSDDescriptorsResp(response *stackdriver.ListMetricDescriptorsResponse) []provider.CustomMetricInfo
- func (t *Translator) GetNodeItems(list *v1.NodeList) []metav1.ObjectMeta
- func (t *Translator) GetPodItems(list *v1.PodList) []metav1.ObjectMeta
- func (t *Translator) GetRespForExternalMetric(response *stackdriver.ListTimeSeriesResponse, metricName string) ([]external_metrics.ExternalMetricValue, error)
- func (t *Translator) GetRespForMultipleObjects(response *stackdriver.ListTimeSeriesResponse, list []metav1.ObjectMeta, ...) ([]custom_metrics.MetricValue, error)
- func (t *Translator) GetRespForSingleObject(response *stackdriver.ListTimeSeriesResponse, ...) (*custom_metrics.MetricValue, error)
- func (t *Translator) ListMetricDescriptors(fallbackForContainerMetrics bool) *stackdriver.ProjectsMetricDescriptorsListCall
Constants ¶
const ( // AllNamespaces is constant to indicate that there is no namespace filter in query AllNamespaces = "" // MaxNumOfArgsInOneOfFilter is the maximum value of one_of() function allowed in Stackdriver Filters MaxNumOfArgsInOneOfFilter = 100 // PrometheusMetricPrefix is the prefix for prometheus metrics PrometheusMetricPrefix = "prometheus.googleapis.com" )
const ( PodSchemaKey = "pods" // PodSchemaKey is the schema key for pod metrics NodeSchemaKey = "nodes" // NodeSchemaKey is the schema key for node metrics )
Variables ¶
This section is empty.
Functions ¶
func NewExternalMetricNotFoundError ¶
func NewExternalMetricNotFoundError(metricName string) *apierr.StatusError
NewExternalMetricNotFoundError returns a status error indicating that the given metric could not be found. It is similar to NewNotFound, but more specialized.
func NewLabelNotAllowedError ¶
func NewLabelNotAllowedError(label string) *apierr.StatusError
NewLabelNotAllowedError returns a status error indicating that the given label is forbidden.
func NewMetricNotFoundError ¶
func NewMetricNotFoundError(resource schema.GroupResource, metricName string) *apierr.StatusError
NewMetricNotFoundError returns a StatusError indicating that the given metric could not be found. It is similar to NewNotFound, but more specialized.
func NewMetricNotFoundForError ¶
func NewMetricNotFoundForError(resource schema.GroupResource, metricName string, resourceName string) *apierr.StatusError
NewMetricNotFoundForError returns a StatusError indicating that the given metric could not be found for the given named object. It is similar to NewNotFound, but more specialized.
func NewNoSuchMetricError ¶
func NewNoSuchMetricError(metricName string, err error) *apierr.StatusError
NewNoSuchMetricError returns a StatusError indicating that the given metric could not be found. It is similar to NewNotFound, but more specialized.
func NewOperationNotSupportedError ¶
func NewOperationNotSupportedError(operation string) *apierr.StatusError
NewOperationNotSupportedError returns a StatusError indicating that the invoked API call is not supported.
Types ¶
type NodeResult ¶
type NodeResult struct { NodeMetric map[string]resource.Quantity TimeInfo map[string]api.TimeInfo *Translator }
NodeResult is struct for constructing the result from all received responses
func NewNodeResult ¶
func NewNodeResult(t *Translator) *NodeResult
NewNodeResult creates a NodeResult
func (*NodeResult) AddCoreNodeMetricFromResponse ¶
func (r *NodeResult) AddCoreNodeMetricFromResponse(response *stackdriver.ListTimeSeriesResponse) error
AddCoreNodeMetricFromResponse for each node adds to map entries from response about metric and TimeInfo.
type PodResult ¶
type PodResult struct { ContainerMetric map[string]map[string]resource.Quantity TimeInfo map[string]api.TimeInfo *Translator }
PodResult is struct for constructing the result from all received responses
func (*PodResult) AddCoreContainerMetricFromResponse ¶
func (r *PodResult) AddCoreContainerMetricFromResponse(response *stackdriver.ListTimeSeriesResponse) error
AddCoreContainerMetricFromResponse for each pod adds to map entries from response about metric and TimeInfo.
type QueryBuilder ¶
type QueryBuilder struct {
// contains filtered or unexported fields
}
QueryBuilder is a builder for ProjectsTimeSeriesListCall
use NewQueryBuilder() to initialize
func NewQueryBuilder ¶
func NewQueryBuilder(translator *Translator, metricName string) QueryBuilder
NewQueryBuilder is the initiator for QueryBuilder
Parameters:
- translator, required for configurations.
- metricName, required to determine the query schema.
Example:
queryBuilder := NewQueryBuilder(NewTranslator(...), "custom.googleapis.com/foo")
func (QueryBuilder) AsContainerType ¶
func (qb QueryBuilder) AsContainerType() QueryBuilder
AsContainerType enforces to query k8s_container type metrics
it it valid only when useNewResourceModel is true
func (QueryBuilder) Build ¶
func (qb QueryBuilder) Build() (*stackdriver.ProjectsTimeSeriesListCall, error)
Build is the last step for QueryBuilder which converts itself into a ProjectsTimeSeriesListCall object
- has to pass the prerequisits specified in QueryBuilder.validate()
- uses the query schema based on useNewResourceModel from translator as well as the metric name.
- composes provided filters using the internal tool FilterBuilder
Example:
projectsTimeSeriesListCall, error = NewQueryBuilder(translator, metricName).Build()
func (QueryBuilder) WithMetricKind ¶
func (qb QueryBuilder) WithMetricKind(metricKind string) QueryBuilder
WithMetricKind adds a metric kind filter to the QueryBuilder
Example:
queryBuilder := NewQueryBuilder(translator, metricName).WithMetricKind("GAUGE")
func (QueryBuilder) WithMetricSelector ¶
func (qb QueryBuilder) WithMetricSelector(metricSelector labels.Selector) QueryBuilder
WithMetricSelector adds a metric selector filter to the QueryBuilder
Example:
// labels comes from "k8s.io/apimachinery/pkg/labels" metricSelector, _ := labels.Parse("metric.labels.custom=test") queryBuilder := NewQueryBuilder(translator, metricName).WithMetricSelector(metricSelector)
func (QueryBuilder) WithMetricValueType ¶
func (qb QueryBuilder) WithMetricValueType(metricValueType string) QueryBuilder
WithMetricValueType adds a metric value type filter to the QueryBuilder
Example:
queryBuilder := NewQueryBuilder(translator, metricName).WithMetricValueType("INT64")
func (QueryBuilder) WithNamespace ¶
func (qb QueryBuilder) WithNamespace(namespace string) QueryBuilder
WithNamespace adds a namespace filter to to the QueryBuilder
- CANNOT be used with WithNodes
Example:
queryBuilder := NewQueryBuilder(translator, metricName).WithNamespace("gmp-test")
func (QueryBuilder) WithNodeNames ¶
func (qb QueryBuilder) WithNodeNames(nodeNames []string) QueryBuilder
func (QueryBuilder) WithNodes ¶
func (qb QueryBuilder) WithNodes(nodes *v1.NodeList) QueryBuilder
WithNodes adds a node filter to the QueryBuilder (used when namespace is empty)
- ONLY one among WithPods, WithPodNames and WithNodes should be used
- CANNOT be used with WithNamespace
Exmaple:
// v1 comes from "k8s.io/api/core/v1" node := v1.Node{ ObjectMeta: metav1.ObjectMeta{ ClusterName: "my-cluster", UID: "my-node-id-1", Name: "my-node-name-1", }, } queryBuilder := NewQueryBuilder(translator, metricName).WithNodes(&v1.NodeList{Items: []v1.Node{node}})
func (QueryBuilder) WithPodNames ¶
func (qb QueryBuilder) WithPodNames(podNames []string) QueryBuilder
WithPodNames adds a pod filter to the QueryBuilder (used when namespace is NOT empty)
ONLY one among WithPods, WithPodNames and WithNodes should be used ¶
Example:
podNames := []string{"pod-1", "pod-2"} queryBuilder := NewQueryBuilder(translator, metricName).WithPodNames(podNames)
func (QueryBuilder) WithPods ¶
func (qb QueryBuilder) WithPods(pods *v1.PodList) QueryBuilder
WithPods adds a pod filter to the QueryBuilder (used when namespace is NOT empty)
ONLY one among WithPods, WithPodNames and WithNodes should be used ¶
Example:
// v1 comes from "k8s.io/api/core/v1" pod := v1.Pod{ ObjectMeta: metav1.ObjectMeta{ ClusterName: "my-cluster", UID: "my-pod-id", Name: "my-pod-name", }, } queryBuilder := NewQueryBuilder(translator, metricName).WithPods(&v1.PodList{Items: []v1.Pod{pod}})
type Translator ¶
type Translator struct {
// contains filtered or unexported fields
}
Translator is a structure used to translate between Custom Metrics API and Stackdriver API
func NewFakeTranslator ¶
func NewFakeTranslator(reqWindow, alignmentPeriod time.Duration, project, cluster, location string, currentTime time.Time, useNewResourceModel bool) (*Translator, *sd.Service)
NewFakeTranslator creates a Translator for testing purposes
func NewTranslator ¶
func NewTranslator(service *stackdriver.Service, gceConf *config.GceConfig, rateInterval time.Duration, alignmentPeriod time.Duration, mapper apimeta.RESTMapper, useNewResourceModel, supportDistributions bool) *Translator
NewTranslator creates a Translator
func (*Translator) CheckMetricUniquenessForPod ¶
func (t *Translator) CheckMetricUniquenessForPod(response *stackdriver.ListTimeSeriesResponse, metricName string) error
CheckMetricUniquenessForPod checks if each pod has at most one container with given metric
func (*Translator) GetCoreContainerMetricFromResponse ¶
func (t *Translator) GetCoreContainerMetricFromResponse(response *stackdriver.ListTimeSeriesResponse) (map[string]map[string]resource.Quantity, map[string]api.TimeInfo, error)
GetCoreContainerMetricFromResponse for each pod extracts map from container name to value of metric and TimeInfo.
func (*Translator) GetCoreNodeMetricFromResponse ¶
func (t *Translator) GetCoreNodeMetricFromResponse(response *stackdriver.ListTimeSeriesResponse) (map[string]resource.Quantity, map[string]api.TimeInfo, error)
GetCoreNodeMetricFromResponse for each node extracts value of metric and TimeInfo.
func (*Translator) GetExternalMetricProject ¶
func (t *Translator) GetExternalMetricProject(metricSelector labels.Selector) (string, error)
GetExternalMetricProject If the metric has "resource.labels.project_id" as a selector, then use a different project
func (*Translator) GetExternalMetricRequest ¶
func (t *Translator) GetExternalMetricRequest(metricName, metricKind, metricValueType string, metricSelector labels.Selector) (*stackdriver.ProjectsTimeSeriesListCall, error)
GetExternalMetricRequest returns Stackdriver request for query for external metric.
func (*Translator) GetMetricKind ¶
func (t *Translator) GetMetricKind(metricName string, metricSelector labels.Selector) (string, string, error)
GetMetricKind returns metricKind for metric metricName, obtained from Stackdriver Monitoring API.
func (*Translator) GetMetricsFromSDDescriptorsResp ¶
func (t *Translator) GetMetricsFromSDDescriptorsResp(response *stackdriver.ListMetricDescriptorsResponse) []provider.CustomMetricInfo
GetMetricsFromSDDescriptorsResp returns an array of MetricInfo for all metric descriptors returned by Stackdriver API that satisfy the requirements: - valueType is "INT64" or "DOUBLE" - metric name doesn't contain "/" character after "custom.googleapis.com/" prefix
func (*Translator) GetNodeItems ¶
func (t *Translator) GetNodeItems(list *v1.NodeList) []metav1.ObjectMeta
GetNodeItems returns list Node Objects
func (*Translator) GetPodItems ¶
func (t *Translator) GetPodItems(list *v1.PodList) []metav1.ObjectMeta
GetPodItems returns list Pod Objects
func (*Translator) GetRespForExternalMetric ¶
func (t *Translator) GetRespForExternalMetric(response *stackdriver.ListTimeSeriesResponse, metricName string) ([]external_metrics.ExternalMetricValue, error)
GetRespForExternalMetric translates Stackdriver response to list of External Metrics
func (*Translator) GetRespForMultipleObjects ¶
func (t *Translator) GetRespForMultipleObjects(response *stackdriver.ListTimeSeriesResponse, list []metav1.ObjectMeta, groupResource schema.GroupResource, metricName string, metricSelector labels.Selector) ([]custom_metrics.MetricValue, error)
GetRespForMultipleObjects translates Stackdriver response to a Custom Metric associated with multiple pods.
func (*Translator) GetRespForSingleObject ¶
func (t *Translator) GetRespForSingleObject(response *stackdriver.ListTimeSeriesResponse, groupResource schema.GroupResource, metricName string, metricSelector labels.Selector, namespace string, name string) (*custom_metrics.MetricValue, error)
GetRespForSingleObject returns translates Stackdriver response to a Custom Metric associated with a single object.
func (*Translator) ListMetricDescriptors ¶
func (t *Translator) ListMetricDescriptors(fallbackForContainerMetrics bool) *stackdriver.ProjectsMetricDescriptorsListCall
ListMetricDescriptors returns Stackdriver request for all custom metrics descriptors.