Skip to content

Commit b3ee0a2

Browse files
authored
Update SDK and tracing (#194)
<!-- The PR description should answer 2 (maybe 3) important questions: --> ### What * Update sdk to 0.5.0 * Add visibility user to tracing spans
1 parent 1be30b6 commit b3ee0a2

File tree

26 files changed

+176
-166
lines changed

26 files changed

+176
-166
lines changed

Cargo.lock

Lines changed: 23 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ unused_async = "allow"
5252
# ndc-models was using version 0.1.2 but we needed rustls fix
5353

5454
ndc-models = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.6" }
55-
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs.git", tag = "v0.4.0" }
55+
ndc-sdk = { git = "https://github.com/hasura/ndc-sdk-rs.git", tag = "v0.5.0" }
5656
ndc-test = { git = "https://github.com/hasura/ndc-spec.git", tag = "v0.1.6" }
5757

5858
smol_str = "0.1"

crates/cli/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub async fn run(command: Command, context: Context<impl Environment>) -> anyhow
6262
binary_cli_manifest,
6363
} => initialize(with_metadata, context, binary_cli_manifest).await?,
6464
Command::Update { subcommand } => update(context, subcommand).await?,
65-
};
65+
}
6666
Ok(())
6767
}
6868

crates/configuration/src/version1.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ async fn configure_stored_procedures(
195195
&mut stored_procs_rows,
196196
)
197197
.await
198-
.map_err(|e| Error::IntrospectionQueryExecutionError(format!("{:?}", e)))?;
198+
.map_err(|e| Error::IntrospectionQueryExecutionError(format!("{e:?}")))?;
199199
let introspected_stored_procedures: Vec<introspection::IntrospectStoredProcedure> =
200200
serde_json::from_slice(&stored_procs_rows)
201201
.map_err(|e| Error::JsonDeserializationError(e.to_string()))?;
@@ -209,9 +209,6 @@ async fn configure_stored_procedures(
209209
std::collections::btree_map::Entry::Occupied(mut e) => {
210210
if config_options.overwrite_existing_stored_procedures {
211211
e.insert(stored_procedure);
212-
} else {
213-
// do not overwrite the existing stored procedure
214-
continue;
215212
}
216213
}
217214
std::collections::btree_map::Entry::Vacant(e) => {
@@ -262,7 +259,7 @@ pub async fn configure(
262259
&mut table_rows,
263260
)
264261
.await
265-
.map_err(|e| Error::IntrospectionQueryExecutionError(format!("{:?}", e)))?;
262+
.map_err(|e| Error::IntrospectionQueryExecutionError(format!("{e:?}")))?;
266263
let tables: Vec<introspection::IntrospectionTable> = serde_json::from_slice(&table_rows)
267264
.map_err(|e| Error::JsonDeserializationError(e.to_string()))?;
268265

@@ -277,7 +274,7 @@ pub async fn configure(
277274
&mut types_rows,
278275
)
279276
.await
280-
.map_err(|e| Error::IntrospectionQueryExecutionError(format!("{:?}", e)))?;
277+
.map_err(|e| Error::IntrospectionQueryExecutionError(format!("{e:?}")))?;
281278
let type_names: Vec<TypeItem> = serde_json::from_slice(&types_rows)
282279
.map_err(|e| Error::JsonDeserializationError(e.to_string()))?;
283280

@@ -457,7 +454,7 @@ fn get_aggregate_functions_for_type(
457454
return_type: metadata::ScalarType(precise_return_type.to_string()),
458455
},
459456
);
460-
};
457+
}
461458

