From 0ff2f9bb605e3937d44957a585701da90c625962 Mon Sep 17 00:00:00 2001 From: Raphael Taylor-Davies <1781103+tustvold@users.noreply.github.com> Date: Sat, 18 Sep 2021 10:24:27 +0100 Subject: [PATCH] feat: alter http query endpoint (#2559) Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> --- perf/perf.py | 8 ++++---- src/influxdb_ioxd/http.rs | 22 ++++++++++------------ tests/common/server_fixture.rs | 8 -------- tests/end_to_end_cases/read_api.rs | 6 ++---- 4 files changed, 16 insertions(+), 28 deletions(-) diff --git a/perf/perf.py b/perf/perf.py index 6d3a1effb8..ef15590c9f 100755 --- a/perf/perf.py +++ b/perf/perf.py @@ -587,8 +587,8 @@ def grpc_create_database(router_id, writer_id): writer.request('influxdata.iox.management.v1.ManagementService', 'CreateDatabase', writer_db_rules) writer_http_addr = 'localhost:%d' % (writer_id * 10000 + 8080) - writer_query_url = 'http://%s/iox/api/v1/databases/%s/query' % (writer_http_addr, db_name) - writer_query_params = {'q': 'select count(1) from sentinel'} + writer_query_url = 'http://%s/api/v3/query' % writer_http_addr + writer_query_params = {'q': 'select count(1) from sentinel', 'd': db_name} response = requests.get(url=writer_query_url, params=writer_query_params, timeout=10) for i in range(20): @@ -641,7 +641,7 @@ def run_test_battery(battery_name, router_id, writer_id, debug=False, do_trace=F # Query writer_http_addr = 'localhost:%d' % (writer_id * 10000 + 8080) - query_url = 'http://%s/iox/api/v1/databases/%s/query' % (writer_http_addr, db_name) + query_url = 'http://%s/api/v3/query' % writer_http_addr queries_filename = os.path.join(battery_dir, 'queries.toml') queries = toml.load(open(queries_filename)) @@ -659,7 +659,7 @@ def run_test_battery(battery_name, router_id, writer_id, debug=False, do_trace=F print('running test "%s"' % name) time_start = time.time() - params = {'q': sql, 'format': 'csv'} + params = {'q': sql, 'format': 'csv', 'd': db_name} headers = {} if do_trace: # TODO remove this after IOx can be configured to sample 100% of traces diff --git a/src/influxdb_ioxd/http.rs b/src/influxdb_ioxd/http.rs index 04d4df9e20..47fd67a5d2 100644 --- a/src/influxdb_ioxd/http.rs +++ b/src/influxdb_ioxd/http.rs @@ -391,7 +391,7 @@ where .post("/api/v2/write", write::) .get("/health", health::) .get("/metrics", handle_metrics::) - .get("/iox/api/v1/databases/:name/query", query::) + .get("/api/v3/query", query::) .get("/debug/pprof", pprof_home::) .get("/debug/pprof/profile", pprof_profile::) .get("/debug/pprof/allocs", pprof_heappy_profile::) @@ -561,6 +561,9 @@ where #[derive(Deserialize, Debug, PartialEq)] /// Parsed URI Parameters of the request to the .../query endpoint struct QueryParams { + #[serde(alias = "database")] + d: String, + #[serde(alias = "query")] q: String, #[serde(default = "default_format")] format: String, @@ -578,19 +581,14 @@ async fn query( let uri_query = req.uri().query().context(ExpectedQueryString {})?; - let QueryParams { q, format } = + let QueryParams { d, q, format } = serde_urlencoded::from_str(uri_query).context(InvalidQueryString { query_string: uri_query, })?; let format = QueryOutputFormat::from_str(&format).context(ParsingFormat { format })?; - let db_name_str = req - .param("name") - .expect("db name must have been set by routerify") - .clone(); - - let db_name = DatabaseName::new(&db_name_str).context(DatabaseNameError)?; + let db_name = DatabaseName::new(&d).context(DatabaseNameError)?; debug!(uri = ?req.uri(), %q, ?format, %db_name, "running SQL query"); let db = server.db(&db_name)?; @@ -1243,7 +1241,7 @@ mod tests { // send query data let response = client .get(&format!( - "{}/iox/api/v1/databases/MyOrg_MyBucket/query?q={}", + "{}/api/v3/query?d=MyOrg_MyBucket&q={}", server_url, "select%20*%20from%20h2o_temperature" )) .send() @@ -1263,7 +1261,7 @@ mod tests { // same response is expected if we explicitly request 'format=pretty' let response = client .get(&format!( - "{}/iox/api/v1/databases/MyOrg_MyBucket/query?q={}&format=pretty", + "{}/api/v3/query?d=MyOrg_MyBucket&q={}&format=pretty", server_url, "select%20*%20from%20h2o_temperature" )) .send() @@ -1280,7 +1278,7 @@ mod tests { // send query data let response = client .get(&format!( - "{}/iox/api/v1/databases/MyOrg_MyBucket/query?q={}&format=csv", + "{}/api/v3/query?d=MyOrg_MyBucket&q={}&format=csv", server_url, "select%20*%20from%20h2o_temperature" )) .send() @@ -1318,7 +1316,7 @@ mod tests { // send query data let response = client .get(&format!( - "{}/iox/api/v1/databases/MyOrg_MyBucket/query?q={}&format=json", + "{}/api/v3/query?d=MyOrg_MyBucket&q={}&format=json", server_url, "select%20*%20from%20h2o_temperature%20order%20by%20surface_degrees" )) .send() diff --git a/tests/common/server_fixture.rs b/tests/common/server_fixture.rs index 59b9515fb5..2be6fca6e5 100644 --- a/tests/common/server_fixture.rs +++ b/tests/common/server_fixture.rs @@ -32,7 +32,6 @@ pub struct BindAddresses { grpc_bind_addr: String, http_base: String, - iox_api_v1_base: String, grpc_base: String, } @@ -66,14 +65,12 @@ impl Default for BindAddresses { let grpc_addr = Self::get_free_port(); let http_base = format!("http://{}", http_addr); - let iox_api_v1_base = format!("http://{}/iox/api/v1", http_addr); let grpc_base = format!("http://{}", grpc_addr); Self { http_bind_addr: http_addr.to_string(), grpc_bind_addr: grpc_addr.to_string(), http_base, - iox_api_v1_base, grpc_base, } } @@ -184,11 +181,6 @@ impl ServerFixture { &self.server.addrs().http_base } - /// Return the base URL for the IOx V1 API - pub fn iox_api_v1_base(&self) -> &str { - &self.server.addrs().iox_api_v1_base - } - /// Return an a http client suitable suitable for communicating with this /// server pub fn influxdb2_client(&self) -> influxdb2_client::Client { diff --git a/tests/end_to_end_cases/read_api.rs b/tests/end_to_end_cases/read_api.rs index 00ff184549..a83fd8d35d 100644 --- a/tests/end_to_end_cases/read_api.rs +++ b/tests/end_to_end_cases/read_api.rs @@ -14,12 +14,10 @@ pub async fn test() { let sql_query = "select * from cpu_load_short"; let client = reqwest::Client::new(); - let db_name = format!("{}_{}", scenario.org_id_str(), scenario.bucket_id_str()); - let path = format!("/databases/{}/query", db_name); - let url = format!("{}{}", server_fixture.iox_api_v1_base(), path); + let url = format!("{}/api/v3/query", server_fixture.http_base()); let mut lines: Vec<_> = client .get(&url) - .query(&[("q", sql_query)]) + .query(&[("q", sql_query), ("d", scenario.database_name().as_str())]) .send() .await .unwrap()