Skip to content

Commit

Permalink
add a connector name function to connector trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Gil Mizrahi committed Oct 27, 2023
1 parent 6b4bded commit 930b968
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 12 deletions.
2 changes: 2 additions & 0 deletions rust-connector-sdk/src/connector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ pub trait Connector {
/// The type of unserializable state
type State;

fn connector_name() -> String;

fn make_empty_configuration() -> Self::RawConfiguration;

async fn update_configuration(
Expand Down
4 changes: 4 additions & 0 deletions rust-connector-sdk/src/connector/example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ impl Connector for Example {
type Configuration = ();
type State = ();

fn connector_name() -> String {
"ndc-example".to_string()
}

fn make_empty_configuration() -> Self::RawConfiguration {}

async fn update_configuration(
Expand Down
3 changes: 2 additions & 1 deletion rust-connector-sdk/src/default_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ where
.unwrap();

let mut metrics_registry = Registry::new();
let metrics = metrics::Metrics::initialize(&mut metrics_registry).unwrap(); // todo: remove unwrap
let metrics =
metrics::Metrics::initialize(&C::connector_name(), &mut metrics_registry).unwrap();
let state = C::try_init_state(&configuration, &mut metrics_registry)
.await
.unwrap();
Expand Down
23 changes: 12 additions & 11 deletions rust-connector-sdk/src/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,71 +30,72 @@ pub struct StatusCodeMetrics {
impl Metrics {
/// Set up counters and gauges used to produce Prometheus metrics
pub fn initialize(
connector_name: &str,
metrics_registry: &mut prometheus::Registry,
) -> Result<Self, prometheus::Error> {
let total_200 = add_int_counter_metric(
metrics_registry,
"hasura_status_code_200_total_count",
format!("{}_status_code_200_total_count", connector_name).as_str(),
"Total number of 200 status codes returned.",
)?;

let total_400 = add_int_counter_metric(
metrics_registry,
"hasura_status_code_400_total_count",
format!("{}_status_code_400_total_count", connector_name).as_str(),
"Total number of 400 status codes returned.",
)?;

let total_403 = add_int_counter_metric(
metrics_registry,
"hasura_status_code_403_total_count",
format!("{}_status_code_403_total_count", connector_name).as_str(),
"Total number of 403 status codes returned.",
)?;

let total_409 = add_int_counter_metric(
metrics_registry,
"hasura_status_code_409_total_count",
format!("{}_status_code_409_total_count", connector_name).as_str(),
"Total number of 409 status codes returned.",
)?;

let total_500 = add_int_counter_metric(
metrics_registry,
"hasura_status_code_500_total_count",
format!("{}_status_code_500_total_count", connector_name).as_str(),
"Total number of 500 status codes returned.",
)?;

let total_501 = add_int_counter_metric(
metrics_registry,
"hasura_status_code_501_total_count",
format!("{}_status_code_501_total_count", connector_name).as_str(),
"Total number of 501 status codes returned.",
)?;

let total_1xx = add_int_counter_metric(
metrics_registry,
"hasura_status_code_1xx_total_count",
format!("{}_status_code_1xx_total_count", connector_name).as_str(),
"Total number of 1xx status codes returned.",
)?;

let total_2xx = add_int_counter_metric(
metrics_registry,
"hasura_status_code_2xx_total_count",
format!("{}_status_code_2xx_total_count", connector_name).as_str(),
"Total number of 2xx status codes returned.",
)?;

let total_3xx = add_int_counter_metric(
metrics_registry,
"hasura_status_code_3xx_total_count",
format!("{}_status_code_3xx_total_count", connector_name).as_str(),
"Total number of 3xx status codes returned.",
)?;

let total_4xx = add_int_counter_metric(
metrics_registry,
"hasura_status_code_4xx_total_count",
format!("{}_status_code_4xx_total_count", connector_name).as_str(),
"Total number of 4xx status codes returned.",
)?;

let total_5xx = add_int_counter_metric(
metrics_registry,
"hasura_status_code_5xx_total_count",
format!("{}_status_code_5xx_total_count", connector_name).as_str(),
"Total number of 5xx status codes returned.",
)?;

Expand Down

0 comments on commit 930b968

Please sign in to comment.