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

[APM] Fix query to mobile transactions main statistics #155895

Merged
merged 4 commits into from
Apr 28, 2023

Conversation

MiriamAparicio
Copy link
Contributor

@MiriamAparicio MiriamAparicio commented Apr 26, 2023

When splitting the query to mobile transactions main statistics, the sessions were left in the errors query and should have been retrieved in the transactions events. This PR fix this issue

@MiriamAparicio MiriamAparicio added bug Fixes for quality problems that affect the customer experience Team:APM All issues that need APM UI Team support release_note:skip Skip the PR/issue when compiling release notes v8.8.0 labels Apr 26, 2023
@MiriamAparicio MiriamAparicio requested a review from a team as a code owner April 26, 2023 15:17
@elasticmachine
Copy link
Contributor

Pinging @elastic/apm-ui (Team:APM)

@apmmachine
Copy link
Contributor

🤖 GitHub comments

Expand to view the GitHub comments

Just comment with:

  • /oblt-deploy : Deploy a Kibana instance using the Observability test environments.
  • run elasticsearch-ci/docs : Re-trigger the docs validation. (use unformatted text in the comment!)

}>;
}

type MainStatistics = Array<{
Copy link
Contributor

Choose a reason for hiding this comment

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

Also, I think this is not used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This type is used in line 194, needed to set which type we want the array returned by merge()

Copy link
Contributor

Choose a reason for hiding this comment

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

I see! I don't fully understand the following if you could please elaborate a bit more

export interface MobileMainStatisticsResponse {
  mainStatistics: Array<{
    name: string | number;
    latency: number | null;
    throughput: number;
    crashRate: number;
  }>;
}

type MainStatistics = Array<{
  name: string | number;
  latency: number | null;
  throughput: number;
  sessions: number;
  crashes?: number;
}>;

cause I would expect to be

export interface MobileMainStatisticsResponse {
  mainStatistics: MainStatistics
}

why do you have to calculate the crashRate here ->

crashRate: item.crashes ? item.crashes / item.sessions : 0,

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The merge of the two query responses is different from the return we want, for instance, we need sessions to calculate the crashRate, but we don't need them to be returned by getMobileMainStatisticsByField(), the main statistics we need are name, latency, throughput, and crashRate.
We calculate the crashRate here, same as we also calculate the throughput

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe the naming is confusing, I can give it a thought and find a more clear name for the type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh I see the confusion, sessions shouldn’t be part of errors query, does it make sense now?

@kibana-ci
Copy link
Collaborator

💚 Build Succeeded

Metrics [docs]

Async chunks

Total size of all lazy-loaded chunks that will be downloaded as the user navigates the app

id before after diff
apm 3.5MB 3.5MB -12.0B
Unknown metric groups

ESLint disabled line counts

id before after diff
enterpriseSearch 17 19 +2
securitySolution 399 402 +3
total +5

Total ESLint disabled count

id before after diff
enterpriseSearch 18 20 +2
securitySolution 479 482 +3
total +5

History

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@@ -55,7 +63,7 @@ export async function getMobileMainStatisticsByField({
}: Props) {
async function getMobileTransactionEventStatistics() {
Copy link
Contributor

Choose a reason for hiding this comment

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

getMobileMainStatisticsByField(){
   async function getMobileTransactionEventStatistics() {}
   async function getMobileErrorEventStatistics(){}
}

Nesting functions can be useful for encapsulating functionality and scoping variables but in this case, it seems it doesn't provide any value.

On the other hand, if there is a possibility of reusing ex getMobileErrorEventStatistics in other parts of the codebase, defining it outside of getMobileMainStatisticsByField could be a more practical approach.

What do you think about defining them outside of getMobileMainStatisticsByField?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought about it, but getMobileErrorEventStatistics is getting crash errors by field, it's not generic enough to be reusable. But I will keep it in mind for when we start implementing more use cases for crashRate

Copy link
Contributor

Choose a reason for hiding this comment

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

but getMobileErrorEventStatistics is getting crash errors by field, it's not generic enough to be reusable.

tbh, I'm not sure what you meant with it 🤔 but I think something like the following will work

const commonPros = {
    kuery,
    apmEventClient,
    serviceName,
    environment,
    start,
    end,
    field,
  };
  const [transactioEventStatistics, errorEventStatistics] = await Promise.all([
    getMobileTransactionEventStatistics(commonPros),
    getMobileErrorEventStatistics(commonPros),
  ]);

Copy link
Contributor

@kpatticha kpatticha left a comment

Choose a reason for hiding this comment

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

LGTM, I only left a comment about the nesting functions

@MiriamAparicio MiriamAparicio merged commit 67b2110 into elastic:main Apr 28, 2023
@MiriamAparicio MiriamAparicio deleted the fix-api-main-query branch April 28, 2023 09:35
kibanamachine pushed a commit to kibanamachine/kibana that referenced this pull request Apr 28, 2023
When splitting the query to mobile transactions main statistics, the
sessions were left in the errors query and should have been retrieved in
the transactions events. This PR fix this issue

(cherry picked from commit 67b2110)
@kibanamachine
Copy link
Contributor

💚 All backports created successfully

Status Branch Result
8.8

Note: Successful backport PRs will be merged automatically after passing CI.

Questions ?

Please refer to the Backport tool documentation

kibanamachine added a commit that referenced this pull request Apr 28, 2023
#156152)

# Backport

This will backport the following commits from `main` to `8.8`:
- [[APM] Fix query to mobile transactions main statistics
(#155895)](#155895)

<!--- Backport version: 8.9.7 -->

### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sqren/backport)

<!--BACKPORT
[{"author":{"name":"Miriam","email":"31922082+MiriamAparicio@users.noreply.github.com"},"sourceCommit":{"committedDate":"2023-04-28T09:35:45Z","message":"[APM]
Fix query to mobile transactions main statistics (#155895)\n\nWhen
splitting the query to mobile transactions main statistics,
the\r\nsessions were left in the errors query and should have been
retrieved in\r\nthe transactions events. This PR fix this
issue","sha":"67b211001fe50d3d2f2430689402f1bab8224294","branchLabelMapping":{"^v8.9.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["bug","Team:APM","release_note:skip","v8.8.0","v8.9.0"],"number":155895,"url":"#155895
Fix query to mobile transactions main statistics (#155895)\n\nWhen
splitting the query to mobile transactions main statistics,
the\r\nsessions were left in the errors query and should have been
retrieved in\r\nthe transactions events. This PR fix this
issue","sha":"67b211001fe50d3d2f2430689402f1bab8224294"}},"sourceBranch":"main","suggestedTargetBranches":["8.8"],"targetPullRequestStates":[{"branch":"8.8","label":"v8.8.0","labelRegex":"^v(\\d+).(\\d+).\\d+$","isSourceBranch":false,"state":"NOT_CREATED"},{"branch":"main","label":"v8.9.0","labelRegex":"^v8.9.0$","isSourceBranch":true,"state":"MERGED","url":"#155895
Fix query to mobile transactions main statistics (#155895)\n\nWhen
splitting the query to mobile transactions main statistics,
the\r\nsessions were left in the errors query and should have been
retrieved in\r\nthe transactions events. This PR fix this
issue","sha":"67b211001fe50d3d2f2430689402f1bab8224294"}}]}] BACKPORT-->

Co-authored-by: Miriam <31922082+MiriamAparicio@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Fixes for quality problems that affect the customer experience release_note:skip Skip the PR/issue when compiling release notes Team:APM All issues that need APM UI Team support v8.8.0 v8.9.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants