Skip to content

Commit

Permalink
fixes influxdata#1987 custom docker repos with non-standard port (inf…
Browse files Browse the repository at this point in the history
…luxdata#2018)

* fixed parsing of docker image name/version

now accounts for custom docker repo's which contain a colon for a non-default port

* 1978: modifying docker test case to have a custom repo with non-standard port

* using a temp var to store index, ran gofmt

* fixes influxdata#1987, renaming iterator to 'i'
  • Loading branch information
alex-sherwin authored and Nick White committed Jan 31, 2017
1 parent 26e4ec4 commit 3876e36
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
16 changes: 10 additions & 6 deletions plugins/inputs/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,18 @@ func (d *Docker) gatherContainer(
cname = strings.TrimPrefix(container.Names[0], "/")
}

// the image name sometimes has a version part.
// ie, rabbitmq:3-management
imageParts := strings.Split(container.Image, ":")
imageName := imageParts[0]
// the image name sometimes has a version part, or a private repo
// ie, rabbitmq:3-management or docker.someco.net:4443/rabbitmq:3-management
imageName := ""
imageVersion := "unknown"
if len(imageParts) > 1 {
imageVersion = imageParts[1]
i := strings.LastIndex(container.Image, ":") // index of last ':' character
if i > -1 {
imageVersion = container.Image[i+1:]
imageName = container.Image[:i]
} else {
imageName = container.Image
}

tags := map[string]string{
"engine_host": d.engine_host,
"container_name": cname,
Expand Down
6 changes: 3 additions & 3 deletions plugins/inputs/docker/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ func (d FakeDockerClient) ContainerList(octx context.Context, options types.Cont
container2 := types.Container{
ID: "b7dfbb9478a6ae55e237d4d74f8bbb753f0817192b5081334dc78476296e2173",
Names: []string{"/etcd2"},
Image: "quay.io/coreos/etcd:v2.2.2",
Image: "quay.io:4443/coreos/etcd:v2.2.2",
Command: "/etcd -name etcd2 -advertise-client-urls http://localhost:2379 -listen-client-urls http://0.0.0.0:2379",
Created: 1455941933,
Status: "Up 4 hours",
Expand Down Expand Up @@ -429,7 +429,7 @@ func TestDockerGatherInfo(t *testing.T) {
},
map[string]string{
"container_name": "etcd2",
"container_image": "quay.io/coreos/etcd",
"container_image": "quay.io:4443/coreos/etcd",
"cpu": "cpu3",
"container_version": "v2.2.2",
"engine_host": "absol",
Expand Down Expand Up @@ -477,7 +477,7 @@ func TestDockerGatherInfo(t *testing.T) {
map[string]string{
"engine_host": "absol",
"container_name": "etcd2",
"container_image": "quay.io/coreos/etcd",
"container_image": "quay.io:4443/coreos/etcd",
"container_version": "v2.2.2",
},
)
Expand Down

0 comments on commit 3876e36

Please sign in to comment.