Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ DerivedData/
Package.resolved
*.pyc
.docc-build
.vscode
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ internal final class ReloadingFileProviderCore<SnapshotType: ConfigSnapshotProto
/// - pollInterval: The interval between timestamp checks.
/// - providerName: The human-readable name of the provider.
/// - fileSystem: The file system to use.
/// - logger: The logger instance, or nil to create a default one.
/// - metrics: The metrics factory, or nil to use a no-op implementation.
/// - logger: The logger instance.
/// - metrics: The metrics factory.
/// - createSnapshot: A closure that creates a snapshot from file data.
/// - Throws: If the initial file load or snapshot creation fails.
internal init(
filePath: FilePath,
pollInterval: Duration,
providerName: String,
fileSystem: any CommonProviderFileSystem,
logger: Logger?,
metrics: (any MetricsFactory)?,
logger: Logger,
metrics: any MetricsFactory,
createSnapshot: @Sendable @escaping (Data) async throws -> SnapshotType
) async throws {
self.filePath = filePath
Expand All @@ -114,7 +114,7 @@ internal final class ReloadingFileProviderCore<SnapshotType: ConfigSnapshotProto
self.createSnapshot = createSnapshot

// Set up the logger with metadata
var logger = logger ?? Logger(label: providerName)
var logger = logger
logger[metadataKey: "\(providerName).filePath"] = .string(filePath.lastComponent?.string ?? "<nil>")
logger[metadataKey: "\(providerName).pollInterval.seconds"] = .string(
pollInterval.components.seconds.description
Expand All @@ -123,7 +123,7 @@ internal final class ReloadingFileProviderCore<SnapshotType: ConfigSnapshotProto

// Set up metrics
self.metrics = ReloadingFileProviderMetrics(
factory: metrics ?? NOOPMetricsHandler.instance,
factory: metrics,
providerName: providerName
)

Expand Down
16 changes: 8 additions & 8 deletions Sources/Configuration/Providers/JSON/ReloadingJSONProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ public final class ReloadingJSONProvider: Sendable {
pollInterval: Duration = .seconds(15),
bytesDecoder: some ConfigBytesFromStringDecoder = .base64,
secretsSpecifier: SecretsSpecifier<String, any Sendable> = .none,
logger: Logger? = nil,
metrics: (any MetricsFactory)? = nil
logger: Logger = Logger(label: "ReloadingJSONProvider"),
metrics: any MetricsFactory = MetricsSystem.factory
) async throws {
try await self.init(
filePath: filePath,
Expand All @@ -116,17 +116,17 @@ public final class ReloadingJSONProvider: Sendable {
/// - bytesDecoder: A decoder of bytes from a string.
/// - secretsSpecifier: A secrets specifier in case some of the values should be treated as secret.
/// - fileSystem: The underlying file system.
/// - logger: The logger instance to use, or nil to create a default one.
/// - metrics: The metrics factory to use, or nil to use a no-op implementation.
/// - logger: The logger instance to use.
/// - metrics: The metrics factory to use.
/// - Throws: If the file cannot be read or parsed, or if the JSON structure is invalid.
internal init(
filePath: FilePath,
pollInterval: Duration,
bytesDecoder: some ConfigBytesFromStringDecoder,
secretsSpecifier: SecretsSpecifier<String, any Sendable>,
fileSystem: some CommonProviderFileSystem,
logger: Logger?,
metrics: (any MetricsFactory)?
logger: Logger,
metrics: any MetricsFactory
) async throws {
self.core = try await ReloadingFileProviderCore(
filePath: filePath,
Expand Down Expand Up @@ -189,8 +189,8 @@ public final class ReloadingJSONProvider: Sendable {
config: ConfigReader,
bytesDecoder: some ConfigBytesFromStringDecoder = .base64,
secretsSpecifier: SecretsSpecifier<String, any Sendable> = .none,
logger: Logger? = nil,
metrics: (any MetricsFactory)? = nil
logger: Logger = Logger(label: "ReloadingJSONProvider"),
metrics: any MetricsFactory = MetricsSystem.factory
) async throws {
try await self.init(
filePath: config.requiredString(forKey: "filePath", as: FilePath.self),
Expand Down
24 changes: 12 additions & 12 deletions Sources/Configuration/Providers/YAML/ReloadingYAMLProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,16 @@ public final class ReloadingYAMLProvider: Sendable {
/// - pollInterval: The interval between file modification checks. Defaults to 15 seconds.
/// - bytesDecoder: The decoder used to convert string values to byte arrays.
/// - secretsSpecifier: Specifies which configuration values should be treated as secrets.
/// - logger: The logger instance to use, or nil to create a default one.
/// - metrics: The metrics factory to use, or nil to use a no-op implementation.
/// - logger: The logger instance to use.
/// - metrics: The metrics factory to use.
/// - Throws: If the file cannot be read or parsed, or if the YAML structure is invalid.
public convenience init(
filePath: FilePath,
pollInterval: Duration = .seconds(15),
bytesDecoder: some ConfigBytesFromStringDecoder = .base64,
secretsSpecifier: SecretsSpecifier<String, Void> = .none,
logger: Logger? = nil,
metrics: (any MetricsFactory)? = nil
logger: Logger = Logger(label: "ReloadingYAMLProvider"),
metrics: any MetricsFactory = MetricsSystem.factory
) async throws {
try await self.init(
filePath: filePath,
Expand All @@ -121,17 +121,17 @@ public final class ReloadingYAMLProvider: Sendable {
/// - bytesDecoder: A decoder of bytes from a string.
/// - secretsSpecifier: A secrets specifier in case some of the values should be treated as secret.
/// - fileSystem: The underlying file system.
/// - logger: The logger instance to use, or nil to create a default one.
/// - metrics: The metrics factory to use, or nil to use a no-op implementation.
/// - logger: The logger instance to use.
/// - metrics: The metrics factory to use.
/// - Throws: If the file cannot be read or parsed, or if the YAML structure is invalid.
internal init(
filePath: FilePath,
pollInterval: Duration,
bytesDecoder: some ConfigBytesFromStringDecoder,
secretsSpecifier: SecretsSpecifier<String, Void>,
fileSystem: some CommonProviderFileSystem,
logger: Logger?,
metrics: (any MetricsFactory)?
logger: Logger,
metrics: any MetricsFactory
) async throws {
self.core = try await ReloadingFileProviderCore(
filePath: filePath,
Expand Down Expand Up @@ -186,15 +186,15 @@ public final class ReloadingYAMLProvider: Sendable {
/// - config: The configuration reader containing the file path.
/// - bytesDecoder: The decoder used to convert string values to byte arrays.
/// - secretsSpecifier: Specifies which configuration values should be treated as secrets.
/// - logger: The logger instance to use, or nil to create a default one.
/// - metrics: The metrics factory to use, or nil to use a no-op implementation.
/// - logger: The logger instance to use.
/// - metrics: The metrics factory to use.
/// - Throws: If the file path is missing, or if the file cannot be read or parsed.
public convenience init(
config: ConfigReader,
bytesDecoder: some ConfigBytesFromStringDecoder = .base64,
secretsSpecifier: SecretsSpecifier<String, Void> = .none,
logger: Logger? = nil,
metrics: (any MetricsFactory)? = nil
logger: Logger = Logger(label: "ReloadingYAMLProvider"),
metrics: any MetricsFactory = MetricsSystem.factory
) async throws {
try await self.init(
filePath: config.requiredString(forKey: "filePath", as: FilePath.self),
Expand Down
5 changes: 3 additions & 2 deletions Tests/ConfigurationTests/ReloadingFileProviderCoreTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import ConfigurationTestingInternal
import Foundation
import ConfigurationTesting
import Logging
import Metrics
import ServiceLifecycle
import Synchronization
import SystemPackage
Expand Down Expand Up @@ -97,7 +98,7 @@ private func withTestProvider<R>(
providerName: "TestProvider",
fileSystem: fileSystem,
logger: .noop,
metrics: nil,
metrics: NOOPMetricsHandler.instance,
createSnapshot: { data in
try TestSnapshot(contents: String(decoding: data, as: UTF8.self))
}
Expand Down Expand Up @@ -155,7 +156,7 @@ struct CoreTests {
providerName: "TestProvider",
fileSystem: fileSystem,
logger: .noop,
metrics: nil,
metrics: NOOPMetricsHandler.instance,
createSnapshot: { data in
try TestSnapshot(contents: String(decoding: data, as: UTF8.self))
}
Expand Down