@@ -16,15 +16,13 @@ package handlers
16
16
import (
17
17
"context"
18
18
"net/http"
19
- "strconv"
20
19
"time"
21
20
22
21
"github.com/aws/amazon-ecs-agent/agent/api"
23
22
"github.com/aws/amazon-ecs-agent/agent/config"
24
23
"github.com/aws/amazon-ecs-agent/agent/credentials"
25
24
"github.com/aws/amazon-ecs-agent/agent/engine/dockerstate"
26
25
agentAPITaskProtectionV1 "github.com/aws/amazon-ecs-agent/agent/handlers/agentapi/taskprotection/v1/handlers"
27
- handlersutils "github.com/aws/amazon-ecs-agent/agent/handlers/utils"
28
26
v1 "github.com/aws/amazon-ecs-agent/agent/handlers/v1"
29
27
v2 "github.com/aws/amazon-ecs-agent/agent/handlers/v2"
30
28
v3 "github.com/aws/amazon-ecs-agent/agent/handlers/v3"
@@ -33,8 +31,8 @@ import (
33
31
"github.com/aws/amazon-ecs-agent/agent/stats"
34
32
"github.com/aws/amazon-ecs-agent/agent/utils/retry"
35
33
auditinterface "github.com/aws/amazon-ecs-agent/ecs-agent/logger/audit"
34
+ "github.com/aws/amazon-ecs-agent/ecs-agent/tmds"
36
35
"github.com/cihub/seelog"
37
- "github.com/didip/tollbooth"
38
36
"github.com/gorilla/mux"
39
37
)
40
38
@@ -61,7 +59,8 @@ func taskServerSetup(credentialsManager credentials.Manager,
61
59
vpcID string ,
62
60
containerInstanceArn string ,
63
61
apiEndpoint string ,
64
- acceptInsecureCert bool ) * http.Server {
62
+ acceptInsecureCert bool ) (* http.Server , error ) {
63
+
65
64
muxRouter := mux .NewRouter ()
66
65
67
66
// Set this to false so that for request like "//v3//metadata/task"
@@ -79,28 +78,13 @@ func taskServerSetup(credentialsManager credentials.Manager,
79
78
80
79
agentAPIV1HandlersSetup (muxRouter , state , credentialsManager , cluster , region , apiEndpoint , acceptInsecureCert )
81
80
82
- limiter := tollbooth .NewLimiter (float64 (steadyStateRate ), nil )
83
- limiter .SetOnLimitReached (handlersutils .LimitReachedHandler (auditLogger ))
84
- limiter .SetBurst (burstRate )
85
-
86
- // Log all requests and then pass through to muxRouter.
87
- loggingMuxRouter := mux .NewRouter ()
88
-
89
- // rootPath is a path for any traffic to this endpoint, "root" mux name will not be used.
90
- rootPath := "/" + handlersutils .ConstructMuxVar ("root" , handlersutils .AnythingRegEx )
91
- loggingMuxRouter .Handle (rootPath , tollbooth .LimitHandler (
92
- limiter , NewLoggingHandler (muxRouter )))
93
-
94
- loggingMuxRouter .SkipClean (false )
95
-
96
- server := http.Server {
97
- Addr : "127.0.0.1:" + strconv .Itoa (config .AgentCredentialsPort ),
98
- Handler : loggingMuxRouter ,
99
- ReadTimeout : readTimeout ,
100
- WriteTimeout : writeTimeout ,
101
- }
102
-
103
- return & server
81
+ return tmds .NewServer (auditLogger ,
82
+ tmds .WithRouter (muxRouter ),
83
+ tmds .WithListenAddress (tmds .AddressIPv4 ()),
84
+ tmds .WithReadTimeout (readTimeout ),
85
+ tmds .WithWriteTimeout (writeTimeout ),
86
+ tmds .WithSteadyStateRate (float64 (steadyStateRate )),
87
+ tmds .WithBurstRate (burstRate ))
104
88
}
105
89
106
90
// v2HandlersSetup adds all handlers in v2 package to the mux router.
@@ -200,9 +184,13 @@ func ServeTaskHTTPEndpoint(
200
184
201
185
auditLogger := audit .NewAuditLog (containerInstanceArn , cfg , logger )
202
186
203
- server := taskServerSetup (credentialsManager , auditLogger , state , ecsClient , cfg .Cluster , cfg .AWSRegion , statsEngine ,
187
+ server , err := taskServerSetup (credentialsManager , auditLogger , state , ecsClient , cfg .Cluster , cfg .AWSRegion , statsEngine ,
204
188
cfg .TaskMetadataSteadyStateRate , cfg .TaskMetadataBurstRate , availabilityZone , vpcID , containerInstanceArn , cfg .APIEndpoint ,
205
189
cfg .AcceptInsecureCert )
190
+ if err != nil {
191
+ seelog .Criticalf ("Failed to set up Task Metadata Server: %v" , err )
192
+ return
193
+ }
206
194
207
195
go func () {
208
196
<- ctx .Done ()
0 commit comments