mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-03 04:10:43 +00:00
fix(usage-stats): usage-stats error handling and filter (#10105)
This commit is contained in:
parent
35cf4f89e5
commit
93b5907f99
@ -8,6 +8,7 @@ import com.linkedin.datahub.graphql.QueryContext;
|
|||||||
import com.linkedin.datahub.graphql.generated.Entity;
|
import com.linkedin.datahub.graphql.generated.Entity;
|
||||||
import com.linkedin.datahub.graphql.generated.UsageQueryResult;
|
import com.linkedin.datahub.graphql.generated.UsageQueryResult;
|
||||||
import com.linkedin.datahub.graphql.types.usage.UsageQueryResultMapper;
|
import com.linkedin.datahub.graphql.types.usage.UsageQueryResultMapper;
|
||||||
|
import com.linkedin.metadata.utils.metrics.MetricUtils;
|
||||||
import com.linkedin.usage.UsageClient;
|
import com.linkedin.usage.UsageClient;
|
||||||
import com.linkedin.usage.UsageTimeRange;
|
import com.linkedin.usage.UsageTimeRange;
|
||||||
import graphql.schema.DataFetcher;
|
import graphql.schema.DataFetcher;
|
||||||
@ -45,9 +46,11 @@ public class DatasetUsageStatsResolver implements DataFetcher<CompletableFuture<
|
|||||||
usageClient.getUsageStats(resourceUrn.toString(), range);
|
usageClient.getUsageStats(resourceUrn.toString(), range);
|
||||||
return UsageQueryResultMapper.map(usageQueryResult);
|
return UsageQueryResultMapper.map(usageQueryResult);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
throw new RuntimeException(
|
log.error(String.format("Failed to load Usage Stats for resource %s", resourceUrn), e);
|
||||||
String.format("Failed to load Usage Stats for resource %s", resourceUrn), e);
|
MetricUtils.counter(this.getClass(), "usage_stats_dropped").inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return UsageQueryResultMapper.EMPTY;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,13 +1,18 @@
|
|||||||
package com.linkedin.datahub.graphql.types.usage;
|
package com.linkedin.datahub.graphql.types.usage;
|
||||||
|
|
||||||
import com.linkedin.datahub.graphql.generated.UsageQueryResult;
|
import com.linkedin.datahub.graphql.generated.UsageQueryResult;
|
||||||
|
import com.linkedin.datahub.graphql.generated.UsageQueryResultAggregations;
|
||||||
import com.linkedin.datahub.graphql.types.mappers.ModelMapper;
|
import com.linkedin.datahub.graphql.types.mappers.ModelMapper;
|
||||||
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
public class UsageQueryResultMapper
|
public class UsageQueryResultMapper
|
||||||
implements ModelMapper<com.linkedin.usage.UsageQueryResult, UsageQueryResult> {
|
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 final UsageQueryResultMapper INSTANCE = new UsageQueryResultMapper();
|
||||||
|
|
||||||
public static UsageQueryResult map(
|
public static UsageQueryResult map(
|
||||||
|
|||||||
@ -188,7 +188,7 @@ public class ESUtils {
|
|||||||
.forEach(
|
.forEach(
|
||||||
criterion -> {
|
criterion -> {
|
||||||
if (Set.of(Condition.EXISTS, Condition.IS_NULL).contains(criterion.getCondition())
|
if (Set.of(Condition.EXISTS, Condition.IS_NULL).contains(criterion.getCondition())
|
||||||
|| !criterion.getValue().trim().isEmpty()
|
|| (criterion.hasValue() && !criterion.getValue().trim().isEmpty())
|
||||||
|| criterion.hasValues()) {
|
|| criterion.hasValues()) {
|
||||||
if (!criterion.isNegated()) {
|
if (!criterion.isNegated()) {
|
||||||
// `filter` instead of `must` (enables caching and bypasses scoring)
|
// `filter` instead of `must` (enables caching and bypasses scoring)
|
||||||
@ -646,6 +646,7 @@ public class ESUtils {
|
|||||||
* <p>For all new code, we should be using the new 'values' field for performing multi-match. This
|
* <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.
|
* is simply retained for backwards compatibility of the search API.
|
||||||
*/
|
*/
|
||||||
|
@Deprecated
|
||||||
private static QueryBuilder buildEqualsFromCriterionWithValue(
|
private static QueryBuilder buildEqualsFromCriterionWithValue(
|
||||||
@Nonnull final String fieldName,
|
@Nonnull final String fieldName,
|
||||||
@Nonnull final Criterion criterion,
|
@Nonnull final Criterion criterion,
|
||||||
|
|||||||
@ -386,14 +386,14 @@ public class UsageStats extends SimpleResourceTemplate<UsageAggregation> {
|
|||||||
Filter filter = new Filter();
|
Filter filter = new Filter();
|
||||||
ArrayList<Criterion> criteria = new ArrayList<>();
|
ArrayList<Criterion> criteria = new ArrayList<>();
|
||||||
Criterion hasUrnCriterion =
|
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);
|
criteria.add(hasUrnCriterion);
|
||||||
if (startTime != null) {
|
if (startTime != null) {
|
||||||
Criterion startTimeCriterion =
|
Criterion startTimeCriterion =
|
||||||
new Criterion()
|
new Criterion()
|
||||||
.setField(ES_FIELD_TIMESTAMP)
|
.setField(ES_FIELD_TIMESTAMP)
|
||||||
.setCondition(Condition.GREATER_THAN_OR_EQUAL_TO)
|
.setCondition(Condition.GREATER_THAN_OR_EQUAL_TO)
|
||||||
.setValue(startTime.toString());
|
.setValues(new StringArray(startTime.toString()));
|
||||||
criteria.add(startTimeCriterion);
|
criteria.add(startTimeCriterion);
|
||||||
}
|
}
|
||||||
if (endTime != null) {
|
if (endTime != null) {
|
||||||
@ -401,7 +401,7 @@ public class UsageStats extends SimpleResourceTemplate<UsageAggregation> {
|
|||||||
new Criterion()
|
new Criterion()
|
||||||
.setField(ES_FIELD_TIMESTAMP)
|
.setField(ES_FIELD_TIMESTAMP)
|
||||||
.setCondition(Condition.LESS_THAN_OR_EQUAL_TO)
|
.setCondition(Condition.LESS_THAN_OR_EQUAL_TO)
|
||||||
.setValue(endTime.toString());
|
.setValues(new StringArray(endTime.toString()));
|
||||||
criteria.add(endTimeCriterion);
|
criteria.add(endTimeCriterion);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user