Skip to content

Commit

Permalink
Make rendering limits configurable.
Browse files Browse the repository at this point in the history
There were several places in code with hardcoded limits for items rendered on charts. It was really inconvenient for the end-user who had to rebuild the entire project to make limits configurable.

This fix moves the actual configuration into an Aggregator interface which is implemented by key plugins. Moreover, a user can now control the limits via ALLURE_RESULTS_LIMIT env variable that could be set before report's generation. Note that a newly added method was intentionally made static as some of the APIs that adjust the limits are also static.
  • Loading branch information
sskorol committed Jun 23, 2021
1 parent c0a3c4e commit 790340f
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.qameta.allure.Aggregator;
import io.qameta.allure.CommonJsonAggregator;
import io.qameta.allure.Constants;
import io.qameta.allure.core.LaunchResults;
Expand Down Expand Up @@ -54,7 +55,7 @@ protected static List<CategoriesTrendItem> getData(final List<LaunchResults> lau
final List<CategoriesTrendItem> data = getHistoryItems(launchesResults);

return Stream.concat(Stream.of(item), data.stream())
.limit(20)
.limit(Aggregator.resultsLimit())
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.qameta.allure.Aggregator;
import io.qameta.allure.CommonJsonAggregator;
import io.qameta.allure.Constants;
import io.qameta.allure.core.LaunchResults;
Expand Down Expand Up @@ -55,7 +56,7 @@ protected Optional<DurationTrendItem> parseItem(final ObjectMapper mapper, final
final List<DurationTrendItem> data = getHistoryItems(launchesResults);

return Stream.concat(Stream.of(item), data.stream())
.limit(20)
.limit(Aggregator.resultsLimit())
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ private void updateHistory(final Map<String, HistoryData> history,
}

final List<HistoryItem> newItems = Stream.concat(Stream.of(newItem), data.getItems().stream())
.limit(20)
.limit(Aggregator.resultsLimit())
.collect(Collectors.toList());
result.setNewFailed(isNewFailed(newItems));
result.setFlaky(isFlaky(newItems));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.qameta.allure.Aggregator;
import io.qameta.allure.CommonJsonAggregator;
import io.qameta.allure.Constants;
import io.qameta.allure.core.LaunchResults;
Expand Down Expand Up @@ -65,7 +66,7 @@ protected Optional<HistoryTrendItem> parseItem(final ObjectMapper mapper, final
final List<HistoryTrendItem> data = getHistoryItems(launchesResults);

return Stream.concat(Stream.of(item), data.stream())
.limit(20)
.limit(Aggregator.resultsLimit())
.collect(Collectors.toList());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.qameta.allure.Aggregator;
import io.qameta.allure.CommonJsonAggregator;
import io.qameta.allure.Constants;
import io.qameta.allure.core.LaunchResults;
Expand Down Expand Up @@ -55,7 +56,7 @@ protected Optional<RetryTrendItem> parseItem(final ObjectMapper mapper, final Js
final List<RetryTrendItem> data = getHistoryItems(launchesResults);

return Stream.concat(Stream.of(item), data.stream())
.limit(20)
.limit(Aggregator.resultsLimit())
.collect(Collectors.toList());
}

Expand Down
12 changes: 12 additions & 0 deletions allure-plugin-api/src/main/java/io/qameta/allure/Aggregator.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.List;
import java.util.Optional;

/**
* Aggregator extension. Can be used to process results and/or generate
Expand All @@ -31,6 +32,17 @@
@FunctionalInterface
public interface Aggregator extends Extension {

/**
* Configure the number of items to be rendered on different charts.
*
* @return RESULTS_LIMIT provided by user, or a default value = 20.
*/
static long resultsLimit() {
return Optional.ofNullable(System.getenv("ALLURE_RESULTS_LIMIT"))
.map(Long::parseLong)
.orElse(20L);
}

/**
* Process report data.
*
Expand Down

0 comments on commit 790340f

Please sign in to comment.