1515public class LgtmResource extends ContainerResource <LgtmContainer , LgtmConfig > {
1616
1717 private ExtensionsCatalog catalog ;
18+ private LgtmConfig config ;
1819
1920 @ Override
2021 public LgtmConfig config (ModulesConfiguration configuration ) {
21- return configuration .lgtm ();
22+ LgtmConfig config = configuration .lgtm ();
23+ this .config = config ;
24+ return config ;
2225 }
2326
2427 @ Override
@@ -32,17 +35,53 @@ public Container<LgtmConfig> container(LgtmConfig config, ModulesConfiguration r
3235 return set (new LgtmContainer (config ));
3336 }
3437
35- // FIXME consolidate config methods.
38+ private int getPrivateOtlpPort () {
39+ if (config != null ) {
40+ return LgtmContainer .getPrivateOtlpPort (config .otlpProtocol ());
41+ } else {
42+ return -1 ;
43+ }
44+ }
45+
46+ private Map <String , String > config (int privatePort , String host ) {
47+ return config (privatePort , host , container .getMappedPort (privatePort ));
48+ }
49+
3650 @ Override
3751 public Map <String , String > config (int privatePort , String host , int publicPort ) {
52+
53+ Map <String , String > containerConfigs = new HashMap <>();
54+
3855 switch (privatePort ) {
3956 case ContainerConstants .GRAFANA_PORT :
40- return Map . of ("grafana.endpoint" , String .format ("http://%s:%s" , host , publicPort ));
41- case ContainerConstants . OTEL_GRPC_EXPORTER_PORT :
57+ containerConfigs . put ("grafana.endpoint" , String .format ("http://%s:%s" , host , publicPort ));
58+ break ;
4259 case ContainerConstants .OTEL_HTTP_EXPORTER_PORT :
43- return Map .of ("otel-collector.url" , String .format ("%s:%s" , host , publicPort ));
60+ if (catalog != null && catalog .hasMicrometerOtlp ()) {
61+
62+ containerConfigs .put ("quarkus.micrometer.export.otlp.url" ,
63+ String .format ("http://%s:%s/v1/metrics" , host ,
64+ publicPort ));
65+ }
66+ // No break, fall through
67+ case ContainerConstants .OTEL_GRPC_EXPORTER_PORT :
68+ containerConfigs .put ("otel-collector.url" , String .format ("%s:%s" , host , publicPort ));
69+ break ;
70+ }
71+
72+ // The OTLP port is probably one of the ports we already compared against, but at compile-time we don't know which one,
73+ // so instead of doing this check as a fallthrough on the switch, do a normal if-check
74+ if (catalog != null && catalog .hasOpenTelemetry ()) {
75+ final int privateOtlpPort = getPrivateOtlpPort ();
76+ if (privateOtlpPort == privatePort ) {
77+ containerConfigs .put ("quarkus.otel.exporter.otlp.endpoint" ,
78+ String .format ("http://%s:%s" , host , publicPort ));
79+ String otlpProtocol = config .otlpProtocol (); // If we got to this stage, config must be not null
80+ containerConfigs .put ("quarkus.otel.exporter.otlp.protocol" , otlpProtocol );
81+ }
82+
4483 }
45- return Map . of () ;
84+ return containerConfigs ;
4685 }
4786
4887 @ Override
@@ -53,23 +92,13 @@ protected LgtmContainer defaultContainer() {
5392 @ Override
5493 public Map <String , String > doStart () {
5594 String host = container .getHost ();
56- int otlpPort = container .getOtlpPort ();
57-
58- //Set non Quarkus properties for convenience and testing.
5995 Map <String , String > containerConfigs = new HashMap <>();
60- containerConfigs .put ("grafana.endpoint" , String .format ("http://%s:%s" , host , container .getGrafanaPort ()));
61- containerConfigs .put ("otel-collector.url" , String .format ("%s:%s" , host , otlpPort ));
6296
63- // set relevant properties for Quarkus extensions directly
64- if (catalog != null && catalog .hasOpenTelemetry ()) {
65- containerConfigs .put ("quarkus.otel.exporter.otlp.endpoint" , String .format ("http://%s:%s" , host , otlpPort ));
66- containerConfigs .put ("quarkus.otel.exporter.otlp.protocol" , container .getOtlpProtocol ());
67- }
68- if (catalog != null && catalog .hasMicrometerOtlp ()) {
69- // always use http -- as that's what Micrometer supports
70- containerConfigs .put ("quarkus.micrometer.export.otlp.url" ,
71- String .format ("http://%s:%s/v1/metrics" , host ,
72- container .getMappedPort (ContainerConstants .OTEL_HTTP_EXPORTER_PORT )));
97+ containerConfigs .putAll (config (ContainerConstants .GRAFANA_PORT , host ));
98+ containerConfigs .putAll (config (ContainerConstants .OTEL_HTTP_EXPORTER_PORT , host ));
99+ // Iff GRPC is the OTLP protocol, overwrite the otel-collector.url we just wrote with the correct grpc one, and set up the otlp endpoints
100+ if (ContainerConstants .OTEL_GRPC_PROTOCOL .equals (container .getOtlpProtocol ())) {
101+ containerConfigs .putAll (config (ContainerConstants .OTEL_GRPC_EXPORTER_PORT , host ));
73102 }
74103 return containerConfigs ;
75104 }
0 commit comments