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

fix(opensearch): handle index not present errors in search api #4965

Merged
merged 11 commits into from
Jun 18, 2024

Conversation

tsdk02
Copy link
Contributor

@tsdk02 tsdk02 commented Jun 12, 2024

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

  • Handled errors when index is not present, by logging the corresponding error message and treating the hits as 0.
  • Changed the structure of OpensearchOutput and corresponding structs which are used to handle the error.

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

The msearch API errors out since the index is not present, so handled the error.

How did you test it?

  • Set up the global search locally
  • Test the global search with any keyword
  • Go through the log, and 5xx errors should not be present anymore, with the errors logged, and handling of the index not found errors.
    image

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@tsdk02 tsdk02 requested a review from lsampras June 12, 2024 10:13
@tsdk02 tsdk02 self-assigned this Jun 12, 2024
@tsdk02 tsdk02 requested a review from a team as a code owner June 12, 2024 10:13
@tsdk02 tsdk02 linked an issue Jun 12, 2024 that may be closed by this pull request
@hyperswitch-bot hyperswitch-bot bot requested a review from a team as a code owner June 12, 2024 10:23
Copy link
Member

@lsampras lsampras left a comment

Choose a reason for hiding this comment

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

Can you also update the readme in crates/analytics/docs to add conditions for enabling the global search on dashboard as well

I believe we have only mentioned audit_log & system_metrics

@@ -53,3 +53,4 @@ strum = { version = "0.26.2", features = ["derive"] }
thiserror = "1.0.58"
time = { version = "0.3.35", features = ["serde", "serde-well-known", "std"] }
tokio = { version = "1.37.0", features = ["macros", "rt-multi-thread"] }
log = "0.4"
Copy link
Member

Choose a reason for hiding this comment

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

we use tracing crate for logging

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

.json::<OpenMsearchOutput<Value>>()
.json::<OpenMsearchOutput>()
Copy link
Member

Choose a reason for hiding this comment

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

Can we read this as a string first using .text() and then try to parse it?
that way we can print the string as part of the parsing error helping us debug this in production environments

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

.hits
.hits
.into_iter()
.map(|hit| hit._source)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.map(|hit| hit._source)
.map(|hit| hit.source)

The _ prefix is a rust convention for unused variables can we remove it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed it

.collect(),
})
} else {
error!("Unexpected status code: {}", success.status);
Copy link
Member

Choose a reason for hiding this comment

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

use the tracing library

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@tsdk02
Copy link
Contributor Author

tsdk02 commented Jun 13, 2024

Can you also update the readme in crates/analytics/docs to add conditions for enabling the global search on dashboard as well

I believe we have only mentioned audit_log & system_metrics

Added global_search=true in the README.md file

lsampras
lsampras previously approved these changes Jun 13, 2024
Comment on lines 35 to 42
Err(parse_error) => {
tracing::error!(
"Failed to parse response: {:?}, raw response: {}",
parse_error,
response_text
);
return Err(error_stack::Report::from(OpenSearchError::ResponseError));
}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Err(parse_error) => {
tracing::error!(
"Failed to parse response: {:?}, raw response: {}",
parse_error,
response_text
);
return Err(error_stack::Report::from(OpenSearchError::ResponseError));
}
er@Err(parse_error) => {
tracing::error!(
"Failed to parse response: {:?}, raw response: {}",
parse_error,
response_text
);
return er.change_context(OpenSearchError::ResponseError);
}

can we do something like this ?

Copy link
Member

Choose a reason for hiding this comment

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

Can we do it a bit more functional ?

something like

.text()
.change_context(OpensearchError::ResponseBodyError)
.and_then(|body|
    serde_json::from_str(&body)
    .change_context(OpensearchError::ResponseDeserializationError)
    .attach_printable(&body)
)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment on lines 75 to 83
impl OpensearchError {
pub fn error_type(&self) -> &str {
&self.error.error_type
}

pub fn reason(&self) -> &str {
&self.error.reason
}
}
Copy link
Member

Choose a reason for hiding this comment

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

where is this being used?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not being used, removed it.

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jun 18, 2024
Merged via the queue into main with commit ae1edb0 Jun 18, 2024
11 checks passed
@Gnanasundari24 Gnanasundari24 deleted the opensearch-error-handling branch June 18, 2024 19:13
pixincreate added a commit that referenced this pull request Jun 20, 2024
…ress-skip

* 'main' of github.com:juspay/hyperswitch: (27 commits)
  feat(cypress): add 2 more payout connectors and bank transfer support for payout (#4993)
  chore(version): 2024.06.20.0
  Refactor(core): reverts the payment method list filtering using constraint graph (#5044)
  feat(router): add payment method type duplication check for `google_pay` (#5023)
  refactor(storage): remove `id` from payment intent, attempt and remove datamodel ext from payment intent (#4923)
  fix(events): Correct parsing of API events with user event_type for Clickhouse (#5022)
  fix(connector):  add local bank redirect type in compatibility layer, default the country to AT for Local Bank Redirect and add creds_identifier in access token  (#5038)
  refactor(connector): add amount conversion framework for noon (#4843)
  fix(logging): fix stack overflow on recording restricted keys (#4423)
  feat(core): Add logger for sessions call failure (#5036)
  chore(version): 2024.06.19.0
  fix(opensearch): handle index not present errors in search api (#4965)
  feat(multitenancy): add tenant_id as a field for data pipeline and support individual database for clickhouse  (#4867)
  refactor: add basic counter metrics for IMC (#5006)
  fix(payment_methods): populate card fields while saving card again during metadata change condition (#5019)
  feat(router): Override the `setup_future_usage` to `on_session` based on the merchant config (#5016)
  chore(docker-compose): pass correct configuration values for running SDK demo app  (#5012)
  refactor: Move trait ConnectorIntegration to crate hyperswitch_interfaces (#4946)
  chore(version): 2024.06.17.0
  chore(process_tracker): use `const` instead of `String` for `business_status` (#4849)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

fix(opensearch): handle index not present errors in search api
4 participants