diff --git a/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs b/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs index b4b0ee3..8b73a87 100644 --- a/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs +++ b/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs @@ -69,6 +69,13 @@ public interface IReplicaInfoBuilder [NotNull] IReplicaInfoBuilder SetUrlPath([CanBeNull] string path); + /// + /// Sets configuration for HostnameProvider. + /// Default value: null + /// Should not be called in conjunction with . + /// + IReplicaInfoBuilder SetupHostnameProvider([CanBeNull] Func hostNameProvider); + /// /// Sets build commit hash. /// By default, it will be parsed from AssemblyTitle attribute of entry assembly. @@ -103,7 +110,7 @@ public interface IReplicaInfoBuilder /// [NotNull] IReplicaInfoBuilder SetProperty([NotNull] string key, [CanBeNull] string value); - + /// /// Sets a custom beacon , which can be overwritten only by restarting the beacon. /// diff --git a/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt b/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt index e69de29..0eda7e1 100644 --- a/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt +++ b/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt @@ -0,0 +1 @@ +Vostok.ServiceDiscovery.IReplicaInfoBuilder.SetupHostnameProvider(System.Func hostNameProvider) -> Vostok.ServiceDiscovery.IReplicaInfoBuilder \ No newline at end of file diff --git a/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs b/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs index 9f3bf53..553ce7c 100644 --- a/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs +++ b/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs @@ -34,11 +34,13 @@ internal class ReplicaInfoBuilder : IReplicaInfoBuilder private List dependencies; private TagCollection tags; + private Func hostNameProvider; + private ReplicaInfoBuilder(bool useFQDN) { environment = "default"; application = EnvironmentInfo.Application; - host = useFQDN ? EnvironmentInfo.FQDN : EnvironmentInfo.Host; + host = useFQDN ? hostNameProvider?.Invoke(useFQDN) ?? EnvironmentInfo.FQDN : EnvironmentInfo.Host; processName = EnvironmentInfo.ProcessName; processId = EnvironmentInfo.ProcessId; baseDirectory = EnvironmentInfo.BaseDirectory; @@ -57,7 +59,7 @@ public static ServiceBeaconInfo Build(ReplicaInfoSetup setup, bool useFQDN) public ServiceBeaconInfo Build() { - url = url ?? BuildUrl(); + url ??= BuildUrl(); if (replica == null) replica = url?.ToString() ?? $"{host}({EnvironmentInfo.ProcessId})"; @@ -166,6 +168,12 @@ public IReplicaInfoBuilder SetUrlPath(string path) return this; } + public IReplicaInfoBuilder SetupHostnameProvider(Func hostNameProvider) + { + this.hostNameProvider = hostNameProvider; + return this; + } + public IReplicaInfoBuilder SetCommitHash(string commitHash) { this.commitHash = commitHash; @@ -195,7 +203,7 @@ public IReplicaInfoBuilder SetProperty(string key, string value) properties[key ?? throw new ArgumentNullException(nameof(key))] = value; return this; } - + public IReplicaInfoBuilder SetTags(TagCollection tags) { this.tags = tags ?? new TagCollection();