metrics should include their labels when printed to ease debugging (#82)
motivation: ease debugging changes: confirm metrics types to CustomStringConvertible
This commit is contained in:
parent
cf757fe4eb
commit
5702ee1174
|
|
@ -84,6 +84,12 @@ public class Counter {
|
|||
}
|
||||
}
|
||||
|
||||
extension Counter: CustomStringConvertible {
|
||||
public var description: String {
|
||||
return "Counter(\(self.label), dimensions: \(self.dimensions))"
|
||||
}
|
||||
}
|
||||
|
||||
public extension Recorder {
|
||||
/// Create a new `Recorder`.
|
||||
///
|
||||
|
|
@ -158,6 +164,12 @@ public class Recorder {
|
|||
}
|
||||
}
|
||||
|
||||
extension Recorder: CustomStringConvertible {
|
||||
public var description: String {
|
||||
return "\(type(of: self))(\(self.label), dimensions: \(self.dimensions), aggregate: \(self.aggregate))"
|
||||
}
|
||||
}
|
||||
|
||||
/// A gauge is a metric that represents a single numerical value that can arbitrarily go up and down.
|
||||
/// Gauges are typically used for measured values like temperatures or current memory usage, but also "counts" that can go up and down, like the number of active threads.
|
||||
/// Gauges are modeled as `Recorder` with a sample size of 1 and that does not perform any aggregation.
|
||||
|
|
@ -356,6 +368,12 @@ public class Timer {
|
|||
}
|
||||
}
|
||||
|
||||
extension Timer: CustomStringConvertible {
|
||||
public var description: String {
|
||||
return "Timer(\(self.label), dimensions: \(self.dimensions))"
|
||||
}
|
||||
}
|
||||
|
||||
/// The `MetricsSystem` is a global facility where the default metrics backend implementation (`MetricsFactory`) can be
|
||||
/// configured. `MetricsSystem` is set up just once in a given program to set up the desired metrics backend
|
||||
/// implementation.
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ extension MetricsTests {
|
|||
("testDestroyingGauge", testDestroyingGauge),
|
||||
("testDestroyingCounter", testDestroyingCounter),
|
||||
("testDestroyingTimer", testDestroyingTimer),
|
||||
("testDescriptions", testDescriptions),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -391,4 +391,21 @@ class MetricsTests: XCTestCase {
|
|||
let identityAgain = ObjectIdentifier(timerAgain)
|
||||
XCTAssertNotEqual(identity, identityAgain, "since the cached metric was released, the created a new should have a different identity")
|
||||
}
|
||||
|
||||
func testDescriptions() throws {
|
||||
let metrics = TestMetrics()
|
||||
MetricsSystem.bootstrapInternal(metrics)
|
||||
|
||||
let timer = Timer(label: "hello.timer")
|
||||
XCTAssertEqual("\(timer)", "Timer(hello.timer, dimensions: [])")
|
||||
|
||||
let counter = Counter(label: "hello.counter")
|
||||
XCTAssertEqual("\(counter)", "Counter(hello.counter, dimensions: [])")
|
||||
|
||||
let gauge = Gauge(label: "hello.gauge")
|
||||
XCTAssertEqual("\(gauge)", "Gauge(hello.gauge, dimensions: [], aggregate: false)")
|
||||
|
||||
let recorder = Recorder(label: "hello.recorder")
|
||||
XCTAssertEqual("\(recorder)", "Recorder(hello.recorder, dimensions: [], aggregate: true)")
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue