diff --git a/.swift-version b/.swift-version index bf77d54..819e07a 100644 --- a/.swift-version +++ b/.swift-version @@ -1 +1 @@ -4.2 +5.0 diff --git a/.travis.yml b/.travis.yml index 85054a8..b022d4d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,14 +24,14 @@ matrix: - os: linux dist: trusty sudo: required - env: SWIFT_SNAPSHOT=4.1.3 KITURA_NIO=1 + env: SWIFT_SNAPSHOT=4.2.4 - os: linux dist: trusty sudo: required - os: linux dist: trusty sudo: required - env: KITURA_NIO=1 + env: SWIFT_SNAPSHOT=4.2.4 KITURA_NIO=1 - os: osx osx_image: xcode9.2 sudo: required @@ -41,19 +41,18 @@ matrix: sudo: required env: SWIFT_SNAPSHOT=4.1.2 - os: osx - osx_image: xcode9.4 + osx_image: xcode10.1 sudo: required - env: SWIFT_SNAPSHOT=4.1.2 KITURA_NIO=1 + env: SWIFT_SNAPSHOT=4.2.1 - os: osx - osx_image: xcode10 + osx_image: xcode10.2 sudo: required - os: osx - osx_image: xcode10 + osx_image: xcode10.1 sudo: required - env: KITURA_NIO=1 + env: SWIFT_SNAPSHOT=4.2.1 KITURA_NIO=1 BREW_INSTALL_PACKAGES="libressl" before_install: - - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then brew update && brew install libressl ; fi - git clone https://github.com/IBM-Swift/Package-Builder.git script: diff --git a/Package.swift b/Package.swift index 0322050..4985488 100644 --- a/Package.swift +++ b/Package.swift @@ -1,6 +1,6 @@ -// swift-tools-version:4.2 +// swift-tools-version:5.0 /** -* Copyright IBM Corporation 2017 +* Copyright IBM Corporation 2017-2019 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,7 +21,7 @@ import Foundation var webSocketPackage: Package.Dependency if ProcessInfo.processInfo.environment["KITURA_NIO"] != nil { - webSocketPackage = .package(url: "https://github.com/IBM-Swift/Kitura-WebSocket-NIO.git", from: "1.0.0") + webSocketPackage = .package(url: "https://github.com/IBM-Swift/Kitura-WebSocket-NIO.git", from: "2.0.0") } else { webSocketPackage = .package(url: "https://github.com/IBM-Swift/Kitura-WebSocket.git", from: "2.0.0") } diff --git a/Package@swift-4.2.swift b/Package@swift-4.2.swift new file mode 100644 index 0000000..e6d9ca9 --- /dev/null +++ b/Package@swift-4.2.swift @@ -0,0 +1,67 @@ +// swift-tools-version:4.2 +/** +* Copyright IBM Corporation 2017-2019 +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ + +import PackageDescription +import Foundation + +var webSocketPackage: Package.Dependency + +if ProcessInfo.processInfo.environment["KITURA_NIO"] != nil { + webSocketPackage = .package(url: "https://github.com/IBM-Swift/Kitura-WebSocket-NIO.git", from: "1.0.0") +} else { + webSocketPackage = .package(url: "https://github.com/IBM-Swift/Kitura-WebSocket.git", from: "2.0.0") +} + +let package = Package( + name: "SwiftMetrics", + products: [ + .library( + name: "SwiftMetrics", + targets: ["SwiftMetrics", + "SwiftMetricsKitura", + "SwiftBAMDC", + "SwiftMetricsBluemix", + "SwiftMetricsDash", + "SwiftMetricsREST", + "SwiftMetricsPrometheus"]), + + .executable(name: "SwiftMetricsEmitSample", targets: ["SwiftMetricsEmitSample"]), + .executable(name: "SwiftMetricsCommonSample", targets: ["SwiftMetricsCommonSample"]), + ], + dependencies: [ + .package(url: "https://github.com/IBM-Swift/Kitura.git", from: "2.3.0"), + webSocketPackage, + .package(url: "https://github.com/IBM-Swift/Swift-cfenv.git", from: "6.0.0"), + .package(url: "https://github.com/RuntimeTools/omr-agentcore", .exact("3.2.4-swift4")), + .package(url: "https://github.com/IBM-Swift/BlueCryptor", from: "1.0.0") + ], + targets: [ + .target(name: "SwiftMetrics", dependencies: ["agentcore", "hcapiplugin", "envplugin", "cpuplugin", "memplugin", "CloudFoundryEnv"]), + .target(name: "SwiftMetricsKitura", dependencies: ["SwiftMetrics", "Kitura"]), + .target(name: "SwiftBAMDC", dependencies: ["SwiftMetricsKitura", "Kitura-WebSocket", "Cryptor"]), + .target(name: "SwiftMetricsBluemix", dependencies: ["SwiftMetricsKitura","SwiftBAMDC"]), + .target(name: "SwiftMetricsDash", dependencies: ["SwiftMetricsBluemix"]), + .target(name: "SwiftMetricsREST", dependencies: ["SwiftMetricsKitura"]), + .target(name: "SwiftMetricsPrometheus", dependencies:["SwiftMetricsKitura"]), + .target(name: "SwiftMetricsCommonSample", dependencies: ["SwiftMetrics"], + path: "commonSample/Sources"), + .target(name: "SwiftMetricsEmitSample", dependencies: ["SwiftMetrics"], + path: "emitSample/Sources"), + .testTarget(name: "CoreSwiftMetricsTests", dependencies: ["SwiftMetrics"]), + .testTarget(name: "SwiftMetricsRESTTests", dependencies: ["SwiftMetricsREST"]) + ] +) diff --git a/Sources/SwiftMetrics/SwiftMonitor.swift b/Sources/SwiftMetrics/SwiftMonitor.swift index 9538099..4f44c05 100644 --- a/Sources/SwiftMetrics/SwiftMonitor.swift +++ b/Sources/SwiftMetrics/SwiftMonitor.swift @@ -189,7 +189,12 @@ public class SwiftMonitor { let values = message.components(separatedBy: "\n") var env: [ String : String ] = [:] for value in values { - if value.contains("="), let firstEquals = value.index(of: "=") { +#if swift(>=4.2) + let firstIndex = value.firstIndex(of: "=") +#else + let firstIndex = value.index(of: "=") +#endif + if value.contains("="), let firstEquals = firstIndex { env[String(value[..=4.2) + let firstIndex = temp_httpUrlReports.data.firstIndex(where: { $0.url == http.url && $0.method == http.requestMethod}) +#else + let firstIndex = temp_httpUrlReports.data.index(where: { $0.url == http.url && $0.method == http.requestMethod}) +#endif + if let index = firstIndex { temp_httpUrlReports.data[index].hits += 1 if (http.duration > temp_httpUrlReports.data[index].longestResponseTime ) { temp_httpUrlReports.data[index].longestResponseTime = http.duration diff --git a/Tests/SwiftMetricsRESTTests/SwiftMetricsRESTTests.swift b/Tests/SwiftMetricsRESTTests/SwiftMetricsRESTTests.swift index ea8b801..481eec5 100644 --- a/Tests/SwiftMetricsRESTTests/SwiftMetricsRESTTests.swift +++ b/Tests/SwiftMetricsRESTTests/SwiftMetricsRESTTests.swift @@ -610,7 +610,12 @@ class SwiftMetricsRESTTests: XCTestCase { for tSMRMPCCcollectionUriString in tSMRMPCCresult2.collectionUris { let tSMRMPCCsplitCollectionUriString = tSMRMPCCcollectionUriString.split(separator: "/") let tSMRMPCCcollectionUriIDString = String(tSMRMPCCsplitCollectionUriString[tSMRMPCCsplitCollectionUriString.count - 1]) - guard let index = idArray.index(of: tSMRMPCCcollectionUriIDString) else { +#if swift(>=4.2) + let firstIndex = idArray.firstIndex(of: tSMRMPCCcollectionUriIDString) +#else + let firstIndex = idArray.index(of: tSMRMPCCcollectionUriIDString) +#endif + guard let index = firstIndex else { print("\(tSMRMPCCresult2)") XCTFail("Collection ID \(tSMRMPCCcollectionUriIDString) not in expected range [0-2]") return