462459
aggregate_functions.insert(
463460
AggregateFunctionName::new("COUNT_BIG".to_string().into()),

crates/ndc-sqlserver/src/connector.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,16 @@ impl<Env: Environment> SQLServerSetup<Env> {
3636
}
3737

3838
#[async_trait]
39-
impl<Env: Environment + Send + Sync> connector::ConnectorSetup for SQLServerSetup<Env> {
39+
impl<Env: Environment + Send + Sync + 'static> connector::ConnectorSetup for SQLServerSetup<Env> {
4040
type Connector = SQLServer;
4141

4242
/// Validate the raw configuration provided by the user,
4343
/// returning a configuration error or a validated [`Connector::Configuration`].
4444
async fn parse_configuration(
4545
&self,
46-
configuration_dir: impl AsRef<Path> + Send,
46+
configuration_dir: &Path,
4747
) -> Result<<Self::Connector as connector::Connector>::Configuration> {
48-
let configuration_file = configuration_dir
49-
.as_ref()
50-
.join(configuration::CONFIGURATION_FILENAME);
48+
let configuration_file = configuration_dir.join(configuration::CONFIGURATION_FILENAME);
5149
let configuration_file_contents =
5250
fs::read_to_string(&configuration_file).await.map_err(|_| {
5351
connector::ParseError::CouldNotFindConfiguration(configuration_file.clone())
@@ -103,22 +101,20 @@ impl<Env: Environment + Send + Sync> connector::ConnectorSetup for SQLServerSetu
103101
}
104102
configuration::Error::IoError(inner) => connector::ParseError::IoError(inner),
105103
configuration::Error::IoErrorButStringified(inner) => {
106-
std::io::Error::new(std::io::ErrorKind::Other, inner).into()
107-
}
108-
configuration::Error::ConnectionPoolError(inner) => {
109-
std::io::Error::new(std::io::ErrorKind::Other, inner).into()
104+
std::io::Error::other(inner).into()
110105
}
106+
configuration::Error::ConnectionPoolError(inner) => std::io::Error::other(inner).into(),
111107
configuration::Error::GetConnectionFromPool(inner) => {
112-
std::io::Error::new(std::io::ErrorKind::Other, inner).into()
108+
std::io::Error::other(inner).into()
113109
}
114110
configuration::Error::JsonDeserializationError(inner) => {
115-
connector::ParseError::from(std::io::Error::new(std::io::ErrorKind::Other, inner))
111+
connector::ParseError::from(std::io::Error::other(inner))
116112
}
117113
configuration::Error::IntrospectionQueryExecutionError(inner) => {
118-
connector::ParseError::from(std::io::Error::new(std::io::ErrorKind::Other, inner))
114+
connector::ParseError::from(std::io::Error::other(inner))
119115
}
120116
configuration::Error::StoredProcedureIntrospectionError(inner) => {
121-
connector::ParseError::from(std::io::Error::new(std::io::ErrorKind::Other, inner))
117+
connector::ParseError::from(std::io::Error::other(inner))
122118
}
123119
})?;
124120

crates/ndc-sqlserver/src/explain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ pub async fn explain(
6363

6464
Ok(response)
6565
}
66-
.instrument(info_span!("/explain"))
66+
.instrument(info_span!("Explain explain", internal.visibility = "user"))
6767
.await
6868
}
6969

crates/ndc-sqlserver/src/mutation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ pub async fn mutation(
5050

5151
Ok(result)
5252
}
53-
.instrument(info_span!("/mutation"))
53+
.instrument(info_span!("Execute mutation"))
5454
.await;
5555

5656
timer.complete_with(result)

crates/ndc-sqlserver/src/schema.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,8 +167,8 @@ fn make_procedure_type(
167167
/// Each native mutation creates two objects:
168168
/// 1. Object with name `{native_mutation_name}_response`, this object
169169
/// will contain two fields:
170-
/// a. affected_rows: int - The rows affected by the native mutation.
171-
/// b. returning: `{native_mutation_name}` - Data returned by the native mutation.
170+
/// a. affected_rows: int - The rows affected by the native mutation.
171+
/// b. returning: `{native_mutation_name}` - Data returned by the native mutation.
172172
/// 2. Object with name `{native_mutation_name}` whose fields will
173173
/// contain the fields specified in the `columns`.
174174
fn get_native_mutations_schema(
@@ -275,7 +275,7 @@ fn get_stored_procedures_schema(
275275
return Err(connector::ErrorResponse::from_error(Box::new(
276276
SchemaError::DuplicateObject(object_type_name),
277277
)));
278-
};
278+
}
279279

280280
let stored_proc_schema = models::ProcedureInfo {
281281
name: proc_name.to_string().into(),

crates/ndc-sqlserver/tests/common/helpers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,12 @@ pub async fn create_router(connection_uri: &str) -> axum::Router {
122122
let setup = connector::SQLServerSetup::new(environment);
123123

124124
// initialise server state with the static configuration.
125-
let state = ndc_sdk::default_main::init_server_state(setup, test_deployment_file)
125+
let state = ndc_sdk::state::init_server_state(setup, &test_deployment_file)
126126
.await
127127
.unwrap();
128128

129129
// create a fresh client
130-
ndc_sdk::default_main::create_router(state, None)
130+
ndc_sdk::default_main::create_router(state, None, None)
131131
}
132132

133133
/// Make a single request against a new server, and get the response.

crates/query-engine/execution/src/metrics.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ impl Timer {
179179
Err(_) => {
180180
self.0.stop_and_discard();
181181
}
182-
};
182+
}
183183
result
184184
}
185185
}
@@ -201,85 +201,85 @@ impl std::error::Error for Error {}
201201
#[derive(Debug, Clone)]
202202
pub struct ErrorMetrics {
203203
/// the connector received an invalid request.
204-
invalid_request_total: IntCounter,
204+
invalid_request: IntCounter,
205205
/// the connector received a request using capabilities it does not support.
206-
unsupported_capability_total: IntCounter,
206+
unsupported_capability: IntCounter,
207207
/// the connector could not fulfill a request because it does not support
208208
/// certain features (which are not described as capabilities).
209-
unsupported_feature_total: IntCounter,
209+
unsupported_feature: IntCounter,
210210
/// the connector had an internal error.
211-
connector_error_total: IntCounter,
211+
connector_error: IntCounter,
212212
/// the database emmited an error.
213-
database_error_total: IntCounter,
213+
database_error: IntCounter,
214214
/// we failed to acquire a database connection from the pool
215-
connection_acquisition_error_total: IntCounter,
215+
connection_acquisition_error: IntCounter,
216216
}
217217

218218
impl ErrorMetrics {
219219
/// Set up counters and gauges used to produce Prometheus metrics
220220
pub fn initialize(metrics_registry: &mut prometheus::Registry) -> Result<Self, Error> {
221-
let invalid_request_total = add_int_counter_metric(
221+
let invalid_request = add_int_counter_metric(
222222
metrics_registry,
223-
"ndc_sqlserver_error_invalid_request_total_count",
223+
"ndc_sqlserver_error_invalid_request_count",
224224
"Total number of invalid requests encountered.",
225225
)?;
226226

227-
let unsupported_capability_total = add_int_counter_metric(
227+
let unsupported_capability = add_int_counter_metric(
228228
metrics_registry,
229-
"ndc_sqlserver_error_unsupported_capability_total_count",
229+
"ndc_sqlserver_error_unsupported_capability_count",
230230
"Total number of invalid requests with unsupported capabilities encountered.",
231231
)?;
232232

233-
let unsupported_feature_total = add_int_counter_metric(
233+
let unsupported_feature = add_int_counter_metric(
234234
metrics_registry,
235-
"ndc_sqlserver_error_unsupported_capabilities_total_count",
235+
"ndc_sqlserver_error_unsupported_capabilities_count",
236236
"Total number of invalid requests with unsupported capabilities encountered.",
237237
)?;
238238

239-
let connector_error_total = add_int_counter_metric(
239+
let connector_error = add_int_counter_metric(
240240
metrics_registry,
241-
"ndc_sqlserver_error_connector_error_total_count",
241+
"ndc_sqlserver_error_connector_error_count",
242242
"Total number of requests failed due to an internal conenctor error.",
243243
)?;
244244

245-
let database_error_total = add_int_counter_metric(
245+
let database_error = add_int_counter_metric(
246246
metrics_registry,
247-
"ndc_sqlserver_error_database_error_total_count",
247+
"ndc_sqlserver_error_database_error_count",
248248
"Total number of requests failed due to a database error.",
249249
)?;
250250

251-
let connection_acquisition_error_total = add_int_counter_metric(
251+
let connection_acquisition_error = add_int_counter_metric(
252252
metrics_registry,
253-
"ndc_sqlserver_error_connection_acquisition_error_total_count",
253+
"ndc_sqlserver_error_connection_acquisition_error_count",
254254
"Total number of failures to acquire a database connection.",
255255
)?;
256256

257257
Ok(ErrorMetrics {
258-
invalid_request_total,
259-
unsupported_capability_total,
260-
unsupported_feature_total,
261-
connector_error_total,
262-
database_error_total,
263-
connection_acquisition_error_total,
258+
invalid_request,
259+
unsupported_capability,
260+
unsupported_feature,
261+
connector_error,
262+
database_error,
263+
connection_acquisition_error,
264264
})
265265
}
266266

267267
pub fn record_invalid_request(&self) {
268-
self.invalid_request_total.inc();
268+
self.invalid_request.inc();
269269
}
270270
pub fn record_unsupported_capability(&self) {
271-
self.unsupported_capability_total.inc();
271+
self.unsupported_capability.inc();
272272
}
273273
pub fn record_unsupported_feature(&self) {
274-
self.unsupported_feature_total.inc();
274+
self.unsupported_feature.inc();
275275
}
276276
pub fn record_connector_error(&self) {
277-
self.connector_error_total.inc();
277+
self.connector_error.inc();
278278
}
279279
pub fn record_database_error(&self) {
280-
self.database_error_total.inc();
280+
self.database_error.inc();
281281
}
282282
pub fn record_connection_acquisition_error(&self) {
283-
self.connection_acquisition_error_total.inc()
283+
self.connection_acquisition_error.inc()
284284
}
285285
}

0 commit comments

Comments
 (0)