Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrc committed May 29, 2020
1 parent dc85d71 commit a871326
Show file tree
Hide file tree
Showing 17 changed files with 27 additions and 115 deletions.
3 changes: 1 addition & 2 deletions agent/acs/handler/payload_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,7 @@ func (payloadHandler *payloadRequestHandler) addPayloadTasks(payload *ecsacs.Pay
}

// Construct a slice with credentials acks from all tasks
var credentialsAcks []*ecsacs.IAMRoleCredentialsAckRequest
credentialsAcks = append(stoppedTasksCredentialsAcks, newTasksCredentialsAcks...)
credentialsAcks := append(stoppedTasksCredentialsAcks, newTasksCredentialsAcks...)
return credentialsAcks, allTasksOK
}

Expand Down
6 changes: 1 addition & 5 deletions agent/api/container/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,7 @@ func (c *Container) GetNextKnownStateProgression() apicontainerstatus.ContainerS
// IsInternal returns true if the container type is `ContainerCNIPause`
// or `ContainerNamespacePause`. It returns false otherwise
func (c *Container) IsInternal() bool {
if c.Type == ContainerNormal {
return false
}

return true
return c.Type != ContainerNormal
}

// IsRunning returns true if the container's known status is either RUNNING
Expand Down
9 changes: 0 additions & 9 deletions agent/api/task/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -2586,15 +2586,6 @@ func (task *Task) GetContainerIndex(containerName string) int {
return -1
}

func (task *Task) requireEnvfiles() bool {
for _, container := range task.Containers {
if container.ShouldCreateWithEnvFiles() {
return true
}
}
return false
}

func (task *Task) initializeEnvfilesResource(config *config.Config, credentialsManager credentials.Manager) error {

for _, container := range task.Containers {
Expand Down
11 changes: 10 additions & 1 deletion agent/api/task/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3434,5 +3434,14 @@ func TestRequiresEnvfiles(t *testing.T) {
Containers: []*apicontainer.Container{container},
}

assert.Equal(t, true, task.requireEnvfiles())
assert.Equal(t, true, requireEnvfiles(task))
}

func requireEnvfiles(task *Task) bool {
for _, container := range task.Containers {
if container.ShouldCreateWithEnvFiles() {
return true
}
}
return false
}
13 changes: 0 additions & 13 deletions agent/api/task/task_unsupported.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,7 @@ import (
)

const (
defaultCPUPeriod = 100 * time.Millisecond // 100ms

// With a 100ms CPU period, we can express 0.01 vCPU to 10 vCPUs
maxTaskVCPULimit = 10
// Reference: http://docs.aws.amazon.com/AmazonECS/latest/APIReference/API_ContainerDefinition.html
minimumCPUShare = 2

minimumCPUPercent = 0
bytesPerMegabyte = 1024 * 1024
)

// PlatformFields consists of fields specific to Linux for a task
Expand Down Expand Up @@ -80,11 +72,6 @@ func (task *Task) initializeCredentialSpecResource(config *config.Config, creden
return errors.New("task credentialspec is only supported on windows")
}

// getAllCredentialSpecRequirements is used to build all the credential spec requirements for the task
func (task *Task) getAllCredentialSpecRequirements() []string {
return nil
}

// GetCredentialSpecResource retrieves credentialspec resource from resource map
func (task *Task) GetCredentialSpecResource() ([]taskresource.TaskResource, bool) {
return []taskresource.TaskResource{}, false
Expand Down
2 changes: 0 additions & 2 deletions agent/api/task/taskvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ const (
HostVolumeType = "host"
DockerVolumeType = "docker"
EFSVolumeType = "efs"

efsVolumePluginCapability = "efsAuth"
)

// TaskVolume is a definition of all the volumes available for containers to
Expand Down
2 changes: 1 addition & 1 deletion agent/app/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ func TestNewTaskEngineRestoreFromCheckpointClusterIDMismatch(t *testing.T) {
_, _, err := agent.newTaskEngine(eventstream.NewEventStream("events", ctx),
credentialsManager, state, imageManager)
assert.Error(t, err)
assert.True(t, isClusterMismatch(err))
assert.IsType(t, clusterMismatchError{}, err)
}

func TestNewTaskEngineRestoreFromCheckpointNewStateManagerError(t *testing.T) {
Expand Down
5 changes: 0 additions & 5 deletions agent/app/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,3 @@ func isTransient(err error) bool {
type clusterMismatchError struct {
error
}

func isClusterMismatch(err error) bool {
_, ok := err.(clusterMismatchError)
return ok
}
15 changes: 3 additions & 12 deletions agent/dockerclient/dockerapi/docker_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,6 @@ import (

const (
dockerDefaultTag = "latest"
// imageNameFormat is the name of a image may look like: repo:tag
imageNameFormat = "%s:%s"
// the buffer size will ensure agent doesn't miss any event from docker
dockerEventBufferSize = 100
// healthCheckStarting is the initial status returned from docker container health check
healthCheckStarting = "starting"
// healthCheckHealthy is the healthy status returned from docker container health check
Expand Down Expand Up @@ -243,9 +239,6 @@ func (dg *dockerGoClient) WithVersion(version dockerclient.DockerVersion) Docker
}
}

// scratchCreateLock guards against multiple 'scratch' image creations at once
var scratchCreateLock sync.Mutex

// NewDockerGoClient creates a new DockerGoClient
// TODO Remove clientfactory parameter once migration to Docker SDK is complete.
func NewDockerGoClient(sdkclientFactory sdkclientfactory.Factory,
Expand Down Expand Up @@ -1035,15 +1028,13 @@ func (dg *dockerGoClient) listImages(ctx context.Context) ListImagesResponse {
if err != nil {
return ListImagesResponse{Error: err}
}
var imagesRepoTag []string
var imageRepoTags []string
imageIDs := make([]string, len(images))
for i, image := range images {
imageIDs[i] = image.ID
for _, imageRepoTag := range image.RepoTags {
imagesRepoTag = append(imagesRepoTag, imageRepoTag)
}
imageRepoTags = append(imageRepoTags, image.RepoTags...)
}
return ListImagesResponse{ImageIDs: imageIDs, RepoTags: imagesRepoTag, Error: nil}
return ListImagesResponse{ImageIDs: imageIDs, RepoTags: imageRepoTags, Error: nil}
}

func (dg *dockerGoClient) SupportedVersions() []dockerclient.DockerVersion {
Expand Down
1 change: 1 addition & 0 deletions agent/dockerclient/dockerapi/docker_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ const (
xMaximumPullRetryDelay = 100 * time.Microsecond
xPullRetryDelayMultiplier = 2
xPullRetryJitterMultiplier = 0.2
dockerEventBufferSize = 100
)

func defaultTestConfig() *config.Config {
Expand Down
1 change: 0 additions & 1 deletion agent/dockerclient/dockerapi/docker_events_buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ type InfiniteBuffer struct {
events []*events.Message
empty bool
waitForEvent sync.WaitGroup
count int
lock sync.RWMutex
}

Expand Down
9 changes: 0 additions & 9 deletions agent/dockerclient/sdkclientfactory/sdkclientfactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,6 @@ import (
"github.com/pkg/errors"
)

const (
// minAPIVersionKey is the docker.Env key for min API version
// This is supported in Docker API versions >=1.25
// https://docs.docker.com/engine/api/version-history/#v125-api-changes
minAPIVersionKey = "MinAPIVersion"
// apiVersionKey is the docker.Env key for API version
apiVersionKey = "ApiVersion"
)

// Factory provides a collection of docker remote clients that include a
// recommended client version as well as a set of alternative supported
// docker clients.
Expand Down
5 changes: 0 additions & 5 deletions agent/ecscni/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,6 @@ func (client *cniClient) SetupNS(
timeout time.Duration) (*current.Result, error) {
ctx, cancel := context.WithTimeout(ctx, timeout)
defer cancel()

type output struct {
result *current.Result
err error
}
return client.setupNS(ctx, cfg)
}

Expand Down
6 changes: 6 additions & 0 deletions agent/stats/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,12 @@ func init() {
cfg.ImagePullBehavior = config.ImagePullPreferCachedBehavior
}

// parseNanoTime returns the time object from a string formatted with RFC3339Nano layout.
func parseNanoTime(value string) time.Time {
ts, _ := time.Parse(time.RFC3339Nano, value)
return ts
}

// eventStream returns the event stream used to receive container change events
func eventStream(name string) *eventstream.EventStream {
eventStream := eventstream.NewEventStream(name, context.Background())
Expand Down
19 changes: 4 additions & 15 deletions agent/stats/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,13 +205,10 @@ func (engine *DockerStatsEngine) Disable() {
// waitToStop waits for the container change event stream close ans stop collection metrics
func (engine *DockerStatsEngine) waitToStop() {
// Waiting for the event stream to close
ctx := engine.containerChangeEventStream.Context()
select {
case <-ctx.Done():
seelog.Debug("Event stream closed, stop listening to the event stream")
engine.containerChangeEventStream.Unsubscribe(containerChangeHandler)
engine.removeAll()
}
<-engine.containerChangeEventStream.Context().Done()
seelog.Debug("Event stream closed, stop listening to the event stream")
engine.containerChangeEventStream.Unsubscribe(containerChangeHandler)
engine.removeAll()
}

// removeAll stops the periodic usage data collection for all containers
Expand Down Expand Up @@ -686,11 +683,3 @@ func (engine *DockerStatsEngine) ContainerDockerStats(taskARN string, containerI
}
return container.statsQueue.GetLastStat(), nil
}

// newMetricsMetadata creates the singleton metadata object.
func newMetricsMetadata(cluster *string, containerInstance *string) *ecstcs.MetricsMetadata {
return &ecstcs.MetricsMetadata{
Cluster: cluster,
ContainerInstance: containerInstance,
}
}
21 changes: 0 additions & 21 deletions agent/stats/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,8 @@ package stats

import (
"math"
"regexp"
"runtime"
"time"

"github.com/cihub/seelog"
"github.com/docker/docker/api/types"
)

Expand All @@ -34,24 +31,6 @@ func nan32() float32 {
return (float32)(math.NaN())
}

// parseNanoTime returns the time object from a string formatted with RFC3339Nano layout.
func parseNanoTime(value string) time.Time {
ts, _ := time.Parse(time.RFC3339Nano, value)
return ts
}

// isNetworkStatsError returns if the error indicates that files in /sys/class/net
// could not be opened.
func isNetworkStatsError(err error) bool {
matched, mErr := regexp.MatchString(networkStatsErrorPattern, err.Error())
if mErr != nil {
seelog.Debugf("Error matching string: %v", mErr)
return false
}

return matched
}

func getNetworkStats(dockerStats *types.StatsJSON) *NetworkStats {
if dockerStats.Networks == nil {
return nil
Expand Down
14 changes: 0 additions & 14 deletions agent/stats/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,6 @@ const (
expectedTxErrors = uint64(0)
)

func TestIsNetworkStatsError(t *testing.T) {
isNetStatsErr := isNetworkStatsError(fmt.Errorf("no such file or directory"))
if isNetStatsErr {
// Expect it to not be a net stats error
t.Error("Error incorrectly reported as network stats error")
}

isNetStatsErr = isNetworkStatsError(fmt.Errorf("open /sys/class/net/veth2f5f3e4/statistics/tx_bytes: no such file or directory"))
if !isNetStatsErr {
// Expect this to be a net stats error
t.Error("Error incorrectly reported as non network stats error")
}
}

func TestDockerStatsToContainerStatsMemUsage(t *testing.T) {
jsonStat := fmt.Sprintf(`
{
Expand Down

0 comments on commit a871326

Please sign in to comment.