Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(usage-stats): usage-stats error handling and filter #10105

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading