From e5bc0b41a9dd1ea8b399646b09896f3c9126c282 Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Tue, 17 Jan 2023 15:07:59 +0100 Subject: [PATCH 1/4] Remove factsengine flag and make fact gathering mandatory --- cmd/config.go | 6 ++-- cmd/config_test.go | 5 ++-- cmd/start.go | 7 ----- internal/agent/agent.go | 64 +++++++++++++++++++---------------------- 4 files changed, 34 insertions(+), 48 deletions(-) diff --git a/cmd/config.go b/cmd/config.go index b98b93ff..57e645d3 100644 --- a/cmd/config.go +++ b/cmd/config.go @@ -85,9 +85,7 @@ func LoadConfig(fileSystem afero.Fs) (*agent.Config, error) { AgentID: agentID, InstanceName: hostname, DiscoveriesConfig: discoveriesConfig, - // Feature flag to enable the facts engine - FactsEngineEnabled: viper.GetBool("factsengine"), - FactsServiceURL: viper.GetString("facts-service-url"), - PluginsFolder: viper.GetString("plugins-folder"), + FactsServiceURL: viper.GetString("facts-service-url"), + PluginsFolder: viper.GetString("plugins-folder"), }, nil } diff --git a/cmd/config_test.go b/cmd/config_test.go index ad6efe65..77450f52 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -66,9 +66,8 @@ func (suite *AgentCmdTestSuite) SetupTest() { AgentID: "some-agent-id", }, }, - FactsEngineEnabled: false, - FactsServiceURL: "amqp://guest:guest@localhost:5672", - PluginsFolder: "/usr/etc/trento/plugins/", + FactsServiceURL: "amqp://guest:guest@localhost:5672", + PluginsFolder: "/usr/etc/trento/plugins/", } } diff --git a/cmd/start.go b/cmd/start.go index 908781df..8fd10628 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -121,13 +121,6 @@ func NewStartCmd() *cobra.Command { panic(err) } - startCmd.Flags(). - Bool("factsengine", false, "Enable the facts engine") - err = startCmd.Flags().MarkHidden("factsengine") - if err != nil { - panic(err) - } - startCmd.Flags().String("facts-service-url", "amqp://guest:guest@localhost:5672", "Facts service queue url") err = startCmd.Flags().MarkHidden("facts-service-url") if err != nil { diff --git a/internal/agent/agent.go b/internal/agent/agent.go index 76e184c5..d43bd847 100644 --- a/internal/agent/agent.go +++ b/internal/agent/agent.go @@ -30,12 +30,11 @@ type Agent struct { } type Config struct { - AgentID string - InstanceName string - DiscoveriesConfig *discovery.DiscoveriesConfig - FactsEngineEnabled bool - FactsServiceURL string - PluginsFolder string + AgentID string + InstanceName string + DiscoveriesConfig *discovery.DiscoveriesConfig + FactsServiceURL string + PluginsFolder string } // NewAgent returns a new instance of Agent with the given configuration @@ -91,42 +90,39 @@ func (a *Agent) Start(ctx context.Context) error { return nil }) - if a.config.FactsEngineEnabled { + gathererRegistry := gatherers.NewRegistry(gatherers.StandardGatherers()) - gathererRegistry := gatherers.NewRegistry(gatherers.StandardGatherers()) + log.Info("loading plugins") - log.Info("loading plugins") - - pluginLoaders := gatherers.PluginLoaders{ - "rpc": &gatherers.RPCPluginLoader{}, - } + pluginLoaders := gatherers.PluginLoaders{ + "rpc": &gatherers.RPCPluginLoader{}, + } - gatherersFromPlugins, err := gatherers.GetGatherersFromPlugins( - pluginLoaders, - a.config.PluginsFolder, - ) - if err != nil { - log.Fatalf("Error loading gatherers from plugins: %s", err) - } + gatherersFromPlugins, err := gatherers.GetGatherersFromPlugins( + pluginLoaders, + a.config.PluginsFolder, + ) + if err != nil { + log.Fatalf("Error loading gatherers from plugins: %s", err) + } - gathererRegistry.AddGatherers(gatherersFromPlugins) + gathererRegistry.AddGatherers(gatherersFromPlugins) - c := factsengine.NewFactsEngine(a.config.AgentID, a.config.FactsServiceURL, *gathererRegistry) + c := factsengine.NewFactsEngine(a.config.AgentID, a.config.FactsServiceURL, *gathererRegistry) - g.Go(func() error { - log.Info("Starting fact gathering service...") - if err := c.Subscribe(); err != nil { - return err - } + g.Go(func() error { + log.Info("Starting fact gathering service...") + if err := c.Subscribe(); err != nil { + return err + } - if err := c.Listen(groupCtx); err != nil { - return err - } + if err := c.Listen(groupCtx); err != nil { + return err + } - log.Info("fact gathering stopped.") - return nil - }) - } + log.Info("fact gathering stopped.") + return nil + }) return g.Wait() } From 477db682de276c77dc53253000f8f261d23907c5 Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Tue, 17 Jan 2023 15:09:12 +0100 Subject: [PATCH 2/4] Unhide facts-service-url flag --- cmd/config_test.go | 4 +++- cmd/start.go | 4 ---- test/fixtures/config/agent.yaml | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/cmd/config_test.go b/cmd/config_test.go index 77450f52..56cb3277 100644 --- a/cmd/config_test.go +++ b/cmd/config_test.go @@ -66,7 +66,7 @@ func (suite *AgentCmdTestSuite) SetupTest() { AgentID: "some-agent-id", }, }, - FactsServiceURL: "amqp://guest:guest@localhost:5672", + FactsServiceURL: "amqp://guest:guest@serviceurl:5672", PluginsFolder: "/usr/etc/trento/plugins/", } } @@ -83,6 +83,7 @@ func (suite *AgentCmdTestSuite) TestConfigFromFlags() { "--server-url=http://serverurl", "--api-key=some-api-key", "--force-agent-id=some-agent-id", + "--facts-service-url=amqp://guest:guest@serviceurl:5672", }) _ = suite.cmd.Execute() @@ -104,6 +105,7 @@ func (suite *AgentCmdTestSuite) TestConfigFromEnv() { os.Setenv("TRENTO_SERVER_URL", "http://serverurl") os.Setenv("TRENTO_API_KEY", "some-api-key") os.Setenv("TRENTO_FORCE_AGENT_ID", "some-agent-id") + os.Setenv("TRENTO_FACTS_SERVICE_URL", "amqp://guest:guest@serviceurl:5672") _ = suite.cmd.Execute() diff --git a/cmd/start.go b/cmd/start.go index 8fd10628..5ed23c28 100644 --- a/cmd/start.go +++ b/cmd/start.go @@ -122,10 +122,6 @@ func NewStartCmd() *cobra.Command { } startCmd.Flags().String("facts-service-url", "amqp://guest:guest@localhost:5672", "Facts service queue url") - err = startCmd.Flags().MarkHidden("facts-service-url") - if err != nil { - panic(err) - } return startCmd } diff --git a/test/fixtures/config/agent.yaml b/test/fixtures/config/agent.yaml index 7c0f7b33..06ced811 100644 --- a/test/fixtures/config/agent.yaml +++ b/test/fixtures/config/agent.yaml @@ -7,3 +7,4 @@ subscription-discovery-period: 900s server-url: http://serverurl api-key: some-api-key force-agent-id: some-agent-id +facts-service-url: amqp://guest:guest@serviceurl:5672 From 5ad256a7acd87be1f768063f2b27c29c815e8176 Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Tue, 17 Jan 2023 15:30:59 +0100 Subject: [PATCH 3/4] Add facts service flag on config file and installer --- install-agent.sh | 29 ++++++++++++++++++++--------- packaging/config/agent.yaml | 8 ++++++++ 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/install-agent.sh b/install-agent.sh index 2a13cd6a..3a1c0da1 100755 --- a/install-agent.sh +++ b/install-agent.sh @@ -11,16 +11,17 @@ your single pane of glass on your SAP Applications. Usage: - sudo ./install-agent.sh --ssh-address --server-url --api-key + sudo ./install-agent.sh --ssh-address --server-url --api-key --facts-service-url Arguments: - --ssh-address The address to which the trento-agent should be reachable for ssh connection by the runner for check execution. - --server-url The trento server url. - --api-key The API key generated byt the trento server installation. - --rolling Use the rolling version instead of the stable one. - --use-tgz Use the trento tar.gz file from GH releases rather than the RPM. - --interval The polling interval in seconds for the discoveries. - --help Print this help. + --ssh-address The address to which the trento-agent should be reachable for ssh connection by the runner for check execution. + --server-url The trento server url. + --facts-service-url The fact gathering service url. + --api-key The API key generated byt the trento server installation. + --rolling Use the rolling version instead of the stable one. + --use-tgz Use the trento tar.gz file from GH releases rather than the RPM. + --interval The polling interval in seconds for the discoveries. + --help Print this help. END } @@ -39,6 +40,7 @@ fi ARGUMENT_LIST=( "ssh-address:" "server-url:" + "facts-service-url" "api-key:" "rolling" "use-tgz" @@ -69,6 +71,11 @@ while [[ $# -gt 0 ]]; do shift 2 ;; + --facts-service-url) + FACTS_SERVICE_URL=$2 + shift 2 + ;; + --api-key) API_KEY=$2 shift 2 @@ -100,6 +107,7 @@ AGENT_CONFIG_FILE="$AGENT_CONFIG_PATH/agent.yaml" AGENT_CONFIG_TEMPLATE=' ssh-address: @SSH_ADDRESS@ server-url: @SERVER_URL@ +facts-service-url: @FACTS_SERVICE_URL@ api-key: @API_KEY@ cloud-discovery-period: @INTERVAL@s cluster-discovery-period: @INTERVAL@s @@ -133,7 +141,9 @@ function configure_installation() { if [[ -z "$SERVER_URL" ]]; then read -rp "Please provide the server url: " SERVER_URL ${AGENT_CONFIG_FILE} diff --git a/packaging/config/agent.yaml b/packaging/config/agent.yaml index c33d5ab1..a0a0004b 100644 --- a/packaging/config/agent.yaml +++ b/packaging/config/agent.yaml @@ -80,8 +80,16 @@ # server-url: http://localhost +############################################################################### + ## Configure the api-key for trento agent to use in the communication with Trento control plane ## Required. ## Find the api key at /settings # api-key: + +############################################################################### + +## Facts gathering service URL + +# facts-service-url: amqp://guest:guest@localhost:5672 \ No newline at end of file From d13d070c78657cbbc4aadc82a0ac74a2d0103c66 Mon Sep 17 00:00:00 2001 From: arbulu89 Date: Tue, 17 Jan 2023 15:55:07 +0100 Subject: [PATCH 4/4] Add the new flag information to docs --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 16bf8f1a..04e1dd2f 100644 --- a/README.md +++ b/README.md @@ -81,16 +81,17 @@ The script will ask you for some input. - `ssh-address`: the address to which the trento-agent should be reachable for ssh connection by the runner for check execution. - `server-ip`: the address where Trento server can be reached. +- `facts-service-url`: the address of the AMQP service shared with Wanda where fact gathering request are received. - `api-key`: the API key generated by the server that allows agents to actually communicate with the control plane You can pass these arguments as flags or env variables too: ``` -curl -sfL https://raw.githubusercontent.com/trento-project/agent/main/install-agent.sh | sudo bash -s - --ssh-address=192.168.33.10 --server-url=http://192.168.33.1 --api-key +curl -sfL https://raw.githubusercontent.com/trento-project/agent/main/install-agent.sh | sudo bash -s - --ssh-address=192.168.33.10 --server-url=http://192.168.33.1 --facts-service-url=amqp://guest:guest@localhost:5672 --api-key ``` ``` -SSH_ADDRESS=192.168.33.10 SERVER_IP=192.168.33.1 API_KEY= sudo ./install-agent.sh +SSH_ADDRESS=192.168.33.10 SERVER_IP=192.168.33.1 FACTS_SERVICE_URL=amqp://guest:guest@localhost:5672 API_KEY= sudo ./install-agent.sh ``` ## Starting Trento Agent service