Skip to content

feat(gRPC): build gRPC client interface to initiate communication with recovery-decider service #8178

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

Merged
merged 150 commits into from
Aug 6, 2025
Merged
Show file tree
Hide file tree
Changes from 139 commits
Commits
Show all changes
150 commits
Select commit Hold shift + click to select a range
809da65
add address field and attempt_count in stripebilling webhook
Apr 2, 2025
8f160b0
Merge branch 'main' into stripebilling_transaction_monitoring_feilds
Apr 2, 2025
bd411f5
add endtime and start time of invoice in webhook
Apr 3, 2025
2e02b84
ran formatter
Apr 4, 2025
fd47398
add full address with encryption
Apr 4, 2025
4a82642
consumes required fields to support transaction monitoring[chargebee]
Apr 9, 2025
dd531f9
formats the code
Apr 9, 2025
01d98a0
Merge branch 'main' into support_for_storing_address
Apr 9, 2025
653cd5d
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Apr 9, 2025
6cae8e1
addresses clippy v2 failure
Apr 9, 2025
787912a
chore: run formatter
hyperswitch-bot[bot] Apr 9, 2025
a5c5d9a
makes billing address optional
Apr 10, 2025
da18869
Merge branch 'main' into stripebilling_transaction_monitoring_feilds
Apr 10, 2025
f5d5294
Merge branch 'support_for_storing_address' into stripebilling_transac…
Apr 10, 2025
826202a
adds get_billing_address_for_invoice function
Apr 10, 2025
d03c564
invoice from webhook for stripebilling
Apr 11, 2025
24dac12
add bool to get invoice from webhook or additional call
Apr 11, 2025
a4262c7
adds billing connector invoice sync flow
Apr 11, 2025
71ec2bc
typo fix
Apr 11, 2025
3b04911
add invoice sync flow to revenue recovery
Apr 11, 2025
44e5a18
chore: run formatter
hyperswitch-bot[bot] Apr 11, 2025
75ef438
adds config to fetch details
Apr 15, 2025
c53b310
recurly invoice sync connector inetgration support
Apr 17, 2025
0479693
add invoice sync call support in recovery incoming file
Apr 17, 2025
4227dfb
Merge branch 'main' into recurly_invoice_sync_support_with_transactio…
Apr 17, 2025
69d5d24
recoveryincoming changes
Apr 17, 2025
6764550
define ve type and change connector integration v1 to v2
Apr 21, 2025
2fe86f9
resolve clippy fails
Apr 21, 2025
3142502
add support for transaction monitoring for recurly
Apr 22, 2025
49f7a22
Merge branch 'main' into billing_connector_invoice_psync_call
Apr 22, 2025
b4c7e71
Merge branch 'billing_connector_invoice_psync_call' into recurly_invo…
Apr 22, 2025
a9899b5
resolve spell checks
Apr 22, 2025
e93d5a7
resolve spell checks
Apr 22, 2025
5aaaea6
Merge branch 'recurly_invoice_sync_support_with_transaction_monitorin…
Apr 23, 2025
da5a505
chore: run formatter
hyperswitch-bot[bot] Apr 23, 2025
d75b207
format the code and remove print statements
Apr 23, 2025
c9f7aa6
cleaning up recurly code
Apr 24, 2025
9bebc57
fix clippy_errors
Apr 24, 2025
86c9715
removed recurly tests since we dont have any payment related thngs to…
Apr 27, 2025
272c416
resolve clippy error
Apr 28, 2025
7378787
Merge branch 'main' into billing_connector_invoice_psync_call
NISHANTH1221 Apr 28, 2025
23ed82c
resolve clippy errors
Apr 28, 2025
23e13fa
resolve merge conflicts
Apr 28, 2025
9e30a2a
Merge branch 'main' into recurly_invoice_sync_support_with_transactio…
Apr 29, 2025
eaf1e40
resolve clippy errors
Apr 29, 2025
b154311
Merge branch 'recurly_invoice_sync_support_with_transaction_monitorin…
NISHANTH1221 Apr 29, 2025
d2e3caa
remove string based matching
Apr 29, 2025
1110062
chore: run formatter
hyperswitch-bot[bot] Apr 29, 2025
7170f7a
Merge branch 'main' into recurly_invoice_sync_support_with_transactio…
Apr 29, 2025
79d8e64
resolve error in clippy-v2
Apr 29, 2025
964fd78
removes unncessary billing address function in Incoming Webhook Trait
Apr 29, 2025
fda03ea
recurly add comment on why we dont need amount convertor
Apr 29, 2025
3e619b7
format the code
Apr 29, 2025
054bf7f
Merge branch 'recurly_invoice_sync_support_with_transaction_monitorin…
Apr 29, 2025
f916cb5
add white space
Apr 29, 2025
f0fe9d5
Merge branch 'main' into stripebilling_transaction_monitoring_feilds
May 2, 2025
1fdab57
consume card details from billing connectors
May 21, 2025
e1483a3
Merge branch 'main' into add_card_information_for_billing_connectors
May 28, 2025
264766f
small bug fix for stripebilling external payments sync flow
May 28, 2025
738037d
build gRPC Client Interface to initiate communication with recovery-t…
AdityaKumaar21 May 29, 2025
167dccd
chore: run formatter
hyperswitch-bot[bot] May 29, 2025
720b422
clippy fix
AdityaKumaar21 May 29, 2025
86a63b6
chore: run formatter
hyperswitch-bot[bot] May 29, 2025
0a516f6
Merge branch 'main' into build-grpc-client-recovery
AdityaKumaar21 May 29, 2025
4c0503d
add connector level support to consume card network and card bin
Jun 2, 2025
48214ee
introducing apis for trainer and decider
AdityaKumaar21 Jun 3, 2025
1b619b3
Delete crates/external_services/src/grpc_client/recovery_trainer_clie…
AdityaKumaar21 Jun 3, 2025
ae153fb
Merge branch 'main' into build-grpc-client-recovery
AdityaKumaar21 Jun 4, 2025
8d78311
Delete proto/recovery_trainer.proto
AdityaKumaar21 Jun 4, 2025
0177ba4
chore: update Cargo.lock
hyperswitch-bot[bot] Jun 4, 2025
fe2af2e
refactor recovery decider client and update proto definitions
AdityaKumaar21 Jun 4, 2025
77b750d
fix clippy
AdityaKumaar21 Jun 4, 2025
32a74f9
chore: run formatter
hyperswitch-bot[bot] Jun 4, 2025
4386261
Final Adjustments
Jun 4, 2025
a4aac2a
chore: run formatter
hyperswitch-bot[bot] Jun 4, 2025
1bdedf7
add card network in stripe billing
Jun 5, 2025
98aeceb
add open api changes
Jun 5, 2025
f478efb
Merge branch 'main' into add_card_information_for_billing_connectors
NISHANTH1221 Jun 5, 2025
38378f9
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Jun 5, 2025
d4b6025
add error codes
Jun 6, 2025
b7fc94e
bring back v1 from v2
Jun 8, 2025
ad3beaa
chore: run formatter
hyperswitch-bot[bot] Jun 8, 2025
c6ed016
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Jun 8, 2025
49e68b5
write correct example for card issuer
Jun 8, 2025
35eae6a
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Jun 8, 2025
9770ff6
resolves comments
Jun 10, 2025
60d745a
decider refactor
AdityaKumaar21 Jun 10, 2025
bd1913e
Rename comments
NISHANTH1221 Jun 11, 2025
f89bf01
chore: run formatter
hyperswitch-bot[bot] Jun 11, 2025
88671ca
Merge branch 'main' into add_card_information_for_billing_connectors
NISHANTH1221 Jun 11, 2025
576b4ab
removed defaults
AdityaKumaar21 Jun 11, 2025
5e7297d
Merge branch 'main' into build-grpc-client-recovery
AdityaKumaar21 Jun 11, 2025
4c50e55
chore: run formatter
hyperswitch-bot[bot] Jun 11, 2025
71e0b4e
refactor: remove TrainerClient and related gRPC functionality
AdityaKumaar21 Jun 11, 2025
3d21400
chore: run formatter
hyperswitch-bot[bot] Jun 11, 2025
ffd75fe
add new BillingConnectorPaymentMethodDetails enum
Jun 11, 2025
2b1d402
chore: run formatter
hyperswitch-bot[bot] Jun 11, 2025
401c7b5
Merge branch 'main' into add_card_information_for_billing_connectors
Jun 12, 2025
aa325bd
make the enum optional
Jun 12, 2025
feb3f88
chore: run formatter
hyperswitch-bot[bot] Jun 12, 2025
89405fb
revert default version and add box pin
Jun 12, 2025
5cead6b
add v2 feeature flag on conversions
Jun 12, 2025
d62ba13
fix proxy
AdityaKumaar21 Jun 12, 2025
5de0d97
add type serde tag and write an time stamp desrializing tag on primit…
Jun 12, 2025
1b768bf
Merge branch 'main' into add_card_information_for_billing_connectors
NISHANTH1221 Jun 12, 2025
0c01259
Merge branch 'add_card_information_for_billing_connectors' into build…
AdityaKumaar21 Jun 13, 2025
4edb072
chore: run formatter
hyperswitch-bot[bot] Jun 13, 2025
f66a288
addressing comments
AdityaKumaar21 Jun 16, 2025
dfdb3e3
Merge remote-tracking branch 'origin' into build-grpc-client-recovery
AdityaKumaar21 Jun 16, 2025
51deffb
fix clippy
AdityaKumaar21 Jun 16, 2025
c26bded
addressing comments
AdityaKumaar21 Jun 17, 2025
77bcbd5
docs(openapi): re-generate OpenAPI specification
hyperswitch-bot[bot] Jun 17, 2025
3aed65b
fix clippy
AdityaKumaar21 Jun 17, 2025
dea1639
chore: run formatter
hyperswitch-bot[bot] Jun 17, 2025
fa5f1ce
add grpc-recovery-header
AdityaKumaar21 Jun 17, 2025
9ecd485
fix clippy
AdityaKumaar21 Jun 17, 2025
3eae00b
addressing comment
AdityaKumaar21 Jun 18, 2025
a9d90a1
refactoring
AdityaKumaar21 Jun 18, 2025
060a33a
Merge branch 'main' into build-grpc-client-recovery
AdityaKumaar21 Jun 19, 2025
273acd1
fix feature flags
AdityaKumaar21 Jun 19, 2025
0536d0e
Merge branch 'main' into build-grpc-client-recovery
AdityaKumaar21 Jun 20, 2025
abf8d50
Merge branch 'main' into build-grpc-client-recovery
AdityaKumaar21 Jun 22, 2025
8dd5919
minor changes
AdityaKumaar21 Jun 24, 2025
baeb245
minor fix
AdityaKumaar21 Jun 24, 2025
7e81472
chore: run formatter
hyperswitch-bot[bot] Jun 24, 2025
920f211
fix clippy
AdityaKumaar21 Jun 24, 2025
20a864f
chore: bump tonic version from 0.12 to 0.13
Aprabhat19 Jun 25, 2025
2bb5234
Merge remote-tracking branch 'origin/bump_tonic' into build-grpc-clie…
AdityaKumaar21 Jun 25, 2025
4b269f1
Merge branch 'main' into build-grpc-client-recovery
AdityaKumaar21 Jun 25, 2025
26fee44
Merge remote-tracking branch 'origin' into build-grpc-client-recovery
AdityaKumaar21 Jun 26, 2025
ff53383
Merge remote-tracking branch 'origin' into build-grpc-client-recovery
AdityaKumaar21 Jul 30, 2025
f791524
feat(revenue_recovery): Introduce recovery timestamp configuration an…
AdityaKumaar21 Jul 30, 2025
3818225
Merge branch 'main' into build-grpc-client-recovery
AdityaKumaar21 Aug 1, 2025
5da1854
fix clippy
AdityaKumaar21 Aug 1, 2025
01aaa59
chore: run formatter
hyperswitch-bot[bot] Aug 1, 2025
553f094
errors fixed
AdityaKumaar21 Aug 4, 2025
da3304a
chore: run formatter
hyperswitch-bot[bot] Aug 4, 2025
e810940
Update build.rs
AdityaKumaar21 Aug 4, 2025
baee0b3
Update Cargo.toml
AdityaKumaar21 Aug 4, 2025
99daa29
resolving comments
AdityaKumaar21 Aug 4, 2025
560a72b
addressing comments
AdityaKumaar21 Aug 5, 2025
7bd8144
fix clippy
AdityaKumaar21 Aug 5, 2025
45435cc
chore: run formatter
hyperswitch-bot[bot] Aug 5, 2025
59f5a77
fix clippy
AdityaKumaar21 Aug 5, 2025
bdddba9
Merge branch 'main' into build-grpc-client-recovery
AdityaKumaar21 Aug 5, 2025
4e19f8f
adding more field in decider request and update the monitoring thresh…
AdityaKumaar21 Aug 6, 2025
d973789
formatting
AdityaKumaar21 Aug 6, 2025
bbdc2a6
adding more fields in decider request
AdityaKumaar21 Aug 6, 2025
c9031ce
Merge branch 'main' into build-grpc-client-recovery
AdityaKumaar21 Aug 6, 2025
ee1735d
chore: run formatter
hyperswitch-bot[bot] Aug 6, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions config/config.example.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,9 @@ host = "localhost" # Unified Connector Service Client Host
port = 8000 # Unified Connector Service Client Port
connection_timeout = 10 # Connection Timeout Duration in Seconds

