feat: alter http query endpoint (#2559)
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>pull/24376/head
parent
63a1ed147f
commit
0ff2f9bb60
|
@ -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
|
||||
|
|
|
@ -391,7 +391,7 @@ where
|
|||
.post("/api/v2/write", write::<M>)
|
||||
.get("/health", health::<M>)
|
||||
.get("/metrics", handle_metrics::<M>)
|
||||
.get("/iox/api/v1/databases/:name/query", query::<M>)
|
||||
.get("/api/v3/query", query::<M>)
|
||||
.get("/debug/pprof", pprof_home::<M>)
|
||||
.get("/debug/pprof/profile", pprof_profile::<M>)
|
||||
.get("/debug/pprof/allocs", pprof_heappy_profile::<M>)
|
||||
|
@ -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<M: ConnectionManager + Send + Sync + Debug + 'static>(
|
|||
|
||||
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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue