This repository has been archived by the owner on Apr 2, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 525
Add decoder for Docker Fluentd [wip] #1666
Open
carlanton
wants to merge
2
commits into
mozilla-services:dev
Choose a base branch
from
carlanton:fluent-docker
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.. _config_docker_fluentd_decoder: | ||
|
||
Docker Fluentd Decoder | ||
=================================== | ||
|
||
.. versionadded:: 0.10 | ||
|
||
| Plugin Name: **SandboxDecoder** | ||
| File Name: **lua_decoders/docker_fluentd.lua** | ||
|
||
.. include:: /../../sandbox/lua/decoders/docker_fluentd.lua | ||
:start-after: --[[ | ||
:end-before: --]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
-- This Source Code Form is subject to the terms of the Mozilla Public | ||
-- License, v. 2.0. If a copy of the MPL was not distributed with this | ||
-- file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
|
||
--[[ | ||
Decode data from Docker's Fluentd logging driver. | ||
|
||
**Note**: The Fluentd logging driver is available in Docker 1.8.0rc1 and later. | ||
|
||
Config: | ||
|
||
- type (string, optional, default nil): | ||
Sets the message 'Type' header to the specified value | ||
|
||
*Example Heka Configuration* | ||
|
||
.. code-block:: ini | ||
|
||
[FluentdInput] | ||
type = "TcpInput" | ||
address = ":24224" | ||
splitter = "MessagePackSplitter" | ||
decoder = "DockerFluentdDecoder" | ||
|
||
[MessagePackSplitter] | ||
# No config | ||
|
||
[DockerFluentdDecoder] | ||
type = "SandboxDecoder" | ||
filename = "lua_decoders/docker_fluentd.lua" | ||
|
||
[DockerFluentdDecoder.config] | ||
type = "docker-fluentd" | ||
|
||
*Example Heka Message* | ||
|
||
.. code-block:: bash | ||
|
||
docker run \ | ||
--log-driver fluentd \ | ||
--log-opt fluentd-address=YOUR_HEKA:24224 \ | ||
-d busybox \ | ||
echo Hello world | ||
|
||
This command should generate something like this: | ||
|
||
:Timestamp: 2015-08-03 20:41:06 +0000 UTC | ||
:Type: docker-fluentd | ||
:Hostname: 192.168.59.103:60088 | ||
:Pid: 0 | ||
:Uuid: da45d947-037d-4870-abbe-671d820ebe8d | ||
:Logger: stdout | ||
:Payload: Hello world | ||
:EnvVersion: | ||
:Severity: 7 | ||
:Fields: | ||
| name:"container_name" type:string value:"/suspicious_meitner" | ||
| name:"tag" type:string value:"docker.7dc19982364b" | ||
| name:"container_id" type:string value:"7dc19982364ba459958041d2fe85e8bdc3825d06397296ddd981c51e5f15cb89" | ||
|
||
--]] | ||
|
||
local mp = require "msgpack" | ||
|
||
local msg_type = read_config("type") | ||
|
||
local msg = { | ||
Timestamp = nil, | ||
EnvVersion = nil, | ||
-- Hostname = nil, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably keep this value in the table and explicitly propagate the incoming message's Hostname value since in case the input has already set it to a useful value by the time splitting happens. |
||
Type = msg_type, | ||
Payload = nil, | ||
Fields = nil, | ||
Severity = nil | ||
} | ||
|
||
-- Unpack and validate Fluentd message pack | ||
function decode(mpac) | ||
local ok, data = pcall(mp.unpack, mpac) | ||
if not ok then | ||
return "MessagePack decode error" | ||
end | ||
|
||
if type(data) ~= "table" then | ||
return "Wrong format" | ||
end | ||
|
||
tag, timestamp, record = unpack(data) | ||
|
||
if type(tag) ~= "string" or type(timestamp) ~= "number" or type(record) ~= "table" then | ||
return "Wrong format" | ||
end | ||
|
||
return nil, tag, timestamp, record | ||
end | ||
|
||
|
||
function process_message() | ||
err, tag, timestamp, record = decode(read_message("Payload")) | ||
if err ~= nil then return -1, err end | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here's where you'd add |
||
msg.Timestamp = timestamp * 1e9 | ||
msg.Payload = record["log"] | ||
msg.Logger = record["source"] | ||
record["source"] = nil | ||
record["log"] = nil | ||
|
||
record["tag"] = tag | ||
msg.Fields = record | ||
|
||
if not pcall(inject_message, msg) then return -1 end | ||
return 0 | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UseMsgBytes config option is automatically supported by Heka for every splitter, and you're not changing the default, so I don't think there's any reason for you to have a UseMsgBytes option. Which in turn means you don't even need a custom config struct.