[grpc_client.recovery_decider_client]
base_url = "http://127.0.0.1:8080" #Base URL

[billing_connectors_invoice_sync]
billing_connectors_which_requires_invoice_sync_call = "recurly" # List of billing connectors which has invoice sync api call

Expand Down
3 changes: 3 additions & 0 deletions config/deployments/env_specific.toml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,9 @@ host = "localhost" # Client Host
port = 7000 # Client Port
service = "dynamo" # Service name

[grpc_client.recovery_decider_client]
base_url = "http://127.0.0.1:8080" #Base URL

[theme.storage]
file_storage_backend = "aws_s3" # Theme storage backend to be used

Expand Down
2 changes: 1 addition & 1 deletion config/deployments/production.toml
Original file line number Diff line number Diff line change
Expand Up @@ -824,4 +824,4 @@ click_to_pay = {connector_list = "adyen, cybersource, trustpay"}

[revenue_recovery]
monitoring_threshold_in_seconds = 2592000
retry_algorithm_type = "cascading"
retry_algorithm_type = "cascading"
7 changes: 7 additions & 0 deletions config/development.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1219,6 +1219,9 @@ host = "localhost"
port = 8000
service = "dynamo"

[grpc_client.recovery_decider_client]
base_url = "http://127.0.0.1:8080"

