interfaces.go 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package metrics
  14. import (
  15. "time"
  16. autoscaling "k8s.io/api/autoscaling/v2beta2"
  17. "k8s.io/api/core/v1"
  18. "k8s.io/apimachinery/pkg/labels"
  19. )
  20. // PodMetric contains pod metric value (the metric values are expected to be the metric as a milli-value)
  21. type PodMetric struct {
  22. Timestamp time.Time
  23. Window time.Duration
  24. Value int64
  25. }
  26. // PodMetricsInfo contains pod metrics as a map from pod names to PodMetricsInfo
  27. type PodMetricsInfo map[string]PodMetric
  28. // MetricsClient knows how to query a remote interface to retrieve container-level
  29. // resource metrics as well as pod-level arbitrary metrics
  30. type MetricsClient interface {
  31. // GetResourceMetric gets the given resource metric (and an associated oldest timestamp)
  32. // for all pods matching the specified selector in the given namespace
  33. GetResourceMetric(resource v1.ResourceName, namespace string, selector labels.Selector) (PodMetricsInfo, time.Time, error)
  34. // GetRawMetric gets the given metric (and an associated oldest timestamp)
  35. // for all pods matching the specified selector in the given namespace
  36. GetRawMetric(metricName string, namespace string, selector labels.Selector, metricSelector labels.Selector) (PodMetricsInfo, time.Time, error)
  37. // GetObjectMetric gets the given metric (and an associated timestamp) for the given
  38. // object in the given namespace
  39. GetObjectMetric(metricName string, namespace string, objectRef *autoscaling.CrossVersionObjectReference, metricSelector labels.Selector) (int64, time.Time, error)
  40. // GetExternalMetric gets all the values of a given external metric
  41. // that match the specified selector.
  42. GetExternalMetric(metricName string, namespace string, selector labels.Selector) ([]int64, time.Time, error)
  43. }