Skip to content

Commit

Permalink
fix(usage-stats): usage-stats error handling and filter (#10105)
Browse files Browse the repository at this point in the history
  • Loading branch information
david-leifker authored Mar 23, 2024
1 parent 35cf4f8 commit 93b5907
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.linkedin.datahub.graphql.generated.Entity;
import com.linkedin.datahub.graphql.generated.UsageQueryResult;
import com.linkedin.datahub.graphql.types.usage.UsageQueryResultMapper;
import com.linkedin.metadata.utils.metrics.MetricUtils;
import com.linkedin.usage.UsageClient;
import com.linkedin.usage.UsageTimeRange;
import graphql.schema.DataFetcher;
Expand Down Expand Up @@ -45,9 +46,11 @@ public CompletableFuture<UsageQueryResult> get(DataFetchingEnvironment environme
usageClient.getUsageStats(resourceUrn.toString(), range);
return UsageQueryResultMapper.map(usageQueryResult);
} catch (Exception e) {
throw new RuntimeException(
String.format("Failed to load Usage Stats for resource %s", resourceUrn), e);
log.error(String.format("Failed to load Usage Stats for resource %s", resourceUrn), e);
MetricUtils.counter(this.getClass(), "usage_stats_dropped").inc();
}

return UsageQueryResultMapper.EMPTY;
});
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
package com.linkedin.datahub.graphql.types.usage;

import com.linkedin.datahub.graphql.generated.UsageQueryResult;
import com.linkedin.datahub.graphql.generated.UsageQueryResultAggregations;
import com.linkedin.datahub.graphql.types.mappers.ModelMapper;
import java.util.List;
import java.util.stream.Collectors;
import javax.annotation.Nonnull;

public class UsageQueryResultMapper
implements ModelMapper<com.linkedin.usage.UsageQueryResult, UsageQueryResult> {

public static final UsageQueryResult EMPTY =
new UsageQueryResult(List.of(), new UsageQueryResultAggregations(0, List.of(), List.of(), 0));

public static final UsageQueryResultMapper INSTANCE = new UsageQueryResultMapper();

public static UsageQueryResult map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public static BoolQueryBuilder buildConjunctiveFilterQuery(
.forEach(
criterion -> {
if (Set.of(Condition.EXISTS, Condition.IS_NULL).contains(criterion.getCondition())
|| !criterion.getValue().trim().isEmpty()
|| (criterion.hasValue() && !criterion.getValue().trim().isEmpty())
|| criterion.hasValues()) {
if (!criterion.isNegated()) {
// `filter` instead of `must` (enables caching and bypasses scoring)
Expand Down Expand Up @@ -646,6 +646,7 @@ private static RangeQueryBuilder buildRangeQueryFromCriterion(
* <p>For all new code, we should be using the new 'values' field for performing multi-match. This
* is simply retained for backwards compatibility of the search API.
*/
@Deprecated
private static QueryBuilder buildEqualsFromCriterionWithValue(
@Nonnull final String fieldName,
@Nonnull final Criterion criterion,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -386,22 +386,22 @@ public Task<UsageQueryResult> query(
Filter filter = new Filter();
ArrayList<Criterion> criteria = new ArrayList<>();
Criterion hasUrnCriterion =
new Criterion().setField("urn").setCondition(Condition.EQUAL).setValue(resource);
new Criterion().setField("urn").setCondition(Condition.EQUAL).setValues(new StringArray(resource));
criteria.add(hasUrnCriterion);
if (startTime != null) {
Criterion startTimeCriterion =
new Criterion()
.setField(ES_FIELD_TIMESTAMP)
.setCondition(Condition.GREATER_THAN_OR_EQUAL_TO)
.setValue(startTime.toString());
.setValues(new StringArray(startTime.toString()));
criteria.add(startTimeCriterion);
}
if (endTime != null) {
Criterion endTimeCriterion =
new Criterion()
.setField(ES_FIELD_TIMESTAMP)
.setCondition(Condition.LESS_THAN_OR_EQUAL_TO)
.setValue(endTime.toString());
.setValues(new StringArray(endTime.toString()));
criteria.add(endTimeCriterion);
}

Expand Down

0 comments on commit 93b5907

Please sign in to comment.