Skip to content

Commit

Permalink
Wire up CassMetrics (#7)
Browse files Browse the repository at this point in the history
* Wire up CassMetrics

* NIOLock not found in older versions of swift-nio
  • Loading branch information
yim-lee authored Nov 7, 2022
1 parent 252d297 commit a39d71d
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Sources/CassandraClient/CassandraClient.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ public class CassandraClient: CassandraSession {
}
}

public func getMetrics() -> CassandraMetrics {
self.defaultSession.getMetrics()
}

/// A `EventLoopGroupProvider` defines how the underlying `EventLoopGroup` used to create the `EventLoop` is provided.
///
/// When `shared`, the `EventLoopGroup` is provided externally and its lifecycle will be managed by the caller.
Expand Down
6 changes: 3 additions & 3 deletions Sources/CassandraClient/Metrics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
@_implementationOnly import CDataStaxDriver

/// ``CassandraClient`` metrics.
public struct CassMetrics: Codable {
public struct CassandraMetrics: Codable {
// MARK: - Requests

/// Minimum in microseconds
Expand All @@ -25,7 +25,7 @@ public struct CassMetrics: Codable {
/// Mean in microseconds
public let requestsMean: UInt
/// Standard deviation in microseconds
public let requestsStddev: UInt
public let requestsStdDev: UInt
/// Median in microseconds
public let requestsMedian: UInt
/// 75th percentile in microseconds
Expand Down Expand Up @@ -71,7 +71,7 @@ public struct CassMetrics: Codable {
self.requestsMin = UInt(metrics.requests.min)
self.requestsMax = UInt(metrics.requests.max)
self.requestsMean = UInt(metrics.requests.mean)
self.requestsStddev = UInt(metrics.requests.stddev)
self.requestsStdDev = UInt(metrics.requests.stddev)
self.requestsMedian = UInt(metrics.requests.median)
self.requestsPercentile75th = UInt(metrics.requests.percentile_75th)
self.requestsPercentile95th = UInt(metrics.requests.percentile_95th)
Expand Down
9 changes: 9 additions & 0 deletions Sources/CassandraClient/Session.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ public protocol CassandraSession {

/// Terminate the session and free resources.
func shutdown() throws

/// Get metrics for this session.
func getMetrics() -> CassandraMetrics
}

internal extension CassandraSession {
Expand Down Expand Up @@ -340,6 +343,12 @@ internal extension CassandraClient {
}
}

func getMetrics() -> CassandraMetrics {
var metrics = CDataStaxDriver.CassMetrics()
cass_session_get_metrics(self.rawPointer, &metrics)
return CassandraMetrics(metrics: metrics)
}

#if compiler(>=5.5) && canImport(_Concurrency)
private struct ConnectionTask {
private let _task: Any
Expand Down
68 changes: 68 additions & 0 deletions docker/docker-compose-dev.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# this file is not designed to be run directly
# instead, use the docker-compose.<os>.<swift> files
# eg docker-compose -f docker/docker-compose.yaml -f docker/docker-compose.2004.56.yaml run test
version: "3"

services:
cassandra:
image: cassandra:3.11
environment:
CASSANDRA_CQL_PORT: 9042
CASSANDRA_USER: cassandra
CASSANDRA_PASSWORD: cassandra
CASSANDRA_KEYSPACE: cassandra
ports:
- 9042:9043

runtime-setup:
image: swift-cassandra-client:default
build:
context: .
dockerfile: Dockerfile

common: &common
image: swift-cassandra-client:default
depends_on: [runtime-setup]
volumes:
- ~/.ssh:/root/.ssh
- ..:/code:z
working_dir: /code
cap_drop:
- CAP_NET_RAW
- CAP_NET_BIND_SERVICE

soundness:
<<: *common
command: /bin/bash -xcl "./scripts/soundness.sh"

build:
<<: *common
environment: []
command: /bin/bash -cl "swift build"

test:
<<: *common
depends_on: [cassandra, runtime-setup]
environment:
CASSANDRA_HOST: cassandra
CASSANDRA_CQL_PORT: 9042
CASSANDRA_USER: cassandra
CASSANDRA_PASSWORD: cassandra
CASSANDRA_KEYSPACE: cassandra
command: >
/bin/bash -xcl "
swift build --build-tests $${SANITIZER_ARG-} && \
while ! nc -z cassandra 9042; do
echo Waiting for Cassandra...;
sleep 3;
done;
swift test $${SANITIZER_ARG-}
"
# util

shell:
<<: *common
entrypoint: /bin/bash

0 comments on commit a39d71d

Please sign in to comment.