Skip to content

Commit

Permalink
kubelet/metrics: Move instrumented_docker.go to dockertools.
Browse files Browse the repository at this point in the history
This can solve the circular import problem when we move the
kubelet.pullImage to dockertools or container package.
  • Loading branch information
Yifan Gu committed Apr 25, 2015
1 parent c3ce410 commit 1a98dd6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,21 @@ See the License for the specific language governing permissions and
limitations under the License.
*/

package metrics
package dockertools

import (
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/dockertools"
docker "github.com/fsouza/go-dockerclient"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/metrics"
"github.com/fsouza/go-dockerclient"
)

var _ dockertools.DockerInterface = instrumentedDockerInterface{}

type instrumentedDockerInterface struct {
client dockertools.DockerInterface
client DockerInterface
}

// Creates an instrumented DockerInterface from an existing DockerInterface.
func NewInstrumentedDockerInterface(dockerClient dockertools.DockerInterface) dockertools.DockerInterface {
func NewInstrumentedDockerInterface(dockerClient DockerInterface) DockerInterface {
return instrumentedDockerInterface{
client: dockerClient,
}
Expand All @@ -39,119 +37,119 @@ func NewInstrumentedDockerInterface(dockerClient dockertools.DockerInterface) do
func (in instrumentedDockerInterface) ListContainers(options docker.ListContainersOptions) ([]docker.APIContainers, error) {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("list_containers").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("list_containers").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.ListContainers(options)
}

func (in instrumentedDockerInterface) InspectContainer(id string) (*docker.Container, error) {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("inspect_container").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("inspect_container").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.InspectContainer(id)
}

func (in instrumentedDockerInterface) CreateContainer(opts docker.CreateContainerOptions) (*docker.Container, error) {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("create_container").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("create_container").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.CreateContainer(opts)
}

func (in instrumentedDockerInterface) StartContainer(id string, hostConfig *docker.HostConfig) error {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("start_container").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("start_container").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.StartContainer(id, hostConfig)
}

func (in instrumentedDockerInterface) StopContainer(id string, timeout uint) error {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("stop_container").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("stop_container").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.StopContainer(id, timeout)
}

func (in instrumentedDockerInterface) RemoveContainer(opts docker.RemoveContainerOptions) error {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("remove_container").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("remove_container").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.RemoveContainer(opts)
}

func (in instrumentedDockerInterface) InspectImage(image string) (*docker.Image, error) {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("inspect_image").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("inspect_image").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.InspectImage(image)
}

func (in instrumentedDockerInterface) ListImages(opts docker.ListImagesOptions) ([]docker.APIImages, error) {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("list_images").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("list_images").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.ListImages(opts)
}

func (in instrumentedDockerInterface) PullImage(opts docker.PullImageOptions, auth docker.AuthConfiguration) error {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("pull_image").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("pull_image").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.PullImage(opts, auth)
}

func (in instrumentedDockerInterface) RemoveImage(image string) error {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("remove_image").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("remove_image").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.RemoveImage(image)
}

func (in instrumentedDockerInterface) Logs(opts docker.LogsOptions) error {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("logs").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("logs").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.Logs(opts)
}

func (in instrumentedDockerInterface) Version() (*docker.Env, error) {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("version").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("version").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.Version()
}

func (in instrumentedDockerInterface) Info() (*docker.Env, error) {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("version").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("version").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.Info()
}

func (in instrumentedDockerInterface) CreateExec(opts docker.CreateExecOptions) (*docker.Exec, error) {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("create_exec").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("create_exec").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.CreateExec(opts)
}

func (in instrumentedDockerInterface) StartExec(startExec string, opts docker.StartExecOptions) error {
start := time.Now()
defer func() {
DockerOperationsLatency.WithLabelValues("start_exec").Observe(SinceInMicroseconds(start))
metrics.DockerOperationsLatency.WithLabelValues("start_exec").Observe(metrics.SinceInMicroseconds(start))
}()
return in.client.StartExec(startExec, opts)
}
2 changes: 1 addition & 1 deletion pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ func NewMainKubelet(
if resyncInterval <= 0 {
return nil, fmt.Errorf("invalid sync frequency %d", resyncInterval)
}
dockerClient = metrics.NewInstrumentedDockerInterface(dockerClient)
dockerClient = dockertools.NewInstrumentedDockerInterface(dockerClient)

// Wait for the Docker daemon to be up (with a timeout).
waitStart := time.Now()
Expand Down

0 comments on commit 1a98dd6

Please sign in to comment.