chore: log gateway env timings
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import ClawdisIPC
|
import ClawdisIPC
|
||||||
import Foundation
|
import Foundation
|
||||||
|
import OSLog
|
||||||
|
|
||||||
// Lightweight SemVer helper (major.minor.patch only) for gateway compatibility checks.
|
// Lightweight SemVer helper (major.minor.patch only) for gateway compatibility checks.
|
||||||
struct Semver: Comparable, CustomStringConvertible, Sendable {
|
struct Semver: Comparable, CustomStringConvertible, Sendable {
|
||||||
@@ -61,6 +62,8 @@ struct GatewayCommandResolution {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum GatewayEnvironment {
|
enum GatewayEnvironment {
|
||||||
|
private static let logger = Logger(subsystem: "com.steipete.clawdis", category: "gateway.env")
|
||||||
|
|
||||||
static func gatewayPort() -> Int {
|
static func gatewayPort() -> Int {
|
||||||
let stored = UserDefaults.standard.integer(forKey: "gatewayPort")
|
let stored = UserDefaults.standard.integer(forKey: "gatewayPort")
|
||||||
return stored > 0 ? stored : 18789
|
return stored > 0 ? stored : 18789
|
||||||
@@ -77,6 +80,15 @@ enum GatewayEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func check() -> GatewayEnvironmentStatus {
|
static func check() -> GatewayEnvironmentStatus {
|
||||||
|
let start = Date()
|
||||||
|
defer {
|
||||||
|
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||||
|
if elapsedMs > 500 {
|
||||||
|
self.logger.warning("gateway env check slow (\(elapsedMs, privacy: .public)ms)")
|
||||||
|
} else {
|
||||||
|
self.logger.debug("gateway env check ok (\(elapsedMs, privacy: .public)ms)")
|
||||||
|
}
|
||||||
|
}
|
||||||
let expected = self.expectedGatewayVersion()
|
let expected = self.expectedGatewayVersion()
|
||||||
let projectRoot = CommandResolver.projectRoot()
|
let projectRoot = CommandResolver.projectRoot()
|
||||||
let projectEntrypoint = CommandResolver.gatewayEntrypoint(in: projectRoot)
|
let projectEntrypoint = CommandResolver.gatewayEntrypoint(in: projectRoot)
|
||||||
@@ -135,6 +147,15 @@ enum GatewayEnvironment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func resolveGatewayCommand() -> GatewayCommandResolution {
|
static func resolveGatewayCommand() -> GatewayCommandResolution {
|
||||||
|
let start = Date()
|
||||||
|
defer {
|
||||||
|
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||||
|
if elapsedMs > 500 {
|
||||||
|
self.logger.warning("gateway command resolve slow (\(elapsedMs, privacy: .public)ms)")
|
||||||
|
} else {
|
||||||
|
self.logger.debug("gateway command resolve ok (\(elapsedMs, privacy: .public)ms)")
|
||||||
|
}
|
||||||
|
}
|
||||||
let projectRoot = CommandResolver.projectRoot()
|
let projectRoot = CommandResolver.projectRoot()
|
||||||
let projectEntrypoint = CommandResolver.gatewayEntrypoint(in: projectRoot)
|
let projectEntrypoint = CommandResolver.gatewayEntrypoint(in: projectRoot)
|
||||||
let status = self.check()
|
let status = self.check()
|
||||||
@@ -191,6 +212,7 @@ enum GatewayEnvironment {
|
|||||||
// MARK: - Internals
|
// MARK: - Internals
|
||||||
|
|
||||||
private static func readGatewayVersion(binary: String) -> Semver? {
|
private static func readGatewayVersion(binary: String) -> Semver? {
|
||||||
|
let start = Date()
|
||||||
let process = Process()
|
let process = Process()
|
||||||
process.executableURL = URL(fileURLWithPath: binary)
|
process.executableURL = URL(fileURLWithPath: binary)
|
||||||
process.arguments = ["--version"]
|
process.arguments = ["--version"]
|
||||||
@@ -202,10 +224,21 @@ enum GatewayEnvironment {
|
|||||||
do {
|
do {
|
||||||
try process.run()
|
try process.run()
|
||||||
process.waitUntilExit()
|
process.waitUntilExit()
|
||||||
|
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||||
|
if elapsedMs > 500 {
|
||||||
|
self.logger.warning(
|
||||||
|
"gateway --version slow (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public)")
|
||||||
|
} else {
|
||||||
|
self.logger.debug(
|
||||||
|
"gateway --version ok (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public)")
|
||||||
|
}
|
||||||
let data = pipe.fileHandleForReading.readToEndSafely()
|
let data = pipe.fileHandleForReading.readToEndSafely()
|
||||||
let raw = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
let raw = String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
return Semver.parse(raw)
|
return Semver.parse(raw)
|
||||||
} catch {
|
} catch {
|
||||||
|
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||||
|
self.logger.error(
|
||||||
|
"gateway --version failed (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public) err=\(error.localizedDescription, privacy: .public)")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
import OSLog
|
||||||
|
|
||||||
enum RuntimeKind: String {
|
enum RuntimeKind: String {
|
||||||
case node
|
case node
|
||||||
@@ -50,6 +51,7 @@ enum RuntimeResolutionError: Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
enum RuntimeLocator {
|
enum RuntimeLocator {
|
||||||
|
private static let logger = Logger(subsystem: "com.steipete.clawdis", category: "runtime")
|
||||||
private static let minNode = RuntimeVersion(major: 22, minor: 0, patch: 0)
|
private static let minNode = RuntimeVersion(major: 22, minor: 0, patch: 0)
|
||||||
|
|
||||||
static func resolve(
|
static func resolve(
|
||||||
@@ -120,6 +122,7 @@ enum RuntimeLocator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static func readVersion(of binary: String, pathEnv: String) -> String? {
|
private static func readVersion(of binary: String, pathEnv: String) -> String? {
|
||||||
|
let start = Date()
|
||||||
let process = Process()
|
let process = Process()
|
||||||
process.executableURL = URL(fileURLWithPath: binary)
|
process.executableURL = URL(fileURLWithPath: binary)
|
||||||
process.arguments = ["--version"]
|
process.arguments = ["--version"]
|
||||||
@@ -132,9 +135,20 @@ enum RuntimeLocator {
|
|||||||
do {
|
do {
|
||||||
try process.run()
|
try process.run()
|
||||||
process.waitUntilExit()
|
process.waitUntilExit()
|
||||||
|
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||||
|
if elapsedMs > 500 {
|
||||||
|
self.logger.warning(
|
||||||
|
"runtime --version slow (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public)")
|
||||||
|
} else {
|
||||||
|
self.logger.debug(
|
||||||
|
"runtime --version ok (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public)")
|
||||||
|
}
|
||||||
let data = pipe.fileHandleForReading.readToEndSafely()
|
let data = pipe.fileHandleForReading.readToEndSafely()
|
||||||
return String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
return String(data: data, encoding: .utf8)?.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||||
} catch {
|
} catch {
|
||||||
|
let elapsedMs = Int(Date().timeIntervalSince(start) * 1000)
|
||||||
|
self.logger.error(
|
||||||
|
"runtime --version failed (\(elapsedMs, privacy: .public)ms) bin=\(binary, privacy: .public) err=\(error.localizedDescription, privacy: .public)")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user