11package graphql .kickstart .spring .web .boot ;
22
3+ import graphql .analysis .MaxQueryComplexityInstrumentation ;
4+ import graphql .analysis .MaxQueryDepthInstrumentation ;
5+ import graphql .execution .instrumentation .tracing .TracingInstrumentation ;
36import graphql .kickstart .servlet .GraphQLWebsocketServlet ;
47import graphql .kickstart .spring .web .boot .metrics .MetricsInstrumentation ;
58import graphql .kickstart .spring .web .boot .metrics .TracingNoResolversInstrumentation ;
69import graphql .kickstart .spring .web .boot .metrics .WebsocketMetrics ;
7- import graphql .analysis .MaxQueryComplexityInstrumentation ;
8- import graphql .analysis .MaxQueryDepthInstrumentation ;
9- import graphql .execution .instrumentation .tracing .TracingInstrumentation ;
1010import io .micrometer .core .instrument .MeterRegistry ;
11- import org . springframework . beans . factory . annotation . Value ;
11+ import lombok . RequiredArgsConstructor ;
1212import org .springframework .boot .actuate .autoconfigure .metrics .MetricsAutoConfiguration ;
1313import org .springframework .boot .actuate .autoconfigure .metrics .export .simple .SimpleMetricsExportAutoConfiguration ;
1414import org .springframework .boot .autoconfigure .AutoConfigureAfter ;
2525 * @author Marcel Overdijk
2626 */
2727@ Configuration
28+ @ RequiredArgsConstructor
2829@ ConditionalOnClass (MetricsAutoConfiguration .class )
2930@ AutoConfigureAfter ({MetricsAutoConfiguration .class , SimpleMetricsExportAutoConfiguration .class ,
3031 GraphQLWebsocketAutoConfiguration .class })
3132@ ConditionalOnProperty (value = "graphql.servlet.enabled" , havingValue = "true" , matchIfMissing = true )
3233@ EnableConfigurationProperties ({GraphQLServletProperties .class })
3334public class GraphQLInstrumentationAutoConfiguration {
3435
35- @ Value ("${graphql.servlet.maxQueryComplexity:#{null}}" )
36- private Integer maxQueryComplexity ;
37-
38- @ Value ("${graphql.servlet.maxQueryDepth:#{null}}" )
39- private Integer maxQueryDepth ;
40-
41- @ Value ("${graphql.servlet.tracing-enabled:'false'}" )
42- private String tracingEnabled ;
36+ private final GraphQLServletProperties graphqlServletProperties ;
4337
4438 @ Bean
4539 @ ConditionalOnMissingBean ({TracingInstrumentation .class , MetricsInstrumentation .class })
46- @ ConditionalOnExpression ("${graphql.servlet.tracing-enabled:'false'}.equals(' metrics-only') "
47- + "|| ${graphql.servlet.tracing-enabled:'false'}.equals( true) " )
40+ @ ConditionalOnExpression ("' ${graphql.servlet.tracing-enabled}' == ' metrics-only' "
41+ + "|| ' ${graphql.servlet.tracing-enabled}' == ' true' " )
4842 public TracingInstrumentation tracingInstrumentation () {
4943 return new TracingInstrumentation ();
5044 }
5145
5246 @ Bean
5347 @ ConditionalOnMissingBean
5448 @ ConditionalOnExpression ("${graphql.servlet.actuator-metrics:false}"
55- + "&& ${graphql.servlet.tracing-enabled:'false'}.toString().equals(' false') " )
49+ + "&& ' ${graphql.servlet.tracing-enabled}' == ' false'" )
5650 public TracingNoResolversInstrumentation tracingNoResolversInstrumentation () {
5751 return new TracingNoResolversInstrumentation ();
5852 }
@@ -61,29 +55,31 @@ public TracingNoResolversInstrumentation tracingNoResolversInstrumentation() {
6155 @ ConditionalOnMissingBean
6256 @ ConditionalOnProperty (value = "graphql.servlet.max-query-complexity" )
6357 public MaxQueryComplexityInstrumentation maxQueryComplexityInstrumentation () {
64- return new MaxQueryComplexityInstrumentation (maxQueryComplexity );
58+ return new MaxQueryComplexityInstrumentation (graphqlServletProperties . getMaxQueryComplexity () );
6559 }
6660
6761 @ Bean
6862 @ ConditionalOnMissingBean
6963 @ ConditionalOnProperty (value = "graphql.servlet.max-query-depth" )
7064 public MaxQueryDepthInstrumentation maxQueryDepthInstrumentation () {
71- return new MaxQueryDepthInstrumentation (maxQueryDepth );
65+ return new MaxQueryDepthInstrumentation (graphqlServletProperties . getMaxQueryDepth () );
7266 }
7367
7468 @ Bean
7569 @ ConditionalOnProperty (value = "graphql.servlet.actuator-metrics" , havingValue = "true" )
7670 @ ConditionalOnBean ({MeterRegistry .class , TracingInstrumentation .class })
7771 @ ConditionalOnMissingBean
7872 public MetricsInstrumentation metricsInstrumentation (MeterRegistry meterRegistry ) {
79- return new MetricsInstrumentation (meterRegistry , Boolean .TRUE .toString ().equals (tracingEnabled ));
73+ return new MetricsInstrumentation (meterRegistry ,
74+ Boolean .TRUE .toString ().equals (graphqlServletProperties .getTracingEnabled ()));
8075 }
8176
8277 @ Bean
8378 @ ConditionalOnProperty (value = "graphql.servlet.actuator-metrics" , havingValue = "true" )
8479 @ ConditionalOnBean ({MeterRegistry .class , GraphQLWebsocketServlet .class })
8580 @ ConditionalOnMissingBean
86- public WebsocketMetrics websocketMetrics (MeterRegistry meterRegistry , GraphQLWebsocketServlet websocketServlet ) {
81+ public WebsocketMetrics websocketMetrics (MeterRegistry meterRegistry ,
82+ GraphQLWebsocketServlet websocketServlet ) {
8783 return new WebsocketMetrics (meterRegistry , websocketServlet );
8884 }
8985
0 commit comments