Files
alloy/internal/component/pyroscope/util/test/container/java.go
korniltsev-grafanista 612bbb3ef1 pyroscope.java: allow custom asprof distributions instead of embeded one. (#4452)
* pyroscope.java: decouple archive extraction from the profiler, remove Profiler(use Distribution).

* playground

* fix args

* cleanup

* todo

* review fix

* review fixes

* pyroscope.java: add integration tests (#4454)

* pyroscope.java: add integration tests

fix package name

Revert "pyroscope.java: Fix java log level parameter (#4440)"

This reverts commit 4909877427.

move the helper to pyroscope package

* second integration test

* revert compose tests

* revert unneeded changes

* fix buildtag

* fix buildtag

* improve start time for pyroscope container

* skip integration test if it's not pyoroscope job

* update makefile

* pyroscope.java: Fix java log level parameter (#4440)

* pyroscope.java: Fix java log level parameter

The version bundled of the async profiler has no loglevel parameter:

```
ts=2025-09-16T08:16:50.898924708Z level=error component_path=/profiling.feature component_id=pyroscope.java.java_pods pid=1184752 err="failed to start: asprof failed to run: asprof failed to run /tmp/alloy-asprof-ae0261b1093f2bc4df44a87300fef98dcdebccb5/bin/asprof: exit status 1  Unrecognized option: --loglevel\n"
```

* Quiet is not a valid argument for the async-profiler cli

It can only be used for attaching using agent

* remove comments

* fix

---------

Co-authored-by: Christian Simon <simon@swine.de>

---------

Co-authored-by: Christian Simon <simon@swine.de>
2025-10-09 15:28:27 +00:00

55 lines
1.5 KiB
Go

package container
import (
"context"
"fmt"
stdlog "log"
"testing"
"time"
"github.com/docker/docker/api/types/container"
"github.com/docker/go-connections/nat"
"github.com/go-kit/log"
"github.com/stretchr/testify/require"
"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
)
func StartJavaApplicationContainer(t *testing.T, ctx context.Context, l log.Logger) (testcontainers.Container, string, int) {
req := testcontainers.ContainerRequest{
Image: "springcommunity/spring-framework-petclinic:latest",
ExposedPorts: []string{"8080/tcp"},
WaitingFor: wait.ForHTTP("/").WithPort("8080/tcp").WithStartupTimeout(3 * time.Minute),
Env: map[string]string{
"JAVA_OPTS": "-Xmx512m -Xms256m",
},
HostConfigModifier: func(hc *container.HostConfig) {
hc.PidMode = "host"
},
}
c, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{
ContainerRequest: req,
Started: true,
Logger: stdlog.New(log.NewStdlibAdapter(l), "", 0),
})
require.NoError(t, err)
t.Cleanup(func() {
err := testcontainers.TerminateContainer(c)
require.NoError(t, err)
})
mappedPort, err := c.MappedPort(ctx, nat.Port("8080/tcp"))
require.NoError(t, err)
host, err := c.Host(ctx)
require.NoError(t, err)
endpoint := fmt.Sprintf("http://%s:%s", host, mappedPort.Port())
inspected, err := c.Inspect(t.Context())
require.NoError(t, err)
return c, endpoint, inspected.State.Pid
}