Skip to content

Commit

Permalink
Add Date as metric type
Browse files Browse the repository at this point in the history
  • Loading branch information
christophhagen committed Oct 20, 2023
1 parent a62fdc2 commit 4f3d4d9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
26 changes: 26 additions & 0 deletions Sources/Clairvoyant/Metric/MetricType.swift
Original file line number Diff line number Diff line change
@@ -1,15 +1,36 @@
import Foundation

public enum MetricType: RawRepresentable {

/// A Swift `Int` type
case integer

/// A Swift `Double` type
case double

/// A Swift `Bool` type
case boolean

/// A Swift `String` type
case string

/// A Swift `Data` type
case data

/// A custom type specific to the application
case customType(named: String)

/// A Swift `ServerStatus` type
case serverStatus

/// A Swift `HTTPStatus` type
case httpStatus

/// A `SemanticVersion` type
case semanticVersion

/// A Swift `Date` type
case date

public var rawValue: String {
switch self {
Expand All @@ -31,6 +52,8 @@ public enum MetricType: RawRepresentable {
return "HTTP Status"
case .semanticVersion:
return "SemanticVersion"
case .date:
return "Date"
}
}

Expand All @@ -44,6 +67,7 @@ public enum MetricType: RawRepresentable {
case "Status": self = .serverStatus
case "HTTP Status": self = .httpStatus
case "SemanticVersion": self = .semanticVersion
case "Date": self = .date
default:
self = .customType(named: rawValue)
}
Expand All @@ -70,6 +94,8 @@ public enum MetricType: RawRepresentable {
return HTTPStatusCode.self
case .semanticVersion:
return SemanticVersion.self
case .date:
return Date.self
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions Sources/Clairvoyant/Metric/StandardMetricTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,8 @@ extension Data: MetricValue {

public static let valueType: MetricType = .data
}

extension Date: MetricValue {

public static let valueType: MetricType = .date
}

0 comments on commit 4f3d4d9

Please sign in to comment.