Skip to content

Commit

Permalink
Merge pull request kubernetes#45614 from yujuhong/container-metrics
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 45809, 46515, 46484, 46516, 45614)

CRI: add methods for container stats

**What this PR does / why we need it**:
Define methods in CRI to get container stats.

**Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: 
Part of  kubernetes/enhancements#290; addresses kubernetes#27097

**Special notes for your reviewer**:
This PR defines the *minimum required* container metrics for the existing components to function, loosely based on the previous discussion on [core metrics](https://github.com/kubernetes/community/blob/master/contributors/design-proposals/core-metrics-pipeline.md) as well as the existing cadvisor/summary APIs.
 
Two new RPC calls are added to the RuntimeService: `ContainerStats` and `ListContainerStats`. The former retrieves stats for a given container, while the latter gets stats for all containers in one call.
 
The stats gathering time of each subsystem can vary substantially (e.g., cpu vs. disk), so even though the on-demand model preferred due to its simplicity, we’d rather give the container runtime more flexibility to determine the collection frequency for each subsystem*. As a trade-off, each piece of stats for the subsystem must contain a timestamp to let kubelet know how fresh/recent the stats are. In the future, we should also recommend a guideline for how recent the stats should be in order to ensure the reliability (e.g., eviction) and the responsiveness (e.g., autoscaling) of the kubernetes cluster.
 
The next step is to plumb this through kubelet so that kubelet can choose consume container stats from CRI or cadvisor. 
 
**Alternatively, we can add calls to get stats of individual subsystems. However, kubelet does not have the complete knowledge of the runtime environment, so this would only lead to unnecessary complexity in kubelet.*


**Release note**:

```release-note
Augment CRI to support retrieving container stats from the runtime.
```
  • Loading branch information
Kubernetes Submit Queue committed May 26, 2017
2 parents 71e0204 + 417e9c8 commit e903c58
Show file tree
Hide file tree
Showing 12 changed files with 7,558 additions and 5,231 deletions.
13 changes: 12 additions & 1 deletion pkg/kubelet/apis/cri/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,23 @@ type PodSandboxManager interface {
PortForward(*runtimeapi.PortForwardRequest) (*runtimeapi.PortForwardResponse, error)
}

// ContainerStatsManager contains methods for retriving the container
// statistics.
type ContainerStatsManager interface {
// ContainerStats returns stats of the container. If the container does not
// exist, the call returns an error.
ContainerStats(req *runtimeapi.ContainerStatsRequest) (*runtimeapi.ContainerStatsResponse, error)
// ListContainerStats returns stats of all running containers.
ListContainerStats(req *runtimeapi.ListContainerStatsRequest) (*runtimeapi.ListContainerStatsResponse, error)
}

// RuntimeService interface should be implemented by a container runtime.
// The methods should be thread-safe.
type RuntimeService interface {
RuntimeVersioner
ContainerManager
PodSandboxManager
ContainerStatsManager

// UpdateRuntimeConfig updates runtime configuration if specified
UpdateRuntimeConfig(runtimeConfig *runtimeapi.RuntimeConfig) error
Expand All @@ -98,5 +109,5 @@ type ImageManagerService interface {
// RemoveImage removes the image.
RemoveImage(image *runtimeapi.ImageSpec) error
// ImageFsInfo returns information of the filesystem that is used to store images.
ImageFsInfo() (*runtimeapi.FsInfo, error)
ImageFsInfo(req *runtimeapi.ImageFsInfoRequest) (*runtimeapi.ImageFsInfoResponse, error)
}
2 changes: 1 addition & 1 deletion pkg/kubelet/apis/cri/testing/fake_image_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (r *FakeImageService) RemoveImage(image *runtimeapi.ImageSpec) error {
}

// ImageFsInfo returns information of the filesystem that is used to store images.
func (r *FakeImageService) ImageFsInfo() (*runtimeapi.FsInfo, error) {
func (r *FakeImageService) ImageFsInfo(req *runtimeapi.ImageFsInfoRequest) (*runtimeapi.ImageFsInfoResponse, error) {
r.Lock()
defer r.Unlock()

Expand Down
8 changes: 8 additions & 0 deletions pkg/kubelet/apis/cri/testing/fake_runtime_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,3 +389,11 @@ func (r *FakeRuntimeService) Attach(req *runtimeapi.AttachRequest) (*runtimeapi.
func (r *FakeRuntimeService) UpdateRuntimeConfig(runtimeCOnfig *runtimeapi.RuntimeConfig) error {
return nil
}

func (r *FakeRuntimeService) ContainerStats(req *runtimeapi.ContainerStatsRequest) (*runtimeapi.ContainerStatsResponse, error) {
return nil, fmt.Errorf("Not implemented")
}

func (r *FakeRuntimeService) ListContainerStats(req *runtimeapi.ListContainerStatsRequest) (*runtimeapi.ListContainerStatsResponse, error) {
return nil, fmt.Errorf("Not implemented")
}
Loading

0 comments on commit e903c58

Please sign in to comment.