This repository has been archived by the owner on Dec 19, 2023. It is now read-only.
forked from yandooo/graphql-spring-boot
-
Notifications
You must be signed in to change notification settings - Fork 325
/
GraphQLInstrumentationAutoConfiguration.java
92 lines (83 loc) · 4.08 KB
/
GraphQLInstrumentationAutoConfiguration.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package graphql.kickstart.autoconfigure.web.servlet;
import graphql.analysis.MaxQueryComplexityInstrumentation;
import graphql.analysis.MaxQueryDepthInstrumentation;
import graphql.execution.instrumentation.tracing.TracingInstrumentation;
import graphql.kickstart.autoconfigure.web.servlet.metrics.MetricsInstrumentation;
import graphql.kickstart.autoconfigure.web.servlet.metrics.TracingNoResolversInstrumentation;
import graphql.kickstart.autoconfigure.web.servlet.metrics.WebsocketMetrics;
import graphql.kickstart.servlet.GraphQLWebsocketServlet;
import io.micrometer.core.instrument.MeterRegistry;
import lombok.RequiredArgsConstructor;
import org.springframework.boot.actuate.autoconfigure.metrics.MetricsAutoConfiguration;
import org.springframework.boot.actuate.autoconfigure.metrics.export.simple.SimpleMetricsExportAutoConfiguration;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/** @author Marcel Overdijk */
@Configuration
@RequiredArgsConstructor
@ConditionalOnClass(MetricsAutoConfiguration.class)
@AutoConfigureAfter({
MetricsAutoConfiguration.class,
SimpleMetricsExportAutoConfiguration.class,
GraphQLWebsocketAutoConfiguration.class
})
@EnableConfigurationProperties(GraphQLServletProperties.class)
@ConditionalOnProperty(
value = "graphql.servlet.enabled",
havingValue = "true",
matchIfMissing = true)
public class GraphQLInstrumentationAutoConfiguration {
private final GraphQLServletProperties graphqlServletProperties;
@Bean
@ConditionalOnMissingBean({TracingInstrumentation.class, MetricsInstrumentation.class})
@ConditionalOnExpression(
"'${graphql.servlet.tracing-enabled:false}' == 'metrics-only' "
+ "|| '${graphql.servlet.tracing-enabled:false}' == 'true'")
public TracingInstrumentation tracingInstrumentation() {
return new TracingInstrumentation();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnExpression(
"${graphql.servlet.actuator-metrics:false} "
+ "&& '${graphql.servlet.tracing-enabled:false}' == 'false'")
public TracingNoResolversInstrumentation tracingNoResolversInstrumentation() {
return new TracingNoResolversInstrumentation();
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "graphql.servlet.max-query-complexity")
public MaxQueryComplexityInstrumentation maxQueryComplexityInstrumentation() {
return new MaxQueryComplexityInstrumentation(graphqlServletProperties.getMaxQueryComplexity());
}
@Bean
@ConditionalOnMissingBean
@ConditionalOnProperty(value = "graphql.servlet.max-query-depth")
public MaxQueryDepthInstrumentation maxQueryDepthInstrumentation() {
return new MaxQueryDepthInstrumentation(graphqlServletProperties.getMaxQueryDepth());
}
@Bean
@ConditionalOnProperty(value = "graphql.servlet.actuator-metrics", havingValue = "true")
@ConditionalOnBean({MeterRegistry.class, TracingInstrumentation.class})
@ConditionalOnMissingBean
public MetricsInstrumentation metricsInstrumentation(MeterRegistry meterRegistry) {
return new MetricsInstrumentation(
meterRegistry,
Boolean.TRUE.toString().equalsIgnoreCase(graphqlServletProperties.getTracingEnabled()));
}
@Bean
@ConditionalOnProperty(value = "graphql.servlet.actuator-metrics", havingValue = "true")
@ConditionalOnBean({MeterRegistry.class, GraphQLWebsocketServlet.class})
@ConditionalOnMissingBean
public WebsocketMetrics websocketMetrics(
MeterRegistry meterRegistry, GraphQLWebsocketServlet websocketServlet) {
return new WebsocketMetrics(meterRegistry, websocketServlet);
}
}