@@ -3,6 +3,7 @@ package grafanalgtm
33import (
44 "context"
55 "fmt"
6+ "time"
67
78 "github.com/testcontainers/testcontainers-go"
89 "github.com/testcontainers/testcontainers-go/log"
@@ -25,30 +26,30 @@ type GrafanaLGTMContainer struct {
2526
2627// Run creates an instance of the Grafana LGTM container type
2728func Run (ctx context.Context , img string , opts ... testcontainers.ContainerCustomizer ) (* GrafanaLGTMContainer , error ) {
28- req := testcontainers.ContainerRequest {
29- Image : img ,
30- ExposedPorts : []string {GrafanaPort , LokiPort , TempoPort , OtlpGrpcPort , OtlpHttpPort , PrometheusPort },
31- WaitingFor : wait .ForLog (".*The OpenTelemetry collector and the Grafana LGTM stack are up and running.*\\ s" ).AsRegexp ().WithOccurrence (1 ),
29+ moduleOpts := []testcontainers.ContainerCustomizer {
30+ testcontainers .WithExposedPorts (GrafanaPort , LokiPort , TempoPort , OtlpGrpcPort , OtlpHttpPort , PrometheusPort ),
31+ testcontainers .WithWaitStrategyAndDeadline (2 * time .Minute ,
32+ wait .ForLog (".*The OpenTelemetry collector and the Grafana LGTM stack are up and running.*\\ s" ).AsRegexp ().WithOccurrence (1 ),
33+ wait .ForListeningPort (GrafanaPort ),
34+ wait .ForListeningPort (LokiPort ),
35+ wait .ForListeningPort (TempoPort ),
36+ wait .ForListeningPort (OtlpGrpcPort ),
37+ wait .ForListeningPort (OtlpHttpPort ),
38+ wait .ForListeningPort (PrometheusPort ),
39+ ),
40+ }
41+
42+ moduleOpts = append (moduleOpts , opts ... )
43+
44+ var c * GrafanaLGTMContainer
45+ ctr , err := testcontainers .Run (ctx , img , moduleOpts ... )
46+ if ctr != nil {
47+ c = & GrafanaLGTMContainer {Container : ctr }
3248 }
33-
34- genericContainerReq := testcontainers.GenericContainerRequest {
35- ContainerRequest : req ,
36- Started : true ,
37- }
38-
39- for _ , opt := range opts {
40- if err := opt .Customize (& genericContainerReq ); err != nil {
41- return nil , fmt .Errorf ("customize: %w" , err )
42- }
43- }
44-
45- container , err := testcontainers .GenericContainer (ctx , genericContainerReq )
4649 if err != nil {
47- return nil , fmt .Errorf ("generic container : %w" , err )
50+ return nil , fmt .Errorf ("run grafana lgtm : %w" , err )
4851 }
4952
50- c := & GrafanaLGTMContainer {Container : container }
51-
5253 url , err := c .OtlpHttpEndpoint (ctx )
5354 if err != nil {
5455 // return the container instance to allow the caller to clean up
0 commit comments