Skip to content

Commit

Permalink
feat: Add fetch_metrics() for HTTP connection managers
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven Yuan committed Jul 1, 2024
1 parent 9d6d175 commit b2e12ba
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Source/AwsCommonRuntimeKit/http/HTTP2StreamManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,21 @@ public class HTTP2StreamManager {
})
}

/// Fetch the current manager metrics from connection manager.
public func fetchMetrics() throws -> HTTPClientConnectionManagerMetrics {
do {
var cManagerMetrics = aws_http_manager_metrics()
aws_http2_stream_manager_fetch_metrics(rawValue, &cManagerMetrics)
return HTTPClientConnectionManagerMetrics(
availableConcurrency: cManagerMetrics.available_concurrency,
pendingConcurrencyAcquires: cManagerMetrics.pending_concurrency_acquires,
leasedConcurrency: cManagerMetrics.leased_concurrency
)
} catch {
throw CommonRunTimeError.crtError(.makeFromLastError())
}
}

deinit {
aws_http2_stream_manager_release(rawValue)
}
Expand Down
15 changes: 15 additions & 0 deletions Source/AwsCommonRuntimeKit/http/HTTPClientConnectionManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ public class HTTPClientConnectionManager {
}
}

/// Fetch the current manager metrics from connection manager.
public func fetchMetrics() throws -> HTTPClientConnectionManagerMetrics {
do {
var cManagerMetrics = aws_http_manager_metrics()
aws_http_connection_manager_fetch_metrics(rawValue, &cManagerMetrics)
return HTTPClientConnectionManagerMetrics(
availableConcurrency: cManagerMetrics.available_concurrency,
pendingConcurrencyAcquires: cManagerMetrics.pending_concurrency_acquires,
leasedConcurrency: cManagerMetrics.leased_concurrency
)
} catch {
throw CommonRunTimeError.crtError(.makeFromLastError())
}
}

deinit {
aws_http_connection_manager_release(rawValue)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0.

public struct HTTPClientConnectionManagerMetrics {
/// The number of additional concurrent requests that can be supported by the HTTP manager without needing to
/// establish additional connections to the target server.
///
/// For connection manager, it equals to connections that's idle.
/// For stream manager, it equals to the number of streams that are possible to be made without creating new
/// connection, although the implementation can create new connection without fully filling it.
public var availableConcurrency: Int
/// The number of requests that are awaiting concurrency to be made available from the HTTP manager.
public var pendingConcurrencyAcquires: Int
/// The number of connections (http/1.1) or streams (for h2 via. stream manager) currently vended to user.
public var leasedConcurrency: Int

public init(
availableConcurrency: Int = 0,
pendingConcurrencyAcquires: Int = 0,
leasedConcurrency: Int = 0
) {
self.availableConcurrency = availableConcurrency
self.pendingConcurrencyAcquires = pendingConcurrencyAcquires
self.leasedConcurrency = leasedConcurrency
}
}

0 comments on commit b2e12ba

Please sign in to comment.