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.

Activity

Automation for Jira 6 February 2024, 22:14 Jira Internal Users

This issue was automatically transitioned to WAITING DEPLOY, as its PR was just merged into master branch in Github.

Automation for Jira 5 February 2024, 18:33 Jira Internal Users

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

Automation for Jira 5 February 2024, 18:19 Jira Internal Users

This issue was automatically transitioned to QA REVIEW, as its PR was just approved in Github.

Automation for Jira 31 January 2024, 22:09 Jira Internal Users

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

Automation for Jira 30 January 2024, 22:34 Jira Internal Users

Github user olivandre has just commited and issue was sent back to the REVIEW column.

Automation for Jira 29 January 2024, 14:24 Jira Internal Users

This issue was automatically transitioned to QA REVIEW, as its PR was just approved in Github.

Automation for Jira 29 January 2024, 13:06 Jira Internal Users

Github user olivandre has just commited and issue was sent back to the REVIEW column.

Douglas Coimbra Lopes 24 January 2024, 19:12 Jira Internal Users

@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

Automation for Jira 24 January 2024, 19:11 Jira Internal Users

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

Automation for Jira 24 January 2024, 18:01 Jira Internal Users

This issue was automatically transitioned to QA REVIEW, as its PR was just approved in Github.

Douglas Coimbra Lopes 23 January 2024, 14:03 Jira Internal Users

@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

Douglas Coimbra Lopes 23 January 2024, 13:25 Jira Internal Users

@André Pereira de Oliveira @Gabriel DAmore Marciano @Jonathan Willian Moraes REGRESSION IS OK FOR THIS BRANCH

Douglas Coimbra Lopes 23 January 2024, 13:20 Jira Internal Users

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

Automation for Jira 22 January 2024, 20:01 Jira Internal Users

@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.

Automation for Jira 22 January 2024, 16:43 Jira Internal Users

: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

Douglas Coimbra Lopes 22 January 2024, 15:56 Jira Internal Users

@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

    curl -X 'DELETE' \
      'https://totvsbarretdev.qarol.ai/api/v3/tenantApps/appheavy/allowed-environments' \
      -H 'accept: application/json' \
      -H 'Content-Type: application/json' \
      -H 'Authorization: Bearer 87a39462a808423c8460972dc1ae2355' \
      -d '[
      "7902a55595634818bdbfdfaa62de07fd"
    ]'

Automation for Jira 22 January 2024, 15:55 Jira Internal Users

: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

Automation for Jira 22 January 2024, 15:47 Jira Internal Users

: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

Douglas Coimbra Lopes 22 January 2024, 15:45 Jira Internal Users

RETESTing steps

ADDING AND IN SEQUENCE REMOVING CUSTOMERS FROM THE ENV LIST

Automation for Jira 22 January 2024, 14:27 Jira Internal Users

Github user olivandre has just commited and issue was sent back to the REVIEW column.

Automation for Jira 22 January 2024, 13:35 Jira Internal Users

: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

Douglas Coimbra Lopes 22 January 2024, 13:31 Jira Internal Users

@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

Automation for Jira 19 January 2024, 14:43 Jira Internal Users

This issue was automatically transitioned to QA REVIEW, as its PR was just approved in Github.

Automation for Jira 18 January 2024, 22:25 Jira Internal Users

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

Automation for Jira 15 January 2024, 14:02 Jira Internal Users

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

Automation for Jira 8 January 2024, 16:42 Jira Internal Users

Message thread link on #red-phone channel:

https://totvscarol.slack.com/archives/C03NT4US9J9/p1704728545727299

Automation for Jira 8 January 2024, 16:42 Jira Internal Users

@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.