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

Include filter parameters labels and childFilter in stats endpoints #6521

Open
rybandrei2014 opened this issue Dec 19, 2024 · 3 comments
Open
Assignees
Labels
area/backend Needs backend code changes enhancement New feature or request

Comments

@rybandrei2014
Copy link
Contributor

Feature description

Execution endpoints allow to use labels and childFilter filters while searching.
Screenshot 2024-12-19 at 7 50 18

Unfortunately following stats endpoints for executions doesn't allow that:

  • /api/v1/stats/executions/daily
  • /api/v1/stats/executions/daily/group-by-flow
  • /api/v1/stats/executions/daily/group-by-namespace
  • /api/v1/stats/executions/latest/group-by-flow

I looked at the source code and it looks like DB repository is prepared for that functionality (method filteringQuery). The problem is that parameters labels and childFilters are not defined in controller action and so passed as null to the method filteringQuery from dailyStatisticsQuery

    private Results dailyStatisticsQuery(
        Condition defaultFilter,
        List<Field<?>> fields,
        @Nullable String query,
        @Nullable String namespace,
        @Nullable String flowId,
        List<FlowFilter> flows,
        @Nullable ZonedDateTime startDate,
        @Nullable ZonedDateTime endDate,
        @Nullable DateUtils.GroupType groupBy
    ) {
        ZonedDateTime finalStartDate = startDate == null ? ZonedDateTime.now().minusDays(30) : startDate;
        ZonedDateTime finalEndDate = endDate == null ? ZonedDateTime.now() : endDate;

        List<Field<?>> dateFields = new ArrayList<>(groupByFields(Duration.between(finalStartDate, finalEndDate), "start_date", groupBy));
        List<Field<?>> selectFields = new ArrayList<>(fields);
        selectFields.addAll(List.of(
            DSL.count().as("count"),
            DSL.min(field("state_duration", Long.class)).as("duration_min"),
            DSL.max(field("state_duration", Long.class)).as("duration_max"),
            DSL.sum(field("state_duration", Long.class)).as("duration_sum")
        ));
        selectFields.addAll(dateFields);

        return jdbcRepository
            .getDslContextWrapper()
            .transactionResult(configuration -> {
                DSLContext context = DSL.using(configuration);

                SelectConditionStep<?> select = context
                    .select(selectFields)
                    .from(this.jdbcRepository.getTable())
                    .where(defaultFilter)
                    .and(field("start_date").greaterOrEqual(finalStartDate.toOffsetDateTime()))
                    .and(field("start_date").lessOrEqual(finalEndDate.toOffsetDateTime()));

                select = filteringQuery(select, namespace, flowId, flows, query, null, null, null);

                List<Field<?>> groupFields = new ArrayList<>(fields);

                groupFields.addAll(dateFields);

                SelectHavingStep<?> finalQuery = select
                    .groupBy(groupFields);

                return finalQuery.fetchMany();
            });
    }

    private <T extends Record> SelectConditionStep<T> filteringQuery(
        SelectConditionStep<T> select,
        @Nullable String namespace,
        @Nullable String flowId,
        @Nullable List<FlowFilter> flows,
        @Nullable String query,
        @Nullable Map<String, String> labels,
        @Nullable String triggerExecutionId,
        @Nullable ChildFilter childFilter
    ) {
        if (namespace != null) {
            if (flowId != null) {
                select = select.and(field("namespace").eq(namespace));
            } else {
                select = select.and(DSL.or(field("namespace").eq(namespace), field("namespace").likeIgnoreCase(namespace + ".%")));
            }
        }

        if (flowId != null) {
            select = select.and(DSL.or(field("flow_id").eq(flowId)));
        }

        if (query != null || labels != null) {
            select = select.and(this.findCondition(query, labels));
        }

        if (triggerExecutionId != null) {
            select = select.and(field("trigger_execution_id").eq(triggerExecutionId));
        }

        if (childFilter != null) {
            if (childFilter.equals(ChildFilter.CHILD)) {
                select = select.and(field("trigger_execution_id").isNotNull());
            } else if (childFilter.equals(ChildFilter.MAIN)) {
                select = select.and(field("trigger_execution_id").isNull());
            }
        }

        if (flows != null) {
            select = select.and(DSL.or(
                flows
                    .stream()
                    .map(e -> field("namespace").eq(e.getNamespace())
                        .and(field("flow_id").eq(e.getId()))
                    )
                    .collect(Collectors.toList())
            ));
        }

        return select;
    }

Is it possible that this extension will be implemented? Thank you

@rybandrei2014 rybandrei2014 added area/backend Needs backend code changes area/frontend Needs frontend code changes enhancement New feature or request labels Dec 19, 2024
@github-project-automation github-project-automation bot moved this to Backlog in Issues Dec 19, 2024
@MilosPaunovic MilosPaunovic removed the area/frontend Needs frontend code changes label Dec 19, 2024
@Amandixit10
Copy link

Hi can i pick this issue, thanks !!

@MilosPaunovic
Copy link
Member

Absolutely, go for it @Amandixit10! 🚀

@Amandixit10
Copy link

I am working on this issue, updating the status here. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/backend Needs backend code changes enhancement New feature or request
Projects
Status: Backlog
Development

No branches or pull requests

3 participants