chore: add duration logs inside secondary functions (#23287)

## Description
> With this code change we are trying to determine which of the
operations present inside the Mono
[here](65fa493843/app/server/appsmith-server/src/main/java/com/appsmith/server/solutions/ce/UserSignupCEImpl.java (L264)).

> Note: 
> One preconceived notion, which I am taking here is that
`getExternalAddressMono ` may be the culprit behind the slowness,
because it makes call to an external address
`"https://api64.ipify.org"`. This doesn't mean that we are ruling out
the other operations, and have added the logs there as well.

#### PR fixes following issue(s)
Fixes #22147 

#### Media
> A video or a GIF is preferred. when using Loom, don’t embed because it
looks like it’s a GIF. instead, just link to the video
>
>
#### Type of change
- Chore (housekeeping or task changes that don't impact user perception)

## Testing
>
#### How Has This Been Tested?
> All existing test cases should pass.
#### Test Plan
> Add Testsmith test cases links that relate to this PR
>
>
#### Issues raised during DP testing
> Link issues raised during DP testing for better visiblity and tracking
(copy link from comments dropped on this PR)
>
>
>
## Checklist:
#### Dev activity
- [x] My code follows the style guidelines of this project
- [x] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [x] New and existing unit tests pass locally with my changes
- [ ] PR is being merged under a feature flag


#### QA activity:
- [ ] [Speedbreak
features](https://github.com/appsmithorg/TestSmith/wiki/Test-plan-implementation#speedbreaker-features-to-consider-for-every-change)
have been covered
- [ ] Test plan covers all impacted features and [areas of
interest](https://github.com/appsmithorg/TestSmith/wiki/Guidelines-for-test-plans/_edit#areas-of-interest)
- [ ] Test plan has been peer reviewed by project stakeholders and other
QA members
- [ ] Manually tested functionality on DP
- [ ] We had an implementation alignment call with stakeholders post QA
Round 2
- [ ] Cypress test cases have been added and approved by SDET/manual QA
- [ ] Added `Test Plan Approved` label after Cypress tests were reviewed
- [ ] Added `Test Plan Approved` label after JUnit tests were reviewed

Co-authored-by: Nilesh Sarupriya <20905988+nsarupr@users.noreply.github.com>
This commit is contained in:
Nilesh Sarupriya 2023-05-15 11:15:31 +05:30 committed by GitHub
parent 5c206ae3ae
commit f0d2a8cf19
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,7 @@ import com.appsmith.server.domains.LoginSource;
import com.appsmith.server.domains.User;
import com.appsmith.server.domains.UserData;
import com.appsmith.server.domains.UserState;
import com.appsmith.server.dtos.EnvChangesResponseDTO;
import com.appsmith.server.dtos.UserSignupDTO;
import com.appsmith.server.dtos.UserSignupRequestDTO;
import com.appsmith.server.exceptions.AppsmithError;
@ -261,55 +262,97 @@ public class UserSignupCEImpl implements UserSignupCE {
userData.setRole(userFromRequest.getRole());
userData.setUseCase(userFromRequest.getUseCase());
Mono<Long> allSecondaryFunctions = Mono.when(
userDataService.updateForUser(user, userData),
Mono.zip(configService.getInstanceId(), NetworkUtils.getExternalAddress().defaultIfEmpty("unknown"))
.flatMap(tuple -> {
final String instanceId = tuple.getT1();
final String ip = tuple.getT2();
log.debug("Installation setup complete.");
String newsletterSignedUpUserEmail = userFromRequest.isSignupForNewsletter() ? user.getEmail() : "";
String newsletterSignedUpUserName = userFromRequest.isSignupForNewsletter() ? user.getName() : "";
Map<String, Object> analyticsProps = new HashMap<>();
analyticsProps.put(DISABLE_TELEMETRY, !userFromRequest.isAllowCollectingAnonymousData());
analyticsProps.put(SUBSCRIBE_MARKETING, userFromRequest.isSignupForNewsletter());
analyticsProps.put(EMAIL, newsletterSignedUpUserEmail);
analyticsProps.put(ROLE, ObjectUtils.defaultIfNull(userData.getRole(), ""));
analyticsProps.put(GOAL, ObjectUtils.defaultIfNull(userData.getUseCase(), ""));
// ip is a reserved keyword for tracking events in Mixpanel though this is allowed in
// Segment. Instead of showing the ip as is Mixpanel provides derived property.
// As we want derived props alongwith the ip address we are sharing the ip
// address in separate keys
// Ref: https://help.mixpanel.com/hc/en-us/articles/360001355266-Event-Properties
analyticsProps.put(IP, ip);
analyticsProps.put(IP_ADDRESS, ip);
analyticsProps.put(NAME, ObjectUtils.defaultIfNull(newsletterSignedUpUserName, ""));
Mono<UserData> userDataMono = userDataService.updateForUser(user, userData)
.elapsed()
.map(pair -> {
log.debug("UserSignupCEImpl::Time taken to update user data for user: {} ms", pair.getT1());
return pair.getT2();
});
analyticsService.identifyInstance(
instanceId,
userData.getRole(),
userData.getUseCase(),
newsletterSignedUpUserEmail,
newsletterSignedUpUserName,
ip);
return analyticsService.sendEvent(
AnalyticsEvents.INSTALLATION_SETUP_COMPLETE.getEventName(),
instanceId,
analyticsProps,
false
);
}),
envManager.applyChanges(Map.of(
Mono<EnvChangesResponseDTO> applyEnvManagerChangesMono = envManager.applyChanges(Map.of(
APPSMITH_DISABLE_TELEMETRY.name(),
String.valueOf(!userFromRequest.isAllowCollectingAnonymousData()),
APPSMITH_INSTANCE_NAME.name(),
commonConfig.getInstanceName(),
APPSMITH_ADMIN_EMAILS.name(),
user.getEmail()
)),
analyticsService.sendObjectEvent(AnalyticsEvents.CREATE_SUPERUSER, user, null)
)
))
.elapsed()
.map(pair -> {
log.debug("UserSignupCEImpl::Time taken to apply env changes: {} ms", pair.getT1());
return pair.getT2();
});
Mono<User> sendCreateSuperUserEvent = analyticsService.sendObjectEvent(AnalyticsEvents.CREATE_SUPERUSER, user, null)
.elapsed()
.map(pair -> {
log.debug("UserSignupCEImpl::Time taken to send create super user event: {} ms", pair.getT1());
return pair.getT2();
});
Mono<String> getInstanceIdMono = configService.getInstanceId()
.elapsed()
.map(pair -> {
log.debug("UserSignupCEImpl::Time taken to get instance ID: {} ms", pair.getT1());
return pair.getT2();
});;
Mono<String> getExternalAddressMono = NetworkUtils.getExternalAddress().defaultIfEmpty("unknown")
.elapsed()
.map(pair -> {
log.debug("UserSignupCEImpl::Time taken to get external address: {} ms", pair.getT1());
return pair.getT2();
});
Mono<Long> installationSetupAnalyticsMono = Mono.zip(getInstanceIdMono, getExternalAddressMono)
.flatMap(tuple -> {
final String instanceId = tuple.getT1();
final String ip = tuple.getT2();
log.debug("Installation setup complete.");
String newsletterSignedUpUserEmail = userFromRequest.isSignupForNewsletter() ? user.getEmail() : "";
String newsletterSignedUpUserName = userFromRequest.isSignupForNewsletter() ? user.getName() : "";
Map<String, Object> analyticsProps = new HashMap<>();
analyticsProps.put(DISABLE_TELEMETRY, !userFromRequest.isAllowCollectingAnonymousData());
analyticsProps.put(SUBSCRIBE_MARKETING, userFromRequest.isSignupForNewsletter());
analyticsProps.put(EMAIL, newsletterSignedUpUserEmail);
analyticsProps.put(ROLE, ObjectUtils.defaultIfNull(userData.getRole(), ""));
analyticsProps.put(GOAL, ObjectUtils.defaultIfNull(userData.getUseCase(), ""));
// ip is a reserved keyword for tracking events in Mixpanel though this is allowed in
// Segment. Instead of showing the ip as is Mixpanel provides derived property.
// As we want derived props alongwith the ip address we are sharing the ip
// address in separate keys
// Ref: https://help.mixpanel.com/hc/en-us/articles/360001355266-Event-Properties
analyticsProps.put(IP, ip);
analyticsProps.put(IP_ADDRESS, ip);
analyticsProps.put(NAME, ObjectUtils.defaultIfNull(newsletterSignedUpUserName, ""));
analyticsService.identifyInstance(
instanceId,
userData.getRole(),
userData.getUseCase(),
newsletterSignedUpUserEmail,
newsletterSignedUpUserName,
ip);
return analyticsService.sendEvent(
AnalyticsEvents.INSTALLATION_SETUP_COMPLETE.getEventName(),
instanceId,
analyticsProps,
false
).thenReturn(1L)
.elapsed()
.map(pair -> {
log.debug("UserSignupCEImpl::Time taken to send installation setup complete analytics event: {} ms", pair.getT1());
return pair.getT2();
});
})
.elapsed()
.map(pair -> {
log.debug("UserSignupCEImpl::Time taken to send installation setup analytics event: {} ms", pair.getT1());
return pair.getT2();
});;
Mono<Long> allSecondaryFunctions = Mono.when(userDataMono, installationSetupAnalyticsMono, applyEnvManagerChangesMono, sendCreateSuperUserEvent)
.thenReturn(1L)
.elapsed()
.map(pair -> {