Update clairvoyant

This commit is contained in:
Christoph Hagen
2023-09-07 14:13:28 +02:00
parent e77efe795c
commit 04248b04af
3 changed files with 17 additions and 17 deletions

View File

@ -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)
}
}

View File

@ -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)
}