Skip to content

Commit bb6db84

Browse files
committed
Remove docs & update getMetrics()
1 parent cb00e4a commit bb6db84

File tree

94 files changed

+18
-22138
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+18
-22138
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ To keep SwiftPrometheus as clean and lightweight as possible, there is no way of
117117
This could look something like this:
118118
```swift
119119
router.get("/metrics") { request -> String in
120-
return myProm.getMetrics()
120+
return myProm.collect()
121121
}
122122
```
123123
Here, I used [Vapor](https://github.com/vapor/vapor) syntax, but this will work with any web framework, since it's just returning a plain String.

Sources/Prometheus/MetricTypes/Counter.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class PromCounter<NumType: Numeric, Labels: MetricLabels>: PromMetric, Pr
4747
///
4848
/// - Returns:
4949
/// Newline seperated Prometheus formatted metric string
50-
public func getMetric() -> String {
50+
public func collect() -> String {
5151
return self.lock.withLock {
5252
var output = [String]()
5353

Sources/Prometheus/MetricTypes/Gauge.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class PromGauge<NumType: Numeric, Labels: MetricLabels>: PromMetric, Prom
4848
///
4949
/// - Returns:
5050
/// Newline seperated Prometheus formatted metric string
51-
public func getMetric() -> String {
51+
public func collect() -> String {
5252
return self.lock.withLock {
5353
var output = [String]()
5454

Sources/Prometheus/MetricTypes/Histogram.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public class PromHistogram<NumType: DoubleRepresentable, Labels: HistogramLabels
7878
///
7979
/// - Returns:
8080
/// Newline seperated Prometheus formatted metric string
81-
public func getMetric() -> String {
81+
public func collect() -> String {
8282
return self.lock.withLock {
8383
var output = [String]()
8484

Sources/Prometheus/MetricTypes/PromMetric.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public protocol PromMetric {
3131
var _type: PromMetricType { get }
3232

3333
/// Retrieves the Prometheus-formatted metric data
34-
func getMetric() -> String
34+
func collect() -> String
3535
}
3636

3737
/// Adding a prometheus instance to all metrics

Sources/Prometheus/MetricTypes/Summary.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class PromSummary<NumType: DoubleRepresentable, Labels: SummaryLabels>: P
7979
///
8080
/// - Returns:
8181
/// Newline seperated Prometheus formatted metric string
82-
public func getMetric() -> String {
82+
public func collect() -> String {
8383
return self.lock.withLock {
8484
var output = [String]()
8585

Sources/Prometheus/Prometheus.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ public class PrometheusClient {
2525
/// Creates prometheus formatted metrics
2626
///
2727
/// - Returns: Newline seperated string with metrics for all Metric Trackers of this Prometheus instance
28-
public func getMetrics() -> String {
28+
public func collect() -> String {
2929
return self.lock.withLock {
30-
return self.metrics.map { $0.getMetric() }.joined(separator: "\n")
30+
return self.metrics.map { $0.collect() }.joined(separator: "\n")
3131
}
3232
}
3333

Sources/PrometheusExample/main.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,5 @@ for _ in 0...Int.random(in: 100...1000) {
113113
summary.observe(Double.random(in: 0...10000), SummaryThing("/test"))
114114
}
115115

116-
let metrics = try! MetricsSystem.prometheus().getMetrics()
116+
let metrics = try! MetricsSystem.prometheus().collect()
117117
print(metrics)

Tests/SwiftPrometheusTests/PrometheusMetricsTests.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ final class PrometheusMetricsTests: XCTestCase {
2222
let counterTwo = Counter(label: "my_counter", dimensions: [("myValue", "labels")])
2323
counterTwo.increment(by: 10)
2424

25-
XCTAssertEqual(prom.getMetrics(), """
25+
XCTAssertEqual(prom.collect(), """
2626
# TYPE my_counter counter
2727
my_counter 10
2828
my_counter{myValue=\"labels\"} 10
@@ -39,7 +39,7 @@ final class PrometheusMetricsTests: XCTestCase {
3939
let gaugeTwo = Gauge(label: "my_gauge", dimensions: [("myValue", "labels")])
4040
gaugeTwo.record(10)
4141

42-
XCTAssertEqual(prom.getMetrics(), """
42+
XCTAssertEqual(prom.collect(), """
4343
# TYPE my_gauge gauge
4444
my_gauge 42.0
4545
my_gauge{myValue=\"labels\"} 10.0
@@ -55,7 +55,7 @@ final class PrometheusMetricsTests: XCTestCase {
5555
let recorderTwo = Recorder(label: "my_histogram", dimensions: [("myValue", "labels")])
5656
recorderTwo.record(3)
5757

58-
XCTAssertEqual(prom.getMetrics(), """
58+
XCTAssertEqual(prom.collect(), """
5959
# TYPE my_histogram histogram
6060
my_histogram_bucket{le="0.005"} 0.0
6161
my_histogram_bucket{le="0.01"} 0.0
@@ -105,7 +105,7 @@ final class PrometheusMetricsTests: XCTestCase {
105105
let summaryTwo = Timer(label: "my_summary", dimensions: [("myValue", "labels")])
106106
summaryTwo.recordNanoseconds(123)
107107

108-
XCTAssertEqual(prom.getMetrics(), """
108+
XCTAssertEqual(prom.collect(), """
109109
# TYPE my_summary summary
110110
my_summary{quantile="0.01"} 1.0
111111
my_summary{quantile="0.05"} 1.0
@@ -132,7 +132,7 @@ final class PrometheusMetricsTests: XCTestCase {
132132
let counter = Counter(label: "my_counter")
133133
counter.increment()
134134
counter.destroy()
135-
XCTAssertEqual(prom.getMetrics(), "")
135+
XCTAssertEqual(prom.collect(), "")
136136
}
137137
}
138138

Tests/SwiftPrometheusTests/SwiftPrometheusTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ final class SwiftPrometheusTests: XCTestCase {
6060
XCTAssertEqual(counter.get(), 20)
6161
XCTAssertEqual(counter.get(BaseLabels(myValue: "labels")), 20)
6262

63-
XCTAssertEqual(counter.getMetric(), "# HELP my_counter Counter for testing\n# TYPE my_counter counter\nmy_counter 20\nmy_counter{myValue=\"labels\"} 20")
63+
XCTAssertEqual(counter.collect(), "# HELP my_counter Counter for testing\n# TYPE my_counter counter\nmy_counter 20\nmy_counter{myValue=\"labels\"} 20")
6464
}
6565

6666
func testGauge() {
@@ -75,7 +75,7 @@ final class SwiftPrometheusTests: XCTestCase {
7575
XCTAssertEqual(gauge.get(), 20)
7676
XCTAssertEqual(gauge.get(BaseLabels(myValue: "labels")), 20)
7777

78-
XCTAssertEqual(gauge.getMetric(), "# HELP my_gauge Gauge for testing\n# TYPE my_gauge gauge\nmy_gauge 20\nmy_gauge{myValue=\"labels\"} 20")
78+
XCTAssertEqual(gauge.collect(), "# HELP my_gauge Gauge for testing\n# TYPE my_gauge gauge\nmy_gauge 20\nmy_gauge{myValue=\"labels\"} 20")
7979
}
8080

8181
func testHistogram() {
@@ -86,7 +86,7 @@ final class SwiftPrometheusTests: XCTestCase {
8686

8787
histogram.observe(3, .init(myValue: "labels"))
8888

89-
XCTAssertEqual(histogram.getMetric(), "# HELP my_histogram Histogram for testing\n# TYPE my_histogram histogram\nmy_histogram_bucket{myValue=\"*\", le=\"0.5\"} 0.0\nmy_histogram_bucket{myValue=\"*\", le=\"1.0\"} 1.0\nmy_histogram_bucket{myValue=\"*\", le=\"2.0\"} 2.0\nmy_histogram_bucket{myValue=\"*\", le=\"3.0\"} 4.0\nmy_histogram_bucket{myValue=\"*\", le=\"5.0\"} 4.0\nmy_histogram_bucket{myValue=\"*\", le=\"+Inf\"} 4.0\nmy_histogram_count{myValue=\"*\"} 4.0\nmy_histogram_sum{myValue=\"*\"} 9.0\nmy_histogram_bucket{myValue=\"labels\", le=\"0.5\"} 0.0\nmy_histogram_bucket{myValue=\"labels\", le=\"1.0\"} 0.0\nmy_histogram_bucket{myValue=\"labels\", le=\"2.0\"} 0.0\nmy_histogram_bucket{myValue=\"labels\", le=\"3.0\"} 1.0\nmy_histogram_bucket{myValue=\"labels\", le=\"5.0\"} 1.0\nmy_histogram_bucket{myValue=\"labels\", le=\"+Inf\"} 1.0\nmy_histogram_count{myValue=\"labels\"} 1.0\nmy_histogram_sum{myValue=\"labels\"} 3.0")
89+
XCTAssertEqual(histogram.collect(), "# HELP my_histogram Histogram for testing\n# TYPE my_histogram histogram\nmy_histogram_bucket{myValue=\"*\", le=\"0.5\"} 0.0\nmy_histogram_bucket{myValue=\"*\", le=\"1.0\"} 1.0\nmy_histogram_bucket{myValue=\"*\", le=\"2.0\"} 2.0\nmy_histogram_bucket{myValue=\"*\", le=\"3.0\"} 4.0\nmy_histogram_bucket{myValue=\"*\", le=\"5.0\"} 4.0\nmy_histogram_bucket{myValue=\"*\", le=\"+Inf\"} 4.0\nmy_histogram_count{myValue=\"*\"} 4.0\nmy_histogram_sum{myValue=\"*\"} 9.0\nmy_histogram_bucket{myValue=\"labels\", le=\"0.5\"} 0.0\nmy_histogram_bucket{myValue=\"labels\", le=\"1.0\"} 0.0\nmy_histogram_bucket{myValue=\"labels\", le=\"2.0\"} 0.0\nmy_histogram_bucket{myValue=\"labels\", le=\"3.0\"} 1.0\nmy_histogram_bucket{myValue=\"labels\", le=\"5.0\"} 1.0\nmy_histogram_bucket{myValue=\"labels\", le=\"+Inf\"} 1.0\nmy_histogram_count{myValue=\"labels\"} 1.0\nmy_histogram_sum{myValue=\"labels\"} 3.0")
9090
}
9191

9292
func testSummary() {
@@ -99,6 +99,6 @@ final class SwiftPrometheusTests: XCTestCase {
9999

100100
summary.observe(123, .init(myValue: "labels"))
101101

102-
XCTAssertEqual(summary.getMetric(), "# HELP my_summary Summary for testing\n# TYPE my_summary summary\nmy_summary{quantile=\"0.5\", myValue=\"*\"} 4.0\nmy_summary{quantile=\"0.9\", myValue=\"*\"} 10000.0\nmy_summary{quantile=\"0.99\", myValue=\"*\"} 10000.0\nmy_summary_count{myValue=\"*\"} 5.0\nmy_summary_sum{myValue=\"*\"} 10130.0\nmy_summary{quantile=\"0.5\", myValue=\"labels\"} 123.0\nmy_summary{quantile=\"0.9\", myValue=\"labels\"} 123.0\nmy_summary{quantile=\"0.99\", myValue=\"labels\"} 123.0\nmy_summary_count{myValue=\"labels\"} 1.0\nmy_summary_sum{myValue=\"labels\"} 123.0")
102+
XCTAssertEqual(summary.collect(), "# HELP my_summary Summary for testing\n# TYPE my_summary summary\nmy_summary{quantile=\"0.5\", myValue=\"*\"} 4.0\nmy_summary{quantile=\"0.9\", myValue=\"*\"} 10000.0\nmy_summary{quantile=\"0.99\", myValue=\"*\"} 10000.0\nmy_summary_count{myValue=\"*\"} 5.0\nmy_summary_sum{myValue=\"*\"} 10130.0\nmy_summary{quantile=\"0.5\", myValue=\"labels\"} 123.0\nmy_summary{quantile=\"0.9\", myValue=\"labels\"} 123.0\nmy_summary{quantile=\"0.99\", myValue=\"labels\"} 123.0\nmy_summary_count{myValue=\"labels\"} 1.0\nmy_summary_sum{myValue=\"labels\"} 123.0")
103103
}
104104
}

0 commit comments

Comments
 (0)