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

feat:usage-diagnoses #3641

Merged
merged 1 commit into from
Jun 25, 2020
Merged

Conversation

ammarkarachi
Copy link
Contributor

Issue #, if available:

Description of changes:

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@kaustavghosh06 kaustavghosh06 self-assigned this Mar 12, 2020
@ammarkarachi ammarkarachi force-pushed the feature/telemetry branch 2 times, most recently from 142b5b4 to 6c4a60b Compare April 10, 2020 22:54
@ammarkarachi ammarkarachi requested a review from undefobj May 19, 2020 18:21
@lgtm-com
Copy link

lgtm-com bot commented May 19, 2020

This pull request introduces 1 alert when merging 81bc4d1dfe18f2cee473b5a25350d68f905ab31a into 39870f1 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@codecov
Copy link

codecov bot commented Jun 5, 2020

Codecov Report

Merging #3641 into master will decrease coverage by 0.99%.
The diff coverage is 72.50%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3641      +/-   ##
==========================================
- Coverage   61.57%   60.57%   -1.00%     
==========================================
  Files         333      349      +16     
  Lines       14550    15133     +583     
  Branches     2764     2865     +101     
==========================================
+ Hits         8959     9167     +208     
- Misses       5164     5478     +314     
- Partials      427      488      +61     
Impacted Files Coverage Δ
packages/amplify-appsync-simulator/src/index.ts 68.36% <0.00%> (-0.71%) ⬇️
...ages/amplify-category-auth/commands/auth/remove.js 80.00% <0.00%> (-5.72%) ⬇️
.../lib/S3AndCloudFront/helpers/cloudfront-manager.js 87.50% <0.00%> (ø)
...g/lib/S3AndCloudFront/helpers/configure-Publish.js 86.58% <0.00%> (-3.29%) ⬇️
...sting/lib/S3AndCloudFront/helpers/file-uploader.js 78.43% <0.00%> (ø)
.../amplify-category-notifications/lib/auth-helper.js 0.00% <0.00%> (ø)
packages/amplify-category-xr/commands/xr/push.js 33.33% <0.00%> (-4.17%) ⬇️
packages/amplify-category-xr/lib/xr-manager.js 13.23% <0.00%> (-0.10%) ⬇️
packages/amplify-cli/src/domain/context.ts 100.00% <ø> (ø)
...amplify-codegen-appsync-model-plugin/src/preset.ts 0.00% <0.00%> (ø)
... and 47 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 3afb335...2a7d318. Read the comment docs.

@ammarkarachi ammarkarachi changed the title Feature/telemetry feat:usage-tracking Jun 5, 2020
@lgtm-com
Copy link

lgtm-com bot commented Jun 5, 2020

This pull request introduces 1 alert when merging 37fe3118e30516b6a90b41aa38fa988e33270054 into 493e631 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@ammarkarachi ammarkarachi marked this pull request as ready for review June 7, 2020 06:02
@ammarkarachi ammarkarachi requested a review from attilah June 9, 2020 21:31
packages/amplify-cli/scripts/post-install.js Outdated Show resolved Hide resolved
@@ -12,18 +13,30 @@ try {
} catch (e) {
// could not delete the cache directory but don't want to fail the installation
}
console.log('\n');
console.log(EOL);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Why are we printing EOLs, to have 2 empty lines? I think we'd be good just a simple empty line.

Copy link
Contributor Author

@ammarkarachi ammarkarachi Jun 11, 2020

Choose a reason for hiding this comment

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

I wanted to make sure it was platform independent
windows it's '\n\r'

Copy link
Contributor

Choose a reason for hiding this comment

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

I meant that how is it different from an empty console.log() statement. We want 2 empty lines or what is the reason?

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 am sorry I misunderstood, it's just to keep separation more obvious

packages/amplify-cli/scripts/post-install.js Outdated Show resolved Hide resolved
packages/amplify-cli/src/config-steps/c0-analyzeProject.js Outdated Show resolved Hide resolved
.circleci/config.base.yml Outdated Show resolved Hide resolved
packages/amplify-cli/src/telemetry/config.ts Outdated Show resolved Hide resolved
packages/amplify-cli/src/telemetry/getConfig.ts Outdated Show resolved Hide resolved
packages/amplify-cli/src/telemetry/getConfig.ts Outdated Show resolved Hide resolved
packages/amplify-cli/src/telemetry/index.ts Outdated Show resolved Hide resolved
@lgtm-com
Copy link

lgtm-com bot commented Jun 15, 2020

This pull request introduces 2 alerts when merging b93457174354cbb4f74121e35204bd72ffe1aeef into f45d32b - view on LGTM.com

new alerts:

  • 2 for Useless assignment to local variable

@lgtm-com
Copy link

lgtm-com bot commented Jun 15, 2020

This pull request introduces 2 alerts when merging d330a9411dcc5b6ff0a1db959f01414a28e698f4 into f45d32b - view on LGTM.com

new alerts:

  • 2 for Useless assignment to local variable

@lgtm-com
Copy link

lgtm-com bot commented Jun 15, 2020

This pull request introduces 2 alerts when merging 097235d045969a46cf993c637e90302a9db2ab15 into f45d32b - view on LGTM.com

new alerts:

  • 2 for Useless assignment to local variable

@ammarkarachi ammarkarachi changed the title feat:usage-tracking feat:usage-diagnoses Jun 15, 2020
@ammarkarachi ammarkarachi requested review from attilah and removed request for undefobj and kaustavghosh06 June 15, 2020 17:34
Copy link
Contributor

@attilah attilah left a comment

Choose a reason for hiding this comment

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

Thanks for addressing the previous comments, added a few new ones.

packages/amplify-cli/src/__tests__/telemetry.test.ts Outdated Show resolved Hide resolved

describe('test telemetry', () => {
beforeAll(() => {
process.env = Object.assign(process.env, { AMPLIFY_CLI_BETA_USAGE_TRACKING_URL: originalUrl });
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we have the BETA in it? I think that we need to use the same variable: AMPLIFY_CLI_USAGE_TRACKING_URL and its value should point to different endpoint during testing.

Copy link
Contributor Author

@ammarkarachi ammarkarachi Jun 25, 2020

Choose a reason for hiding this comment

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

What do you mean by testing? e2e tests?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We shouldn't be exposing a beta url to the public also.

packages/amplify-cli/src/__tests__/telemetry.test.ts Outdated Show resolved Hide resolved

export function write(context: Context, keyValues: Object) {
Config.Instance.setValues(keyValues);
fs.writeFileSync(getPath(context), JSON.stringify(Config.Instance));
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this can fail if ~/.amplify directory does not exist, not?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

~/.amplify the directory is created during a plugin scan.

@@ -0,0 +1,23 @@
import semver from 'semver';

const APIVersionToPayloadVersion = new Map<string, Array<string>>([['v1.0', ['1.0.0']]]);
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the design here? a given CLI version just reports 1 version of the payload what we change over time. So the CLI does not have to support multiple versions.

On the other hand it seems that the getLatestApiVersion() is doing the version calculation on every call which seems to be suboptimal as this code is on the hot path if telemetry is enabled, if you decide to keep the multiple versions here, can we cache it between invocations?

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 want the API version to be mapped to payload version. This way it's explicit if there are any major changes we would have to make sure the API works with the new payload. No we are not caching it. It's kind of excessive to cache something that's been called twice in a lifetime

import { getLatestApiVersion } from './VersionManager';

const version = getLatestApiVersion();
const prodUrl = `https://aws-amplify-cli-telemetry.us-east-1.amazonaws.com/${version}/metrics`;
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems that the payload version and the API version for telemetry is coupled together?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes the payload version is coupled together with the API version


const version = getLatestApiVersion();
const prodUrl = `https://aws-amplify-cli-telemetry.us-east-1.amazonaws.com/${version}/metrics`;
export function getUrl(): UrlWithStringQuery {
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we caching the result of this function between invocations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No we are not caching it. It's kind of excessive to cache something that's been called twice in a lifetime when the software is running

this.input = redactInput(input, true);
}

static get Instance(): ITelemetry {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need static instance variable in the ITelemetry implementations?

This only accessed through context, which already has an instance of those classes.

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 is how a singleton is created

}
init(installationUuid: String, version: String, input: any): void {}

private static instance: NoTelemetry;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as for the other ITelemetry implementation.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as telemetry

@ammarkarachi ammarkarachi requested a review from attilah June 25, 2020 17:32
@ammarkarachi ammarkarachi merged commit 30a7fe7 into aws-amplify:master Jun 25, 2020
ammarkarachi added a commit that referenced this pull request Jun 25, 2020
ammarkarachi added a commit that referenced this pull request Jul 27, 2020
nikhname pushed a commit to nikhname/amplify-cli that referenced this pull request Jul 27, 2020
@github-actions
Copy link

This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 26, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants