heavy Elasticsearch config queries in tasks-sql - Part 2
Description
CAPL - Bug default text according to the team DoR (Definition of Ready)
01 - PERSON OF CONTACT (PERSON THAT CAN ANSWER QUESTIONS ABOUT THE PROBLEM):
@henrique.cavarsan
02 - PROBLEM (WHAT'S THE ISSUE?):
It is necessary to optimize the Elasticsearch queries in the config; they are too heavy and affecting the ES latency times.
These queries are executed by the worker-sql in task-sql, and here is the log:
https://cloudlogging.app.goo.gl/uZ3h9AUotiE7mUSJ8
It would be interesting not to use config-* in these queries if possible.
03 - STEPS TO REPRODUCE (STEP (1...N), VIDEO, SCREENSHOTS, LOGS FOLDER, HEARTBEAT, ETC. – IF IS NOT POSSIBLE TO REPRODUCE EXPLAIN THE REASON):
04 - LINKS (ADD A LINK TO THE BUG OR TO THE TENANT):
https://cloudlogging.app.goo.gl/uZ3h9AUotiE7mUSJ8
05 - EXPECTED BEHAVIOR (LIST THE EXPECTED BEHAVIORS TO CONSIDER THIS BUG AS DONE):
We need to do this for this card:
- When a SQL task starts in a unified tenant scenario, we are searching for all TenantApps that matches the CarolAppName and then for each record TenantApp that we found, we are searching the Tenant based on the TenantId of the TenantApp just to find which one of all TenantApps belongs to the Unified Tenant to prepare the fanout and subscription the data processed by pipeline.
// BigQueryProcessTaskProcessor.java:L428
if (shouldFanOut(fanOut, tenant)) {
allowedCustomerTenantIDs =
MdmSingletonManager.getInstance(TenantAppService.class).getAllowedCustomerTenantIDs(uad);
if (CollectionUtils.isNotEmpty(customerTenantIds)
&& CollectionUtils.isNotEmpty(allowedCustomerTenantIDs)) {
allowedCustomerTenantIdsIntersect =
SetUtils.intersection(new HashSet<>(customerTenantIds), allowedCustomerTenantIDs);
}
}
But the way we get the tenant ids that should fanout/send subscriptions is through getting all the TenantApps with mdmName
that matches with the same CarolApp name from the unified tenant.
// TenantAppServiceImpl.java:L3194
public Set<String> getAllowedCustomerTenantIDs(UserAccessDetails userAccessDetails) {
var tenant = getTenantService().getTenant(userAccessDetails, userAccessDetails.getTenantId());
if (Boolean.FALSE.equals(tenant.getMdmIsUnified())) {
throw new ApplicationException(
Status.PRECONDITION_FAILED, "List all customer tenants is able only to Tenant Unified");
}
TenantApp unifiedTenantApp = this.getUnifiedTenantApp(userAccessDetails);
List<TenantApp> allTenantApps;
try {
allTenantApps = this.getAllByCarolAppName(unifiedTenantApp.getMdmName());
} catch (RecordNotFoundException e) {
throw new ApplicationException(
Status.NOT_FOUND, e.getMessage(), unifiedTenantApp.getMdmName(), e);
}
var customerTenants =
this.getCustomerTenants(unifiedTenantApp.getMdmTenantId(), new ArrayList<>(allTenantApps))
.stream()
.map(Tenant::getMdmId)
.collect(Collectors.toSet());
// check the tenants install carol app are allowed, when the strategy is HYBRID
if (!CollectionUtils.containsAny(
unifiedTenantApp.getMdmPipelineAllowedEnvironments(),
TenantApp.ALL_TENANTS_WITH_INSTALLED_APP_ALLOWED)) {
return SetUtils.intersection(
customerTenants, unifiedTenantApp.getMdmPipelineAllowedEnvironments());
}
return customerTenants;
}
- Implement a Cache to know what are the TenantApps linked to a Carol App by name.
This issue was automatically transitioned to WAITING DEPLOY, as its PR was just merged into master branch in Github.
Github user douglascoimbra has just approved a PR (added as Shard Assignee in this Jira issue).
fix: https://totvslabs.atlassian.net/browse/CAPL-5267#icft=CAPL-5267 add cache TENANT_APPS_BY_NAME
This issue was automatically transitioned to QA REVIEW, as its PR was just approved in Github.
This issue was automatically transitioned to REVIEW, as its PR (not DRAFT and not WIP) was just created in Github.
fix: https://totvslabs.atlassian.net/browse/CAPL-5267#icft=CAPL-5267 add cache TENANT_APPS_BY_NAME
Github user olivandre has just commited and issue was sent back to the REVIEW column.
This issue was automatically transitioned to QA REVIEW, as its PR was just approved in Github.
Github user olivandre has just commited and issue was sent back to the REVIEW column.
@Gabriel DAmore Marciano @Geny Isam Hamud Herrera @Jonathan Willian Moraes Until we get the de topic regarding Access Token solved, we will hold the merge of this card into the master. cc @Moises Jose Soares Filho @wilson.souza
Github user douglascoimbra has just approved a PR (added as Shard Assignee in this Jira issue).
fix: https://totvslabs.atlassian.net/browse/CAPL-5267#icft=CAPL-5267 add cache TENANT_APPS_BY_NAME
This issue was automatically transitioned to QA REVIEW, as its PR was just approved in Github.
@André Pereira de Oliveira This card has been validated by the QA team. It is pending only the code review.
cc @Gabriel DAmore Marciano @Jonathan Willian Moraes
@André Pereira de Oliveira @Gabriel DAmore Marciano @Jonathan Willian Moraes REGRESSION IS OK FOR THIS BRANCH
ALLOWED LIST ADDING/REMOVAL
CACHE ACTION
CACHE ACTION
RUNNING SQL PROCESSING WHERE THE CUSTOMER DOES NOT BELONG TO THE ALLOWED LIST
UPDATING CAROL APP TO BE SQL ONLY
LIST OF APPS INSTALLED
REMOVING CAROL APP
THE LIST HAS BEEN UPDATED
APP REINSTALLED
LIST UPDATED 1
LIST UPDATED 2
@henrique.cavarsan ,
@Jonathan Willian Moraes , @André Pereira de Oliveira , @Douglas Coimbra Lopes , @Gabriel DAmore Marciano , @Reinaldo Oliveira Machado Junior
This issue was planned to be delivered until 2024-02-12. You can check that by consulting the issue in the Due Date field.
Dates already planned for this issue: 2024-01-23, 2024-02-12
If External Issue Link field is filled, customer was also informed on JIRA TOTVS.
:rotating_light: Cenario encontrado no .
• Ao tentar remover um customer tenant da lista de allowed da unificada (HybridApp), o endpoint retorna um Internal Server error
• GCP:
• :fine2: Update: na branch `master` o comportamento nao acontece. Evidencia logo abaixo
• Detalhes no card cc
Edited on Slack - platform-internal - Douglas Coimbra Lopes
@André Pereira de Oliveira TEST FAILED
Internal Server Error when we try to remove a customer from the unified tenantApp List
1
2
3
4
5
6
7
8
:rotating_light: Cenario encontrado no .
• Ao tentar remover um customer tenant da lista de allowed da unificada (HybridApp), o endpoint retorna um Internal Server error
• GCP:
• Checando se na master o erro jah acontece
• Detalhes no card cc
Sent by Slack - platform-internal - Douglas Coimbra Lopes
:rotating_light: Conforme discutido em call para alinhamento do , encontrado cenario onde os customers obtem o carol app instalado fora da lista da unif, culminando em um erro de GCP voltado ao `.totvslabs.mdm.app.scheduler.ClearCacheEntitiesJob`
:white_check_mark: Update Topico retestado e corrigido, testes em progresso
GCP:
• Detalhes no card. cc
Edited on Slack - platform-internal - Douglas Coimbra Lopes
RETESTing steps
ADDING AND IN SEQUENCE REMOVING CUSTOMERS FROM THE ENV LIST
Github user olivandre has just commited and issue was sent back to the REVIEW column.
:rotating_light: Conforme discutido em call para alinhamento do , encontrado cenario onde os customers obtem o carol app instalado fora da lista da unif, culminando em um erro de GCP voltado ao `.totvslabs.mdm.app.scheduler.ClearCacheEntitiesJob`
GCP:
• Detalhes no card. cc
Sent by Slack - platform-internal - Douglas Coimbra Lopes
@André Pereira de Oliveira TEST FAILED
When we have an unified tenant with an app installed + at least one customer, but the customer itself is out of the unif app list, an error occurs on GCP regarding the
DEFAULT.com.totvslabs.mdm.app.scheduler.ClearCacheEntitiesJob
https://cloudlogging.app.goo.gl/6gqocwiebeH4hfkaA
cc @Jonathan Willian Moraes @Gabriel DAmore Marciano
This issue was automatically transitioned to QA REVIEW, as its PR was just approved in Github.
This issue was automatically transitioned to REVIEW, as its PR (not DRAFT and not WIP) was just created in Github.
fix: https://totvslabs.atlassian.net/browse/CAPL-5267#icft=CAPL-5267 add cache TENANT_APPS_BY_NAME
This issue was automatically transitioned to REVIEW, as its PR (not DRAFT and not WIP) was just created in Github.
fix: https://totvslabs.atlassian.net/browse/CAPL-5267#icft=CAPL-5267 - add cache allowed tenants
Message thread link on #red-phone channel:
https://totvscarol.slack.com/archives/C03NT4US9J9/p1704728545727299
@henrique.cavarsan ,
@Gabriel DAmore Marciano , @Renan Schroeder , @Gabriel DAmore Marciano
This issue was planned to be delivered until 2024-01-23. You can check that by consulting the issue in the Due Date field.
Dates already planned for this issue: 2024-01-23
If External Issue Link field is filled, customer was also informed on JIRA TOTVS.