internal/testrunner/runners/script: provide mechanism to inspect agent containers#3107
Conversation
internal/testrunner/script/agents.go
Outdated
| ts.Setenv(*networkNameLabel, depInfo.NetworkName) | ||
| } | ||
| if *containerNameLabel != "" { | ||
| ts.Setenv(*containerNameLabel, fmt.Sprintf("elastic-package-agent-%s-%s-%s-%s-1", filepath.Base(pkgRoot), ds, info.Test.RunID, depInfo.Name)) |
There was a problem hiding this comment.
@mrodm Is this a reasonable way to reconstruct this? I did not see any direct representation of the container name for the container running the agent.
I expect that the suffix will ~always be "-1" since the run ID is a random value and we would not expect to have collisions between running agents, even in the case that a script started two or more agents (something that I would imagine would be vanishingly rare in itself).
There was a problem hiding this comment.
LGTM.
As a reference, this is the code where the docker project name is built:
elastic-package/internal/agentdeployer/agent.go
Lines 235 to 241 in 6a690bf
An example from nginx would be (data stream access):
elastic-package-agent-nginx-access-11932-elastic-agent-1
The only difference would be if input packages are being tested.
In that case, the docker project name would not contain the dataStream string.
elastic-package-agent-sql_input-46311-elastic-agent-1
75b1f2c to
c7f5df1
Compare
c7f5df1 to
cecdc18
Compare
mrodm
left a comment
There was a problem hiding this comment.
LGTM
Just a couple of comments to rename some messages to refer to the right function.
Not sure about adding the new method to the DockerComposeAgentDeployer without adding it to the AgentDeployer interface.
| // ProjectName returns the Docker Compose project name for the agent. | ||
| func (d *DockerComposeAgentDeployer) ProjectName(runID string) string { | ||
| return fmt.Sprintf("elastic-package-agent-%s-%s", d.agentName(), runID) | ||
| } |
There was a problem hiding this comment.
Just re-reviewing this PR, I realised that DockerComposeAgentDeployer implements the interface AgentDeployer.
And this ProjectName method is not there.
I think it would be better to add this method to the interface too.
That would enforce to add this method also to KubernetesAgentDeployer, but I'm not sure that makes sense there, because in that case the agent runs directly in k8s and not in a docker-compose scenario.
@efd6 @elastic/ecosystem WDYT about this ?
There was a problem hiding this comment.
I think it would be better to add this method to the interface too.
I guess it is not an issue to keep that method as a public one but not being part of the AgentDeployer interface. Specially, because this new method does not make sense in KubernetesAgentDeployer as mentioned in:
That would enforce to add this method also to KubernetesAgentDeployer, but I'm not sure that makes sense there, because in that case the agent runs directly in k8s and not in a docker-compose scenario.
| // ProjectName returns the Docker Compose project name for the agent. | ||
| func (d *DockerComposeAgentDeployer) ProjectName(runID string) string { | ||
| return fmt.Sprintf("elastic-package-agent-%s-%s", d.agentName(), runID) | ||
| } |
There was a problem hiding this comment.
I think it would be better to add this method to the interface too.
I guess it is not an issue to keep that method as a public one but not being part of the AgentDeployer interface. Specially, because this new method does not make sense in KubernetesAgentDeployer as mentioned in:
That would enforce to add this method also to KubernetesAgentDeployer, but I'm not sure that makes sense there, because in that case the agent runs directly in k8s and not in a docker-compose scenario.
This was intentional and follows the Go approach to progressive code repair. The interface advertises the generic consumer's interface, but we are not the generic consumer. It's not needed right now (and likely never will be needed), so it should not be added until it is. This is for three reasons: 1. it's a breaking change, 2. a dummy method would have to be added to all the other implementers of the interface (related to 1.) and 3. "The bigger the interface, the weaker the abstraction."). This is also discussed in this "Hacking with Andrew and Brad" episode (1h, and I don't recall the exact time stamp, sorry); the gist of the discussion then is that Go is not Java and so it's not necessary to define interface inclusion on types before-hand. I believe it would be a mistake and an antipattern to add the method to the interface at this stage. |
Agreed, let's keep that function there just in |
internal/testrunner/script/agents.go
Outdated
| ts.Fatalf("unsupported: ! compile_registry_state") | ||
| } | ||
| clearStdStreams(ts) | ||
| flg := flag.NewFlagSet("uninstall", flag.ContinueOnError) |
There was a problem hiding this comment.
| flg := flag.NewFlagSet("uninstall", flag.ContinueOnError) | |
| flg := flag.NewFlagSet("compile_registry_state", flag.ContinueOnError) |
docs/howto/script_testing.md
Outdated
| - `install_agent [-profile <profile>] [-timeout <duration>] [<network_name_label>]`: install an Elastic Agent policy, setting the environment variable named in the positional argument | ||
| - `install_agent [-profile <profile>] [-timeout <duration>] [-container_name <container_name_label>] [-network_name <network_name_label>]`: install an Elastic Agent policy, setting the environment variables named in the container_name and network_name arguments | ||
| - `uninstall_agent [-profile <profile>] [-timeout <duration>]`: remove an installed Elastic Agent policy | ||
| - `compile_registry_state [-start <first_id_to_use>] <path_to_registry_log>`: compile a Filebeat registry log.json file into a registry state and print it to stdout |
There was a problem hiding this comment.
There's also the -pretty flag to document.
|
/test |
1 similar comment
|
/test |
💚 Build Succeeded
History
cc @efd6 |
Please take a look.
The addition to the get_docs test demonstrates how this can be used with a trivial example.