Skip to content

Commit 5c8c0d9

Browse files
committed
change keep_alive option to disable_keep_alive
1 parent 7d225aa commit 5c8c0d9

File tree

5 files changed

+32
-30
lines changed

5 files changed

+32
-30
lines changed

command/command.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,8 +693,8 @@ func buildUA(ver, rev string) string {
693693
}
694694

695695
// NewMackerelClient returns Mackerel API client for mackerel-agent
696-
func NewMackerelClient(apibase, apikey, ver, rev string, verbose bool, keepAlive bool) (*mackerel.API, error) {
697-
api, err := mackerel.NewAPI(apibase, apikey, verbose, keepAlive)
696+
func NewMackerelClient(apibase, apikey, ver, rev string, verbose bool, disableKeepAlive bool) (*mackerel.API, error) {
697+
api, err := mackerel.NewAPI(apibase, apikey, verbose, disableKeepAlive)
698698
if err != nil {
699699
return nil, err
700700
}
@@ -708,7 +708,7 @@ func NewMackerelClient(apibase, apikey, ver, rev string, verbose bool, keepAlive
708708
// Prepare sets up API and registers the host data to the Mackerel server.
709709
// Use returned values to call Run().
710710
func Prepare(conf *config.Config, ameta *AgentMeta) (*App, error) {
711-
api, err := NewMackerelClient(conf.Apibase, conf.Apikey, ameta.Version, ameta.Revision, conf.Verbose, conf.KeepAlive)
711+
api, err := NewMackerelClient(conf.Apibase, conf.Apikey, ameta.Version, ameta.Revision, conf.Verbose, conf.DisableKeepAlive)
712712
if err != nil {
713713
return nil, fmt.Errorf("failed to prepare an api: %s", err.Error())
714714
}

commands.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func doRetire(fs *flag.FlagSet, argv []string) error {
156156
return fmt.Errorf("hostID file is not found or empty")
157157
}
158158

159-
api, err := command.NewMackerelClient(conf.Apibase, conf.Apikey, version, gitcommit, conf.Verbose, conf.KeepAlive)
159+
api, err := command.NewMackerelClient(conf.Apibase, conf.Apikey, version, gitcommit, conf.Verbose, conf.DisableKeepAlive)
160160
if err != nil {
161161
return fmt.Errorf("faild to create api client: %s", err)
162162
}

config/config.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -93,24 +93,24 @@ func (c *CloudPlatform) UnmarshalText(text []byte) error {
9393

9494
// Config represents mackerel-agent's configuration file.
9595
type Config struct {
96-
Apibase string
97-
Apikey string
98-
Root string
99-
Pidfile string
100-
Conffile string
101-
Roles []string
102-
Verbose bool
103-
Silent bool
104-
Diagnostic bool `toml:"diagnostic"`
105-
KeepAlive bool `toml:"keep_alive"`
106-
DisplayName string `toml:"display_name"`
107-
HostStatus HostStatus `toml:"host_status" conf:"parent"`
108-
Disks Disks `toml:"disks" conf:"parent"`
109-
Filesystems Filesystems `toml:"filesystems" conf:"parent"`
110-
Interfaces Interfaces `toml:"interfaces" conf:"parent"`
111-
HTTPProxy string `toml:"http_proxy"`
112-
HTTPSProxy string `toml:"https_proxy"`
113-
CloudPlatform CloudPlatform `toml:"cloud_platform"`
96+
Apibase string
97+
Apikey string
98+
Root string
99+
Pidfile string
100+
Conffile string
101+
Roles []string
102+
Verbose bool
103+
Silent bool
104+
Diagnostic bool `toml:"diagnostic"`
105+
DisableKeepAlive bool `toml:"disable_keep_alive"`
106+
DisplayName string `toml:"display_name"`
107+
HostStatus HostStatus `toml:"host_status" conf:"parent"`
108+
Disks Disks `toml:"disks" conf:"parent"`
109+
Filesystems Filesystems `toml:"filesystems" conf:"parent"`
110+
Interfaces Interfaces `toml:"interfaces" conf:"parent"`
111+
HTTPProxy string `toml:"http_proxy"`
112+
HTTPSProxy string `toml:"https_proxy"`
113+
CloudPlatform CloudPlatform `toml:"cloud_platform"`
114114

115115
// This Plugin field is used to decode the toml file. After reading the
116116
// configuration from file, this field is set to nil.
@@ -448,8 +448,8 @@ func LoadConfig(conffile string) (*Config, error) {
448448
if !config.Diagnostic {
449449
config.Diagnostic = DefaultConfig.Diagnostic
450450
}
451-
if !config.KeepAlive {
452-
config.KeepAlive = true
451+
if !config.DisableKeepAlive {
452+
config.DisableKeepAlive = DefaultConfig.DisableKeepAlive
453453
}
454454

455455
return config, err

config/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ func TestLoadConfig(t *testing.T) {
100100
t.Error("should be false (default value should be used)")
101101
}
102102

103-
if config.KeepAlive != true {
104-
t.Error("should be true (default value should be used)")
103+
if config.DisableKeepAlive != false {
104+
t.Error("should be false (default value should be used)")
105105
}
106106
}
107107

mackerel/api.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,17 @@ func infoError(msg string) *InfoError {
5757
}
5858

5959
// NewAPI creates a new instance of API.
60-
func NewAPI(rawurl string, apiKey string, verbose bool, keepAlive bool) (*API, error) {
60+
func NewAPI(rawurl string, apiKey string, verbose bool, disableKeepAlive bool) (*API, error) {
6161
c, err := mkr.NewClientWithOptions(apiKey, rawurl, verbose)
6262
if err != nil {
6363
return nil, err
6464
}
6565
c.PrioritizedLogger = logger
66-
c.HTTPClient.Transport = &http.Transport{
67-
DisableKeepAlives: true,
68-
}
66+
t := http.DefaultTransport.(*http.Transport).Clone()
67+
print(disableKeepAlive)
68+
t.DisableKeepAlives = disableKeepAlive
69+
c.HTTPClient.Transport = t
70+
6971
return &API{Client: c}, nil
7072
}
7173

0 commit comments

Comments
 (0)