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

SDT-159: SDT: submitQuery response status doesn't reflect results ret… #464

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

kiran-yenigala-hmcts
Copy link
Collaborator

…urned from CMC

Before creating a pull request make sure that:

  • commit messages are meaningful and follow good commit message guidelines
  • README and other documentation has been updated / added (if needed)
  • tests have been updated / new tests has been added (if needed)

Please remove this line and everything above and fill the following sections:

JIRA link (if applicable)

Change description

Does this PR introduce a breaking change? (check one with "x")

[ ] Yes
[ ] No

@hmcts-jenkins-a-to-c
Copy link
Contributor

Plan Result

Plan: 2 to add, 1 to change, 0 to destroy.
  • Create
    • module.application_insights.azurerm_monitor_action_group.action_group
    • module.application_insights.azurerm_monitor_activity_log_alert.main
  • Update
    • module.application_insights.azurerm_application_insights.this
Change Result (Click me)
  # module.application_insights.azurerm_application_insights.this will be updated in-place
  ~ resource "azurerm_application_insights" "this" {
      ~ daily_data_cap_notifications_disabled = false -> true
        id                                    = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.Insights/components/civil-sdt-appinsights-aat"
        name                                  = "civil-sdt-appinsights-aat"
        tags                                  = {
            "application"         = "civil"
            "autoShutdown"        = "true"
            "builtFrom"           = "https://github.com/HMCTS/civil-sdt.git"
            "businessArea"        = "CFT"
            "contactSlackChannel" = "#civil_contact"
            "environment"         = "staging"
            "managedBy"           = "Civil"
        }
        # (15 unchanged attributes hidden)
    }

  # module.application_insights.azurerm_monitor_action_group.action_group will be created
  + resource "azurerm_monitor_action_group" "action_group" {
      + enabled             = true
      + id                  = (known after apply)
      + location            = "global"
      + name                = "Civil-Aat-Warning-Alerts"
      + resource_group_name = "civil-sdt-aat"
      + short_name          = "civ-aat"
      + tags                = {
          + "application"         = "civil"
          + "autoShutdown"        = "true"
          + "builtFrom"           = "https://github.com/HMCTS/civil-sdt.git"
          + "businessArea"        = "CFT"
          + "contactSlackChannel" = "#civil_contact"
          + "environment"         = "staging"
          + "managedBy"           = "Civil"
        }

      + azure_function_receiver {
          + function_app_resource_id = "/subscriptions/96c274ce-846d-4e48-89a7-d528432298a7/resourceGroups/cft-alerts-slack-aat/providers/Microsoft.Web/sites/cft-alerts-slack-aat"
          + function_name            = "httpTrigger"
          + http_trigger_url         = (sensitive value)
          + name                     = "slack-alerts"
          + use_common_alert_schema  = true
        }
    }

  # module.application_insights.azurerm_monitor_activity_log_alert.main will be created
  + resource "azurerm_monitor_activity_log_alert" "main" {
      + description         = "Monitors for application insight reaching it's daily cap."
      + enabled             = true
      + id                  = (known after apply)
      + name                = "Application Insights daily cap reached"
      + resource_group_name = "civil-sdt-aat"
      + scopes              = [
          + "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.Insights/components/civil-sdt-appinsights-aat",
        ]
      + tags                = {
          + "application"         = "civil"
          + "autoShutdown"        = "true"
          + "builtFrom"           = "https://github.com/HMCTS/civil-sdt.git"
          + "businessArea"        = "CFT"
          + "contactSlackChannel" = "#civil_contact"
          + "environment"         = "staging"
          + "managedBy"           = "Civil"
        }

      + action {
          + action_group_id    = (known after apply)
          + webhook_properties = {
              + "from"           = "terraform"
              + "slackChannelId" = "C020H1XLM9S"
            }
        }

      + criteria {
          + category       = "Administrative"
          + level          = "Warning"
          + operation_name = "Microsoft.Insights/Components/DailyCapReached/Action"
          + resource_id    = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.Insights/components/civil-sdt-appinsights-aat"
        }
    }

Plan: 2 to add, 1 to change, 0 to destroy.

@hmcts-jenkins-a-to-c hmcts-jenkins-a-to-c bot deployed to preview March 13, 2024 10:59 Active
Copy link
Collaborator

Choose a reason for hiding this comment

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

There's three situations where the response will be incorrect:

1.) Results returned from each ConsumerGateway are within maximum limit, but when combined they exceed it. In this case the response will not contain status code 78 (Results truncated - maximum number allowed reached).
2.) Results are returned from ConsumerGateway, but no results returned from CMCConsumerGateway. Assuming that CMCConsumerGateway would return a FeignException, this would cause the response to contain status code 77 (No defence notifications found for requested period) event though the response contained some results.
3.) Results are returned from ConsumerGateway and too many results returned by CMCConsumerGateway. The response would correctly contain status code 78 (from FeignException), but the number of responses would exceed the maximum.

A possible solution for 1 and 3 would be to send a value in the request to CMCConsumerGateway. The value would be the number of results already returned by ConsumerGateway. CMCConsumerGateway would need to subtract this from the default maximum number and use this as the maximum number when determining whether to truncate the results and return status code 78. Alternatively, the subtraction could be done within the SDT code. The value sent to CMCConsumerGateway would then be the maximum number that can be returned without needing to truncate the results and return status code 78.

A possible solution for 2 would be that if CMCConsumerGateway returns status code 77 then check the response from ConsumerGateway. If the response from ConsumerGateway doesn't have a status code of 77 then don't set it to 77.

@hmcts-jenkins-a-to-c
Copy link
Contributor

Plan Result (aat)

⚠️ Resource Deletion will happen ⚠️

This plan contains resource delete operation. Please check the plan result very carefully!

Plan: 3 to add, 10 to change, 3 to destroy.
  • Update
    • azurerm_key_vault_secret.POSTGRES-HOST
    • azurerm_key_vault_secret.POSTGRES-HOST-V15
    • azurerm_key_vault_secret.POSTGRES-USER
    • azurerm_key_vault_secret.POSTGRES-USER-V15
    • azurerm_key_vault_secret.servicebus-pricing-tier
    • module.application_insights.azurerm_application_insights.this
    • module.postgresql.random_password.password
    • module.postgresql-v15.random_password.password
    • module.servicebus-namespace.azurerm_servicebus_namespace.servicebus_namespace
    • module.servicebus-namespace.azurerm_servicebus_namespace_authorization_rule.send_listen_auth_rule
  • Replace
    • module.servicebus-sdt-queue.azurerm_servicebus_queue.servicebus_queue
    • module.servicebus-sdt-queue.azurerm_servicebus_queue_authorization_rule.listen_auth_rule
    • module.servicebus-sdt-queue.azurerm_servicebus_queue_authorization_rule.send_auth_rule
Change Result (Click me)
  # azurerm_key_vault_secret.POSTGRES-HOST will be updated in-place
  ~ resource "azurerm_key_vault_secret" "POSTGRES-HOST" {
        id                      = "https://civil-sdt-aat.vault.azure.net/secrets/civil-sdt-POSTGRES-HOST/6503ebd373d04231827cb267ac070313"
        name                    = "civil-sdt-POSTGRES-HOST"
        tags                    = {}
        # (6 unchanged attributes hidden)
    }

  # azurerm_key_vault_secret.POSTGRES-HOST-V15 will be updated in-place
  ~ resource "azurerm_key_vault_secret" "POSTGRES-HOST-V15" {
        id                      = "https://civil-sdt-aat.vault.azure.net/secrets/civil-sdt-POSTGRES-HOST-V15/d3ab62dae90543c9a27fb3734e7b3eba"
        name                    = "civil-sdt-POSTGRES-HOST-V15"
        tags                    = {}
        # (6 unchanged attributes hidden)
    }

  # azurerm_key_vault_secret.POSTGRES-USER will be updated in-place
  ~ resource "azurerm_key_vault_secret" "POSTGRES-USER" {
        id                      = "https://civil-sdt-aat.vault.azure.net/secrets/civil-sdt-POSTGRES-USER/8d9eaea20c224995bacc6124b33ab3ad"
        name                    = "civil-sdt-POSTGRES-USER"
        tags                    = {}
        # (6 unchanged attributes hidden)
    }

  # azurerm_key_vault_secret.POSTGRES-USER-V15 will be updated in-place
  ~ resource "azurerm_key_vault_secret" "POSTGRES-USER-V15" {
        id                      = "https://civil-sdt-aat.vault.azure.net/secrets/civil-sdt-POSTGRES-USER-V15/23d525866a584e67ac1b5c3aa27faf08"
        name                    = "civil-sdt-POSTGRES-USER-V15"
        tags                    = {}
        # (6 unchanged attributes hidden)
    }

  # azurerm_key_vault_secret.servicebus-pricing-tier will be updated in-place
  ~ resource "azurerm_key_vault_secret" "servicebus-pricing-tier" {
        id                      = "https://civil-sdt-aat.vault.azure.net/secrets/civil-sdt-servicebus-pricing-tier/ec8f49ce375846bda379808fc1528a17"
        name                    = "civil-sdt-servicebus-pricing-tier"
        tags                    = {}
        # (6 unchanged attributes hidden)
    }

  # module.application_insights.azurerm_application_insights.this will be updated in-place
  ~ resource "azurerm_application_insights" "this" {
        id                                    = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.Insights/components/civil-sdt-appinsights-aat"
        name                                  = "civil-sdt-appinsights-aat"
        tags                                  = {
            "application"         = "civil"
            "autoShutdown"        = "true"
            "builtFrom"           = "https://github.com/HMCTS/civil-sdt.git"
            "businessArea"        = "CFT"
            "contactSlackChannel" = "#civil_contact"
            "environment"         = "staging"
            "managedBy"           = "Civil"
        }
        # (16 unchanged attributes hidden)
    }

  # module.postgresql.random_password.password will be updated in-place
  ~ resource "random_password" "password" {
        id               = "none"
        # (13 unchanged attributes hidden)
    }

  # module.postgresql-v15.random_password.password will be updated in-place
  ~ resource "random_password" "password" {
        id               = "none"
        # (13 unchanged attributes hidden)
    }

  # module.servicebus-namespace.azurerm_servicebus_namespace.servicebus_namespace will be updated in-place
  ~ resource "azurerm_servicebus_namespace" "servicebus_namespace" {
        id                                  = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.ServiceBus/namespaces/civil-sdt-servicebus-aat"
        name                                = "civil-sdt-servicebus-aat"
        tags                                = {
            "Destroy Me"          = "No"
            "Team Contact"        = "#civil-sdt"
            "application"         = "civil"
            "autoShutdown"        = "true"
            "builtFrom"           = "https://github.com/HMCTS/civil-sdt.git"
            "businessArea"        = "CFT"
            "contactSlackChannel" = "#civil_contact"
            "environment"         = "staging"
            "managedBy"           = "Civil"
        }
        # (14 unchanged attributes hidden)

        # (1 unchanged block hidden)
    }

  # module.servicebus-namespace.azurerm_servicebus_namespace_authorization_rule.send_listen_auth_rule will be updated in-place
  ~ resource "azurerm_servicebus_namespace_authorization_rule" "send_listen_auth_rule" {
        id                          = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.ServiceBus/namespaces/civil-sdt-servicebus-aat/authorizationRules/SendAndListenSharedAccessKey"
        name                        = "SendAndListenSharedAccessKey"
        # (8 unchanged attributes hidden)
    }

  # module.servicebus-sdt-queue.data.azurerm_servicebus_namespace.this will be read during apply
  # (depends on a resource or a module with changes pending)
 <= data "azurerm_servicebus_namespace" "this" {
      + capacity                            = (known after apply)
      + default_primary_connection_string   = (sensitive value)
      + default_primary_key                 = (sensitive value)
      + default_secondary_connection_string = (sensitive value)
      + default_secondary_key               = (sensitive value)
      + endpoint                            = (known after apply)
      + id                                  = (known after apply)
      + location                            = (known after apply)
      + name                                = "civil-sdt-servicebus-aat"
      + premium_messaging_partitions        = (known after apply)
      + resource_group_name                 = "civil-sdt-aat"
      + sku                                 = (known after apply)
      + tags                                = (known after apply)
      + zone_redundant                      = (known after apply)
    }

  # module.servicebus-sdt-queue.azurerm_servicebus_queue.servicebus_queue must be replaced
-/+ resource "azurerm_servicebus_queue" "servicebus_queue" {
      ~ id                                      = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.ServiceBus/namespaces/civil-sdt-servicebus-aat/queues/civil-sdt-in-out-aat" -> (known after apply)
      ~ max_message_size_in_kilobytes           = 256 -> (known after apply)
        name                                    = "civil-sdt-in-out-aat"
      ~ namespace_id                            = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.ServiceBus/namespaces/civil-sdt-servicebus-aat" # forces replacement -> (known after apply) # forces replacement
        # (13 unchanged attributes hidden)
    }

  # module.servicebus-sdt-queue.azurerm_servicebus_queue_authorization_rule.listen_auth_rule must be replaced
-/+ resource "azurerm_servicebus_queue_authorization_rule" "listen_auth_rule" {
      ~ id                                = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.ServiceBus/namespaces/civil-sdt-servicebus-aat/queues/civil-sdt-in-out-aat/authorizationRules/ListenSharedAccessKey" -> (known after apply)
        name                              = "ListenSharedAccessKey"
      ~ primary_connection_string         = (sensitive value)
      + primary_connection_string_alias   = (sensitive value)
      ~ primary_key                       = (sensitive value)
      ~ queue_id                          = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.ServiceBus/namespaces/civil-sdt-servicebus-aat/queues/civil-sdt-in-out-aat" # forces replacement -> (known after apply) # forces replacement
      ~ secondary_connection_string       = (sensitive value)
      + secondary_connection_string_alias = (sensitive value)
      ~ secondary_key                     = (sensitive value)
        # (3 unchanged attributes hidden)
    }

  # module.servicebus-sdt-queue.azurerm_servicebus_queue_authorization_rule.send_auth_rule must be replaced
-/+ resource "azurerm_servicebus_queue_authorization_rule" "send_auth_rule" {
      ~ id                                = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.ServiceBus/namespaces/civil-sdt-servicebus-aat/queues/civil-sdt-in-out-aat/authorizationRules/SendSharedAccessKey" -> (known after apply)
        name                              = "SendSharedAccessKey"
      ~ primary_connection_string         = (sensitive value)
      + primary_connection_string_alias   = (sensitive value)
      ~ primary_key                       = (sensitive value)
      ~ queue_id                          = "/subscriptions/1c4f0704-a29e-403d-b719-b90c34ef14c9/resourceGroups/civil-sdt-aat/providers/Microsoft.ServiceBus/namespaces/civil-sdt-servicebus-aat/queues/civil-sdt-in-out-aat" # forces replacement -> (known after apply) # forces replacement
      ~ secondary_connection_string       = (sensitive value)
      + secondary_connection_string_alias = (sensitive value)
      ~ secondary_key                     = (sensitive value)
        # (3 unchanged attributes hidden)
    }

Plan: 3 to add, 10 to change, 3 to destroy.

@hmcts-jenkins-a-to-c hmcts-jenkins-a-to-c bot deployed to preview April 15, 2024 10:52 Active
@hmcts-jenkins-a-to-c hmcts-jenkins-a-to-c bot deployed to preview April 16, 2024 09:17 Active
submitQueryRequest.setResultCount(2000);
IErrorLog errorLog = new ErrorLog();
errorLog.setErrorCode("78");
errorLog.setErrorText("maximum number of defences reached");
Copy link
Collaborator

Choose a reason for hiding this comment

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

The error text for code 78 will be "Results truncated - maximum number allowed reached."

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

addressed

@@ -433,23 +433,21 @@ private void sendRequestToTargetApp(final ISubmitQueryRequest submitQueryRequest
SubmitQueryResponse mcolSubmitQueryResponse =
requestConsumer.submitQuery(submitQueryRequest, connectionTimeOut, requestTimeOut);

if (Boolean.TRUE.equals(submitQueryRequest.getBulkCustomer().getReadyForAlternateService())) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should this have been removed? Do we always want to query CMC regardless of whether the customer is ready for it or not?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

no, this should be here, this is what discussed during initial requirements

Comment on lines +518 to +519


Copy link
Collaborator

Choose a reason for hiding this comment

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

Remove one of these blank lines.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

updateResponseStatus(submitQueryRequest, submitQueryResponse, response);
} catch (FeignException e) {
boolean noResults = NO_DATA == e.status() || NOT_FOUND == e.status();
if (!noResults) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could not noResults be replaced with a positively named variable instead? Something like resultsExist. It would make the logic a bit easier to understand.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

NO_DATA == e.status() || NOT_FOUND == e.status();
these status codes mean, no data

Copy link
Collaborator

Choose a reason for hiding this comment

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

It was more the use of a double negative. Double negatives are a bit harder to understand, so I wondered if there was a way of changing it to a positive. For example, "if (resultsExist)" is easier to understand than "if (not noResults)" despite them meaning the same thing.

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.

2 participants