Skip to content

Commit

Permalink
Report endpoints in error messages (#91)
Browse files Browse the repository at this point in the history
Report endpoints in Rust SDK error messages
  • Loading branch information
lootag authored Nov 27, 2024
1 parent 380453a commit 9558d9f
Show file tree
Hide file tree
Showing 25 changed files with 1,160 additions and 186 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ jobs:
AWS_REGION: ${{ secrets.AWS_REGION }}
METRICS_BUCKET: ${{ secrets.METRICS_BUCKET }}
LOGS_BUCKET: ${{ secrets.LOGS_BUCKET }}
run: cargo nextest run --all
run: cargo nextest run --no-tests=warn --all
working-directory: rust/examples

examples_windows:
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
AWS_REGION: ${{ secrets.AWS_REGION }}
METRICS_BUCKET: ${{ secrets.METRICS_BUCKET }}
LOGS_BUCKET: ${{ secrets.LOGS_BUCKET }}
run: cargo nextest run --all
run: cargo nextest run --no-tests=warn --all
working-directory: rust/examples

clippy:
Expand Down
64 changes: 46 additions & 18 deletions rust/cx-sdk/src/client/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ use crate::{
ReplaceActionResponse,
actions_service_client::ActionsServiceClient,
},
error::Result,
error::{
Result,
SdkApiError,
},
metadata::CallProperties,
util::make_request_with_metadata,
};
Expand Down Expand Up @@ -94,13 +97,17 @@ impl ActionsClient {
&self.teams_level_metadata_map,
);
//let client = self.service_client.lock().await.descri
self.service_client
Ok(self
.service_client
.lock()
.await
.create_action(request)
.await
.map(|r| r.into_inner())
.map_err(From::from)
.map_err(|status| SdkApiError {
status,
endpoint: "/com.coralogixapis.actions.v2.ActionsService/CreateAction".into(),
})?
.into_inner())
}

/// Replaces the existing [`Action`] identified by its id.
Expand All @@ -114,13 +121,17 @@ impl ActionsClient {
},
&self.teams_level_metadata_map,
);
self.service_client
Ok(self
.service_client
.lock()
.await
.replace_action(request)
.await
.map(|r| r.into_inner())
.map_err(From::from)
.map_err(|status| SdkApiError {
status,
endpoint: "/com.coralogixapis.actions.v2.ActionsService/ReplaceAction".to_string(),
})?
.into_inner())
}

/// Deletes the [`Action`] identified by its id.
Expand All @@ -134,13 +145,17 @@ impl ActionsClient {
},
&self.teams_level_metadata_map,
);
self.service_client
Ok(self
.service_client
.lock()
.await
.delete_action(request)
.await
.map(|r| r.into_inner())
.map_err(From::from)
.map_err(|status| SdkApiError {
status,
endpoint: "/com.coralogixapis.actions.v2.ActionsService/DeleteAction".to_string(),
})?
.into_inner())
}

/// Retrieves the [`Action`] by id.
Expand All @@ -155,13 +170,18 @@ impl ActionsClient {
&self.teams_level_metadata_map,
);

self.service_client
Ok(self
.service_client
.lock()
.await
.get_action(request)
.await
.map(|r| r.into_inner().action)
.map_err(From::from)
.map_err(|status| SdkApiError {
status,
endpoint: "/com.coralogixapis.actions.v2.ActionsService/GetAction".to_string(),
})?
.into_inner()
.action)
}

/// Retrieves a list of all [`Action`]s.
Expand All @@ -172,13 +192,18 @@ impl ActionsClient {
let request =
make_request_with_metadata(ListActionsRequest {}, &self.teams_level_metadata_map);

self.service_client
Ok(self
.service_client
.lock()
.await
.list_actions(request)
.await
.map(|r| r.into_inner().actions)
.map_err(From::from)
.map_err(|status| SdkApiError {
status,
endpoint: "/com.coralogixapis.actions.v2.ActionsService/ListActions".to_string(),
})?
.into_inner()
.actions)
}

/// Orders the actions.
Expand All @@ -205,7 +230,10 @@ impl ActionsClient {
.await
.order_actions(request)
.await
.map(|_| ())
.map_err(From::from)
.map_err(|status| SdkApiError {
status,
endpoint: "/com.coralogixapis.actions.v2.ActionsService/OrderActions".to_string(),
})?;
Ok(())
}
}
51 changes: 45 additions & 6 deletions rust/cx-sdk/src/client/alerts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::error::{
SdkApiError,
SdkError,
};
use crate::{
CoralogixRegion,
auth::AuthContext,
Expand Down Expand Up @@ -171,7 +175,13 @@ impl AlertsClient {
.get_alert_def(request)
.await
.map(|r| r.into_inner())
.map_err(From::from)
.map_err(|status| {
SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerts.v3.AlertDefsService/GetAlertDef"
.into(),
})
})
}
}

Expand All @@ -185,7 +195,13 @@ impl AlertsClient {
.list_alert_defs(request)
.await
.map(|r| r.into_inner())
.map_err(From::from)
.map_err(|status| {
SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerts.v3.AlertDefsService/ListAlertDefs"
.into(),
})
})
}
}

