Skip to content
This repository was archived by the owner on Sep 17, 2024. It is now read-only.

Commit 41cf3bf

Browse files
committed
chore: reorder methods allphabetically
1 parent 3363726 commit 41cf3bf

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

e2e/_suites/ingest-manager/fleet.go

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -429,32 +429,6 @@ func checkFleetConfiguration() error {
429429
return nil
430430
}
431431

432-
// isAgentOnline extracts the status for an agent, identified by its hotname
433-
// It will wuery Fleet's agents endpoint
434-
func isAgentOnline(hostname string) (bool, error) {
435-
jsonResponse, err := getOnlineAgents()
436-
if err != nil {
437-
return false, err
438-
}
439-
440-
agents := jsonResponse.Path("list")
441-
442-
for _, agent := range agents.Children() {
443-
agentStatus := agent.Path("active").Data().(bool)
444-
agentHostname := agent.Path("local_metadata.host.hostname").Data().(string)
445-
if agentHostname == hostname {
446-
log.WithFields(log.Fields{
447-
"active": agentStatus,
448-
"hostname": hostname,
449-
}).Debug("Agent status retrieved")
450-
451-
return agentStatus, nil
452-
}
453-
}
454-
455-
return false, fmt.Errorf("The agent '" + hostname + "' was not found in Fleet")
456-
}
457-
458432
// createFleetConfiguration sends a POST request to Fleet forcing the
459433
// recreation of the configuration
460434
func createFleetConfiguration() error {
@@ -751,3 +725,29 @@ func getOnlineAgents() (*gabs.Container, error) {
751725

752726
return jsonResponse, nil
753727
}
728+
729+
// isAgentOnline extracts the status for an agent, identified by its hotname
730+
// It will wuery Fleet's agents endpoint
731+
func isAgentOnline(hostname string) (bool, error) {
732+
jsonResponse, err := getOnlineAgents()
733+
if err != nil {
734+
return false, err
735+
}
736+
737+
agents := jsonResponse.Path("list")
738+
739+
for _, agent := range agents.Children() {
740+
agentStatus := agent.Path("active").Data().(bool)
741+
agentHostname := agent.Path("local_metadata.host.hostname").Data().(string)
742+
if agentHostname == hostname {
743+
log.WithFields(log.Fields{
744+
"active": agentStatus,
745+
"hostname": hostname,
746+
}).Debug("Agent status retrieved")
747+
748+
return agentStatus, nil
749+
}
750+
}
751+
752+
return false, fmt.Errorf("The agent '" + hostname + "' was not found in Fleet")
753+
}

e2e/_suites/ingest-manager/ingest-manager_test.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,27 @@ func (imts *IngestManagerTestSuite) processStateOnTheHost(process string, state
249249
return nil
250250
}
251251

252-
func startAgent(profile string, serviceName string) error {
253-
cmd := []string{"elastic-agent", "run"}
254-
err := execCommandInService(profile, serviceName, cmd, true)
252+
func execCommandInService(profile string, serviceName string, cmds []string, detach bool) error {
253+
serviceManager := services.NewServiceManager()
254+
255+
composes := []string{
256+
profile, // profile name
257+
serviceName, // service
258+
}
259+
composeArgs := []string{"exec", "-T"}
260+
if detach {
261+
composeArgs = append(composeArgs, "-d")
262+
}
263+
composeArgs = append(composeArgs, serviceName)
264+
composeArgs = append(composeArgs, cmds...)
265+
266+
err := serviceManager.RunCommand(profile, composes, composeArgs, profileEnv)
255267
if err != nil {
256268
log.WithFields(log.Fields{
257-
"command": cmd,
269+
"command": cmds,
258270
"error": err,
259271
"service": serviceName,
260-
}).Error("Could not run the agent")
272+
}).Error("Could not execute command in container")
261273

262274
return err
263275
}
@@ -295,27 +307,15 @@ func getContainerHostname(containerName string) (string, error) {
295307
return hostname, nil
296308
}
297309

298-
func execCommandInService(profile string, serviceName string, cmds []string, detach bool) error {
299-
serviceManager := services.NewServiceManager()
300-
301-
composes := []string{
302-
profile, // profile name
303-
serviceName, // service
304-
}
305-
composeArgs := []string{"exec", "-T"}
306-
if detach {
307-
composeArgs = append(composeArgs, "-d")
308-
}
309-
composeArgs = append(composeArgs, serviceName)
310-
composeArgs = append(composeArgs, cmds...)
311-
312-
err := serviceManager.RunCommand(profile, composes, composeArgs, profileEnv)
310+
func startAgent(profile string, serviceName string) error {
311+
cmd := []string{"elastic-agent", "run"}
312+
err := execCommandInService(profile, serviceName, cmd, true)
313313
if err != nil {
314314
log.WithFields(log.Fields{
315-
"command": cmds,
315+
"command": cmd,
316316
"error": err,
317317
"service": serviceName,
318-
}).Error("Could not execute command in container")
318+
}).Error("Could not run the agent")
319319

320320
return err
321321
}

0 commit comments

Comments
 (0)