Polish GraphQL changes
See gh-29140 Closes gh-29194
This commit is contained in:
@@ -35,6 +35,12 @@ import io.micrometer.core.instrument.Timer;
|
||||
import org.springframework.boot.actuate.metrics.AutoTimer;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Micrometer-based {@link SimpleInstrumentation}.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public class GraphQlMetricsInstrumentation extends SimpleInstrumentation {
|
||||
|
||||
private final MeterRegistry registry;
|
||||
@@ -127,7 +133,7 @@ public class GraphQlMetricsInstrumentation extends SimpleInstrumentation {
|
||||
|
||||
private Timer.Sample sample;
|
||||
|
||||
private AtomicLong dataFetchingCount = new AtomicLong(0L);
|
||||
private final AtomicLong dataFetchingCount = new AtomicLong();
|
||||
|
||||
RequestMetricsInstrumentationState(AutoTimer autoTimer, MeterRegistry registry) {
|
||||
this.timer = autoTimer.builder("graphql.request");
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.springframework.util.CollectionUtils;
|
||||
* Factory methods for Tags associated with a GraphQL request.
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @since 1.0.0
|
||||
* @since 2.7.0
|
||||
*/
|
||||
public final class GraphQlTags {
|
||||
|
||||
@@ -72,7 +72,7 @@ public final class GraphQlTags {
|
||||
builder.append('$');
|
||||
for (Object segment : pathSegments) {
|
||||
try {
|
||||
int index = Integer.parseUnsignedInt(segment.toString());
|
||||
Integer.parseUnsignedInt(segment.toString());
|
||||
builder.append("[*]");
|
||||
}
|
||||
catch (NumberFormatException exc) {
|
||||
@@ -90,13 +90,13 @@ public final class GraphQlTags {
|
||||
|
||||
public static Tag dataFetchingPath(InstrumentationFieldFetchParameters parameters) {
|
||||
ExecutionStepInfo executionStepInfo = parameters.getExecutionStepInfo();
|
||||
StringBuilder dataFetchingType = new StringBuilder();
|
||||
StringBuilder dataFetchingPath = new StringBuilder();
|
||||
if (executionStepInfo.hasParent() && executionStepInfo.getParent().getType() instanceof GraphQLObjectType) {
|
||||
dataFetchingType.append(((GraphQLObjectType) executionStepInfo.getParent().getType()).getName());
|
||||
dataFetchingType.append('.');
|
||||
dataFetchingPath.append(((GraphQLObjectType) executionStepInfo.getParent().getType()).getName());
|
||||
dataFetchingPath.append('.');
|
||||
}
|
||||
dataFetchingType.append(executionStepInfo.getPath().getSegmentName());
|
||||
return Tag.of("path", dataFetchingType.toString());
|
||||
dataFetchingPath.append(executionStepInfo.getPath().getSegmentName());
|
||||
return Tag.of("path", dataFetchingPath.toString());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ class GraphQlMetricsInstrumentationTests {
|
||||
|
||||
Timer timer = this.registry.find("graphql.request").timer();
|
||||
assertThat(timer).isNotNull();
|
||||
assertThat(timer.takeSnapshot().count()).isEqualTo(1);
|
||||
assertThat(timer.count()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -120,7 +120,7 @@ class GraphQlMetricsInstrumentationTests {
|
||||
|
||||
Timer timer = this.registry.find("graphql.datafetcher").timer();
|
||||
assertThat(timer).isNotNull();
|
||||
assertThat(timer.takeSnapshot().count()).isEqualTo(1);
|
||||
assertThat(timer.count()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -135,7 +135,7 @@ class GraphQlMetricsInstrumentationTests {
|
||||
|
||||
Timer timer = this.registry.find("graphql.datafetcher").timer();
|
||||
assertThat(timer).isNotNull();
|
||||
assertThat(timer.takeSnapshot().count()).isEqualTo(1);
|
||||
assertThat(timer.count()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,7 +150,7 @@ class GraphQlMetricsInstrumentationTests {
|
||||
|
||||
Timer timer = this.registry.find("graphql.datafetcher").timer();
|
||||
assertThat(timer).isNotNull();
|
||||
assertThat(timer.takeSnapshot().count()).isEqualTo(1);
|
||||
assertThat(timer.count()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user