Expand All @@ -207,7 +223,13 @@ impl AlertsClient {
.create_alert_def(request)
.await
.map(|r| r.into_inner())
.map_err(From::from)
.map_err(|status| {
SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerts.v3.AlertDefsService/CreateAlertDef"
.into(),
})
})
}
}

Expand All @@ -229,7 +251,13 @@ impl AlertsClient {
.replace_alert_def(request)
.await
.map(|r| r.into_inner())
.map_err(From::from)
.map_err(|status| {
SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerts.v3.AlertDefsService/ReplaceAlertDef"
.into(),
})
})
}
}

Expand All @@ -247,7 +275,13 @@ impl AlertsClient {
.delete_alert_def(request)
.await
.map(|_| ())
.map_err(From::from)
.map_err(|status| {
SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerts.v3.AlertDefsService/DeleteAlertDef"
.into(),
})
})
}
}

Expand All @@ -269,7 +303,12 @@ impl AlertsClient {
.set_active(request)
.await
.map(|_| ())
.map_err(From::from)
.map_err(|status| {
SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerts.v3.AlertDefsService/SetActive".into(),
})
})
}
}
}
50 changes: 43 additions & 7 deletions rust/cx-sdk/src/client/alerts_scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ use crate::{
auth::AuthContext,
error::{
Result,
SdkApiError,
SdkError,
},
metadata::CallProperties,
Expand Down Expand Up @@ -108,7 +109,12 @@ impl AlertSchedulerClient {
.create_alert_scheduler_rule(request)
.await
.map(|r| r.into_inner().alert_scheduler_rule.unwrap()) //There should not be a case where the result is successful but the alert_scheduler_rule is None
.map_err(From::from)
.map_err(
|status| SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerting.alert_scheduler_rule_protobuf.v1.AlertSchedulerRuleService/CreateAlertSchedulerRule".into(),
}),
)
}

/// Creates multiple Alert Scheduler Rules
Expand Down Expand Up @@ -143,7 +149,12 @@ impl AlertSchedulerClient {
.map(|response| response.alert_scheduler_rule.unwrap()) //There should not be a case where the result is successful but the alert_scheduler_rule is None
.collect()
})
.map_err(From::from)
.map_err(
|status| SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerting.alert_scheduler_rule_protobuf.v1.AlertSchedulerRuleService/CreateBulkAlertSchedulerRule".into(),
}),
)
}

/// Updates an existing Alert Scheduler Rule identified by its unique identifier.
Expand All @@ -167,7 +178,12 @@ impl AlertSchedulerClient {
.update_alert_scheduler_rule(request)
.await
.map(|r| r.into_inner().alert_scheduler_rule.unwrap()) //There should not be a case where the result is successful but the alert_scheduler_rule is None
.map_err(From::from)
.map_err(
|status| SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerting.alert_scheduler_rule_protobuf.v1.AlertSchedulerRuleService/UpdateAlertSchedulerRule".into(),
}),
)
}

/// Updates multiple existing Alert Scheduler Rules identified by their unique identifiers.
Expand Down Expand Up @@ -201,7 +217,12 @@ impl AlertSchedulerClient {
.map(|response| response.alert_scheduler_rule.unwrap()) //There should not be a case where the result is successful but the alert_scheduler_rule is None
.collect()
})
.map_err(From::from)
.map_err(
|status| SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerting.alert_scheduler_rule_protobuf.v1.AlertSchedulerRuleService/UpdateBulkAlertSchedulerRule".into(),
}),
)
}

/// Retrieves an Alert Scheduler Rule by its unique identifier.
Expand All @@ -221,7 +242,12 @@ impl AlertSchedulerClient {
.get_alert_scheduler_rule(request)
.await
.map(|r| r.into_inner().alert_scheduler_rule.unwrap())
.map_err(From::from)
.map_err(
|status| SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerting.alert_scheduler_rule_protobuf.v1.AlertSchedulerRuleService/GetAlertSchedulerRule".into(),
}),
)
}

/// Retrieves multiple Alert Scheduler Rules by their unique identifiers.
Expand Down Expand Up @@ -262,7 +288,12 @@ impl AlertSchedulerClient {
let response = r.into_inner();
(response.alert_scheduler_rules, response.next_page_token)
})
.map_err(SdkError::from)?;
.map_err(
|status| SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerting.alert_scheduler_rule_protobuf.v1.AlertSchedulerRuleService/GetBulkAlertSchedulerRule".into(),
}),
)?;
all_rules.extend(alert_scheduler_rules);
if new_token.is_empty() {
next_page_token = None;
Expand Down Expand Up @@ -290,6 +321,11 @@ impl AlertSchedulerClient {
.delete_alert_scheduler_rule(request)
.await
.map(|_| ())
.map_err(From::from)
.map_err(
|status| SdkError::ApiError(SdkApiError {
status,
endpoint: "/com.coralogixapis.alerting.alert_scheduler_rule_protobuf.v1.AlertSchedulerRuleService/DeleteAlertSchedulerRule".into(),
}),
)
}
}
Loading

0 comments on commit 9558d9f

Please sign in to comment.