diff --git a/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/exception/DataHubGraphQLError.java b/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/exception/DataHubGraphQLError.java index d7e530d9dbe4d..15c539a608cc0 100644 --- a/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/exception/DataHubGraphQLError.java +++ b/datahub-graphql-core/src/main/java/com/linkedin/datahub/graphql/exception/DataHubGraphQLError.java @@ -38,6 +38,10 @@ private Map buildExtensions(DataHubGraphQLErrorCode errorCode) { return extensions; } + public int getErrorCode() { + return errorCode.getCode(); + } + @Override public String getMessage() { return message; diff --git a/metadata-service/graphql-servlet-impl/src/main/java/com/datahub/graphql/GraphQLController.java b/metadata-service/graphql-servlet-impl/src/main/java/com/datahub/graphql/GraphQLController.java index 49e2b501b8591..c7f8ffbae1d68 100644 --- a/metadata-service/graphql-servlet-impl/src/main/java/com/datahub/graphql/GraphQLController.java +++ b/metadata-service/graphql-servlet-impl/src/main/java/com/datahub/graphql/GraphQLController.java @@ -9,6 +9,7 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import com.linkedin.datahub.graphql.GraphQLEngine; +import com.linkedin.datahub.graphql.exception.DataHubGraphQLError; import com.linkedin.metadata.utils.metrics.MetricUtils; import graphql.ExecutionResult; import java.util.Collections; @@ -126,9 +127,25 @@ void getGraphQL(HttpServletRequest request, HttpServletResponse response) { throw new UnsupportedOperationException("GraphQL gets not supported."); } + private void observeErrors(ExecutionResult executionResult) { + executionResult.getErrors().forEach(graphQLError -> { + if (graphQLError instanceof DataHubGraphQLError) { + DataHubGraphQLError dhGraphQLError = (DataHubGraphQLError) graphQLError; + int errorCode = dhGraphQLError.getErrorCode(); + MetricUtils.get().counter(MetricRegistry.name(this.getClass(), "errorCode", Integer.toString(errorCode))).inc(); + } else { + MetricUtils.get().counter(MetricRegistry.name(this.getClass(), "errorType", graphQLError.getErrorType().toString())).inc(); + } + }); + if (executionResult.getErrors().size() != 0) { + MetricUtils.get().counter(MetricRegistry.name(this.getClass(), "error")).inc(); + } + } + @SuppressWarnings("unchecked") private void submitMetrics(ExecutionResult executionResult) { try { + observeErrors(executionResult); Object tracingInstrumentation = executionResult.getExtensions().get("tracing"); if (tracingInstrumentation instanceof Map) { Map tracingMap = (Map) tracingInstrumentation; @@ -137,11 +154,12 @@ private void submitMetrics(ExecutionResult executionResult) { // Extract top level resolver, parent is top level query. Assumes single query per call. List> resolvers = (List>) executionData.get("resolvers"); Optional> - parentResolver = resolvers.stream().filter(resolver -> resolver.get("parentType").equals("Query")).findFirst(); + parentResolver = resolvers.stream().filter(resolver -> resolver.get("parentType").equals("Query")).findFirst(); String fieldName = parentResolver.isPresent() ? (String) parentResolver.get().get("fieldName") : "UNKNOWN"; MetricUtils.get().histogram(MetricRegistry.name(this.getClass(), fieldName)).update(totalDuration); } } catch (Exception e) { + MetricUtils.get().counter(MetricRegistry.name(this.getClass(), "submitMetrics", "exception")).inc(); log.error("Unable to submit metrics for GraphQL call.", e); } }