Skip to content

Commit a39d71d

Browse files
authored
Wire up CassMetrics (#7)
* Wire up CassMetrics * NIOLock not found in older versions of swift-nio
1 parent 252d297 commit a39d71d

File tree

4 files changed

+84
-3
lines changed

4 files changed

+84
-3
lines changed

Sources/CassandraClient/CassandraClient.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,10 @@ public class CassandraClient: CassandraSession {
160160
}
161161
}
162162

163+
public func getMetrics() -> CassandraMetrics {
164+
self.defaultSession.getMetrics()
165+
}
166+
163167
/// A `EventLoopGroupProvider` defines how the underlying `EventLoopGroup` used to create the `EventLoop` is provided.
164168
///
165169
/// When `shared`, the `EventLoopGroup` is provided externally and its lifecycle will be managed by the caller.

Sources/CassandraClient/Metrics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
@_implementationOnly import CDataStaxDriver
1616

1717
/// ``CassandraClient`` metrics.
18-
public struct CassMetrics: Codable {
18+
public struct CassandraMetrics: Codable {
1919
// MARK: - Requests
2020

2121
/// Minimum in microseconds
@@ -25,7 +25,7 @@ public struct CassMetrics: Codable {
2525
/// Mean in microseconds
2626
public let requestsMean: UInt
2727
/// Standard deviation in microseconds
28-
public let requestsStddev: UInt
28+
public let requestsStdDev: UInt
2929
/// Median in microseconds
3030
public let requestsMedian: UInt
3131
/// 75th percentile in microseconds
@@ -71,7 +71,7 @@ public struct CassMetrics: Codable {
7171
self.requestsMin = UInt(metrics.requests.min)
7272
self.requestsMax = UInt(metrics.requests.max)
7373
self.requestsMean = UInt(metrics.requests.mean)
74-
self.requestsStddev = UInt(metrics.requests.stddev)
74+
self.requestsStdDev = UInt(metrics.requests.stddev)
7575
self.requestsMedian = UInt(metrics.requests.median)
7676
self.requestsPercentile75th = UInt(metrics.requests.percentile_75th)
7777
self.requestsPercentile95th = UInt(metrics.requests.percentile_95th)

Sources/CassandraClient/Session.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ public protocol CassandraSession {
7777

7878
/// Terminate the session and free resources.
7979
func shutdown() throws
80+
81+
/// Get metrics for this session.
82+
func getMetrics() -> CassandraMetrics
8083
}
8184

8285
internal extension CassandraSession {
@@ -340,6 +343,12 @@ internal extension CassandraClient {
340343
}
341344
}
342345

346+
func getMetrics() -> CassandraMetrics {
347+
var metrics = CDataStaxDriver.CassMetrics()
348+
cass_session_get_metrics(self.rawPointer, &metrics)
349+
return CassandraMetrics(metrics: metrics)
350+
}
351+
343352
#if compiler(>=5.5) && canImport(_Concurrency)
344353
private struct ConnectionTask {
345354
private let _task: Any

docker/docker-compose-dev.yaml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# this file is not designed to be run directly
2+
# instead, use the docker-compose.<os>.<swift> files
3+
# eg docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.2004.56.yaml run test
4+
version: "3"
5+
6+
services:
7+
cassandra:
8+
image: cassandra:3.11
9+
environment:
10+
CASSANDRA_CQL_PORT: 9042
11+
CASSANDRA_USER: cassandra
12+
CASSANDRA_PASSWORD: cassandra
13+
CASSANDRA_KEYSPACE: cassandra
14+
ports:
15+
- 9042:9043
16+
17+
runtime-setup:
18+
image: swift-cassandra-client:default
19+
build:
20+
context: .
21+
dockerfile: Dockerfile
22+
23+
common: &common
24+
image: swift-cassandra-client:default
25+
depends_on: [runtime-setup]
26+
volumes:
27+
- ~/.ssh:/root/.ssh
28+
- ..:/code:z
29+
working_dir: /code
30+
cap_drop:
31+
- CAP_NET_RAW
32+
- CAP_NET_BIND_SERVICE
33+
34+
soundness:
35+
<<: *common
36+
command: /bin/bash -xcl "./scripts/soundness.sh"
37+
38+
build:
39+
<<: *common
40+
environment: []
41+
command: /bin/bash -cl "swift build"
42+
43+
test:
44+
<<: *common
45+
depends_on: [cassandra, runtime-setup]
46+
environment:
47+
CASSANDRA_HOST: cassandra
48+
CASSANDRA_CQL_PORT: 9042
49+
CASSANDRA_USER: cassandra
50+
CASSANDRA_PASSWORD: cassandra
51+
CASSANDRA_KEYSPACE: cassandra
52+
command: >
53+
/bin/bash -xcl "
54+
swift build --build-tests $${SANITIZER_ARG-} && \
55+
56+
while ! nc -z cassandra 9042; do
57+
echo Waiting for Cassandra...;
58+
sleep 3;
59+
done;
60+
61+
swift test $${SANITIZER_ARG-}
62+
"
63+
64+
# util
65+
66+
shell:
67+
<<: *common
68+
entrypoint: /bin/bash

0 commit comments

Comments
 (0)