camunda / camunda-bpm-platform

Flexible framework for workflow and decision automation with BPMN and DMN. Integration with Quarkus, Spring, Spring Boot, CDI.
https://camunda.com/
Apache License 2.0
4.11k stars 1.55k forks source link

Create metrics API to provide grouped data #3967

Closed danielkelemen closed 7 months ago

danielkelemen commented 11 months ago

Acceptance Criteria (Required on creation)

Example response for months - subscriptionStart = 15. Feb 2023 - groupBy = month - period = last 12 months - metrics = TU,PI,DI ```json [ { // TU shows value from contract start! "startDate": "2023.01.15", "subscriptionYear": 2022, "metrics": { "TU": 100, "PI": 123, "DI": 123 } }, { "startDate": "2023.02.15", "subscriptionYear": 2022, // last subscription month for 2022 "metrics": { "TU": 110, "PI": 123, "DI": 123 } }, { "startDate": "2023.03.15", "subscriptionYear": 2023, // first subscription month for 2023, TU resets "metrics": { "TU": 10, "PI": 123, "DI": 123 } }, { "startDate": "2023.04.15", "subscriptionYear": 2023, "metrics": { "TU": 20, "PI": 123, "DI": 123 } }, { "startDate": "2023.05.15", "subscriptionYear": 2023, "metrics": { "TU": 30, "PI": 123, "DI": 123 } } ] ```
Example response for years - subscriptionStart = 15. Feb 2023 - groupBy = year - period = null (=all available years) - metrics = all ```json [ { "startDate": "2021.01.15", "subscriptionYear": 2021, "metrics": { "TU": 100, "PI": 123, "DI": 123, "FNI": 2, "EDE": 3 } }, { "startDate": "2022.01.15", "subscriptionYear": 2022, "metrics": { "TU": 110, "PI": 123, "DI": 123, "FNI": 2, "EDE": 3 } }, { "startDate": "2023.01.15", "subscriptionYear": 2023, "metrics": { "TU": 110, "PI": 123, "DI": 123, "FNI": 2, "EDE": 3 } } ] ```

Hints

Links

Breakdown

### Tasks
- [ ] https://github.com/camunda/camunda-bpm-platform/pull/4084
- [ ] https://github.com/camunda/camunda-bpm-platform/pull/4155
danielkelemen commented 8 months ago

Decisions:

How does the query work?

The query calculates and groups on two new key columns: SUBSCRIPTION_YEAR_ and SUBSCRIPTION_MONTH_. These are calculated based on the provided subscriptionStartDate and the meter log TIMESTAMP_. The subscriptionStartDate is always applied with respect to the meter log's year and month, it's not just one static date.

TL;DR: If a meter log is before the subscription start's month and day then it belongs to the previous subscription period, if it's after then to the current period.

Example:

Let's say our subscriptionStartDate=15/02/2024 and we have one meter log with TIMESTAMP_=14/02/2024, then:

If the meter log had TIMESTAMP_=15/02/2024, then:

danielkelemen commented 8 months ago

Problem:

TU metric shows unique users within the period. In the monthly view we want to show the accumulated TU metric to which we need the unique users from subscriptions start until the end of the month. We can't just add up the monthly unique users because that can count users multiple times. TU query needs to be adjusted.

Solution: In the monthly TU query, we group by ASSIGNEEHASH and only count the earliest occurrence within the selected period.

danielkelemen commented 7 months ago

Problem:

In webapp/admin source package there are no classes for db queries and for this feature we need a new private API with query.