Move container log definition to container class

This commit is contained in:
Onur Filiz
2018-04-25 00:38:14 -07:00
committed by Robbie Zhang
parent 345b53d816
commit 22bafee6a8
2 changed files with 30 additions and 14 deletions

View File

@@ -1,6 +1,7 @@
package fargate
import (
"fmt"
"time"
"github.com/aws/aws-sdk-go/aws"
@@ -18,6 +19,11 @@ const (
containerStatusRunning = "RUNNING"
containerStatusStopped = "STOPPED"
// Container log configuration options.
containerLogOptionRegion = "awslogs-region"
containerLogOptionGroup = "awslogs-group"
containerLogOptionStreamPrefix = "awslogs-stream-prefix"
// Default container resource limits.
containerDefaultCPULimit = VCPU / 4
containerDefaultMemoryLimit = 512 * MiB
@@ -65,6 +71,21 @@ func newContainerFromDefinition(def *ecs.ContainerDefinition, startTime *time.Ti
return &cntr, nil
}
// ConfigureLogs configures container logs to be sent to the given CloudWatch log group.
func (cntr *container) configureLogs(region string, logGroupName string, streamPrefix string) {
streamPrefix = fmt.Sprintf("%s_%s", streamPrefix, *cntr.definition.Name)
// Fargate requires awslogs log driver.
cntr.definition.LogConfiguration = &ecs.LogConfiguration{
LogDriver: aws.String(ecs.LogDriverAwslogs),
Options: map[string]*string{
containerLogOptionRegion: aws.String(region),
containerLogOptionGroup: aws.String(logGroupName),
containerLogOptionStreamPrefix: aws.String(streamPrefix),
},
}
}
// GetStatus returns the status of a container running in Fargate.
func (cntr *container) getStatus(runtimeState *ecs.Container) corev1.ContainerStatus {
var reason string