Skip to content

Commit

Permalink
Add a wrapper to trace queries issued by 'compute_ctl'.
Browse files Browse the repository at this point in the history
This allows more fine-grained tracing of how much time each query
takes during compute startup.

The tracing is done in a new wrapper crate around the 'postgres'
crate, so that it's as transparent as possible to the calling
code. The wrapper could be used elsewhere too, but for now it's only
used in 'compute_ctl'.
  • Loading branch information
hlinnaka committed Jan 20, 2023
1 parent 20b1e26 commit f050d70
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 9 deletions.
11 changes: 10 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ pq_proto = { version = "0.1", path = "./libs/pq_proto/" }
remote_storage = { version = "0.1", path = "./libs/remote_storage/" }
safekeeper_api = { version = "0.1", path = "./libs/safekeeper_api" }
storage_broker = { version = "0.1", path = "./storage_broker/" } # Note: main broker code is inside the binary crate, so linking with the library shouldn't be heavy.
tracing-postgres = { version = "0.1", path = "./libs/tracing-postgres/" }
tenant_size_model = { version = "0.1", path = "./libs/tenant_size_model/" }
utils = { version = "0.1", path = "./libs/utils/" }

Expand Down
2 changes: 1 addition & 1 deletion compute_tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ clap.workspace = true
futures.workspace = true
hyper = { workspace = true, features = ["full"] }
notify.workspace = true
postgres.workspace = true
regex.workspace = true
serde.workspace = true
serde_json.workspace = true
Expand All @@ -20,6 +19,7 @@ tokio = { workspace = true, features = ["rt", "rt-multi-thread"] }
tokio-postgres.workspace = true
tracing.workspace = true
tracing-subscriber.workspace = true
tracing-postgres.workspace = true
url.workspace = true

workspace_hack.workspace = true
5 changes: 3 additions & 2 deletions compute_tools/src/checker.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{anyhow, Result};
use postgres::Client;
use tokio_postgres::NoTls;
use tracing::{error, instrument};
use tracing_postgres::{Client, NoTls};

use crate::compute::ComputeNode;

Expand All @@ -24,6 +23,8 @@ pub fn create_writability_check_data(client: &mut Client) -> Result<()> {

#[instrument(skip_all)]
pub async fn check_writability(compute: &ComputeNode) -> Result<()> {
// XXX: There is no tracing wrapper around tokio_postgres. But we have
// a span for the whole function, that's good enough for now.
let (client, connection) = tokio_postgres::connect(compute.connstr.as_str(), NoTls).await?;
if client.is_closed() {
return Err(anyhow!("connection to postgres closed"));
Expand Down
2 changes: 1 addition & 1 deletion compute_tools/src/compute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use std::sync::RwLock;

use anyhow::{Context, Result};
use chrono::{DateTime, Utc};
use postgres::{Client, NoTls};
use serde::{Serialize, Serializer};
use tracing::{info, instrument, warn};
use tracing_postgres::{Client, NoTls};

use crate::checker::create_writability_check_data;
use crate::config;
Expand Down
2 changes: 1 addition & 1 deletion compute_tools/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::{thread, time};

use anyhow::Result;
use chrono::{DateTime, Utc};
use postgres::{Client, NoTls};
use tracing::{debug, info};
use tracing_postgres::{Client, NoTls};

use crate::compute::ComputeNode;

Expand Down
2 changes: 1 addition & 1 deletion compute_tools/src/pg_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use std::time::{Duration, Instant};

use anyhow::{bail, Result};
use notify::{RecursiveMode, Watcher};
use postgres::{Client, Transaction};
use serde::Deserialize;
use tracing::{debug, instrument};
use tracing_postgres::{Client, Transaction};

const POSTGRES_WAIT_TIMEOUT: Duration = Duration::from_millis(60 * 1000); // milliseconds

Expand Down
3 changes: 1 addition & 2 deletions compute_tools/src/spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@ use std::path::Path;
use std::str::FromStr;

use anyhow::Result;
use postgres::config::Config;
use postgres::{Client, NoTls};
use serde::Deserialize;
use tracing::{info, info_span, instrument, span_enabled, warn, Level};
use tracing_postgres::{Client, Config, NoTls};

use crate::compute::ComputeNode;
use crate::config;
Expand Down
10 changes: 10 additions & 0 deletions libs/tracing-postgres/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "tracing-postgres"
version = "0.1.0"
edition.workspace = true
license.workspace = true

[dependencies]
postgres.workspace = true
tracing.workspace = true
workspace_hack = { version = "0.1", path = "../../workspace_hack" }
Loading

0 comments on commit f050d70

Please sign in to comment.