Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 39 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ let package = Package(
.library(name: "SmithyCBOR", targets: ["SmithyCBOR"]),
.library(name: "SmithyWaitersAPI", targets: ["SmithyWaitersAPI"]),
.library(name: "SmithyTestUtil", targets: ["SmithyTestUtil"]),
.library(name: "SmithySwiftNIO", targets: ["SmithySwiftNIO"]),
.library(name: "SmithyTelemetryAPI", targets: ["SmithyTelemetryAPI"]),
.library(name: "SmithyHTTPClientAPI", targets: ["SmithyHTTPClientAPI"]),
],
dependencies: {
var dependencies: [Package.Dependency] = [
.package(url: "https://github.com/awslabs/aws-crt-swift.git", exact: "0.54.2"),
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
.package(url: "https://github.com/open-telemetry/opentelemetry-swift", from: "1.13.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", from: "1.26.0"),
.package(url: "https://github.com/swift-server/async-http-client.git", exact: "1.22.0"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just noting that this needs to be switched to from: for release...
IIRC this is exact for testing the minimum supported version?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yup exactly, will switch it to from since we can see it passed all integration tests

]

let isDocCEnabled = ProcessInfo.processInfo.environment["AWS_SWIFT_SDK_ENABLE_DOCC"] != nil
Expand All @@ -75,10 +78,27 @@ let package = Package(
.product(name: "Logging", package: "swift-log"),
]
),
.target(
name: "SmithyTelemetryAPI",
dependencies: [
"Smithy",
]
),
.target(
name: "SmithyHTTPClientAPI",
dependencies: [
"Smithy",
"SmithyHTTPAPI",
"SmithyTelemetryAPI",
.product(name: "AwsCommonRuntimeKit", package: "aws-crt-swift"),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This CRT dependency is not needed & should be removed.

(also, any "API" package shouldn't depend on an external implementation like CRT, per SRA)

]
),
.target(
name: "ClientRuntime",
dependencies: [
"Smithy",
"SmithyTelemetryAPI",
"SmithyHTTPClientAPI",
"SmithyRetriesAPI",
"SmithyRetries",
"SmithyXML",
Expand All @@ -98,7 +118,6 @@ let package = Package(
"SmithyChecksums",
"SmithyCBOR",
.product(name: "AwsCommonRuntimeKit", package: "aws-crt-swift"),
.product(name: "AsyncHTTPClient", package: "async-http-client"),
// Only include these on macOS, iOS, tvOS, watchOS, and macCatalyst (visionOS and Linux are excluded)
.product(
name: "InMemoryExporter",
Expand All @@ -125,6 +144,17 @@ let package = Package(
.copy("PrivacyInfo.xcprivacy")
]
),
.target(
name: "SmithySwiftNIO",
dependencies: [
"Smithy",
"SmithyHTTPAPI",
"SmithyStreams",
"SmithyHTTPClientAPI",
.product(name: "AsyncHTTPClient", package: "async-http-client"),
],
path: "Sources/SmithySwiftNIO"
),
.target(
name: "SmithyRetriesAPI"
),
Expand Down Expand Up @@ -270,6 +300,13 @@ let package = Package(
],
resources: [ .process("Resources") ]
),
.testTarget(
name: "SmithySwiftNIOTests",
dependencies: [
"SmithySwiftNIO",
"SmithyTestUtil",
]
),
.testTarget(
name: "SmithyCBORTests",
dependencies: ["SmithyCBOR", "ClientRuntime", "SmithyTestUtil"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import protocol SmithyHTTPAuthAPI.AuthSchemeResolver
import protocol SmithyHTTPAuthAPI.AuthSchemeResolverParameters
import struct SmithyRetries.DefaultRetryStrategy
import struct SmithyRetries.ExponentialBackoffStrategy
import SmithyTelemetryAPI
import protocol SmithyRetriesAPI.RetryErrorInfoProvider
import protocol SmithyRetriesAPI.RetryStrategy
import struct SmithyRetriesAPI.RetryStrategyOptions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ import protocol SmithyHTTPAPI.HTTPClient
import class SmithyHTTPAPI.HTTPRequest
import class SmithyHTTPAPI.HTTPResponse
import enum SmithyHTTPAPI.HTTPStatusCode
import class SmithyHTTPClientAPI.HttpTelemetry
import enum SmithyHTTPClientAPI.HttpMetricsAttributesKeys
import class SmithyStreams.BufferedStream
import SmithyTelemetryAPI
#if os(Linux)
import Glibc
#elseif !os(Windows)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* SPDX-License-Identifier: Apache-2.0.
*/

import class SmithyHTTPClientAPI.HttpTelemetry

struct CRTClientEngineConfig: Sendable {

/// Max connections the manager can contain per endpoint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import AwsCommonRuntimeKit
import struct Smithy.Attributes
import enum Smithy.ByteStream
import class SmithyHTTPClientAPI.HttpTelemetry
import enum SmithyHTTPClientAPI.HttpMetricsAttributesKeys

extension HTTP2Stream {
/// Returns the recommended size, in bytes, for the data to write
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,87 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import AwsCommonRuntimeKit
import struct Foundation.TimeInterval
import enum Smithy.URIScheme
import struct SmithyHTTPAPI.Headers
import SmithyHTTPClientAPI

public class HttpClientConfiguration {

/// The timeout for establishing a connection, in seconds.
///
/// If none is provided, the client will use default values based on the platform.
public var connectTimeout: TimeInterval?

/// The timeout for socket, in seconds.
/// Sets maximum time to wait between two data packets.
/// Used to close stale connections that have no activity.
///
/// Defaults to 60 seconds if no value is provided.
public var socketTimeout: TimeInterval

/// HTTP headers to be submitted with every HTTP request.
///
/// If none is provided, defaults to no extra headers.
public var defaultHeaders: Headers

/// The maximum connections the HTTP client makes per host or per endpoint depending on the OS.
///
/// For Apple platforms, it will be per host.
/// For Linux, it will be per endpoint (protocol + host + port).
public var maxConnections: Int

// add any other properties here you want to give the service operations
// control over to be mapped to the Http Client

/// The URL scheme to be used for HTTP requests. Supported values are `http` and `https`.
///
/// If none is provided, the default protocol for the operation will be used
public var protocolType: URIScheme?

/// Custom TLS configuration for HTTPS connections.
///
/// Enables specifying client certificates and trust stores for secure communication.
/// Defaults to system's TLS settings if `nil`.
public var tlsConfiguration: (any TLSConfiguration)?

/// HTTP Client Telemetry
public var telemetry: HttpTelemetry?

/// Creates a configuration object for a SDK HTTP client.
///
/// Not all configuration settings may be followed by all clients.
/// - Parameters:
/// - connectTimeout: The maximum time to wait for a connection to be established.
/// - socketTimeout: The maximum time to wait between data packets.
/// - defaultHeaders: HTTP headers to be included with every HTTP request.
/// Note that certain headers may cause your API request to fail. Defaults to no headers.
/// - protocolType: The HTTP scheme (`http` or `https`) to be used for API requests. Defaults to the operation's standard configuration.
/// - tlsConfiguration: Optional custom TLS configuration for HTTPS requests. If `nil`, defaults to a standard configuration.
/// - maxConnections: The maximum number of connections the HTTP client makes per host (for Apple platforms) or per endpoint (for Linux). For non-mac Apple platforms, defaults to 6. For macOS and Linux, defaults to 50.
public init(
connectTimeout: TimeInterval? = nil,
socketTimeout: TimeInterval = 60.0,
protocolType: URIScheme = .https,
defaultHeaders: Headers = Headers(),
tlsConfiguration: (any TLSConfiguration)? = nil,
telemetry: HttpTelemetry? = nil,
maxConnections: Int? = nil
) {
self.socketTimeout = socketTimeout
self.protocolType = protocolType
self.defaultHeaders = defaultHeaders
self.connectTimeout = connectTimeout
self.tlsConfiguration = tlsConfiguration
self.telemetry = telemetry
if let maxConnections {
self.maxConnections = maxConnections
} else {
#if os(macOS) || os(Linux)
self.maxConnections = 50
#else // iOS, ipadOS, watchOS, tvOS.
self.maxConnections = 6 // URLSession default.
#endif
}
}
}
/// Typealias for backward compatibility.
/// The actual implementation is now in SmithyHTTPClientAPI.
public typealias HttpClientConfiguration = SmithyHTTPClientAPI.HTTPClientConfiguration
12 changes: 12 additions & 0 deletions Sources/ClientRuntime/Networking/Http/TLSConfiguration.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//
// Copyright Amazon.com Inc. or its affiliates.
// All Rights Reserved.
//
// SPDX-License-Identifier: Apache-2.0
//

import SmithyHTTPClientAPI

/// Typealias for backward compatibility.
/// The actual implementation is now in SmithyHTTPClientAPI.
public typealias TLSConfiguration = SmithyHTTPClientAPI.TLSConfiguration
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import class Foundation.DispatchQueue
import class Foundation.InputStream
import class Foundation.NSObject
import class Foundation.OutputStream
import class SmithyHTTPClientAPI.HttpTelemetry
import enum SmithyHTTPClientAPI.HttpMetricsAttributesKeys
import class Foundation.RunLoop
import class Foundation.Stream
import protocol Foundation.StreamDelegate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import class Foundation.NSRecursiveLock
import var Foundation.NSURLAuthenticationMethodClientCertificate
import var Foundation.NSURLAuthenticationMethodServerTrust
import struct Foundation.TimeInterval
import class SmithyHTTPClientAPI.HttpTelemetry
import enum SmithyHTTPClientAPI.HttpMetricsAttributesKeys
import class Foundation.URLAuthenticationChallenge
import struct Foundation.URLComponents
import class Foundation.URLCredential
Expand All @@ -27,6 +29,7 @@ import class Foundation.URLResponse
import class Foundation.URLSession
import class Foundation.URLSessionConfiguration
import protocol Foundation.URLSessionDataDelegate
import SmithyTelemetryAPI
import class Foundation.URLSessionDataTask
import class Foundation.URLSessionTask
import class Foundation.URLSessionTaskMetrics
Expand Down
2 changes: 2 additions & 0 deletions Sources/ClientRuntime/Plugins/TelemetryPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import SmithyTelemetryAPI

public class TelemetryPlugin: Plugin {
private let telemetryProvider: TelemetryProvider

Expand Down
14 changes: 4 additions & 10 deletions Sources/ClientRuntime/Telemetry/Context/TelemetryContext.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

/// A Telemetry Context is a container that can be associated with Tracers and Metrics.
///
/// Context implementations may be containers for execution-scoped values across API boundaries (both in-process and
/// distributed).
public protocol TelemetryContext: Sendable {
import SmithyTelemetryAPI

/// Make this context the currently active context.
///
/// - Returns: the scope of the current context
func makeCurrent() -> TelemetryScope
}
/// Typealias for backward compatibility.
/// The actual implementation is now in SmithyTelemetryAPI.
public typealias TelemetryContext = SmithyTelemetryAPI.TelemetryContext
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

/// A Telemetry Context Manager manages the Telemetry Contexts in a client.
///
/// Implementations should be able to manage contexts in a thread-safe way.
public protocol TelemetryContextManager: Sendable {
import SmithyTelemetryAPI

/// - Returns: the current Telemetry Context
func current() -> TelemetryContext
}
/// Typealias for backward compatibility.
/// The actual implementation is now in SmithyTelemetryAPI.
public typealias TelemetryContextManager = SmithyTelemetryAPI.TelemetryContextManager
9 changes: 4 additions & 5 deletions Sources/ClientRuntime/Telemetry/Context/TelemetryScope.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

/// Delineates a Telemetry Scope that has a beginning and end, particularly for Telemetry Contexts.
public protocol TelemetryScope: Sendable {
import SmithyTelemetryAPI

/// Ends the scope.
func end()
}
/// Typealias for backward compatibility.
/// The actual implementation is now in SmithyTelemetryAPI.
public typealias TelemetryScope = SmithyTelemetryAPI.TelemetryScope
Loading
Loading