Skip to content

Commit

Permalink
Move appnet client interface to ecs-agent (#3827)
Browse files Browse the repository at this point in the history
* Move appnet client lib to ecs-agent

* Removed updated version on dependencies in go.mod for agent and ecs-agent

* appnet client: changes for shared lib

* appnet client: shared lib

* appnet client: shared lib

* appnet client: new mocks

* appnet client: new mocks

* appnet client: add generate_mocks to agent vendor

* appnet client: remove arguments passed to createclient

* appnet client: updated api mock

* appnet client: Fix name on service_connect_linux

* Remove ECSTaskProtectionSDK from interface.go

* Update mocks

* AppnetClient: Updated interface to remove appnet

* Updated api mocks

* Fix go imports

* AppnetClient: Update files in vendor dir

* AppnetClient: Update import for mock appnet client

* Test fix

---------

Co-authored-by: Richa Gangwar <ricgang@amazon.com>
  • Loading branch information
2 people authored and chienhanlin committed Aug 8, 2023
1 parent c5e0e5c commit 52a6991
Show file tree
Hide file tree
Showing 19 changed files with 190 additions and 95 deletions.
2 changes: 1 addition & 1 deletion agent/api/generate_mocks.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

package api

//go:generate mockgen -destination=mocks/api_mocks.go -copyright_file=../../scripts/copyright_file github.com/aws/amazon-ecs-agent/agent/api ECSSDK,ECSSubmitStateSDK,ECSClient,AppnetClient
//go:generate mockgen -destination=mocks/api_mocks.go -copyright_file=../../scripts/copyright_file github.com/aws/amazon-ecs-agent/agent/api ECSSDK,ECSSubmitStateSDK,ECSClient
8 changes: 0 additions & 8 deletions agent/api/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ package api

import (
"github.com/aws/amazon-ecs-agent/ecs-agent/ecs_client/model/ecs"
prometheus "github.com/prometheus/client_model/go"
)

// ECSClient is an interface over the ECSSDK interface which abstracts away some
Expand Down Expand Up @@ -77,10 +76,3 @@ type ECSSubmitStateSDK interface {
SubmitTaskStateChange(*ecs.SubmitTaskStateChangeInput) (*ecs.SubmitTaskStateChangeOutput, error)
SubmitAttachmentStateChanges(*ecs.SubmitAttachmentStateChangesInput) (*ecs.SubmitAttachmentStateChangesOutput, error)
}

// AppnetClient is an interface with customized Appnet client that
// implements the GetStats and DrainInboundConnections
type AppnetClient interface {
GetStats(adminSocketPath string, statsRequest string) (map[string]*prometheus.MetricFamily, error)
DrainInboundConnections(adminSocketPath string, drainRequest string) error
}
55 changes: 1 addition & 54 deletions agent/api/mocks/api_mocks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions agent/engine/docker_task_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ type DockerTaskEngine struct {
client dockerapi.DockerClient
dataClient data.Client
cniClient ecscni.CNIClient
appnetClient api.AppnetClient
appnetClient appnet.AppNetClient

containerChangeEventStream *eventstream.EventStream

Expand Down Expand Up @@ -226,7 +226,7 @@ func NewDockerTaskEngine(cfg *config.Config,
imageManager: imageManager,
hostResourceManager: hostResourceManager,
cniClient: ecscni.NewClient(cfg.CNIPluginsPath),
appnetClient: appnet.Client(),
appnetClient: appnet.CreateClient(),

metadataManager: metadataManager,
serviceconnectManager: serviceConnectManager,
Expand Down
4 changes: 2 additions & 2 deletions agent/engine/docker_task_engine_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/aws/amazon-ecs-agent/agent/api/appmesh"
apicontainer "github.com/aws/amazon-ecs-agent/agent/api/container"
apicontainerstatus "github.com/aws/amazon-ecs-agent/agent/api/container/status"
mock_api "github.com/aws/amazon-ecs-agent/agent/api/mocks"
"github.com/aws/amazon-ecs-agent/agent/api/serviceconnect"
apitask "github.com/aws/amazon-ecs-agent/agent/api/task"
apitaskstatus "github.com/aws/amazon-ecs-agent/agent/api/task/status"
Expand All @@ -54,6 +53,7 @@ import (
"github.com/aws/amazon-ecs-agent/agent/taskresource/ssmsecret"
resourcestatus "github.com/aws/amazon-ecs-agent/agent/taskresource/status"
mock_ioutilwrapper "github.com/aws/amazon-ecs-agent/agent/utils/ioutilwrapper/mocks"
mock_appnet "github.com/aws/amazon-ecs-agent/ecs-agent/api/appnet/mocks"
"github.com/aws/amazon-ecs-agent/ecs-agent/api/attachmentinfo"
apieni "github.com/aws/amazon-ecs-agent/ecs-agent/api/eni"
"github.com/aws/amazon-ecs-agent/ecs-agent/api/status"
Expand Down Expand Up @@ -989,7 +989,7 @@ func TestContainersWithServiceConnect(t *testing.T) {
defer ctrl.Finish()

cniClient := mock_ecscni.NewMockCNIClient(ctrl)
appnetClient := mock_api.NewMockAppnetClient(ctrl)
appnetClient := mock_appnet.NewMockAppNetClient(ctrl)
taskEngine.(*DockerTaskEngine).cniClient = cniClient
taskEngine.(*DockerTaskEngine).appnetClient = appnetClient
taskEngine.(*DockerTaskEngine).taskSteadyStatePollInterval = taskSteadyStatePollInterval
Expand Down
5 changes: 2 additions & 3 deletions agent/stats/service_connect_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"strings"
"sync"

"github.com/aws/amazon-ecs-agent/agent/api"
"github.com/aws/amazon-ecs-agent/ecs-agent/api/appnet"

apitask "github.com/aws/amazon-ecs-agent/agent/api/task"
Expand All @@ -33,7 +32,7 @@ import (

type ServiceConnectStats struct {
stats []*ecstcs.GeneralMetricsWrapper
appnetClient api.AppnetClient
appnetClient appnet.AppNetClient
sent bool
lock sync.RWMutex
}
Expand All @@ -50,7 +49,7 @@ var directionToMetricType = map[string]string{

func newServiceConnectStats() (*ServiceConnectStats, error) {
return &ServiceConnectStats{
appnetClient: appnet.Client(),
appnetClient: appnet.CreateClient(),
}, nil
}

Expand Down
2 changes: 1 addition & 1 deletion agent/stats/service_connect_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func TestRetrieveServiceConnectMetrics(t *testing.T) {
ts.Start()

serviceConnectStats := &ServiceConnectStats{
appnetClient: appnet.Client(),
appnetClient: appnet.CreateClient(),
}
serviceConnectStats.retrieveServiceConnectStats(t1)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions agent/vendor/modules.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ github.com/aws/amazon-ecs-agent/ecs-agent/acs/session
github.com/aws/amazon-ecs-agent/ecs-agent/acs/session/testconst
github.com/aws/amazon-ecs-agent/ecs-agent/api
github.com/aws/amazon-ecs-agent/ecs-agent/api/appnet
github.com/aws/amazon-ecs-agent/ecs-agent/api/appnet/mocks
github.com/aws/amazon-ecs-agent/ecs-agent/api/attachmentinfo
github.com/aws/amazon-ecs-agent/ecs-agent/api/eni
github.com/aws/amazon-ecs-agent/ecs-agent/api/errors
Expand Down
Loading

0 comments on commit 52a6991

Please sign in to comment.