Skip to content

Conversation

@efd6
Copy link
Contributor

@efd6 efd6 commented Nov 25, 2025

Please take a look.

The addition to the get_docs test demonstrates how this can be used with a trivial example.

@efd6 efd6 self-assigned this Nov 25, 2025
@efd6 efd6 added enhancement New feature or request Team:Ecosystem Label for the Packages Ecosystem team Team:Security-Service Integrations Security Service Integrations Team labels Nov 25, 2025
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))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.
As a reference, this is the code where the docker project name is built:

composeProjectName := fmt.Sprintf("elastic-package-agent-%s-%s", d.agentName(), agentInfo.Test.RunID)

func (d *DockerComposeAgentDeployer) agentName() string {
name := d.packageName
if d.dataStream != "" && d.dataStream != "." {
name = fmt.Sprintf("%s-%s", name, d.dataStream)
}
return name
}

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

@efd6 efd6 marked this pull request as ready for review November 25, 2025 05:32
@efd6 efd6 requested review from a team and andrewkroh November 25, 2025 05:32
@efd6 efd6 force-pushed the script_test_agent_container_identity branch from 75b1f2c to c7f5df1 Compare November 27, 2025 00:15
@efd6 efd6 force-pushed the script_test_agent_container_identity branch from c7f5df1 to cecdc18 Compare November 27, 2025 00:19
mrodm
mrodm previously approved these changes Dec 1, 2025
Copy link
Contributor

@mrodm mrodm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM
Just a couple of comments to rename some messages to refer to the right function.

@mrodm mrodm dismissed their stale review December 1, 2025 12:17

Not sure about adding the new method to the DockerComposeAgentDeployer without adding it to the AgentDeployer interface.

Comment on lines +231 to +234
// 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)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just re-reviewing this PR, I realised that DockerComposeAgentDeployer implements the interface AgentDeployer.

type AgentDeployer interface {

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.

func (ksd *KubernetesAgentDeployer) SetUp(ctx context.Context, agentInfo AgentInfo) (DeployedAgent, error) {

@efd6 @elastic/ecosystem WDYT about this ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +231 to +234
// 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)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@efd6
Copy link
Contributor Author

efd6 commented Dec 1, 2025

Not sure about adding the new method to the DockerComposeAgentDeployer without adding it to the AgentDeployer interface.

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.

@elasticmachine
Copy link
Collaborator

💚 Build Succeeded

History

cc @efd6

@mrodm
Copy link
Contributor

mrodm commented Dec 2, 2025

Not sure about adding the new method to the DockerComposeAgentDeployer without adding it to the AgentDeployer interface.

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 DockerComposeAgentDeployer.
Thanks for the references!

Copy link
Contributor

@teresaromero teresaromero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Team:Ecosystem Label for the Packages Ecosystem team Team:Security-Service Integrations Security Service Integrations Team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants