Skip to content

Commit ff85e19

Browse files
committed
Minor changes
1 parent ac05b69 commit ff85e19

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

ecs-agent/tmds/server.go

+20-10
Original file line numberDiff line numberDiff line change
@@ -28,68 +28,78 @@ import (
2828
)
2929

3030
const (
31-
// TMDS port
31+
// TMDS IP and port
32+
IPv4 = "127.0.0.1"
3233
Port = 51679
3334
)
3435

3536
// IPv4 address for TMDS
3637
func AddressIPv4() string {
37-
return fmt.Sprintf("127.0.0.1:%d", Port)
38+
return fmt.Sprintf("%s:%d", IPv4, Port)
3839
}
3940

41+
// Configuration for TMDS
4042
type Config struct {
41-
listenAddress string
42-
readTimeout time.Duration
43-
writeTimeout time.Duration
44-
steadyStateRate float64
45-
burstRate int
46-
router *mux.Router
43+
listenAddress string // http server listen address
44+
readTimeout time.Duration // http server read timeout
45+
writeTimeout time.Duration // http server write timeout
46+
steadyStateRate float64 // steady request rate limit
47+
burstRate int // burst request rate limit
48+
router *mux.Router // router with routes configured
4749
}
4850

51+
// Function type for updating TMDS config
4952
type ConfigOpt func(*Config) error
5053

54+
// Set TMDS listen address
5155
func WithListenAddress(listenAddr string) ConfigOpt {
5256
return func(c *Config) error {
5357
c.listenAddress = listenAddr
5458
return nil
5559
}
5660
}
5761

62+
// Set TMDS read timeout
5863
func WithReadTimeout(readTimeout time.Duration) ConfigOpt {
5964
return func(c *Config) error {
6065
c.readTimeout = readTimeout
6166
return nil
6267
}
6368
}
6469

70+
// Set TMDS write timeout
6571
func WithWriteTimeout(writeTimeout time.Duration) ConfigOpt {
6672
return func(c *Config) error {
6773
c.writeTimeout = writeTimeout
6874
return nil
6975
}
7076
}
7177

78+
// Set TMDS steady request rate limit
7279
func WithSteadyStateRate(steadyStateRate float64) ConfigOpt {
7380
return func(c *Config) error {
7481
c.steadyStateRate = steadyStateRate
7582
return nil
7683
}
7784
}
7885

86+
// Set TMDS burst request rate limit
7987
func WithBurstRate(burstRate int) ConfigOpt {
8088
return func(c *Config) error {
8189
c.burstRate = burstRate
8290
return nil
8391
}
8492
}
8593

94+
// Set TMDS router
8695
func WithRouter(router *mux.Router) ConfigOpt {
8796
return func(c *Config) error {
8897
c.router = router
8998
return nil
9099
}
91100
}
92101

102+
// Create a new HTTP Task Metadata Server (TMDS)
93103
func NewServer(auditLogger audit.AuditLogger, options ...ConfigOpt) (*http.Server, error) {
94104
config := new(Config)
95105
for _, opt := range options {
@@ -98,10 +108,10 @@ func NewServer(auditLogger audit.AuditLogger, options ...ConfigOpt) (*http.Serve
98108
}
99109
}
100110

101-
return setup(auditLogger, *config)
111+
return setup(auditLogger, config)
102112
}
103113

104-
func setup(auditLogger audit.AuditLogger, config Config) (*http.Server, error) {
114+
func setup(auditLogger audit.AuditLogger, config *Config) (*http.Server, error) {
105115
if config.listenAddress == "" {
106116
return nil, errors.New("listenAddress cannot be empty")
107117
}

ecs-agent/tmds/server_integ_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"testing"
2323
"time"
2424

25-
"github.com/aws/amazon-ecs-agent/ecs-agent/logger/audit/mocks"
25+
mock_audit "github.com/aws/amazon-ecs-agent/ecs-agent/logger/audit/mocks"
2626
"github.com/golang/mock/gomock"
2727
"github.com/gorilla/mux"
2828
"github.com/stretchr/testify/assert"

0 commit comments

Comments
 (0)