1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Use a regex to match environment variables #27565

Signed-off-by: Joseph Rothrock <rothrock@rothrock.org>
This commit is contained in:
Joseph Rothrock 2016-11-08 16:34:47 -08:00
parent e1c5e72902
commit 9758a2a724
11 changed files with 89 additions and 34 deletions

View file

@ -39,6 +39,7 @@ const (
splunkGzipCompressionKey = "splunk-gzip"
splunkGzipCompressionLevelKey = "splunk-gzip-level"
envKey = "env"
envRegexKey = "env-regex"
labelsKey = "labels"
tagKey = "tag"
)
@ -235,7 +236,10 @@ func New(info logger.Info) (logger.Logger, error) {
}
}
attrs := info.ExtraAttributes(nil)
attrs, err := info.ExtraAttributes(nil)
if err != nil {
return nil, err
}
var (
postMessagesFrequency = getAdvancedOptionDuration(envVarPostMessagesFrequency, defaultPostMessagesFrequency)
@ -538,6 +542,7 @@ func ValidateLogOpt(cfg map[string]string) error {
case splunkGzipCompressionKey:
case splunkGzipCompressionLevelKey:
case envKey:
case envRegexKey:
case labelsKey:
case tagKey:
default:

View file

@ -25,9 +25,10 @@ func TestValidateLogOpt(t *testing.T) {
splunkVerifyConnectionKey: "true",
splunkGzipCompressionKey: "true",
splunkGzipCompressionLevelKey: "1",
envKey: "a",
labelsKey: "b",
tagKey: "c",
envKey: "a",
envRegexKey: "^foo",
labelsKey: "b",
tagKey: "c",
})
if err != nil {
t.Fatal(err)
@ -215,8 +216,9 @@ func TestInlineFormatWithNonDefaultOptions(t *testing.T) {
splunkIndexKey: "myindex",
splunkFormatKey: splunkFormatInline,
splunkGzipCompressionKey: "true",
tagKey: "{{.ImageName}}/{{.Name}}",
labelsKey: "a",
tagKey: "{{.ImageName}}/{{.Name}}",
labelsKey: "a",
envRegexKey: "^foo",
},
ContainerID: "containeriid",
ContainerName: "/container_name",
@ -225,6 +227,7 @@ func TestInlineFormatWithNonDefaultOptions(t *testing.T) {
ContainerLabels: map[string]string{
"a": "b",
},
ContainerEnv: []string{"foo_finder=bar"},
}
hostname, err := info.Hostname()
@ -295,6 +298,7 @@ func TestInlineFormatWithNonDefaultOptions(t *testing.T) {
event["source"] != "stdout" ||
event["tag"] != "container_image_name/container_name" ||
event["attrs"].(map[string]interface{})["a"] != "b" ||
event["attrs"].(map[string]interface{})["foo_finder"] != "bar" ||
len(event) != 4 {
t.Fatalf("Unexpected event in message %v", event)
}