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(Telemetry): Add projectId to payload #10180

Merged
merged 1 commit into from Nov 3, 2021

Conversation

pgrzesik
Copy link
Contributor

@pgrzesik pgrzesik commented Nov 1, 2021

Reported internally, add projectId to telemetry

Before releasing, related backend PR needs to be merged

@codecov
Copy link

codecov bot commented Nov 1, 2021

Codecov Report

Merging #10180 (db9cc19) into master (254e70c) will decrease coverage by 0.03%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #10180      +/-   ##
==========================================
- Coverage   85.38%   85.35%   -0.04%     
==========================================
  Files         339      339              
  Lines       13819    13831      +12     
==========================================
+ Hits        11800    11806       +6     
- Misses       2019     2025       +6     
Impacted Files Coverage Δ
lib/plugins/aws/deploy/index.js 98.68% <100.00%> (+0.05%) ⬆️
lib/plugins/aws/provider.js 94.31% <100.00%> (+0.01%) ⬆️
lib/utils/telemetry/generatePayload.js 90.90% <100.00%> (+0.43%) ⬆️
lib/Serverless.js 66.96% <0.00%> (-2.51%) ⬇️
lib/plugins/aws/info/index.js 97.22% <0.00%> (+0.07%) ⬆️

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 254e70c...db9cc19. Read the comment docs.

@pgrzesik pgrzesik requested a review from medikoo November 2, 2021 08:04
@@ -128,7 +129,7 @@ const getServiceConfig = ({ configuration, options, variableSources }) => {

// This method is explicitly kept as synchronous. The reason for it being the fact that it needs to
// be executed in such manner due to its use in `process.on('SIGINT')` handler.
module.exports = ({
module.exports = async ({
Copy link
Contributor

Choose a reason for hiding this comment

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

This method needs to stay sync, see comment you've added above previously :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed the approach 👍

@@ -80,6 +84,12 @@ class AwsDeploy {
.getStage()} ${style.aside(`(${this.serverless.getProvider('aws').getRegion()})`)}`
);
log.info(); // Ensure gap between verbose logging

try {
Copy link
Contributor

Choose a reason for hiding this comment

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

This try/catch is ineffective (async functions cannot crash sync way)

What I had in mind, was something as:

this.serverless.provider.getAccountId().then(
  accountId => this.accountId = accountId,
  () => { /* Ignore any error */}
);

And I wouldn't further handle result promise. I don't think there's any need to do that.
Use case would be, if this request, could take longer than deployment, but I don't think it can be the case

@@ -1437,6 +1437,9 @@ class AwsProvider {
// Store credentials in this variable to avoid creating them several times (messes up MFA).
this.cachedCredentials = null;

// Store accountId to be used in `generateTelemetry` logic
this.cachedAccountId = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not this.accountId ?

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 particular reason other than using similar naming to cachedCredentials above, but I don't have a strong opinion - I'll change it

@pgrzesik pgrzesik force-pushed the introduce-project-id-tracking branch 2 times, most recently from ee00e97 to 6f23ea6 Compare November 2, 2021 14:52
@pgrzesik pgrzesik requested a review from medikoo November 2, 2021 15:06
this.serverless
.getProvider('aws')
.getAccountId()
.then((accountId) => (this.serverless.getProvider('aws').accountId = accountId));
Copy link
Contributor

Choose a reason for hiding this comment

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

  • this.serverless .getProvider('aws') is accessible at this.provider why not rely on that?
  • getAccountId() resolves with accountId, why not simply take it from there?
  • Let's silence eventual rejection (otherwise it'll throw as unhandled in case of e.g. missing credentials)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Good point
  2. I'm not sure what do you mean by that - could you explain?
  3. of course 🤦

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure what do you mean by that - could you explain?

Sorry, I misread the code, ignore this one

@@ -165,7 +172,7 @@ class AwsDeploy {
}
},

'finalize': () => {
'finalize': async () => {
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 change is not needed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

@@ -298,6 +299,17 @@ module.exports = ({
payload.config = getServiceConfig({ configuration, options, variableSources });
payload.isConfigValid = getConfigurationValidationResult(configuration);
payload.dashboard.orgUid = serverless && serverless.service.orgUid;

if (command === 'deploy' && isAwsProvider) {
const serviceName = configuration && configuration.service.name;
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 condifugration cannot be falsy here.

Also service name, can be set directly at service I think (e.g. in case where configurationInput is passed)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed


if (command === 'deploy' && isAwsProvider) {
const serviceName = configuration && configuration.service.name;
const accountId = serverless && serverless.getProvider('aws').accountId;
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably put && serverless in main condition, and assume it unconditionally here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

changed

Copy link
Contributor

@medikoo medikoo left a comment

Choose a reason for hiding this comment

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

Looks great 👍

@pgrzesik pgrzesik merged commit cc7d7e4 into master Nov 3, 2021
@pgrzesik pgrzesik deleted the introduce-project-id-tracking branch November 3, 2021 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants