aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.39k stars 2.11k forks source link

AWSCloudWatchProvider writes infinity number of errors if user doesn't have permissions to write logs to CloudWatch #9575

Open sergey-koryshev opened 2 years ago

sergey-koryshev commented 2 years ago

Before opening, please confirm:

JavaScript Framework

Angular

Amplify APIs

Not applicable

Amplify Categories

Not applicable

Environment information

``` # Put output below this line System: OS: Windows 10 10.0.22000 CPU: (8) x64 Intel(R) Core(TM) i5-10400H CPU @ 2.60GHz Memory: 2.57 GB / 15.61 GB Binaries: Node: 14.18.0 - C:\Program Files\nodejs\node.EXE npm: 6.14.15 - C:\Program Files\nodejs\npm.CMD Browsers: Edge: Spartan (44.22000.120.0), Chromium (98.0.1108.43) Internet Explorer: 11.0.22000.120 npmPackages: @angular-devkit/build-angular: ~0.1102.4 => 0.1102.14 @angular-eslint/builder: 4.3.0 => 4.3.0 @angular-eslint/eslint-plugin: 4.3.0 => 4.3.0 @angular-eslint/eslint-plugin-template: 4.3.0 => 4.3.0 @angular-eslint/schematics: 4.3.0 => 4.3.0 @angular-eslint/template-parser: 4.3.0 => 4.3.0 @angular/animations: ~11.2.5 => 11.2.14 @angular/animations/browser: undefined () @angular/animations/browser/testing: undefined () @angular/cdk: ~11.2.4 => 11.2.13 @angular/cdk/a11y: undefined () @angular/cdk/accordion: undefined () @angular/cdk/bidi: undefined () @angular/cdk/clipboard: undefined () @angular/cdk/coercion: undefined () @angular/cdk/collections: undefined () @angular/cdk/drag-drop: undefined () @angular/cdk/keycodes: undefined () @angular/cdk/layout: undefined () @angular/cdk/observers: undefined () @angular/cdk/overlay: undefined () @angular/cdk/platform: undefined () @angular/cdk/portal: undefined () @angular/cdk/scrolling: undefined () @angular/cdk/stepper: undefined () @angular/cdk/table: undefined () @angular/cdk/testing: undefined () @angular/cdk/testing/protractor: undefined () @angular/cdk/testing/testbed: undefined () @angular/cdk/text-field: undefined () @angular/cdk/tree: undefined () @angular/cli: ~11.2.4 => 11.2.14 @angular/common: ~11.2.5 => 11.2.14 @angular/common/http: undefined () @angular/common/http/testing: undefined () @angular/common/testing: undefined () @angular/common/upgrade: undefined () @angular/compiler: ~11.2.5 => 11.2.14 @angular/compiler-cli: ~11.2.5 => 11.2.14 @angular/compiler/testing: undefined () @angular/core: ~11.2.5 => 11.2.14 @angular/core/testing: undefined () @angular/flex-layout: 11.0.0-beta.33 => 11.0.0-beta.33 @angular/flex-layout/core: undefined () @angular/flex-layout/extended: undefined () @angular/flex-layout/flex: undefined () @angular/flex-layout/grid: undefined () @angular/flex-layout/server: undefined () @angular/forms: ~11.2.5 => 11.2.14 @angular/language-service: ~11.2.5 => 11.2.14 @angular/material: ~11.2.4 => 11.2.13 @angular/material/autocomplete: undefined () @angular/material/autocomplete/testing: undefined () @angular/material/badge: undefined () @angular/material/badge/testing: undefined () @angular/material/bottom-sheet: undefined () @angular/material/bottom-sheet/testing: undefined () @angular/material/button: undefined () @angular/material/button-toggle: undefined () @angular/material/button-toggle/testing: undefined () @angular/material/button/testing: undefined () @angular/material/card: undefined () @angular/material/card/testing: undefined () @angular/material/checkbox: undefined () @angular/material/checkbox/testing: undefined () @angular/material/chips: undefined () @angular/material/chips/testing: undefined () @angular/material/core: undefined () @angular/material/core/testing: undefined () @angular/material/datepicker: undefined () @angular/material/datepicker/testing: undefined () @angular/material/dialog: undefined () @angular/material/dialog/testing: undefined () @angular/material/divider: undefined () @angular/material/divider/testing: undefined () @angular/material/expansion: undefined () @angular/material/expansion/testing: undefined () @angular/material/form-field: undefined () @angular/material/form-field/testing: undefined () @angular/material/form-field/testing/control: undefined () @angular/material/grid-list: undefined () @angular/material/grid-list/testing: undefined () @angular/material/icon: undefined () @angular/material/icon/testing: undefined () @angular/material/input: undefined () @angular/material/input/testing: undefined () @angular/material/list: undefined () @angular/material/list/testing: undefined () @angular/material/menu: undefined () @angular/material/menu/testing: undefined () @angular/material/paginator: undefined () @angular/material/paginator/testing: undefined () @angular/material/progress-bar: undefined () @angular/material/progress-bar/testing: undefined () @angular/material/progress-spinner: undefined () @angular/material/progress-spinner/testing: undefined () @angular/material/radio: undefined () @angular/material/radio/testing: undefined () @angular/material/select: undefined () @angular/material/select/testing: undefined () @angular/material/sidenav: undefined () @angular/material/sidenav/testing: undefined () @angular/material/slide-toggle: undefined () @angular/material/slide-toggle/testing: undefined () @angular/material/slider: undefined () @angular/material/slider/testing: undefined () @angular/material/snack-bar: undefined () @angular/material/snack-bar/testing: undefined () @angular/material/sort: undefined () @angular/material/sort/testing: undefined () @angular/material/stepper: undefined () @angular/material/stepper/testing: undefined () @angular/material/table: undefined () @angular/material/table/testing: undefined () @angular/material/tabs: undefined () @angular/material/tabs/testing: undefined () @angular/material/toolbar: undefined () @angular/material/toolbar/testing: undefined () @angular/material/tooltip: undefined () @angular/material/tooltip/testing: undefined () @angular/material/tree: undefined () @angular/material/tree/testing: undefined () @angular/platform-browser: ~11.2.5 => 11.2.14 @angular/platform-browser-dynamic: ~11.2.5 => 11.2.14 @angular/platform-browser-dynamic/testing: undefined () @angular/platform-browser/animations: undefined () @angular/platform-browser/testing: undefined () @angular/router: ~11.2.5 => 11.2.14 @angular/router/testing: undefined () @angular/router/upgrade: undefined () @compodoc/compodoc: ^1.1.15 => 1.1.15 @iconify/icons-emojione: ~1.1.0 => 1.1.0 @iconify/icons-fa-brands: ~1.1.0 => 1.1.1 @iconify/icons-fa-solid: ~1.1.0 => 1.1.1 @iconify/icons-ic: ~1.1.3 => 1.1.9 @iconify/icons-logos: ~1.1.9 => 1.1.10 @ngneat/until-destroy: ~8.0.4 => 8.0.4 @ngx-formly/core: ^5.0.0 => 5.10.22 @ngx-formly/core/json-schema: undefined () @ngx-formly/core/select: undefined () @ngx-formly/material: ^5.0.0 => 5.10.22 @ngx-formly/material/checkbox: undefined () @ngx-formly/material/datepicker: undefined () @ngx-formly/material/form-field: undefined () @ngx-formly/material/input: undefined () @ngx-formly/material/multicheckbox: undefined () @ngx-formly/material/native-select: undefined () @ngx-formly/material/radio: undefined () @ngx-formly/material/select: undefined () @ngx-formly/material/slider: undefined () @ngx-formly/material/textarea: undefined () @ngx-formly/material/toggle: undefined () @ngx-formly/schematics: ^5.10.21 => 5.10.22 @ngx-loading-bar/core: ~5.1.1 => 5.1.2 @ngx-loading-bar/http-client: ^5.1.2 => 5.1.2 @ngx-loading-bar/router: ~5.1.1 => 5.1.2 @types/faker: ^5.1.5 => 5.5.8 @types/jasmine: ~3.6.1 => 3.6.11 @types/jasminewd2: ~2.0.8 => 2.0.10 @types/lodash: ^4.14.176 => 4.14.176 @types/node: ~14.14.7 => 14.14.45 @types/showdown: ~1.9.3 => 1.9.4 @types/simplebar: ~5.1.1 => 5.1.2 @types/uuid: ^8.3.1 => 8.3.1 @typescript-eslint/eslint-plugin: 4.16.1 => 4.16.1 @typescript-eslint/parser: 4.16.1 => 4.16.1 @visurel/iconify-angular: ~11.0.0 => 11.0.0 angular-calendar: ~0.29.0-beta.9 => 0.29.0-beta.10 angular-in-memory-web-api: ^0.11.0 => 0.11.0 angular-split: ^5.0.0 => 5.0.0 apexcharts: ~3.25.0 => 3.25.0 aws-amplify: ^4.3.10 => 4.3.10 aws-sdk: ^2.968.0 => 2.977.0 date-fns: ~2.19.0 => 2.19.0 deep-copy-ts: ^0.5.0 => 0.5.0 deepdash-es: ^5.3.9 => 5.3.9 eslint: ^7.6.0 => 7.32.0 eslint-config-prettier: ^8.3.0 => 8.3.0 eslint-plugin-prettier: ^4.0.0 => 4.0.0 example-typescript: 1.0.0 faker: ~5.4.0 => 5.4.0 file-saver: ^2.0.5 => 2.0.5 highlight.js: ~10.6.0 => 10.6.0 jasmine-core: ~3.5.0 => 3.5.0 (2.8.0, 3.9.0) jasmine-spec-reporter: ~5.0.0 => 5.0.2 jwt-decode: ^3.1.2 => 3.1.2 karma: ~5.0.0 => 5.0.9 karma-chrome-launcher: ~3.1.0 => 3.1.0 karma-jasmine: ~4.0.0 => 4.0.1 karma-jasmine-html-reporter: ^1.5.0 => 1.5.4 lib: 0.0.1 material-icons: ^1.2.0 => 1.2.0 ngx-quicklink: ~0.2.7 => 0.2.7 ngx-quill: ~13.2.0 => 13.2.0 ngx-showdown: ~6.0.0 => 6.0.0 node-example: 1.0.0 postcss: ^8.1.0 => 8.3.6 (8.2.15, 6.0.23, 7.0.36) postcss-scss: ^3.0.5 => 3.0.5 prettier: ^2.4.1 => 2.4.1 protractor: ~7.0.0 => 7.0.0 protractor-example: 1.0.0 quill: ~1.3.7 => 1.3.7 rxjs: ~6.6.0 => 6.6.7 (6.6.3) rxjs/ajax: undefined () rxjs/fetch: undefined () rxjs/internal-compatibility: undefined () rxjs/operators: undefined () rxjs/testing: undefined () rxjs/webSocket: undefined () showdown: ~1.9.1 => 1.9.1 simplebar: ~5.3.0 => 5.3.5 tailwindcss: ~2.0.3 => 2.0.4 ts-node: ~8.3.0 => 8.3.0 tslib: ^2.0.0 => 2.3.1 (1.14.1, 2.1.0) typescript: ~4.1.5 => 4.1.6 (4.1.5, 3.9.10) typescript-example: 1.0.0 uuid: ^8.3.2 => 8.3.2 (3.4.0, 3.3.2) xlsx: ^0.17.2 => 0.17.2 zone-mix: undefined () zone-node: undefined () zone-testing: undefined () zone.js: ~0.11.3 => 0.11.4 zone.js/async-test: undefined () zone.js/async-test.min: undefined () zone.js/fake-async-test: undefined () zone.js/fake-async-test.min: undefined () zone.js/jasmine-patch: undefined () zone.js/jasmine-patch.min: undefined () zone.js/long-stack-trace-zone: undefined () zone.js/long-stack-trace-zone.min: undefined () zone.js/mocha-patch: undefined () zone.js/mocha-patch.min: undefined () zone.js/proxy: undefined () zone.js/proxy.min: undefined () zone.js/sync-test: undefined () zone.js/sync-test.min: undefined () zone.js/task-tracking: undefined () zone.js/task-tracking.min: undefined () zone.js/webapis-media-query: undefined () zone.js/webapis-media-query.min: undefined () zone.js/webapis-notification: undefined () zone.js/webapis-notification.min: undefined () zone.js/webapis-rtc-peer-connection: undefined () zone.js/webapis-rtc-peer-connection.min: undefined () zone.js/webapis-shadydom: undefined () zone.js/webapis-shadydom.min: undefined () zone.js/wtf: undefined () zone.js/wtf.min: undefined () zone.js/zone-bluebird: undefined () zone.js/zone-bluebird.min: undefined () zone.js/zone-error: undefined () zone.js/zone-error.min: undefined () zone.js/zone-legacy: undefined () zone.js/zone-legacy.min: undefined () zone.js/zone-patch-canvas: undefined () zone.js/zone-patch-canvas.min: undefined () zone.js/zone-patch-cordova: undefined () zone.js/zone-patch-cordova.min: undefined () zone.js/zone-patch-electron: undefined () zone.js/zone-patch-electron.min: undefined () zone.js/zone-patch-fetch: undefined () zone.js/zone-patch-fetch.min: undefined () zone.js/zone-patch-jsonp: undefined () zone.js/zone-patch-jsonp.min: undefined () zone.js/zone-patch-message-port: undefined () zone.js/zone-patch-message-port.min: undefined () zone.js/zone-patch-promise-test: undefined () zone.js/zone-patch-promise-test.min: undefined () zone.js/zone-patch-resize-observer: undefined () zone.js/zone-patch-resize-observer.min: undefined () zone.js/zone-patch-rxjs: undefined () zone.js/zone-patch-rxjs-fake-async: undefined () zone.js/zone-patch-rxjs-fake-async.min: undefined () zone.js/zone-patch-rxjs.min: undefined () zone.js/zone-patch-socket-io: undefined () zone.js/zone-patch-socket-io.min: undefined () zone.js/zone-patch-user-media: undefined () zone.js/zone-patch-user-media.min: undefined () npmGlobalPackages: @angular/cli: 12.2.8 @aws-amplify/cli: 7.6.2 vercel: 23.1.2 ```

Describe the bug

If user doesn't have permissions to write logs to AWS CloudWatch then AWSCloudWatchProvider infinitely write errors to console image

I didn't find an ability to set maximum attempts for logging operation.

Expected behavior

There must be a setting to prevent infinity errors if AWSCloudWatchProvider can't write logs to AWS CloudWatch

Reproduction steps

  1. Setup support of AWSCloudWatchProvider based on information in PR: #8309
  2. Don't set up permissions for user to write logs to AWS CloudWatch
  3. Log any message by method info:
    this.logger.info('Hello there!');

Code Snippet

// Put your code below this line.

Log output

``` // Put your logs below this line ERROR Error: Uncaught (in promise): TypeError: Cannot read properties of undefined (reading 'byteLength') TypeError: Cannot read properties of undefined (reading 'byteLength') at e.isEmptyData (main-es2015.2da9cc8bfe1407a83cd0.js:1:3319443) at t.update (main-es2015.2da9cc8bfe1407a83cd0.js:1:2371814) at t.update (main-es2015.2da9cc8bfe1407a83cd0.js:1:2362061) at m (main-es2015.2da9cc8bfe1407a83cd0.js:1:2762228) at main-es2015.2da9cc8bfe1407a83cd0.js:1:2771115 at main-es2015.2da9cc8bfe1407a83cd0.js:1:2780803 at Object.next (main-es2015.2da9cc8bfe1407a83cd0.js:1:2780908) at main-es2015.2da9cc8bfe1407a83cd0.js:1:2779846 at new D (polyfills-es2015.cd76d172a63b55c49116.js:1:17825) at u (main-es2015.2da9cc8bfe1407a83cd0.js:1:2779594) at b (polyfills-es2015.cd76d172a63b55c49116.js:1:15960) at new D (polyfills-es2015.cd76d172a63b55c49116.js:1:17853) at u (main-es2015.2da9cc8bfe1407a83cd0.js:1:2779594) at main-es2015.2da9cc8bfe1407a83cd0.js:1:2770984 at t.getSigningKey (main-es2015.2da9cc8bfe1407a83cd0.js:1:2771709) at t. (main-es2015.2da9cc8bfe1407a83cd0.js:1:2768988) at main-es2015.2da9cc8bfe1407a83cd0.js:1:2780803 at Object.next (main-es2015.2da9cc8bfe1407a83cd0.js:1:2780908) at a (main-es2015.2da9cc8bfe1407a83cd0.js:1:2779650) at l.invoke (polyfills-es2015.cd76d172a63b55c49116.js:1:6581) [ERROR] 06:19.360 AWSCloudWatch - error getting log group - TypeError: Cannot read properties of undefined (reading 'byteLength') [ERROR] 06:19.360 AWSCloudWatch - failure during log group search: TypeError: Cannot read properties of undefined (reading 'byteLength') [ERROR] 06:19.360 AWSCloudWatch - failure while getting next sequence token: TypeError: Cannot read properties of undefined (reading 'byteLength') [ERROR] 06:19.360 AWSCloudWatch - error during _safeUploadLogEvents: TypeError: Cannot read properties of undefined (reading 'byteLength') [ERROR] 06:19.360 AWSCloudWatch - error when calling _safeUploadLogEvents in the timer interval - TypeError: Cannot read properties of undefined (reading 'byteLength') ```

aws-exports.js

No response

Manual configuration

{
  aws_project_region: 'hidden',
  Auth: {    
    identityPoolId: 'hidden',
    region: 'hidden',
    identityPoolRegion: 'hidden',
    userPoolId: 'hidden',
    userPoolWebClientId: 'hidden',
  },
  Logging: {
    logGroupName: 'SomeGroup',
    logStreamName: 'SomeStreamName',
  },
  csm_enabled: true,
}

Additional configuration

No response

Mobile Device

No response

Mobile Operating System

No response

Mobile Browser

No response

Mobile Browser Version

No response

Additional information and screenshots

No response

dapriett commented 1 year ago

May be related to my bug: https://github.com/aws-amplify/amplify-js/issues/10172

Possibly will need to refactor AWSCloudWatchProvider._getNextSequenceToken, move out _validateLogGroupExistsAndCreate and _validateLogStreamExists to make sure those succeed before kicking off _initiateLogPushInterval

abdallahshaban557 commented 1 year ago

Thank you for the feedback @dapriett - I am going to close your issue and use this one for our team to investigate it further. Thank you for referencing it!

cwomack commented 1 year ago

Commenting to give update on this issue after seeing #10891 opened recently. We are marking these issues tied to AWSCloudWatchProvider as known bugs and will be looking into a fixes soon.

DarylBeattie commented 10 months ago

This issue still exists, FYI.

abdallahshaban557 commented 10 months ago

Hi @DaryBeattie - we are planning on introducing a revamped version of our CloudWatch logger, which will also enable you change your logging configuration remotely as well. You can see an example of it that is available for Swift and Android developers.

DarylBeattie commented 10 months ago

Hi Abdallah,

Thanks for responding about my issue.

That's great, yes -- and I did see that article already and read it. :)

But the big question after I read that was: does it, or will it, work with React Native?

Sincerely, Daryl.

On Thu, Aug 10, 2023 at 11:08 PM Abdallah Shaban @.***> wrote:

Hi @DaryBeattie https://github.com/DaryBeattie - we are planning on introducing a revamped version of our CloudWatch logger, which will also enable you change your logging configuration remotely as well. You can see an example of it that is available https://aws.amazon.com/blogs/mobile/aws-amplify-cloudwatch-logger-is-now-available-for-swift-and-android/#:~:text=We%20are%20excited%20to%20announce,different%20parts%20of%20your%20app. for Swift and Android developers.

— Reply to this email directly, view it on GitHub https://github.com/aws-amplify/amplify-js/issues/9575#issuecomment-1674161098, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZYETGR6LWVJEXJS2I5ALP3XUWO4VANCNFSM5ODPALSA . You are receiving this because you were mentioned.Message ID: @.***>

