File tree 2 files changed +13
-4
lines changed
Sources/Prometheus/MetricTypes
Tests/SwiftPrometheusTests
2 files changed +13
-4
lines changed Original file line number Diff line number Diff line change @@ -221,7 +221,7 @@ public class PromHistogram<NumType: DoubleRepresentable>: PromMetric {
221
221
return histogram
222
222
} else {
223
223
return lock. withLock {
224
- if let histogram = subHistograms [ labels] {
224
+ if let histogram = self . subHistograms [ labels] {
225
225
precondition ( histogram. name == self . name,
226
226
"""
227
227
Somehow got 2 subHistograms with the same data type / labels
Original file line number Diff line number Diff line change @@ -29,7 +29,7 @@ final class HistogramTests: XCTestCase {
29
29
helpText: " Histogram for testing " ,
30
30
buckets: Buckets . exponential ( start: 1 , factor: 2 , count: 63 ) )
31
31
let elg = MultiThreadedEventLoopGroup ( numberOfThreads: 8 )
32
- let semaphore = DispatchSemaphore ( value: 2 )
32
+ let semaphore = DispatchSemaphore ( value: 0 )
33
33
_ = elg. next ( ) . submit {
34
34
for _ in 1 ... 1_000 {
35
35
let labels = DimensionLabels ( [ ( " myValue " , " 1 " ) ] )
@@ -51,9 +51,18 @@ final class HistogramTests: XCTestCase {
51
51
semaphore. signal ( )
52
52
}
53
53
semaphore. wait ( )
54
+ semaphore. wait ( )
54
55
try elg. syncShutdownGracefully ( )
55
- XCTAssertTrue ( histogram. collect ( ) . contains ( " my_histogram_count 4000.0 " ) )
56
- XCTAssertTrue ( histogram. collect ( ) . contains ( " my_histogram_sum 4000.0 " ) )
56
+
57
+ let output = histogram. collect ( )
58
+ XCTAssertTrue ( output. contains ( " my_histogram_count 4000.0 " ) )
59
+ XCTAssertTrue ( output. contains ( " my_histogram_sum 4000.0 " ) )
60
+
61
+ XCTAssertTrue ( output. contains ( #"my_histogram_count{myValue="1"} 2000.0"# ) )
62
+ XCTAssertTrue ( output. contains ( #"my_histogram_sum{myValue="1"} 2000.0"# ) )
63
+
64
+ XCTAssertTrue ( output. contains ( #"my_histogram_count{myValue="2"} 2000.0"# ) )
65
+ XCTAssertTrue ( output. contains ( #"my_histogram_sum{myValue="2"} 2000.0"# ) )
57
66
}
58
67
59
68
func testHistogramSwiftMetrics( ) {
You can’t perform that action at this time.
0 commit comments