-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tracing): add query tracing for the session in the `executeWithT…
…racing` method (#43) closes #42 Signed-off-by: Daniel Boll <[email protected]>
- Loading branch information
1 parent
a5d1252
commit 08ce2e2
Showing
8 changed files
with
237 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Cluster } from "../index.js"; | ||
|
||
const nodes = process.env.CLUSTER_NODES?.split(",") ?? ["127.0.0.1:9042"]; | ||
|
||
console.log(`Connecting to ${nodes}`); | ||
|
||
const cluster = new Cluster({ nodes }); | ||
const session = await cluster.connect(); | ||
|
||
const { tracing } = await session.executeWithTracing( | ||
"SELECT * FROM system_schema.scylla_tables", | ||
[], | ||
// { | ||
// prepare: true, | ||
// }, | ||
); | ||
|
||
console.log(tracing); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[toolchain] | ||
channel = "nightly" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod tracing; | ||
pub mod uuid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use std::{collections::HashMap, net::IpAddr}; | ||
|
||
use serde::Serialize; | ||
|
||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct CqlTimestampWrapper(pub scylla::frame::value::CqlTimestamp); | ||
#[derive(Debug, Clone, PartialEq, Eq)] | ||
pub struct CqlTimeuuidWrapper(pub scylla::frame::value::CqlTimeuuid); | ||
|
||
impl Serialize for CqlTimestampWrapper { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
serializer.serialize_i64(self.0.0) | ||
} | ||
} | ||
|
||
impl Serialize for CqlTimeuuidWrapper { | ||
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> | ||
where | ||
S: serde::Serializer, | ||
{ | ||
serializer.serialize_str(format!("{}", self.0).as_str()) | ||
} | ||
} | ||
|
||
/// Tracing info retrieved from `system_traces.sessions` | ||
/// with all events from `system_traces.events` | ||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)] | ||
pub struct TracingInfo { | ||
pub client: Option<IpAddr>, | ||
pub command: Option<String>, | ||
pub coordinator: Option<IpAddr>, | ||
pub duration: Option<i32>, | ||
pub parameters: Option<HashMap<String, String>>, | ||
pub request: Option<String>, | ||
/// started_at is a timestamp - time since unix epoch | ||
pub started_at: Option<CqlTimestampWrapper>, | ||
|
||
pub events: Vec<TracingEvent>, | ||
} | ||
|
||
/// A single event happening during a traced query | ||
#[derive(Debug, Clone, PartialEq, Eq, Serialize)] | ||
pub struct TracingEvent { | ||
pub event_id: CqlTimeuuidWrapper, | ||
pub activity: Option<String>, | ||
pub source: Option<IpAddr>, | ||
pub source_elapsed: Option<i32>, | ||
pub thread: Option<String>, | ||
} | ||
|
||
impl From<scylla::tracing::TracingInfo> for TracingInfo { | ||
fn from(info: scylla::tracing::TracingInfo) -> Self { | ||
Self { | ||
client: info.client, | ||
command: info.command, | ||
coordinator: info.coordinator, | ||
duration: info.duration, | ||
parameters: info.parameters, | ||
request: info.request, | ||
started_at: info.started_at.map(CqlTimestampWrapper), | ||
events: info.events.into_iter().map(TracingEvent::from).collect(), | ||
} | ||
} | ||
} | ||
|
||
impl From<scylla::tracing::TracingEvent> for TracingEvent { | ||
fn from(event: scylla::tracing::TracingEvent) -> Self { | ||
Self { | ||
event_id: CqlTimeuuidWrapper(event.event_id), | ||
activity: event.activity, | ||
source: event.source, | ||
source_elapsed: event.source_elapsed, | ||
thread: event.thread, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters