Skip to content

Commit

Permalink
fix(metrics): get fieldName for GraphQL Mutation queries (datahub-pro…
Browse files Browse the repository at this point in the history
  • Loading branch information
trialiya authored Mar 22, 2024
1 parent 13f4993 commit e484094
Showing 1 changed file with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nonnull;
Expand Down Expand Up @@ -193,12 +192,14 @@ private void submitMetrics(ExecutionResult executionResult) {
// Extract top level resolver, parent is top level query. Assumes single query per call.
List<Map<String, Object>> resolvers =
(List<Map<String, Object>>) executionData.get("resolvers");
Optional<Map<String, Object>> parentResolver =
resolvers.stream()
.filter(resolver -> resolver.get("parentType").equals("Query"))
.findFirst();
String fieldName =
parentResolver.isPresent() ? (String) parentResolver.get().get("fieldName") : "UNKNOWN";
resolvers.stream()
.filter(
resolver -> List.of("Query", "Mutation").contains(resolver.get("parentType")))
.findFirst()
.map(parentResolver -> parentResolver.get("fieldName"))
.map(Object::toString)
.orElse("UNKNOWN");
MetricUtils.get()
.histogram(MetricRegistry.name(this.getClass(), fieldName))
.update(totalDuration);
Expand Down

0 comments on commit e484094

Please sign in to comment.