Skip to content

Commit 7120245

Browse files
committed
swiftformat
1 parent daaf182 commit 7120245

File tree

13 files changed

+66
-78
lines changed

13 files changed

+66
-78
lines changed

Sources/Exporters/DatadogExporter/Metrics/MetricUtils.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ internal struct MetricUtils: Encodable {
2222
/// getType maps a metric into a Datadog type
2323
static func getType(metric: Metric) -> String {
2424
switch metric.aggregationType {
25-
case .doubleSum, .intSum:
26-
return countType
27-
case .doubleSummary, .intSummary, .intGauge, .doubleGauge:
28-
return gaugeType
25+
case .doubleSum, .intSum:
26+
return countType
27+
case .doubleSummary, .intSummary, .intGauge, .doubleGauge:
28+
return gaugeType
2929
}
3030
}
3131

Sources/Exporters/DatadogExporter/Metrics/MetricsExporter.swift

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ internal class MetricsExporter {
2222
throw ExporterError(description: "Metrics Exporter need an api key")
2323
}
2424

25-
self.configuration = config
25+
configuration = config
2626

2727
let filesOrchestrator = FilesOrchestrator(
2828
directory: try Directory(withSubdirectoryPath: metricsDirectory),
@@ -76,18 +76,18 @@ internal class MetricsExporter {
7676
let labels = metricData.labels
7777
tags.append(contentsOf: MetricUtils.getTags(labels: labels))
7878
switch metric.aggregationType {
79-
case .doubleSum:
80-
let sum = metricData as! SumData<Double>
81-
return DDMetricPoint(timestamp: metricData.timestamp, value: sum.sum)
82-
case .intSum:
83-
let sum = metricData as! SumData<Int>
84-
return DDMetricPoint(timestamp: metricData.timestamp, value: Double(sum.sum))
85-
case .doubleSummary, .doubleGauge:
86-
let summary = metricData as! SummaryData<Double>
87-
return DDMetricPoint(timestamp: metricData.timestamp, value: summary.sum)
88-
case .intSummary, .intGauge:
89-
let summary = metricData as! SummaryData<Int>
90-
return DDMetricPoint(timestamp: metricData.timestamp, value: Double(summary.sum))
79+
case .doubleSum:
80+
let sum = metricData as! SumData<Double>
81+
return DDMetricPoint(timestamp: metricData.timestamp, value: sum.sum)
82+
case .intSum:
83+
let sum = metricData as! SumData<Int>
84+
return DDMetricPoint(timestamp: metricData.timestamp, value: Double(sum.sum))
85+
case .doubleSummary, .doubleGauge:
86+
let summary = metricData as! SummaryData<Double>
87+
return DDMetricPoint(timestamp: metricData.timestamp, value: summary.sum)
88+
case .intSummary, .intGauge:
89+
let summary = metricData as! SummaryData<Int>
90+
return DDMetricPoint(timestamp: metricData.timestamp, value: Double(summary.sum))
9191
}
9292
}
9393

Sources/Exporters/OpenTelemetryProtocol/metric/MetricsAdapter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,10 @@ struct MetricsAdapter {
6565
protoDataPoint.labels.append(kvp)
6666
}
6767

68-
protoMetric.doubleGauge.dataPoints.append(protoDataPoint);
68+
protoMetric.doubleGauge.dataPoints.append(protoDataPoint)
6969
case .intGauge:
7070
guard let gaugeData = $0 as? SumData<Int> else {
71-
break
71+
break
7272
}
7373

7474
var protoDataPoint = Opentelemetry_Proto_Metrics_V1_IntDataPoint()

Sources/Exporters/Prometheus/PrometheusExporterExtensions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
import Foundation
77
import OpenTelemetrySdk
88

9-
public struct PrometheusExporterExtensions {
9+
public enum PrometheusExporterExtensions {
1010
static let prometheusCounterType = "counter"
1111
static let prometheusSummaryType = "summary"
1212
static let prometheusSummarySumPostFix = "_sum"

Sources/OpenTelemetryApi/Metrics/ProxyMeter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ public struct ProxyMeter: Meter {
2929
return realMeter?.createDoubleMeasure(name: name, absolute: absolute) ?? AnyMeasureMetric<Double>(NoopMeasureMetric<Double>())
3030
}
3131

32-
public func createIntObservableGauge(name: String, callback: @escaping (IntObserverMetric) -> ()) -> IntObserverMetric {
32+
public func createIntObservableGauge(name: String, callback: @escaping (IntObserverMetric) -> Void) -> IntObserverMetric {
3333
return realMeter?.createIntObservableGauge(name: name, callback: callback) ?? NoopIntObserverMetric()
3434
}
3535

36-
public func createDoubleObservableGauge(name: String, callback: @escaping (DoubleObserverMetric) -> ()) -> DoubleObserverMetric {
36+
public func createDoubleObservableGauge(name: String, callback: @escaping (DoubleObserverMetric) -> Void) -> DoubleObserverMetric {
3737
return realMeter?.createDoubleObservableGauge(name: name, callback: callback) ?? NoopDoubleObserverMetric()
3838
}
3939

Sources/OpenTelemetrySdk/Metrics/Aggregators/MaxValueAggregator.swift

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,41 +3,39 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
76
import Foundation
87

9-
public class MaxValueAggregator<T: SignedNumeric & Comparable>: Aggregator<T> {
8+
public class MaxValueAggregator<T: SignedNumeric & Comparable>: Aggregator<T> {
109
var value: T = 0
1110
var pointCheck: T = 0
1211

1312
private let lock = Lock()
1413

15-
public override func update(value: T) {
14+
override public func update(value: T) {
1615
lock.withLockVoid {
17-
if (value > self.value) {
16+
if value > self.value {
1817
self.value = value
1918
}
2019
}
2120
}
2221

23-
public override func checkpoint() {
22+
override public func checkpoint() {
2423
lock.withLockVoid {
2524
super.checkpoint()
2625
self.pointCheck = self.value
2726
self.value = 0
2827
}
2928
}
3029

31-
public override func toMetricData() -> MetricData {
30+
override public func toMetricData() -> MetricData {
3231
return SumData<T>(startTimestamp: lastStart, timestamp: lastEnd, sum: pointCheck)
3332
}
3433

35-
public override func getAggregationType() -> AggregationType {
34+
override public func getAggregationType() -> AggregationType {
3635
if T.self == Double.Type.self {
3736
return .doubleGauge
3837
} else {
3938
return .intGauge
4039
}
4140
}
4241
}
43-

Sources/OpenTelemetrySdk/Metrics/DoubleObservableGaugeSdk.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import Foundation
77
import OpenTelemetryApi
88

9-
class DoubleObservableGaugeSdk : DoubleObserverMetric {
9+
class DoubleObservableGaugeSdk: DoubleObserverMetric {
1010
public private(set) var observerHandles = [LabelSet: DoubleObservableGaugeHandle]()
11-
let name : String
12-
var callback : (DoubleObserverMetric) -> Void
11+
let name: String
12+
var callback: (DoubleObserverMetric) -> Void
1313

1414
init(measurementName: String, callback: @escaping (DoubleObserverMetric) -> Void) {
15-
self.name = measurementName
15+
name = measurementName
1616
self.callback = callback
1717
}
1818

@@ -33,4 +33,3 @@ class DoubleObservableGaugeSdk : DoubleObserverMetric {
3333
callback(self)
3434
}
3535
}
36-

Sources/OpenTelemetrySdk/Metrics/IntObservableGaugeHandle.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
76
import Foundation
87
import OpenTelemetryApi
98

Sources/OpenTelemetrySdk/Metrics/IntObservableGaugeSdk.swift

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@
66
import Foundation
77
import OpenTelemetryApi
88

9-
10-
class IntObservableGaugeSdk : IntObserverMetric {
9+
class IntObservableGaugeSdk: IntObserverMetric {
1110
public private(set) var observerHandles = [LabelSet: IntObservableGaugeHandle]()
12-
let name : String
13-
var callback : (IntObserverMetric) -> Void
11+
let name: String
12+
var callback: (IntObserverMetric) -> Void
1413

15-
init(measurementName: String, callback: @escaping (IntObserverMetric)->Void) {
16-
self.name = measurementName
14+
init(measurementName: String, callback: @escaping (IntObserverMetric) -> Void) {
15+
name = measurementName
1716
self.callback = callback
1817
}
1918

Sources/OpenTelemetrySdk/Metrics/MeterSdk.swift

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class MeterSdk: Meter {
1010
fileprivate let collectLock = Lock()
1111
let meterName: String
1212
var metricProcessor: MetricProcessor
13-
var instrumentationLibraryInfo : InstrumentationLibraryInfo
13+
var instrumentationLibraryInfo: InstrumentationLibraryInfo
1414
var resource: Resource
1515

1616
var intGauges = [String: IntObservableGaugeSdk]()
@@ -23,10 +23,10 @@ class MeterSdk: Meter {
2323
var doubleObservers = [String: DoubleObserverMetricSdk]()
2424

2525
init(meterSharedState: MeterSharedState, instrumentationLibraryInfo: InstrumentationLibraryInfo) {
26-
self.meterName = instrumentationLibraryInfo.name
27-
self.resource = meterSharedState.resource
28-
self.metricProcessor = meterSharedState.metricProcessor
29-
self.instrumentationLibraryInfo = instrumentationLibraryInfo
26+
meterName = instrumentationLibraryInfo.name
27+
resource = meterSharedState.resource
28+
metricProcessor = meterSharedState.metricProcessor
29+
self.instrumentationLibraryInfo = instrumentationLibraryInfo
3030
}
3131

3232
func getLabelSet(labels: [String: String]) -> LabelSet {
@@ -37,7 +37,6 @@ class MeterSdk: Meter {
3737
collectLock.withLockVoid {
3838
var boundInstrumentsToRemove = [LabelSet]()
3939

40-
4140
intCounters.forEach { counter in
4241
let metricName = counter.key
4342
let counterInstrument = counter.value
@@ -112,7 +111,7 @@ class MeterSdk: Meter {
112111
intMeasures.forEach { measure in
113112
let metricName = measure.key
114113
let measureInstrument = measure.value
115-
var metric = Metric(namespace: meterName, name: metricName, desc: meterName + metricName, type: AggregationType.intSummary, resource: resource, instrumentationLibraryInfo: instrumentationLibraryInfo)
114+
var metric = Metric(namespace: meterName, name: metricName, desc: meterName + metricName, type: AggregationType.intSummary, resource: resource, instrumentationLibraryInfo: instrumentationLibraryInfo)
116115
measureInstrument.boundInstruments.forEach { boundInstrument in
117116
let labelSet = boundInstrument.key
118117
let aggregator = boundInstrument.value.getAggregator()
@@ -143,12 +142,12 @@ class MeterSdk: Meter {
143142
let metricName = gauge.key
144143
let gaugeInstrument = gauge.value
145144

146-
var metric = Metric(namespace: meterName, name: metricName, desc: meterName+metricName, type: .intGauge, resource: resource, instrumentationLibraryInfo: instrumentationLibraryInfo)
145+
var metric = Metric(namespace: meterName, name: metricName, desc: meterName + metricName, type: .intGauge, resource: resource, instrumentationLibraryInfo: instrumentationLibraryInfo)
147146

148147
gaugeInstrument.invokeCallback()
149148

150149
gaugeInstrument.observerHandles.forEach { handle in
151-
let labelSet = handle.key
150+
let labelSet = handle.key
152151
let aggregator = handle.value.aggregator
153152
aggregator.checkpoint()
154153

@@ -163,12 +162,12 @@ class MeterSdk: Meter {
163162
let metricName = gauge.key
164163
let gaugeInstrument = gauge.value
165164

166-
var metric = Metric(namespace: meterName, name: metricName, desc: meterName+metricName, type: .doubleGauge, resource: resource, instrumentationLibraryInfo: instrumentationLibraryInfo)
165+
var metric = Metric(namespace: meterName, name: metricName, desc: meterName + metricName, type: .doubleGauge, resource: resource, instrumentationLibraryInfo: instrumentationLibraryInfo)
167166

168167
gaugeInstrument.invokeCallback()
169168

170169
gaugeInstrument.observerHandles.forEach { handle in
171-
let labelSet = handle.key
170+
let labelSet = handle.key
172171
let aggregator = handle.value.aggregator
173172
aggregator.checkpoint()
174173

@@ -179,8 +178,6 @@ class MeterSdk: Meter {
179178
metricProcessor.process(metric: metric)
180179
}
181180

182-
183-
184181
intObservers.forEach { observer in
185182
let metricName = observer.key
186183
let observerInstrument = observer.value
@@ -218,7 +215,6 @@ class MeterSdk: Meter {
218215
}
219216
}
220217

221-
222218
func createIntObservableGauge(name: String, callback: @escaping (IntObserverMetric) -> Void) -> IntObserverMetric {
223219
var gauge = intGauges[name]
224220
if gauge == nil {
@@ -238,10 +234,10 @@ class MeterSdk: Meter {
238234
doubleGauges[name] = gauge!
239235
}
240236
}
241-
return gauge!
237+
return gauge!
242238
}
243239

244-
func createIntCounter(name: String, monotonic: Bool) -> AnyCounterMetric<Int> {
240+
func createIntCounter(name: String, monotonic _: Bool) -> AnyCounterMetric<Int> {
245241
var counter = intCounters[name]
246242
if counter == nil {
247243
counter = CounterMetricSdk<Int>(name: name)
@@ -252,7 +248,7 @@ class MeterSdk: Meter {
252248
return AnyCounterMetric<Int>(counter!)
253249
}
254250

255-
func createDoubleCounter(name: String, monotonic: Bool) -> AnyCounterMetric<Double> {
251+
func createDoubleCounter(name: String, monotonic _: Bool) -> AnyCounterMetric<Double> {
256252
var counter = doubleCounters[name]
257253
if counter == nil {
258254
counter = CounterMetricSdk<Double>(name: name)
@@ -263,7 +259,7 @@ class MeterSdk: Meter {
263259
return AnyCounterMetric<Double>(counter!)
264260
}
265261

266-
func createIntMeasure(name: String, absolute: Bool) -> AnyMeasureMetric<Int> {
262+
func createIntMeasure(name: String, absolute _: Bool) -> AnyMeasureMetric<Int> {
267263
var measure = intMeasures[name]
268264
if measure == nil {
269265
measure = MeasureMetricSdk<Int>(name: name)
@@ -274,7 +270,7 @@ class MeterSdk: Meter {
274270
return AnyMeasureMetric<Int>(measure!)
275271
}
276272

277-
func createDoubleMeasure(name: String, absolute: Bool) -> AnyMeasureMetric<Double> {
273+
func createDoubleMeasure(name: String, absolute _: Bool) -> AnyMeasureMetric<Double> {
278274
var measure = doubleMeasures[name]
279275
if measure == nil {
280276
measure = MeasureMetricSdk<Double>(name: name)
@@ -285,7 +281,7 @@ class MeterSdk: Meter {
285281
return AnyMeasureMetric<Double>(measure!)
286282
}
287283

288-
func createIntObserver(name: String, absolute: Bool, callback: @escaping (IntObserverMetric) -> Void) -> IntObserverMetric {
284+
func createIntObserver(name: String, absolute _: Bool, callback: @escaping (IntObserverMetric) -> Void) -> IntObserverMetric {
289285
var observer = intObservers[name]
290286
if observer == nil {
291287
observer = IntObserverMetricSdk(metricName: name, callback: callback)
@@ -296,7 +292,7 @@ class MeterSdk: Meter {
296292
return observer!
297293
}
298294

299-
func createDoubleObserver(name: String, absolute: Bool, callback: @escaping (DoubleObserverMetric) -> Void) -> DoubleObserverMetric {
295+
func createDoubleObserver(name: String, absolute _: Bool, callback: @escaping (DoubleObserverMetric) -> Void) -> DoubleObserverMetric {
300296
var observer = doubleObservers[name]
301297
if observer == nil {
302298
observer = DoubleObserverMetricSdk(metricName: name, callback: callback)

0 commit comments

Comments
 (0)