Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker Log Plugin #4360

Closed
wants to merge 6 commits into from
Closed

Docker Log Plugin #4360

wants to merge 6 commits into from

Conversation

prashanthjbabu
Copy link
Contributor

@prashanthjbabu prashanthjbabu commented Jun 29, 2018

Resolves #1483

This PR introduces a telegraf plugin to get docker logs . Sample output :

docker_log,containerId=4325333a47ab42c78b8bf5cb01d5b0972321f857a4b9e116856b4f0459047077,host=prash-laptop log=" root@4325333a47ab:/# ls -l\r\n" 1530162134000000000 docker_log,containerId=4325333a47ab42c78b8bf5cb01d5b0972321f857a4b9e116856b4f0459047077,host=prash-laptop log=" total 64\r\n drwxr-xr-x 2 root root 4096 May 26 00:45 bin\r\n drwxr-xr-x 2 root root 4096 Apr 24 08:34 boot\r\n drwxr-xr-x 5 root root 360 Jun 28 05:01 dev\r\n drwxr-xr-x 1 root root 4096 Jun 28 05:01 etc\r\n drwxr-xr-x 2 root root 4096 Apr 24 08:34 home\r\n drwxr-xr-x 8 root root 4096 May 26 00:44 lib\r\n drwxr-xr-x 2 root root 4096 May 26 00:44 lib64\r\n drwxr-xr-x 2 root root 4096 May 26 00:44 media\r\n drwxr-xr-x 2 root root 4096 May 26 00:44 mnt\r\n" 1530162134000000000

The plugin is a Telegraf service input plugin which creates a new goroutine for every running container and listens for the log stream using the docker engine APIs . Whenever it gets data from the stream it pushes it out with tags.

Required for all PRs:

  • Signed CLA.
  • Associated README.md updated.
  • Has appropriate unit tests.

@Puneeth-n
Copy link

Any idea when this plugin would be available? @prashanthjbabu Awesome work here :)

@prashanthjbabu
Copy link
Contributor Author

@Puneeth-n Thank you :) !

@ytzelf
Copy link

ytzelf commented Sep 25, 2018

Any ETA on merging? That'd be brilliant. Thanks a lot for PR

Copy link
Contributor

@glinton glinton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution!

## Only collect metrics for these containers. Values will be appended to
## container_name_include.
## Deprecated (1.4.0), use container_name_include
container_names = []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this config option as there isn't much value in replicating deprecated options from the docker plugin.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken care of this!


- docker_log
- tags:
- containerId
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe container_name, as it would match the docker plugin better and be more human friendly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added containerName and kept containerId as well just incase it is used for matching

}

func NewEnvClient() (Client, error) {
client, err := docker.NewEnvClient()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Technically this is deprecated and should be NewClientWithOpts(FromEnv)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken care of this!

sockets.ConfigureTransport(transport, proto, addr)
httpClient := &http.Client{Transport: transport}

client, err := docker.NewClient(host, version, httpClient, defaultHeaders)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NewClient is also deprecated in favor of NewClientWithOpts

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken care of this!


type DockerLogs struct {
Endpoint string
ContainerNames []string // deprecated in 1.4; use container_name_include
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove ContainerNames

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken care of this!

ctx, cancel := context.WithTimeout(context.Background(), d.Timeout.Duration)
defer cancel()
if d.client == nil {
log.Println("ERR:Dock client is null")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use telegraf error logging syntax - E! Error to log

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken care of this!

}

func (d *DockerLogs) addToContainerList(containerId string, logReader io.ReadCloser) error {
d.containerList[containerId] = logReader
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should lock around the read/writes of this map

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken care of this!

}
}
}
func (d *DockerLogs) Start(acc telegraf.Accumulator) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a newline before this function

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken care of this!

}
return err
}
if len(data) > 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just check if num > 0

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taken care of this!

@glinton glinton added this to the 1.9.0 milestone Sep 28, 2018
@prashanthjbabu
Copy link
Contributor Author

Hi glinton,
Thanks for taking the time to review this ! Unfortunately I've lost the original branch in my github account , therefore I had to recreate it with a new PR. The new PR can be found at #4773 . Commits till 447235b are identical to the old PR . I've added a new commit 82ec26d to address the changes you requested.
Thanks,
Prashanth

@prashanthjbabu prashanthjbabu mentioned this pull request Sep 29, 2018
3 tasks
@glinton
Copy link
Contributor

glinton commented Oct 1, 2018

Closing in favor of #4773

@glinton glinton closed this Oct 1, 2018
@russorat russorat removed this from the 1.9.0 milestone Oct 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants