-
Notifications
You must be signed in to change notification settings - Fork 4.8k
perf: reduce redundant Segment API calls (~35% cut, ~88M calls/month) #42216
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
Open
subrata71
wants to merge
2
commits into
release
Choose a base branch
from
fix/reduce-segment-api-calls
base: release
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,5 @@ | ||
| package com.appsmith.server.solutions.ce; | ||
|
|
||
| import com.appsmith.external.constants.AnalyticsEvents; | ||
| import com.appsmith.external.datatypes.ClientDataType; | ||
| import com.appsmith.external.dtos.ExecuteActionDTO; | ||
| import com.appsmith.external.dtos.ParamProperty; | ||
|
|
@@ -21,23 +20,17 @@ | |
| import com.appsmith.server.acl.AclPermission; | ||
| import com.appsmith.server.applications.base.ApplicationService; | ||
| import com.appsmith.server.configurations.CommonConfig; | ||
| import com.appsmith.server.constants.Constraint; | ||
| import com.appsmith.server.constants.FieldName; | ||
| import com.appsmith.server.datasources.base.DatasourceService; | ||
| import com.appsmith.server.datasourcestorages.base.DatasourceStorageService; | ||
| import com.appsmith.server.domains.Application; | ||
| import com.appsmith.server.domains.ApplicationMode; | ||
| import com.appsmith.server.domains.DatasourceContext; | ||
| import com.appsmith.server.domains.NewAction; | ||
| import com.appsmith.server.domains.Plugin; | ||
| import com.appsmith.server.domains.User; | ||
| import com.appsmith.server.dtos.ExecuteActionMetaDTO; | ||
| import com.appsmith.server.exceptions.AppsmithError; | ||
| import com.appsmith.server.exceptions.AppsmithException; | ||
| import com.appsmith.server.featureflags.CachedFeatures; | ||
| import com.appsmith.server.helpers.ActionExecutionSolutionHelper; | ||
| import com.appsmith.server.helpers.DatasourceAnalyticsUtils; | ||
| import com.appsmith.server.helpers.DateUtils; | ||
| import com.appsmith.server.helpers.PluginExecutorHelper; | ||
| import com.appsmith.server.newactions.base.NewActionService; | ||
| import com.appsmith.server.newpages.base.NewPageService; | ||
|
|
@@ -92,7 +85,6 @@ | |
| import java.util.regex.Pattern; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static com.appsmith.external.constants.CommonFieldName.REDACTED_DATA; | ||
| import static com.appsmith.external.constants.spans.ActionSpan.ACTION_EXECUTION_CACHED_DATASOURCE; | ||
| import static com.appsmith.external.constants.spans.ActionSpan.ACTION_EXECUTION_DATASOURCE_CONTEXT; | ||
| import static com.appsmith.external.constants.spans.ActionSpan.ACTION_EXECUTION_EDITOR_CONFIG; | ||
|
|
@@ -1191,143 +1183,7 @@ private Mono<ActionExecutionRequest> sendExecuteAnalyticsEvent( | |
| request.setProperties(stringProperties); | ||
| } | ||
|
|
||
| return Mono.justOrEmpty(actionDTO.getApplicationId()) | ||
| .flatMap(applicationService::findById) | ||
| .defaultIfEmpty(new Application()) | ||
| .flatMap(application -> Mono.zip( | ||
| Mono.just(application), | ||
| sessionUserService.getCurrentUser(), | ||
| newPageService.getNameByPageId(actionDTO.getPageId(), executeActionDto.getViewMode()), | ||
| pluginService.getByIdWithoutPermissionCheck(actionDTO.getPluginId()), | ||
| datasourceStorageService.getEnvironmentNameFromEnvironmentIdForAnalytics( | ||
| datasourceStorage.getEnvironmentId()))) | ||
| .flatMap(tuple -> { | ||
| final Application application = tuple.getT1(); | ||
| final User user = tuple.getT2(); | ||
| final String pageName = tuple.getT3(); | ||
| final Plugin plugin = tuple.getT4(); | ||
| final String environmentName = tuple.getT5(); | ||
|
|
||
| final PluginType pluginType = actionDTO.getPluginType(); | ||
| final String appMode = TRUE.equals(executeActionDto.getViewMode()) | ||
| ? ApplicationMode.PUBLISHED.toString() | ||
| : ApplicationMode.EDIT.toString(); | ||
|
|
||
| final Map<String, Object> data = new HashMap<>(); | ||
| data.put("username", user.getUsername()); | ||
| data.put("type", pluginType); | ||
| data.put("pluginName", plugin.getName()); | ||
| data.put("name", actionDTO.getName()); | ||
|
|
||
| Map<String, Object> datasourceInfo = new HashMap<>(); | ||
| datasourceInfo.put("name", datasourceStorage.getName()); | ||
| data.put("datasource", datasourceInfo); | ||
|
|
||
| data.put("workspaceId", application.getWorkspaceId()); | ||
| data.put("appId", actionDTO.getApplicationId()); | ||
| data.put(FieldName.APP_MODE, appMode); | ||
| data.put("appName", application.getName()); | ||
| data.put("isExampleApp", application.getAppIsExample()); | ||
|
|
||
| String dsCreatedAt = ""; | ||
| if (datasourceStorage.getCreatedAt() != null) { | ||
| dsCreatedAt = DateUtils.ISO_FORMATTER.format(datasourceStorage.getCreatedAt()); | ||
| } | ||
| List<Param> paramsList = executeActionDto.getParams(); | ||
| if (paramsList == null) { | ||
| paramsList = new ArrayList<>(); | ||
| } | ||
| List<String> executionParams = | ||
| paramsList.stream().map(param -> param.getValue()).collect(Collectors.toList()); | ||
|
|
||
| data.put("request", request); | ||
| data.put( | ||
| "isSuccessfulExecution", | ||
| ObjectUtils.defaultIfNull(actionExecutionResult.getIsExecutionSuccess(), false)); | ||
| data.put("statusCode", ObjectUtils.defaultIfNull(actionExecutionResult.getStatusCode(), "")); | ||
| data.put("timeElapsed", timeElapsed); | ||
| data.put("actionCreated", DateUtils.ISO_FORMATTER.format(actionDTO.getCreatedAt())); | ||
| data.put("actionId", ObjectUtils.defaultIfNull(actionDTO.getId(), "")); | ||
| data.put( | ||
| FieldName.ACTION_EXECUTION_REQUEST_PARAMS_SIZE, | ||
| executeActionDto.getTotalReadableByteCount()); | ||
| data.put(FieldName.ACTION_EXECUTION_REQUEST_PARAMS_COUNT, executionParams.size()); | ||
|
|
||
| setContextSpecificProperties(data, actionDTO, pageName); | ||
|
|
||
| ActionExecutionResult.PluginErrorDetails pluginErrorDetails = | ||
| actionExecutionResult.getPluginErrorDetails(); | ||
| data.put("pluginErrorDetails", ObjectUtils.defaultIfNull(pluginErrorDetails, "")); | ||
| if (pluginErrorDetails != null) { | ||
| data.put("appsmithErrorCode", pluginErrorDetails.getAppsmithErrorCode()); | ||
| data.put("appsmithErrorMessage", pluginErrorDetails.getAppsmithErrorMessage()); | ||
| data.put("errorType", pluginErrorDetails.getErrorType()); | ||
| } | ||
|
|
||
| data.putAll(DatasourceAnalyticsUtils.getAnalyticsPropertiesWithStorageOnActionExecution( | ||
| datasourceStorage, dsCreatedAt, environmentName)); | ||
|
|
||
| // Add the error message in case of erroneous execution | ||
| if (FALSE.equals(actionExecutionResult.getIsExecutionSuccess())) { | ||
| String errorJson; | ||
| try { | ||
| errorJson = objectMapper.writeValueAsString(actionExecutionResult.getBody()); | ||
| } catch (JsonProcessingException e) { | ||
| log.warn("Unable to serialize action execution error result to JSON.", e); | ||
| errorJson = "\"Failed to serialize error data to JSON.\""; | ||
| } | ||
| data.put("error", errorJson); | ||
| } | ||
|
|
||
| if (actionExecutionResult.getStatusCode() != null) { | ||
| data.put("statusCode", actionExecutionResult.getStatusCode()); | ||
| } | ||
|
|
||
| String executionRequestQuery = ""; | ||
| if (actionExecutionResult.getRequest() != null | ||
| && actionExecutionResult.getRequest().getQuery() != null) { | ||
| executionRequestQuery = | ||
| actionExecutionResult.getRequest().getQuery(); | ||
| } | ||
|
|
||
| final Map<String, Object> eventData = new HashMap<>(); | ||
| eventData.put(FieldName.ACTION, actionDTO); | ||
| eventData.put(FieldName.DATASOURCE, datasourceStorage); | ||
| eventData.put(FieldName.APP_MODE, appMode); | ||
| eventData.put(FieldName.ACTION_EXECUTION_RESULT, actionExecutionResult); | ||
| eventData.put(FieldName.ACTION_EXECUTION_TIME, timeElapsed); | ||
| eventData.put(FieldName.ACTION_EXECUTION_QUERY, executionRequestQuery); | ||
| eventData.put(FieldName.APPLICATION, application); | ||
| eventData.put(FieldName.PLUGIN, plugin); | ||
|
|
||
| if (executeActionDto.getTotalReadableByteCount() <= Constraint.MAX_ANALYTICS_SIZE_BYTES) { | ||
| // Only send params info if total size is less than 5 MB | ||
| eventData.put(FieldName.ACTION_EXECUTION_REQUEST_PARAMS, executionParams); | ||
| } else { | ||
| eventData.put(FieldName.ACTION_EXECUTION_REQUEST_PARAMS, REDACTED_DATA); | ||
| } | ||
| if (executeActionDto != null) { | ||
| // Remove the value from the executeActionDto.params before sending to mixpanel as it contains | ||
| // user submitted data | ||
| if (executeActionDto.getParams() != null) { | ||
| executeActionDto.getParams().forEach(param -> param.setValue(REDACTED_DATA)); | ||
| } | ||
| data.put(FieldName.ACTION_EXECUTION_REQUEST_PARAMS_VALUE_MAP, executeActionDto.getParams()); | ||
| data.put( | ||
| FieldName.ACTION_EXECUTION_INVERT_PARAMETER_MAP, | ||
| executeActionDto.getInvertParameterMap()); | ||
| } | ||
| data.put(FieldName.ACTION_CONFIGURATION, rawActionConfiguration); | ||
| data.put(FieldName.EVENT_DATA, eventData); | ||
| data.put(FieldName.ACTION_CONFIGURATION_RUN_BEHAVIOUR, actionDTO.getRunBehaviour()); | ||
| return analyticsService | ||
| .sendObjectEvent(AnalyticsEvents.EXECUTE_ACTION, actionDTO, data) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The PR description says that we aren't touching the server-side execute_ACTION_TRIGGERED, but then the second commit removes it (that's seemingly this one). Was this intentional and the PR description is out of date? |
||
| .thenReturn(request); | ||
| }) | ||
| .onErrorResume(error -> { | ||
| log.warn("Error sending action execution data point", error); | ||
| return Mono.just(request); | ||
| }); | ||
| return Mono.just(request); | ||
| } | ||
|
|
||
| protected void setContextSpecificProperties(Map<String, Object> data, ActionDTO actionDTO, String contextName) { | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🗄️ Data Integrity & Integration | 🟠 Major | ⚡ Quick win
Add a trailing flush to preserve every model-update count.
Both implementations emit accumulated updates only when another update arrives after the throttle interval. Pending counts remain unreported if updates stop.
app/client/src/widgets/CustomWidget/widget/index.tsx#L431-L440: schedule a trailing emission for the pending count.app/client/src/widgets/wds/WDSCustomWidget/widget/index.tsx#L112-L121: use the same trailing-flush implementation.📍 Affects 2 files
app/client/src/widgets/CustomWidget/widget/index.tsx#L431-L440(this comment)app/client/src/widgets/wds/WDSCustomWidget/widget/index.tsx#L112-L121🤖 Prompt for AI Agents