[theme.storage]
file_storage_backend = "file_system" # Theme storage backend to be used

Expand Down Expand Up @@ -1256,6 +1259,10 @@ ucs_only_connectors = [
monitoring_threshold_in_seconds = 2592000
retry_algorithm_type = "cascading"

[revenue_recovery.recovery_timestamp]
initial_timestamp_in_hours = 1
final_timestamp_in_days = 30

[clone_connector_allowlist]
merchant_ids = "merchant_123, merchant_234" # Comma-separated list of allowed merchant IDs
connector_names = "stripe, adyen" # Comma-separated list of allowed connector names
Expand Down
16 changes: 14 additions & 2 deletions crates/external_services/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ email = ["dep:aws-config"]
aws_s3 = ["dep:aws-config", "dep:aws-sdk-s3"]
hashicorp-vault = ["dep:vaultrs"]
v1 = ["hyperswitch_interfaces/v1", "common_utils/v1"]
v2 = ["hyperswitch_interfaces/v2", "common_utils/v2"]
revenue_recovery = [
"dep:prost",
"dep:router_env",
"tokio/macros",
"tokio/rt-multi-thread",
"dep:hyper-util",
"dep:http-body-util",
"prost-types",
]
dynamic_routing = [
"dep:prost",
"dep:api_models",
Expand Down Expand Up @@ -43,8 +53,10 @@ serde = { version = "1.0.219", features = ["derive"] }
thiserror = "1.0.69"
vaultrs = { version = "0.7.4", optional = true }
prost = { version = "0.13", optional = true }
prost-types = { version = "0.13", optional = true }
time = { version = "0.3.41", features = ["serde", "serde-well-known", "std"] }
tokio = "1.45.1"
tonic = "0.13.1"
tonic = "0.13.1"
tonic-reflection = "0.13.1"
tonic-types = "0.13.1"
hyper-util = { version = "0.1.12", optional = true }
Expand All @@ -68,7 +80,7 @@ api_models = { version = "0.1.0", path = "../api_models", optional = true }


[build-dependencies]
tonic-build = "0.13.1"
tonic-build = "0.13.1"
router_env = { version = "0.1.0", path = "../router_env", default-features = false, optional = true }

[lints]
Expand Down
20 changes: 19 additions & 1 deletion crates/external_services/build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
#[allow(clippy::expect_used)]
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Compilation for v2 protos
#[cfg(feature = "revenue_recovery")]
{
let proto_base_path = router_env::workspace_path().join("proto");
let out_dir = std::path::PathBuf::from(std::env::var("OUT_DIR")?);
let v2_proto_files = [proto_base_path.join("recovery_decider.proto")];
tonic_build::configure()
.out_dir(&out_dir)
.compile_well_known_types(true)
.extern_path(".google.protobuf.Timestamp", "::prost_types::Timestamp")
.type_attribute(
"google.protobuf.Timestamp",
"#[derive(serde::Serialize, serde::Deserialize)]",
)
.compile_protos(&v2_proto_files, &[&proto_base_path])
.expect("Failed to compile revenue-recovery proto files");
}

// Compilation for dynamic_routing protos
#[cfg(feature = "dynamic_routing")]
{
// Get the directory of the current crate

let proto_path = router_env::workspace_path().join("proto");
let success_rate_proto_file = proto_path.join("success_rate.proto");
let contract_routing_proto_file = proto_path.join("contract_routing.proto");
Expand Down
42 changes: 36 additions & 6 deletions crates/external_services/src/grpc_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ pub mod dynamic_routing;
/// gRPC based Heath Check Client interface implementation
#[cfg(feature = "dynamic_routing")]
pub mod health_check_client;
/// gRPC based Recovery Trainer Client interface implementation
#[cfg(feature = "revenue_recovery")]
pub mod revenue_recovery;

/// gRPC based Unified Connector Service Client interface implementation
pub mod unified_connector_service;
use std::{fmt::Debug, sync::Arc};
Expand All @@ -14,19 +18,26 @@ use common_utils::consts;
use dynamic_routing::{DynamicRoutingClientConfig, RoutingStrategy};
#[cfg(feature = "dynamic_routing")]
use health_check_client::HealthCheckClient;
#[cfg(feature = "dynamic_routing")]
#[cfg(any(feature = "dynamic_routing", feature = "revenue_recovery"))]
use hyper_util::client::legacy::connect::HttpConnector;
#[cfg(feature = "dynamic_routing")]
use router_env::logger;
use serde;
#[cfg(feature = "dynamic_routing")]
#[cfg(any(feature = "dynamic_routing", feature = "revenue_recovery"))]
use tonic::body::Body;

#[cfg(feature = "revenue_recovery")]
pub use self::revenue_recovery::common::GrpcRecoveryHeaders;
#[cfg(feature = "revenue_recovery")]
pub use self::revenue_recovery::recovery_decider_client::{
DeciderRequest, DeciderResponse, RecoveryDeciderClientConfig, RecoveryDeciderClientInterface,
RecoveryDeciderError, RecoveryDeciderResult,
};
use crate::grpc_client::unified_connector_service::{
UnifiedConnectorServiceClient, UnifiedConnectorServiceClientConfig,
};

#[cfg(feature = "dynamic_routing")]
#[cfg(any(feature = "dynamic_routing", feature = "revenue_recovery"))]
/// Hyper based Client type for maintaining connection pool for all gRPC services
pub type Client = hyper_util::client::legacy::Client<HttpConnector, Body>;

Expand All @@ -39,15 +50,22 @@ pub struct GrpcClients {
/// Health Check client for all gRPC services
#[cfg(feature = "dynamic_routing")]
pub health_client: HealthCheckClient,
/// Recovery Decoder Client
#[cfg(feature = "revenue_recovery")]
pub recovery_decider_client: Option<Box<dyn RecoveryDeciderClientInterface>>,
/// Unified Connector Service client
pub unified_connector_service_client: Option<UnifiedConnectorServiceClient>,
}

/// Type that contains the configs required to construct a gRPC client with its respective services.
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize, Default)]
pub struct GrpcClientSettings {
#[cfg(feature = "dynamic_routing")]
/// Configs for Dynamic Routing Client
pub dynamic_routing_client: Option<DynamicRoutingClientConfig>,
#[cfg(feature = "revenue_recovery")]
/// Configs for Recovery Decider Client
pub recovery_decider_client: Option<RecoveryDeciderClientConfig>,
/// Configs for Unified Connector Service client
pub unified_connector_service: Option<UnifiedConnectorServiceClientConfig>,
}
Expand All @@ -59,7 +77,8 @@ impl GrpcClientSettings {
/// This function will be called at service startup.
#[allow(clippy::expect_used)]
pub async fn get_grpc_client_interface(&self) -> Arc<GrpcClients> {
#[cfg(feature = "dynamic_routing")]
// Define the hyper client if any gRPC feature is enabled
#[cfg(any(feature = "dynamic_routing", feature = "revenue_recovery"))]
let client =
hyper_util::client::legacy::Client::builder(hyper_util::rt::TokioExecutor::new())
.http2_only(true)
Expand All @@ -75,18 +94,29 @@ impl GrpcClientSettings {
.flatten();

#[cfg(feature = "dynamic_routing")]
let health_client = HealthCheckClient::build_connections(self, client)
let health_client = HealthCheckClient::build_connections(self, client.clone())
.await
.expect("Failed to build gRPC connections");

let unified_connector_service_client =
UnifiedConnectorServiceClient::build_connections(self).await;

#[cfg(feature = "revenue_recovery")]
let recovery_decider_client = self
.recovery_decider_client
.as_ref()
.map(|config| config.get_recovery_decider_connection(client.clone()))
.transpose()
.expect("Failed to establish a connection with the Recovery Decider Server")
.map(|client| -> Box<dyn RecoveryDeciderClientInterface> { Box::new(client) });

Arc::new(GrpcClients {
#[cfg(feature = "dynamic_routing")]
dynamic_routing: dynamic_routing_connection,
#[cfg(feature = "dynamic_routing")]
health_client,
#[cfg(feature = "revenue_recovery")]
recovery_decider_client,
unified_connector_service_client,
})
}
Expand Down Expand Up @@ -145,7 +175,7 @@ pub(crate) fn create_grpc_request<T: Debug>(message: T, headers: GrpcHeaders) ->
let mut request = tonic::Request::new(message);
request.add_headers_to_grpc_request(headers);

logger::info!(dynamic_routing_request=?request);
logger::info!(?request);

request
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/// common file for revenue recovery
pub mod common;
/// Recovery Decider client
pub mod recovery_decider_client;
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
use std::fmt::Debug;

use common_utils::consts;
use router_env::logger;

/// Errors in time conversion
#[derive(Debug, thiserror::Error)]
pub enum DateTimeConversionError {
#[error("Invalid timestamp value from prost Timestamp: out of representable range")]
/// Error for out of range
TimestampOutOfRange,
}

/// Contains recovery grpc headers
#[derive(Debug)]
pub struct GrpcRecoveryHeaders {
/// Request id
pub request_id: Option<String>,
}

/// Trait to add necessary recovery headers to the tonic Request
pub(crate) trait AddRecoveryHeaders {
/// Add necessary recovery header fields to the tonic Request
fn add_recovery_headers(&mut self, headers: GrpcRecoveryHeaders);
}

impl<T> AddRecoveryHeaders for tonic::Request<T> {
#[track_caller]
fn add_recovery_headers(&mut self, headers: GrpcRecoveryHeaders) {
headers.request_id.map(|request_id| {
request_id
.parse()
.map(|request_id_val| {
self
.metadata_mut()
.append(consts::X_REQUEST_ID, request_id_val)
})
.inspect_err(
|err| logger::warn!(header_parse_error=?err,"invalid {} received",consts::X_REQUEST_ID),
)
.ok();
});
}
}

/// Creates a tonic::Request with recovery headers added.
pub(crate) fn create_revenue_recovery_grpc_request<T: Debug>(
message: T,
recovery_headers: GrpcRecoveryHeaders,
) -> tonic::Request<T> {
let mut request = tonic::Request::new(message);
request.add_recovery_headers(recovery_headers);
request
}
Loading
Loading