Skip to content

Commit

Permalink
Revert "Add env for http monitor container command (elastic#25746)" (e…
Browse files Browse the repository at this point in the history
…lastic#25757)

This reverts commit 6b61c96.
  • Loading branch information
blakerouse authored May 18, 2021
1 parent 5233fb0 commit 7d1eb8d
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 93 deletions.
1 change: 0 additions & 1 deletion x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
- Add error log entry when listener creation fails {issue}23483[23482]
- Handle case where policy doesn't contain Fleet connection information {pull}25707[25707]
- Fix fleet-server.yml spec to not overwrite existing keys {pull}25741[25741]
- Add env for http monitor container command {pull}25746[25746]

==== New features

Expand Down
92 changes: 0 additions & 92 deletions x-pack/elastic-agent/pkg/agent/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,9 @@ import (

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/configuration"

"github.com/hectane/go-acl"
"github.com/spf13/cobra"
"gopkg.in/yaml.v2"

"github.com/elastic/beats/v7/libbeat/common/file"
"github.com/elastic/beats/v7/libbeat/common/transport/tlscommon"
"github.com/elastic/beats/v7/libbeat/kibana"
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
Expand Down Expand Up @@ -272,11 +270,6 @@ func runContainerCmd(streams *cli.IOStreams, cmd *cobra.Command, cfg setupConfig
return run(streams, logToStderr)
}

err = prepareAgent(cfg)
if err != nil {
return err
}

if cfg.Kibana.Fleet.Setup {
client, err = kibanaClient(cfg.Kibana)
if err != nil {
Expand Down Expand Up @@ -332,67 +325,6 @@ func runContainerCmd(streams *cli.IOStreams, cmd *cobra.Command, cfg setupConfig
return run(streams, logToStderr)
}

func prepareAgent(cfg setupConfig) error {
// if http monitoring is not enabled then nothing needs to be done
if !cfg.Agent.Monitoring.HTTP.Enabled {
return nil
}

err := func() error {
pathConfigFile := paths.ConfigFile()
rawConfig, err := config.LoadFile(pathConfigFile)
if err != nil {
return fmt.Errorf("failed open config for reading: %s", err)
}

agentCfgOnly := struct {
Agent agentConfig `config:"agent"`
}{
Agent: cfg.Agent,
}
err = rawConfig.Merge(&agentCfgOnly)
if err != nil {
return err
}
data, err := rawConfig.ToMapStr()
if err != nil {
return err
}
dataStr, err := yaml.Marshal(data)
if err != nil {
return err
}

// Matches the same rotation used by enrollment command, but must be duplicated here do to the path
// that this code takes.
const fsSafeTs = "2006-01-02T15-04-05.9999"

ts := time.Now()
backFilename := pathConfigFile + "." + ts.Format(fsSafeTs) + ".bak"
err = file.SafeFileRotate(backFilename, pathConfigFile)
if err != nil {
return err
}

fd, err := os.OpenFile(pathConfigFile, os.O_CREATE|os.O_WRONLY, 0600)
if err != nil {
return err
}
defer fd.Close()

_, err = fd.Write(dataStr)
if err != nil {
return err
}

return acl.Chmod(pathConfigFile, 0600)
}()
if err != nil {
return fmt.Errorf("failed to prepare elastic-agent.yml configuration: %s", err)
}
return nil
}

func buildEnrollArgs(cfg setupConfig, token string, policyID string) ([]string, error) {
args := []string{
"enroll", "-f",
Expand Down Expand Up @@ -886,7 +818,6 @@ type kibanaAPIKeyDetail struct {
// setup configuration

type setupConfig struct {
Agent agentConfig `config:"agent"`
Fleet fleetConfig `config:"fleet"`
FleetServer fleetServerConfig `config:"fleet_server"`
Kibana kibanaConfig `config:"kibana"`
Expand All @@ -900,20 +831,6 @@ type elasticsearchConfig struct {
ServiceToken string `config:"service_token"`
}

type agentConfig struct {
Monitoring agentMonitoringConfig `config:"monitoring"`
}

type agentMonitoringConfig struct {
HTTP agentMonitoringHTTPConfig `config:"http"`
}

type agentMonitoringHTTPConfig struct {
Enabled bool `config:"enabled"`
Host string `config:"host"`
Port string `config:"port"`
}

type fleetConfig struct {
CA string `config:"ca"`
Enroll bool `config:"enroll"`
Expand Down Expand Up @@ -962,15 +879,6 @@ func defaultAccessConfig() (setupConfig, error) {
}

cfg := setupConfig{
Agent: agentConfig{
Monitoring: agentMonitoringConfig{
HTTP: agentMonitoringHTTPConfig{
Enabled: envBool("AGENT_MONITORING_HTTP_ENABLE"),
Host: envWithDefault("0.0.0.0", "AGENT_MONITORING_HTTP_HOST"),
Port: envWithDefault("6791", "AGENT_MONITORING_HTTP_PORT"),
},
},
},
Fleet: fleetConfig{
CA: envWithDefault("", "FLEET_CA", "KIBANA_CA", "ELASTICSEARCH_CA"),
Enroll: envBool("FLEET_ENROLL", "FLEET_SERVER_ENABLE"),
Expand Down

0 comments on commit 7d1eb8d

Please sign in to comment.