Browse code

Add image metrics for push and pull

Signed-off-by: Daniel Nephin <dnephin@gmail.com>

Daniel Nephin authored on 2018/06/08 07:26:07
Showing 2 changed files
... ...
@@ -5,6 +5,7 @@ import (
5 5
 	"io"
6 6
 	"runtime"
7 7
 	"strings"
8
+	"time"
8 9
 
9 10
 	dist "github.com/docker/distribution"
10 11
 	"github.com/docker/distribution/reference"
... ...
@@ -20,6 +21,7 @@ import (
20 20
 // PullImage initiates a pull operation. image is the repository name to pull, and
21 21
 // tag may be either empty, or indicate a specific tag to pull.
22 22
 func (i *ImageService) PullImage(ctx context.Context, image, tag, os string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error {
23
+	start := time.Now()
23 24
 	// Special case: "pull -a" may send an image name with a
24 25
 	// trailing :. This is ugly, but let's not break API
25 26
 	// compatibility.
... ...
@@ -44,7 +46,9 @@ func (i *ImageService) PullImage(ctx context.Context, image, tag, os string, met
44 44
 		}
45 45
 	}
46 46
 
47
-	return i.pullImageWithReference(ctx, ref, os, metaHeaders, authConfig, outStream)
47
+	err = i.pullImageWithReference(ctx, ref, os, metaHeaders, authConfig, outStream)
48
+	imageActions.WithValues("pull").UpdateSince(start)
49
+	return err
48 50
 }
49 51
 
50 52
 func (i *ImageService) pullImageWithReference(ctx context.Context, ref reference.Named, os string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error {
... ...
@@ -3,6 +3,7 @@ package images // import "github.com/docker/docker/daemon/images"
3 3
 import (
4 4
 	"context"
5 5
 	"io"
6
+	"time"
6 7
 
7 8
 	"github.com/docker/distribution/manifest/schema2"
8 9
 	"github.com/docker/distribution/reference"
... ...
@@ -14,6 +15,7 @@ import (
14 14
 
15 15
 // PushImage initiates a push operation on the repository named localName.
16 16
 func (i *ImageService) PushImage(ctx context.Context, image, tag string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error {
17
+	start := time.Now()
17 18
 	ref, err := reference.ParseNormalizedNamed(image)
18 19
 	if err != nil {
19 20
 		return err
... ...
@@ -59,5 +61,6 @@ func (i *ImageService) PushImage(ctx context.Context, image, tag string, metaHea
59 59
 	err = distribution.Push(ctx, ref, imagePushConfig)
60 60
 	close(progressChan)
61 61
 	<-writesDone
62
+	imageActions.WithValues("push").UpdateSince(start)
62 63
 	return err
63 64
 }