Skip to content

Commit 1929cf5

Browse files
committed
attempt to fix recursion hell as micronaut http client setup tries to
build the OtlpMetriceRequest that used the TS DB OauthRetriever that itself causes the http client to try and do it's thing
1 parent 16295be commit 1929cf5

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

  • IoTDBJDBC/src/main/java/com/oracle/demo/timg/iot/iotdbjdbc/messagehandler/outputs/http/normalizeddata/timeseriesdb/otlp

IoTDBJDBC/src/main/java/com/oracle/demo/timg/iot/iotdbjdbc/messagehandler/outputs/http/normalizeddata/timeseriesdb/otlp/OtlpMetricsRequestFilter.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.oracle.demo.timg.iot.iotdbjdbc.messagehandler.outputs.http.normalizeddata.timeseriesdb.oauth.TimeSeriesDBOAuthTokenRequestFilter;
1010
import com.oracle.demo.timg.iot.iotdbjdbc.messagehandler.outputs.http.normalizeddata.timeseriesdb.oauth.TimeSeriesDBOAuthTokenRetriever;
1111

12+
import io.micronaut.context.BeanProvider;
1213
import io.micronaut.context.annotation.Requires;
1314
import io.micronaut.context.event.StartupEvent;
1415
import io.micronaut.http.MutableHttpRequest;
@@ -20,24 +21,38 @@
2021

2122
//@ClientFilter(patterns = { "${" + TimeSeriesDBProperties.TIME_SERIES_PROPERTY_METRICS_PATH + ":/tel/v1/metrics}",
2223
// "${" + TimeSeriesDBProperties.TIME_SERIES_PROPERTY_METRICS_PATH + ":/tel/v1/metrics}/**" })
23-
@ClientFilter(patterns = "/tel/v1/metrics")
24+
@ClientFilter(patterns = "/tel/v1/metrics", serviceId = OtlpProperties.METRICS_CLIENT_ID)
2425
@Requires(property = TimeSeriesDBProperties.TIME_SERIES_PROPERTY_ENABLED, value = "true", defaultValue = "false")
26+
@Requires(property = "micronaut.http.services.timeseriesmetrics.url")
27+
@Requires(property = "micronaut.http.services.timeseriesoauth.url")
2528
@Log
2629
public class OtlpMetricsRequestFilter {
27-
private final TimeSeriesDBOAuthTokenRetriever tokenRetriever;
30+
// private final TimeSeriesDBOAuthTokenRetriever tokenRetriever;
31+
// need to do this using a provider as otherwise we hit a massive recursion that
32+
// goes this then the retriever that itself uses a http client and so
33+
// ends up in the http client framework that then tries to load this again on
34+
// setting this up that ultimately results in stack overflow
35+
// using the bean provider delays the retriever setup until this is constructed,
36+
// and hopefully also the retriever and it's client
37+
private final BeanProvider<TimeSeriesDBOAuthTokenRetriever> tokenRetriever;
2838

2939
@Inject
30-
public OtlpMetricsRequestFilter(TimeSeriesDBOAuthTokenRetriever tokenRetriever) {
31-
log.info("OtlpMetricsRequestFilter constructor");
40+
public OtlpMetricsRequestFilter(BeanProvider<TimeSeriesDBOAuthTokenRetriever> tokenRetriever) {
3241
this.tokenRetriever = tokenRetriever;
3342
}
3443

44+
// @Inject
45+
// public OtlpMetricsRequestFilter(TimeSeriesDBOAuthTokenRetriever tokenRetriever) {
46+
// log.info("OtlpMetricsRequestFilter constructor");
47+
// this.tokenRetriever = tokenRetriever;
48+
// }
49+
3550
@RequestFilter
3651
public void doFilter(MutableHttpRequest<?> request) {
3752
log.info("Running metrics OTLP filtering");
3853
try {
39-
String token = tokenRetriever.getToken();
40-
String tokenType = tokenRetriever.getTokenType();
54+
String token = tokenRetriever.get().getToken();
55+
String tokenType = tokenRetriever.get().getTokenType();
4156
log.info("Got the token and tokenType");
4257
request.getHeaders().add(AUTHORIZATION, (tokenType == null ? "Bearer" : tokenType) + " " + token);
4358
request.getHeaders().add(TimeSeriesDBOAuthTokenRequestFilter.HEADER_REQUEST_ID,

0 commit comments

Comments
 (0)