5
5
6
6
package io .opentelemetry .contrib .jmxscraper .target_systems ;
7
7
8
- import static org .assertj .core .api .Assertions .assertThat ;
9
-
10
8
import com .linecorp .armeria .server .ServerBuilder ;
11
9
import com .linecorp .armeria .server .grpc .GrpcService ;
12
10
import com .linecorp .armeria .testing .junit5 .server .ServerExtension ;
13
11
import io .grpc .stub .StreamObserver ;
14
- import io .opentelemetry .contrib .jmxscraper .JmxConnectorBuilder ;
15
12
import io .opentelemetry .contrib .jmxscraper .JmxScraperContainer ;
16
13
import io .opentelemetry .proto .collector .metrics .v1 .ExportMetricsServiceRequest ;
17
14
import io .opentelemetry .proto .collector .metrics .v1 .ExportMetricsServiceResponse ;
18
15
import io .opentelemetry .proto .collector .metrics .v1 .MetricsServiceGrpc ;
19
- import java .io .IOException ;
20
16
import java .util .ArrayList ;
21
17
import java .util .List ;
22
18
import java .util .concurrent .BlockingQueue ;
23
19
import java .util .concurrent .ExecutionException ;
24
20
import java .util .concurrent .LinkedBlockingDeque ;
25
- import javax .management .remote .JMXConnector ;
26
21
import org .junit .jupiter .api .AfterAll ;
27
22
import org .junit .jupiter .api .AfterEach ;
28
23
import org .junit .jupiter .api .BeforeAll ;
35
30
import org .testcontainers .containers .output .Slf4jLogConsumer ;
36
31
37
32
public abstract class TargetSystemIntegrationTest {
38
-
39
- private static final Logger logger = LoggerFactory .getLogger (TargetSystemIntegrationTest . class );
33
+ private static final Logger targetSystemLogger = LoggerFactory . getLogger ( "TargetSystemContainer" );
34
+ private static final Logger jmxScraperLogger = LoggerFactory .getLogger ("JmxScraperContainer" );
40
35
private static final String TARGET_SYSTEM_NETWORK_ALIAS = "targetsystem" ;
41
36
private static String otlpEndpoint ;
42
37
@@ -54,6 +49,9 @@ public abstract class TargetSystemIntegrationTest {
54
49
private JmxScraperContainer scraper ;
55
50
56
51
private static final String OTLP_HOST = "host.testcontainers.internal" ;
52
+
53
+ // JMX communication only happens between container, and we don't have to use JMX
54
+ // from host to container, we can use a fixed port.
57
55
private static final int JMX_PORT = 9999 ;
58
56
59
57
@ BeforeAll
@@ -93,27 +91,14 @@ void endToEndTest() {
93
91
94
92
target =
95
93
createTargetContainer (JMX_PORT )
96
- .withLogConsumer (new Slf4jLogConsumer (logger ))
94
+ .withLogConsumer (new Slf4jLogConsumer (targetSystemLogger ))
97
95
.withNetwork (network )
98
- .withExposedPorts (JMX_PORT )
99
96
.withNetworkAliases (TARGET_SYSTEM_NETWORK_ALIAS );
100
97
target .start ();
101
98
102
- String targetHost = target .getHost ();
103
- Integer targetPort = target .getMappedPort (JMX_PORT );
104
- logger .info (
105
- "Target system started, JMX port: {} mapped to {}:{}" , JMX_PORT , targetHost , targetPort );
106
-
107
- // TODO : wait for metrics to be sent and add assertions on what is being captured
108
- // for now we just test that we can connect to remote JMX using our client.
109
- try (JMXConnector connector = JmxConnectorBuilder .createNew (targetHost , targetPort ).build ()) {
110
- assertThat (connector .getMBeanServerConnection ()).isNotNull ();
111
- } catch (IOException e ) {
112
- throw new RuntimeException (e );
113
- }
114
-
115
99
scraper =
116
100
new JmxScraperContainer (otlpEndpoint )
101
+ .withLogConsumer (new Slf4jLogConsumer (jmxScraperLogger ))
117
102
.withNetwork (network )
118
103
.withService (TARGET_SYSTEM_NETWORK_ALIAS , JMX_PORT );
119
104
0 commit comments