abdallahshaban557 commented 10 months ago

Yes, we are planning to have it work with React Native as well!

DarylBeattie commented 10 months ago

And another big question....

I just logged this bug: https://github.com/aws-amplify/amplify-js/issues/11785

Will this new logger make that bug completely obsolete?

(I thought you were replying about my new bug, but it appears you were not!)

On Thu, Aug 10, 2023 at 11:27 PM Daryl Beattie @.***> wrote:

Hi Abdallah,

Thanks for responding about my issue.

That's great, yes -- and I did see that article already and read it. :)

But the big question after I read that was: does it, or will it, work with React Native?

Sincerely, Daryl.

On Thu, Aug 10, 2023 at 11:08 PM Abdallah Shaban @.***> wrote:

Hi @DaryBeattie https://github.com/DaryBeattie - we are planning on introducing a revamped version of our CloudWatch logger, which will also enable you change your logging configuration remotely as well. You can see an example of it that is available https://aws.amazon.com/blogs/mobile/aws-amplify-cloudwatch-logger-is-now-available-for-swift-and-android/#:~:text=We%20are%20excited%20to%20announce,different%20parts%20of%20your%20app. for Swift and Android developers.

— Reply to this email directly, view it on GitHub https://github.com/aws-amplify/amplify-js/issues/9575#issuecomment-1674161098, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZYETGR6LWVJEXJS2I5ALP3XUWO4VANCNFSM5ODPALSA . You are receiving this because you were mentioned.Message ID: @.***>

abdallahshaban557 commented 10 months ago

We will fix this bug as well, Daryl!

DarylBeattie commented 10 months ago

Wow, uh… honestly you made my day. 🙂 Thank you!!!

On Thu, Aug 10, 2023 at 11:36 PM Abdallah Shaban @.***> wrote:

We will fix this bug as well, Daryl!

— Reply to this email directly, view it on GitHub https://github.com/aws-amplify/amplify-js/issues/9575#issuecomment-1674173120, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZYETGQL5GAVUH66Y3EIRNLXUWSDLANCNFSM5ODPALSA . You are receiving this because you were mentioned.Message ID: @.***>