|
9 | 9 | import com.oracle.demo.timg.iot.iotdbjdbc.messagehandler.outputs.http.normalizeddata.timeseriesdb.oauth.TimeSeriesDBOAuthTokenRequestFilter; |
10 | 10 | import com.oracle.demo.timg.iot.iotdbjdbc.messagehandler.outputs.http.normalizeddata.timeseriesdb.oauth.TimeSeriesDBOAuthTokenRetriever; |
11 | 11 |
|
| 12 | +import io.micronaut.context.BeanProvider; |
12 | 13 | import io.micronaut.context.annotation.Requires; |
13 | 14 | import io.micronaut.context.event.StartupEvent; |
14 | 15 | import io.micronaut.http.MutableHttpRequest; |
|
20 | 21 |
|
21 | 22 | //@ClientFilter(patterns = { "${" + TimeSeriesDBProperties.TIME_SERIES_PROPERTY_METRICS_PATH + ":/tel/v1/metrics}", |
22 | 23 | // "${" + 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) |
24 | 25 | @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") |
25 | 28 | @Log |
26 | 29 | 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; |
28 | 38 |
|
29 | 39 | @Inject |
30 | | - public OtlpMetricsRequestFilter(TimeSeriesDBOAuthTokenRetriever tokenRetriever) { |
31 | | - log.info("OtlpMetricsRequestFilter constructor"); |
| 40 | + public OtlpMetricsRequestFilter(BeanProvider<TimeSeriesDBOAuthTokenRetriever> tokenRetriever) { |
32 | 41 | this.tokenRetriever = tokenRetriever; |
33 | 42 | } |
34 | 43 |
|
| 44 | +// @Inject |
| 45 | +// public OtlpMetricsRequestFilter(TimeSeriesDBOAuthTokenRetriever tokenRetriever) { |
| 46 | +// log.info("OtlpMetricsRequestFilter constructor"); |
| 47 | +// this.tokenRetriever = tokenRetriever; |
| 48 | +// } |
| 49 | + |
35 | 50 | @RequestFilter |
36 | 51 | public void doFilter(MutableHttpRequest<?> request) { |
37 | 52 | log.info("Running metrics OTLP filtering"); |
38 | 53 | try { |
39 | | - String token = tokenRetriever.getToken(); |
40 | | - String tokenType = tokenRetriever.getTokenType(); |
| 54 | + String token = tokenRetriever.get().getToken(); |
| 55 | + String tokenType = tokenRetriever.get().getTokenType(); |
41 | 56 | log.info("Got the token and tokenType"); |
42 | 57 | request.getHeaders().add(AUTHORIZATION, (tokenType == null ? "Bearer" : tokenType) + " " + token); |
43 | 58 | request.getHeaders().add(TimeSeriesDBOAuthTokenRequestFilter.HEADER_REQUEST_ID, |
|
0 commit comments