mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Updated AWS logstream to understand tags
Signed-off-by: French Ben <frenchben@docker.com>
This commit is contained in:
parent
02bc2e652b
commit
3661510f7f
2 changed files with 39 additions and 1 deletions
|
@ -19,6 +19,7 @@ import (
|
|||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/daemon/logger/loggerutils"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
)
|
||||
|
||||
|
@ -28,6 +29,7 @@ const (
|
|||
regionEnvKey = "AWS_REGION"
|
||||
logGroupKey = "awslogs-group"
|
||||
logStreamKey = "awslogs-stream"
|
||||
tagKey = "tag"
|
||||
batchPublishFrequency = 5 * time.Second
|
||||
|
||||
// See: http://docs.aws.amazon.com/AmazonCloudWatchLogs/latest/APIReference/API_PutLogEvents.html
|
||||
|
@ -88,7 +90,11 @@ func init() {
|
|||
// the EC2 Instance Metadata Service.
|
||||
func New(ctx logger.Context) (logger.Logger, error) {
|
||||
logGroupName := ctx.Config[logGroupKey]
|
||||
logStreamName := ctx.ContainerID
|
||||
logStreamName, err := loggerutils.ParseLogTag(ctx, "{{.FullID}}")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if ctx.Config[logStreamKey] != "" {
|
||||
logStreamName = ctx.Config[logStreamKey]
|
||||
}
|
||||
|
@ -350,6 +356,7 @@ func ValidateLogOpt(cfg map[string]string) error {
|
|||
case logGroupKey:
|
||||
case logStreamKey:
|
||||
case regionKey:
|
||||
case tagKey:
|
||||
default:
|
||||
return fmt.Errorf("unknown log opt '%s' for %s log driver", key, name)
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import (
|
|||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/daemon/logger/loggerutils"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
)
|
||||
|
||||
|
@ -691,3 +692,33 @@ func TestCollectBatchWithDuplicateTimestamps(t *testing.T) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateTagSuccess(t *testing.T) {
|
||||
mockClient := newMockClient()
|
||||
ctx := logger.Context{
|
||||
ContainerName: "/test-container",
|
||||
ContainerID: "container-abcdefghijklmnopqrstuvwxyz01234567890",
|
||||
Config: map[string]string{"tag": "{{.Name}}/{{.FullID}}"},
|
||||
}
|
||||
logStreamName, e := loggerutils.ParseLogTag(ctx, loggerutils.DefaultTemplate)
|
||||
if e != nil {
|
||||
t.Errorf("Error generating tag: %q", e)
|
||||
}
|
||||
stream := &logStream{
|
||||
client: mockClient,
|
||||
logGroupName: groupName,
|
||||
logStreamName: logStreamName,
|
||||
}
|
||||
mockClient.createLogStreamResult <- &createLogStreamResult{}
|
||||
|
||||
err := stream.create()
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("Received unexpected err: %v\n", err)
|
||||
}
|
||||
argument := <-mockClient.createLogStreamArgument
|
||||
|
||||
if *argument.LogStreamName != "test-container/container-abcdefghijklmnopqrstuvwxyz01234567890" {
|
||||
t.Errorf("Expected LogStreamName to be %s", "test-container/container-abcdefghijklmnopqrstuvwxyz01234567890")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue