blob: 31ce625adb3547557608709f992060ef2490ee60 [file] [log] [blame]
Matthias Andreas Benkard832a54e2019-01-29 09:27:38 +01001// Copyright 2018 The Kubernetes Authors.
2//
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//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15package provider
16
17import (
18 "time"
19
20 corev1 "k8s.io/api/core/v1"
21 apitypes "k8s.io/apimachinery/pkg/types"
22 metrics "k8s.io/metrics/pkg/apis/metrics"
23)
24
25// MetricsProvider is both a PodMetricsProvider and a NodeMetricsProvider
26type MetricsProvider interface {
27 PodMetricsProvider
28 NodeMetricsProvider
29}
30
31// TimeSpan represents the timing information for a metric, which was
32// potentially calculated over some window of time (e.g. for CPU usage rate).
33type TimeInfo struct {
34 // NB: we consider the earliest timestamp amongst multiple containers
35 // for the purposes of determining if a metric is tained by a time
36 // period, like pod startup (used by things like the HPA).
37
38 // Timestamp is the time at which the metrics were initially collected.
39 // In the case of a rate metric, it should be the timestamp of the last
40 // data point used in the calculation. If it represents multiple metric
41 // points, it should be the earliest such timestamp from all of the points.
42 Timestamp time.Time
43
44 // Window represents the window used to calculate rate metrics associated
45 // with this timestamp.
46 Window time.Duration
47}
48
49// PodMetricsProvider knows how to fetch metrics for the containers in a pod.
50type PodMetricsProvider interface {
51 // GetContainerMetrics gets the latest metrics for all containers in each listed pod,
52 // returning both the metrics and the associated collection timestamp.
53 // If a pod is missing, the container metrics should be nil for that pod.
54 GetContainerMetrics(pods ...apitypes.NamespacedName) ([]TimeInfo, [][]metrics.ContainerMetrics, error)
55}
56
57// NodeMetricsProvider knows how to fetch metrics for a node.
58type NodeMetricsProvider interface {
59 // GetNodeMetrics gets the latest metrics for the given nodes,
60 // returning both the metrics and the associated collection timestamp.
61 // If a node is missing, the resourcelist should be nil for that node.
62 GetNodeMetrics(nodes ...string) ([]TimeInfo, []corev1.ResourceList, error)
63}