Update clairvoyant
This commit is contained in:
parent
e77efe795c
commit
04248b04af
@ -8,7 +8,9 @@ let package = Package(
|
||||
],
|
||||
dependencies: [
|
||||
.package(url: "https://github.com/vapor/vapor.git", from: "4.0.0"),
|
||||
.package(url: "https://github.com/christophhagen/clairvoyant.git", from: "0.5.0"),
|
||||
.package(url: "https://github.com/christophhagen/Clairvoyant", from: "0.9.0"),
|
||||
.package(url: "https://github.com/christophhagen/ClairvoyantVapor", from: "0.2.0"),
|
||||
.package(url: "https://github.com/christophhagen/ClairvoyantBinaryCodable", from: "0.3.1"),
|
||||
],
|
||||
targets: [
|
||||
.target(
|
||||
@ -16,7 +18,8 @@ let package = Package(
|
||||
dependencies: [
|
||||
.product(name: "Vapor", package: "vapor"),
|
||||
.product(name: "Clairvoyant", package: "Clairvoyant"),
|
||||
|
||||
.product(name: "ClairvoyantVapor", package: "ClairvoyantVapor"),
|
||||
.product(name: "ClairvoyantBinaryCodable", package: "ClairvoyantBinaryCodable"),
|
||||
],
|
||||
swiftSettings: [
|
||||
// Enable better optimizations when building in Release configuration. Despite the use of
|
||||
|
@ -56,7 +56,7 @@ final class DeviceManager {
|
||||
private func updateMessageCountMetric() {
|
||||
Task {
|
||||
let lastValue = await messagesToDeviceMetric.lastValue()?.value ?? 0
|
||||
try? await messagesToDeviceMetric.update(lastValue + 1)
|
||||
_ = try? await messagesToDeviceMetric.update(lastValue + 1)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,12 @@
|
||||
import Vapor
|
||||
import Clairvoyant
|
||||
import ClairvoyantVapor
|
||||
import ClairvoyantBinaryCodable
|
||||
|
||||
var deviceManager: DeviceManager!
|
||||
|
||||
private var provider: VaporMetricProvider!
|
||||
|
||||
enum ServerError: Error {
|
||||
case invalidAuthenticationFileContent
|
||||
case invalidAuthenticationToken
|
||||
@ -20,23 +24,15 @@ public func configure(_ app: Application) async throws {
|
||||
let storageFolder = URL(fileURLWithPath: app.directory.resourcesDirectory)
|
||||
let logFolder = storageFolder.appendingPathComponent("logs")
|
||||
|
||||
let accessManager = AccessTokenManager([])
|
||||
let monitor = await MetricObserver(
|
||||
logFolder: logFolder,
|
||||
accessManager: accessManager,
|
||||
logMetricId: "sesame.log")
|
||||
let monitor = MetricObserver(logFileFolder: logFolder, logMetricId: "sesame.log")
|
||||
MetricObserver.standard = monitor
|
||||
|
||||
let status = try await Metric<ServerStatus>("sesame.status")
|
||||
try await status.update(.initializing)
|
||||
|
||||
await monitor.registerRoutes(app)
|
||||
_ = try await status.update(.initializing)
|
||||
|
||||
let configUrl = storageFolder.appendingPathComponent("config.json")
|
||||
let config = try Config(loadFrom: configUrl)
|
||||
|
||||
config.authenticationTokens.map { $0.data(using: .utf8)! }.forEach(accessManager.add)
|
||||
|
||||
app.http.server.configuration.port = config.port
|
||||
|
||||
let keyFile = storageFolder.appendingPathComponent(config.keyFileName)
|
||||
@ -48,6 +44,9 @@ public func configure(_ app: Application) async throws {
|
||||
deviceTimeout: config.deviceTimeout)
|
||||
|
||||
try routes(app)
|
||||
|
||||
provider = .init(observer: monitor, accessManager: config.authenticationTokens)
|
||||
provider.registerRoutes(app)
|
||||
|
||||
// Gracefully shut down by closing potentially open socket
|
||||
DispatchQueue.global(qos: .utility).asyncAfter(deadline: .now() + .seconds(5)) {
|
||||
@ -56,7 +55,7 @@ public func configure(_ app: Application) async throws {
|
||||
}
|
||||
}
|
||||
|
||||
try await status.update(.nominal)
|
||||
_ = try await status.update(.nominal)
|
||||
print("[\(dateFormatter.string(from: Date()))] Server started")
|
||||
}
|
||||
|
||||
@ -85,7 +84,5 @@ func log(_ message: String) {
|
||||
print(message)
|
||||
return
|
||||
}
|
||||
Task {
|
||||
await observer.log(message)
|
||||
}
|
||||
observer.log(message)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user