Skip to content

Commit

Permalink
change keep_alive option to disable_keep_alive
Browse files Browse the repository at this point in the history
  • Loading branch information
appare45 committed Dec 11, 2024
1 parent 7d225aa commit 5c8c0d9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
6 changes: 3 additions & 3 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -693,8 +693,8 @@ func buildUA(ver, rev string) string {
}

// NewMackerelClient returns Mackerel API client for mackerel-agent
func NewMackerelClient(apibase, apikey, ver, rev string, verbose bool, keepAlive bool) (*mackerel.API, error) {
api, err := mackerel.NewAPI(apibase, apikey, verbose, keepAlive)
func NewMackerelClient(apibase, apikey, ver, rev string, verbose bool, disableKeepAlive bool) (*mackerel.API, error) {
api, err := mackerel.NewAPI(apibase, apikey, verbose, disableKeepAlive)
if err != nil {
return nil, err
}
Expand All @@ -708,7 +708,7 @@ func NewMackerelClient(apibase, apikey, ver, rev string, verbose bool, keepAlive
// Prepare sets up API and registers the host data to the Mackerel server.
// Use returned values to call Run().
func Prepare(conf *config.Config, ameta *AgentMeta) (*App, error) {
api, err := NewMackerelClient(conf.Apibase, conf.Apikey, ameta.Version, ameta.Revision, conf.Verbose, conf.KeepAlive)
api, err := NewMackerelClient(conf.Apibase, conf.Apikey, ameta.Version, ameta.Revision, conf.Verbose, conf.DisableKeepAlive)
if err != nil {
return nil, fmt.Errorf("failed to prepare an api: %s", err.Error())
}
Expand Down
2 changes: 1 addition & 1 deletion commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func doRetire(fs *flag.FlagSet, argv []string) error {
return fmt.Errorf("hostID file is not found or empty")
}

api, err := command.NewMackerelClient(conf.Apibase, conf.Apikey, version, gitcommit, conf.Verbose, conf.KeepAlive)
api, err := command.NewMackerelClient(conf.Apibase, conf.Apikey, version, gitcommit, conf.Verbose, conf.DisableKeepAlive)
if err != nil {
return fmt.Errorf("faild to create api client: %s", err)
}
Expand Down
40 changes: 20 additions & 20 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,24 +93,24 @@ func (c *CloudPlatform) UnmarshalText(text []byte) error {

// Config represents mackerel-agent's configuration file.
type Config struct {
Apibase string
Apikey string
Root string
Pidfile string
Conffile string
Roles []string
Verbose bool
Silent bool
Diagnostic bool `toml:"diagnostic"`
KeepAlive bool `toml:"keep_alive"`
DisplayName string `toml:"display_name"`
HostStatus HostStatus `toml:"host_status" conf:"parent"`
Disks Disks `toml:"disks" conf:"parent"`
Filesystems Filesystems `toml:"filesystems" conf:"parent"`
Interfaces Interfaces `toml:"interfaces" conf:"parent"`
HTTPProxy string `toml:"http_proxy"`
HTTPSProxy string `toml:"https_proxy"`
CloudPlatform CloudPlatform `toml:"cloud_platform"`
Apibase string
Apikey string
Root string
Pidfile string
Conffile string
Roles []string
Verbose bool
Silent bool
Diagnostic bool `toml:"diagnostic"`
DisableKeepAlive bool `toml:"disable_keep_alive"`
DisplayName string `toml:"display_name"`
HostStatus HostStatus `toml:"host_status" conf:"parent"`
Disks Disks `toml:"disks" conf:"parent"`
Filesystems Filesystems `toml:"filesystems" conf:"parent"`
Interfaces Interfaces `toml:"interfaces" conf:"parent"`
HTTPProxy string `toml:"http_proxy"`
HTTPSProxy string `toml:"https_proxy"`
CloudPlatform CloudPlatform `toml:"cloud_platform"`

// This Plugin field is used to decode the toml file. After reading the
// configuration from file, this field is set to nil.
Expand Down Expand Up @@ -448,8 +448,8 @@ func LoadConfig(conffile string) (*Config, error) {
if !config.Diagnostic {
config.Diagnostic = DefaultConfig.Diagnostic
}
if !config.KeepAlive {
config.KeepAlive = true
if !config.DisableKeepAlive {
config.DisableKeepAlive = DefaultConfig.DisableKeepAlive
}

return config, err
Expand Down
4 changes: 2 additions & 2 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func TestLoadConfig(t *testing.T) {
t.Error("should be false (default value should be used)")
}

if config.KeepAlive != true {
t.Error("should be true (default value should be used)")
if config.DisableKeepAlive != false {
t.Error("should be false (default value should be used)")
}
}

Expand Down
10 changes: 6 additions & 4 deletions mackerel/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,17 @@ func infoError(msg string) *InfoError {
}

// NewAPI creates a new instance of API.
func NewAPI(rawurl string, apiKey string, verbose bool, keepAlive bool) (*API, error) {
func NewAPI(rawurl string, apiKey string, verbose bool, disableKeepAlive bool) (*API, error) {
c, err := mkr.NewClientWithOptions(apiKey, rawurl, verbose)
if err != nil {
return nil, err
}
c.PrioritizedLogger = logger
c.HTTPClient.Transport = &http.Transport{
DisableKeepAlives: true,
}
t := http.DefaultTransport.(*http.Transport).Clone()
print(disableKeepAlive)
t.DisableKeepAlives = disableKeepAlive
c.HTTPClient.Transport = t

return &API{Client: c}, nil
}

Expand Down

0 comments on commit 5c8c0d9

Please sign in to comment.