@@ -236,65 +236,67 @@ private struct StringCodingKey: CodingKey {
236
236
237
237
238
238
/// Helper for dimensions
239
- private struct DimensionLabels : MetricLabels {
239
+ public struct DimensionLabels : MetricLabels {
240
240
let dimensions : [ ( String , String ) ]
241
241
242
- init ( ) {
242
+ public init ( ) {
243
243
self . dimensions = [ ]
244
244
}
245
245
246
- init ( _ dimensions: [ ( String , String ) ] ) {
246
+ public init ( _ dimensions: [ ( String , String ) ] ) {
247
247
self . dimensions = dimensions
248
248
}
249
249
250
- func encode( to encoder: Encoder ) throws {
250
+ public func encode( to encoder: Encoder ) throws {
251
251
var container = encoder. container ( keyedBy: StringCodingKey . self)
252
252
try self . dimensions. forEach {
253
253
try container. encode ( $0. 1 , forKey: . init( $0. 0 ) )
254
254
}
255
255
}
256
256
257
- func hash( into hasher: inout Hasher ) {
257
+ public func hash( into hasher: inout Hasher ) {
258
258
hasher. combine ( dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } )
259
259
}
260
260
261
261
fileprivate var identifiers : String {
262
262
return dimensions. map { $0. 0 } . joined ( separator: " - " )
263
263
}
264
264
265
- static func == ( lhs: DimensionLabels , rhs: DimensionLabels ) -> Bool {
265
+ public static func == ( lhs: DimensionLabels , rhs: DimensionLabels ) -> Bool {
266
266
return lhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } == rhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " }
267
267
}
268
268
}
269
269
270
270
/// Helper for dimensions
271
- private struct DimensionHistogramLabels : HistogramLabels {
271
+ /// swift-metrics api doesn't allow setting buckets explicitly.
272
+ /// If default buckets don't fit, this Labels implementation is a nice default to create Prometheus metric types wtih
273
+ public struct DimensionHistogramLabels : HistogramLabels {
272
274
/// Bucket
273
- var le : String
275
+ public var le : String
274
276
/// Dimensions
275
277
let dimensions : [ ( String , String ) ]
276
278
277
279
/// Empty init
278
- init ( ) {
280
+ public init ( ) {
279
281
self . le = " "
280
282
self . dimensions = [ ]
281
283
}
282
284
283
285
/// Init with dimensions
284
- init ( _ dimensions: [ ( String , String ) ] ) {
286
+ public init ( _ dimensions: [ ( String , String ) ] ) {
285
287
self . le = " "
286
288
self . dimensions = dimensions
287
289
}
288
290
289
- func encode( to encoder: Encoder ) throws {
291
+ public func encode( to encoder: Encoder ) throws {
290
292
var container = encoder. container ( keyedBy: StringCodingKey . self)
291
293
try self . dimensions. forEach {
292
294
try container. encode ( $0. 1 , forKey: . init( $0. 0 ) )
293
295
}
294
296
try container. encode ( le, forKey: . init( " le " ) )
295
297
}
296
298
297
- func hash( into hasher: inout Hasher ) {
299
+ public func hash( into hasher: inout Hasher ) {
298
300
hasher. combine ( dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } )
299
301
hasher. combine ( le)
300
302
}
@@ -303,39 +305,39 @@ private struct DimensionHistogramLabels: HistogramLabels {
303
305
return dimensions. map { $0. 0 } . joined ( separator: " - " )
304
306
}
305
307
306
- static func == ( lhs: DimensionHistogramLabels , rhs: DimensionHistogramLabels ) -> Bool {
308
+ public static func == ( lhs: DimensionHistogramLabels , rhs: DimensionHistogramLabels ) -> Bool {
307
309
return lhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } == rhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } && rhs. le == lhs. le
308
310
}
309
311
}
310
312
311
313
/// Helper for dimensions
312
- private struct DimensionSummaryLabels : SummaryLabels {
314
+ public struct DimensionSummaryLabels : SummaryLabels {
313
315
/// Quantile
314
- var quantile : String
316
+ public var quantile : String
315
317
/// Dimensions
316
318
let dimensions : [ ( String , String ) ]
317
319
318
320
/// Empty init
319
- init ( ) {
321
+ public init ( ) {
320
322
self . quantile = " "
321
323
self . dimensions = [ ]
322
324
}
323
325
324
326
/// Init with dimensions
325
- init ( _ dimensions: [ ( String , String ) ] ) {
327
+ public init ( _ dimensions: [ ( String , String ) ] ) {
326
328
self . quantile = " "
327
329
self . dimensions = dimensions
328
330
}
329
331
330
- func encode( to encoder: Encoder ) throws {
332
+ public func encode( to encoder: Encoder ) throws {
331
333
var container = encoder. container ( keyedBy: StringCodingKey . self)
332
334
try self . dimensions. forEach {
333
335
try container. encode ( $0. 1 , forKey: . init( $0. 0 ) )
334
336
}
335
337
try container. encode ( quantile, forKey: . init( " quantile " ) )
336
338
}
337
339
338
- func hash( into hasher: inout Hasher ) {
340
+ public func hash( into hasher: inout Hasher ) {
339
341
hasher. combine ( dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } )
340
342
hasher. combine ( quantile)
341
343
}
@@ -344,7 +346,7 @@ private struct DimensionSummaryLabels: SummaryLabels {
344
346
return dimensions. map { $0. 0 } . joined ( separator: " - " )
345
347
}
346
348
347
- static func == ( lhs: DimensionSummaryLabels , rhs: DimensionSummaryLabels ) -> Bool {
349
+ public static func == ( lhs: DimensionSummaryLabels , rhs: DimensionSummaryLabels ) -> Bool {
348
350
return lhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } == rhs. dimensions. map { " \( $0. 0 ) - \( $0. 1 ) " } && rhs. quantile == lhs. quantile
349
351
}
350
352
}
0 commit comments