From def779e20b619a4de836fd0c5ff9c337d54c11db Mon Sep 17 00:00:00 2001 From: Fedor Korotkov Date: Tue, 7 Feb 2023 11:04:45 -0500 Subject: [PATCH] Report to Sentry instead of Puppy (#402) Instead of logging locally let's report to Sentry. --- Package.resolved | 18 ------------------ Package.swift | 2 -- Sources/tart/Commands/Prune.swift | 5 ++--- Sources/tart/Root.swift | 15 --------------- Sources/tart/VMStorageOCI.swift | 19 ++++++++++++++----- 5 files changed, 16 insertions(+), 43 deletions(-) diff --git a/Package.resolved b/Package.resolved index 0496bea..6ec2cfd 100644 --- a/Package.resolved +++ b/Package.resolved @@ -18,15 +18,6 @@ "revision" : "772883073d044bc754d401cabb6574624eb3778f" } }, - { - "identity" : "puppy", - "kind" : "remoteSourceControl", - "location" : "https://github.com/sushichop/Puppy", - "state" : { - "revision" : "3e8d87f714f14244878752a6bb71ea465119f8a1", - "version" : "0.5.1" - } - }, { "identity" : "sentry-cocoa", "kind" : "remoteSourceControl", @@ -81,15 +72,6 @@ "version" : "1.0.3" } }, - { - "identity" : "swift-log", - "kind" : "remoteSourceControl", - "location" : "https://github.com/apple/swift-log.git", - "state" : { - "revision" : "6fe203dc33195667ce1759bf0182975e4653ba1c", - "version" : "1.4.4" - } - }, { "identity" : "swift-numerics", "kind" : "remoteSourceControl", diff --git a/Package.swift b/Package.swift index de9e7f4..1430f6a 100644 --- a/Package.swift +++ b/Package.swift @@ -15,7 +15,6 @@ let package = Package( .package(url: "https://github.com/apple/swift-algorithms", from: "1.0.0"), .package(url: "https://github.com/apple/swift-async-algorithms", branch: "main"), .package(url: "https://github.com/malcommac/SwiftDate", from: "6.3.1"), - .package(url: "https://github.com/sushichop/Puppy", from: "0.5.1"), .package(url: "https://github.com/antlr/antlr4", branch: "dev"), .package(url: "https://github.com/apple/swift-atomics.git", .upToNextMajor(from: "1.0.0")), .package(url: "https://github.com/nicklockwood/SwiftFormat", from: "0.50.6"), @@ -29,7 +28,6 @@ let package = Package( .product(name: "ArgumentParser", package: "swift-argument-parser"), .product(name: "Dynamic", package: "Dynamic"), .product(name: "SwiftDate", package: "SwiftDate"), - .product(name: "Puppy", package: "Puppy"), .product(name: "Antlr4Static", package: "Antlr4"), .product(name: "Atomics", package: "swift-atomics"), .product(name: "Sentry", package: "sentry-cocoa"), diff --git a/Sources/tart/Commands/Prune.swift b/Sources/tart/Commands/Prune.swift index cdcc6c5..e52ce52 100644 --- a/Sources/tart/Commands/Prune.swift +++ b/Sources/tart/Commands/Prune.swift @@ -100,10 +100,9 @@ struct Prune: AsyncParsableCommand { cacheReclaimedBytes += try prunable.sizeBytes() try prunable.delete() - puppy.info("deleting \(prunable.url)...") - } - puppy.info("reclaimed \(cacheReclaimedBytes) bytes") + try SentrySDK.span?.setExtra(value: prunable.sizeBytes(), key: prunable.url.formatted()); + } SentrySDK.span?.setMeasurement(name: "gc_disk_reclaimed", value: cacheReclaimedBytes as NSNumber, unit: MeasurementUnitInformation.byte); } diff --git a/Sources/tart/Root.swift b/Sources/tart/Root.swift index e987b6f..6e4febc 100644 --- a/Sources/tart/Root.swift +++ b/Sources/tart/Root.swift @@ -1,16 +1,7 @@ import ArgumentParser import Foundation -import Puppy import Sentry -var puppy = Puppy.default - -class LogFormatter: LogFormattable { - func formatMessage(_ level: LogLevel, message: String, tag: String, function: String, file: String, line: UInt, swiftLogInfo: [String: String], label: String, date: Date, threadID: UInt64) -> String { - "\(date) \(level) \(message)" - } -} - @main struct Root: AsyncParsableCommand { static var configuration = CommandConfiguration( @@ -80,12 +71,6 @@ struct Root: AsyncParsableCommand { // Set line-buffered output for stdout setlinebuf(stdout) - // Initialize file logger - let logFileURL = try Config().tartHomeDir.appendingPathComponent("tart.log") - let fileLogger = try FileLogger("org.cirruslabs.tart", fileURL: logFileURL) - fileLogger.format = LogFormatter() - puppy.add(fileLogger) - // Parse and run command do { var command = try parseAsRoot() diff --git a/Sources/tart/VMStorageOCI.swift b/Sources/tart/VMStorageOCI.swift index 0d89bf6..f126a9e 100644 --- a/Sources/tart/VMStorageOCI.swift +++ b/Sources/tart/VMStorageOCI.swift @@ -166,16 +166,25 @@ class VMStorageOCI: PrunableStorage { let availableCapacityBytes = max(UInt64(capacityImportant), UInt64(capacityAvailable)) if capacityImportant == 0 || capacityAvailable == 0 { - puppy.warning("important capacity \(capacityImportant) bytes, " - + "available capacity is \(capacityAvailable) bytes") + SentrySDK.capture(message: "Zero capacity") { scope in + scope.setLevel(.warning) + + scope.setContext(value: [ + "volumeAvailableCapacityForImportantUsageKey": capacityImportant, + "volumeAvailableCapacityKey": capacityAvailable, + ], key: "Attributes") + } } // There is a suspicious that occasionally capacity is returned as zero which can't be true. // Let's validate to avoid unnecessary pruning. if 0 < availableCapacityBytes && availableCapacityBytes < requiredCapacityBytes { - puppy.info("pruning cache to accommodate \(name) with a disk of size \(uncompressedDiskSize) bytes (" - + "available capacity is \(availableCapacityBytes) bytes, required capacity " - + "is \(requiredCapacityBytes) bytes)") + let transaction = SentrySDK.startTransaction(name: "Automatically Pruning Cache", operation: "prune", bindToScope: true) + transaction.setData(value: name, key: "name") + transaction.setData(value: uncompressedDiskSize, key: "uncompressedDiskSize") + transaction.setData(value: availableCapacityBytes, key: "availableCapacity") + transaction.setData(value: requiredCapacityBytes, key: "requiredCapacity") + defer { transaction.finish() } try Prune.pruneReclaim(reclaimBytes: requiredCapacityBytes - availableCapacityBytes) }