Skip to content

feat: implement histogram analytics use case #12364

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

dev-marek
Copy link
Contributor

@dev-marek dev-marek commented Jul 1, 2025

Issue

https://gravitee.atlassian.net/browse/APIM-10031

Description

Implement MAPI and logic for histogram analytics for v4 API based on v2 implementation

Additional context


📚  View the storybook of this branch here

@dev-marek dev-marek marked this pull request as ready for review July 4, 2025 13:02
@dev-marek dev-marek requested a review from a team as a code owner July 4, 2025 13:02
@dev-marek dev-marek force-pushed the apim-10031-return-histogram-data branch from 5306e5c to 0692ffc Compare July 4, 2025 13:03
Copy link
Contributor

@jourdiw jourdiw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super clean and easy to read 👏

@@ -191,6 +194,17 @@ public Optional<TopFailedAggregate> searchTopFailedApis(QueryContext queryContex
return this.client.search(indexes, null, esQuery).map(SearchTopFailedApisAdapter::adaptResponse).blockingGet();
}

@Override
public List<HistogramAggregate<?>> searchHistogram(QueryContext queryContext, HistogramQuery query) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT of including a Collection definitionVersions and call the appropriate index? This could help in the future if we start creating histograms from both indexes.
I'll let @Okhelifi weigh in too 👍

@@ -58,4 +61,6 @@ public interface AnalyticsRepository {
Optional<TopHitsAggregate> searchTopApps(QueryContext queryContext, TopHitsQueryCriteria criteria);

Optional<TopFailedAggregate> searchTopFailedApis(QueryContext queryContext, TopFailedQueryCriteria criteria);

List<HistogramAggregate<?>> searchHistogram(QueryContext queryContext, HistogramQuery query);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you use ? instead of reflecting more what is accepted by a HistogramAggregate T extends Number?

}
return aggregations
.stream()
.map(a -> new Aggregation(a.getField(), Aggregation.AggregationType.valueOf(a.getType().toUpperCase())))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYT about handling if a.getType() is null and if a.getType().toUppercase() is not a given value of Aggregation.AggregationType?

}

private void validateApiProxy(Api api) {
if (api.getApiDefinitionHttpV4().isTcpProxy()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will be a NPE if the Api is Native. WDYT of -->

Suggested change
if (api.getApiDefinitionHttpV4().isTcpProxy()) {
if (api.getApiDefinitionHttpV4() != null && api.getApiDefinitionHttpV4().isTcpProxy()) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The use case mocks all interactions with the services, which I find a bit of a bummer since the onion architecture allows us to test up to the repository level.
@jgiovaresco @Okhelifi Is there an official point of view from the devs about mocks in the onion architecture services?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree we should avoid mocks in UseCase tests. Especially in this case where we have InMemory implementations available for ApiCrudService and AnalyticsQueryService

@jourdiw
Copy link
Contributor

jourdiw commented Jul 4, 2025

Some tests for the ApiAnalyticsResource would be nice 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants