Skip to content

stats: flush stats based on application lifecycle#717

Merged
rebello95 merged 21 commits intomasterfrom
flush-platform
Mar 3, 2020
Merged

stats: flush stats based on application lifecycle#717
rebello95 merged 21 commits intomasterfrom
flush-platform

Conversation

@rebello95
Copy link
Copy Markdown
Contributor

@rebello95 rebello95 commented Mar 2, 2020

Description

This change adds the ability to automatically flush stats based on application lifecycle changes (in addition to the scheduled flushing interval).

Enabling this flushing system is done automatically when the iOS/Android clients are instantiated.

On iOS, this is done by observing NSNotificationCenter.

Android requires an Application context to use for registering lifecycle callbacks. To accommodate this, the Application is now passed in to the Android builder instead of the Context.

Right now this new stats flushing behavior is enabled by default. In the future, we would like to investigate making it optional using the builder pattern. For example:

EnvoyClientBuilder()
  .addAppLifecycleHandling()
  .build()
AndroidEnvoyClientBuilder(baseContext)
  .addAppLifecycleHandling(getApplication())
  .build()

#721 will track this work.

As part of this PR, I also updated some documentation to better reflect the differences between Android/Java interfaces and those present on iOS.

Testing

  • Tested locally and verified that stats are flushed when backgrounding the iOS and Android sample apps
  • Sample apps use this new mechanism

Risk Level

Low, this is an additive change.

Issues

Resolves #573

Signed-off-by: Michael Rebello me@michaelrebello.com

Adds functionality built on top of the upstream Envoy changes in envoyproxy/envoy#10097 which will allow the bridging layers to manually flush stats based on lifecycle changes in the mobile application.

Follow-up PRs will call these functions from Java/Objective-C.

Part of #573.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
@rebello95 rebello95 added the work in progress Not yet ready for review label Mar 2, 2020
Signed-off-by: Michael Rebello <me@michaelrebello.com>
@rebello95 rebello95 changed the base branch from expose-flush to master March 3, 2020 00:26
rebello95 and others added 4 commits March 2, 2020 17:45
Adding the following stats to the allow-list based on [these Envoy docs](https://www.envoyproxy.io/docs/envoy/latest/configuration/upstream/cluster_manager/cluster_stats):

- `upstream_rq_retry`
- `upstream_rq_retry_overflow`
- `upstream_rq_retry_success`

Also re-alphabetized the stats list.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
Adds functionality built on top of the upstream Envoy changes in envoyproxy/envoy#10097 which will allow the bridging layers to manually flush stats based on lifecycle changes in the mobile application.

Note: Stats must be flushed from the main Envoy thread, as validated by the following assertion failure that occurs when attempting to flush from another thread:

```
[2020-02-27 14:38:43.181][4716580][critical][assert] [external/envoy/source/common/thread_local/thread_local_impl.cc:190] assert failure: std::this_thread::get_id() == main_thread_id_.
```

Follow-up PRs will call these functions from Java/Objective-C.

Part of #573.

Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
@rebello95 rebello95 marked this pull request as ready for review March 3, 2020 02:25
rebello95 and others added 2 commits March 2, 2020 22:22
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>

Signed-off-by: Alan Chiu <achiu@lyft.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
@rebello95 rebello95 added observability/stats platform/android Issues related to Android platform/ios Issues related to iOS and removed work in progress Not yet ready for review labels Mar 3, 2020
@rebello95 rebello95 requested a review from buildbreaker March 3, 2020 07:17
buildbreaker
buildbreaker previously approved these changes Mar 3, 2020
Signed-off-by: Michael Rebello <me@michaelrebello.com>
Signed-off-by: Michael Rebello <me@michaelrebello.com>
@rebello95 rebello95 merged commit 0e09f82 into master Mar 3, 2020
@rebello95 rebello95 deleted the flush-platform branch March 3, 2020 07:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

observability/stats platform/android Issues related to Android platform/ios Issues related to iOS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

stats: expose API to flush stats based on lifecycle events

2 participants