From bcf42dd97e7a7515775ac318adb95547971184a8 Mon Sep 17 00:00:00 2001 From: "kulbachnyi.v" Date: Mon, 25 Dec 2023 11:58:16 +0500 Subject: [PATCH 1/7] feat: Added configuration method for host name --- Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs | 9 ++++++++- Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt | 1 + Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs | 14 +++++++++++--- 3 files changed, 20 insertions(+), 4 deletions(-) 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(); From fd161defbc5362fa9f78fec258fcdc6791719fd6 Mon Sep 17 00:00:00 2001 From: "kulbachnyi.v" Date: Mon, 25 Dec 2023 12:45:09 +0500 Subject: [PATCH 2/7] fix: updated ReplicaInfoBuilder --- Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs b/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs index 553ce7c..aa7fc4b 100644 --- a/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs +++ b/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs @@ -11,12 +11,12 @@ namespace Vostok.ServiceDiscovery internal class ReplicaInfoBuilder : IReplicaInfoBuilder { private const string DependenciesDelimiter = ";"; - private readonly string host; private readonly int? processId; private readonly string baseDirectory; private readonly Dictionary properties = new Dictionary(); + private string host; private string processName; private string environment; @@ -34,13 +34,15 @@ internal class ReplicaInfoBuilder : IReplicaInfoBuilder private List dependencies; private TagCollection tags; + private bool useFQDN; private Func hostNameProvider; private ReplicaInfoBuilder(bool useFQDN) { environment = "default"; application = EnvironmentInfo.Application; - host = useFQDN ? hostNameProvider?.Invoke(useFQDN) ?? EnvironmentInfo.FQDN : EnvironmentInfo.Host; + this.useFQDN = useFQDN; + host = useFQDN ? EnvironmentInfo.FQDN : EnvironmentInfo.Host; processName = EnvironmentInfo.ProcessName; processId = EnvironmentInfo.ProcessId; baseDirectory = EnvironmentInfo.BaseDirectory; @@ -59,10 +61,13 @@ public static ServiceBeaconInfo Build(ReplicaInfoSetup setup, bool useFQDN) public ServiceBeaconInfo Build() { + if (hostNameProvider != null) + { + host = hostNameProvider(useFQDN); + } + url ??= BuildUrl(); - - if (replica == null) - replica = url?.ToString() ?? $"{host}({EnvironmentInfo.ProcessId})"; + replica ??= url.ToString(); if (url != null) { From bf5543a1cc64624068ac80294bd47ac779467946 Mon Sep 17 00:00:00 2001 From: "kulbachnyi.v" Date: Thu, 28 Dec 2023 10:31:16 +0500 Subject: [PATCH 3/7] fix: refactored ReplicaInfoBuilder --- Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs | 2 +- Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt | 2 +- Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs b/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs index 8b73a87..a2e301c 100644 --- a/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs +++ b/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs @@ -74,7 +74,7 @@ public interface IReplicaInfoBuilder /// Default value: null /// Should not be called in conjunction with . /// - IReplicaInfoBuilder SetupHostnameProvider([CanBeNull] Func hostNameProvider); + IReplicaInfoBuilder SetHostnameProvider([CanBeNull] Func hostNameProvider); /// /// Sets build commit hash. diff --git a/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt b/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt index 0eda7e1..09c08a7 100644 --- a/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt +++ b/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt @@ -1 +1 @@ -Vostok.ServiceDiscovery.IReplicaInfoBuilder.SetupHostnameProvider(System.Func hostNameProvider) -> Vostok.ServiceDiscovery.IReplicaInfoBuilder \ No newline at end of file +Vostok.ServiceDiscovery.IReplicaInfoBuilder.SetHostnameProvider(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 aa7fc4b..c269660 100644 --- a/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs +++ b/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs @@ -173,7 +173,7 @@ public IReplicaInfoBuilder SetUrlPath(string path) return this; } - public IReplicaInfoBuilder SetupHostnameProvider(Func hostNameProvider) + public IReplicaInfoBuilder SetHostnameProvider(Func hostNameProvider) { this.hostNameProvider = hostNameProvider; return this; From c306ac4a9aea950f404253c8e7fc31a67c727a48 Mon Sep 17 00:00:00 2001 From: "kulbachnyi.v" Date: Thu, 28 Dec 2023 10:42:42 +0500 Subject: [PATCH 4/7] fix: added test for SetHostNameProvider --- Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs b/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs index fe2773b..a2c91af 100644 --- a/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs +++ b/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs @@ -63,7 +63,8 @@ public void Should_be_configurable() .SetCommitHash("ASDF") .SetReleaseDate("released now") .SetDependencies(new List {"dep-a", "dep-b"}) - .SetTags(new TagCollection{"tag1", {"tag2", "value"}}), false); + .SetTags(new TagCollection{"tag1", {"tag2", "value"}}) + .SetHostnameProvider(useFqdn => "newHostName"), false); info.ReplicaInfo.Environment.Should().Be("custom-environment"); info.ReplicaInfo.Application.Should().Be("Vostok.App.1"); @@ -82,6 +83,8 @@ public void Should_be_configurable() properties[ReplicaInfoKeys.CommitHash].Should().Be("ASDF"); properties[ReplicaInfoKeys.ReleaseDate].Should().Be("released now"); properties[ReplicaInfoKeys.Dependencies].Should().Be("dep-a;dep-b"); + + properties[ReplicaInfoKeys.Host].Should().Be("newHostName"); } [Test] From 64576329ef7d822fca2f427ba0fec9d565a4d8d3 Mon Sep 17 00:00:00 2001 From: "kulbachnyi.v" Date: Fri, 29 Dec 2023 10:53:00 +0500 Subject: [PATCH 5/7] fix: refactored hostname provider for vpn --- .../ReplicaInfoBuilder_Tests.cs | 68 +++++++++++++++---- .../IReplicaInfoBuilder.cs | 2 +- .../PublicAPI.Unshipped.txt | 2 +- Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs | 15 ++-- 4 files changed, 64 insertions(+), 23 deletions(-) diff --git a/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs b/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs index a2c91af..815333c 100644 --- a/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs +++ b/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs @@ -63,13 +63,14 @@ public void Should_be_configurable() .SetCommitHash("ASDF") .SetReleaseDate("released now") .SetDependencies(new List {"dep-a", "dep-b"}) - .SetTags(new TagCollection{"tag1", {"tag2", "value"}}) - .SetHostnameProvider(useFqdn => "newHostName"), false); + .SetTags(new TagCollection {"tag1", {"tag2", "value"}}) + .SetVpnHostnameProvider(() => "newHostname"), + false); info.ReplicaInfo.Environment.Should().Be("custom-environment"); info.ReplicaInfo.Application.Should().Be("Vostok.App.1"); info.ReplicaInfo.Replica.Should().Be("https://github.com:123/vostok"); - info.Tags.Should().BeEquivalentTo(new TagCollection{"tag1", {"tag2", "value"}}); + info.Tags.Should().BeEquivalentTo(new TagCollection {"tag1", {"tag2", "value"}}); var properties = info.ReplicaInfo.Properties; @@ -84,20 +85,24 @@ public void Should_be_configurable() properties[ReplicaInfoKeys.ReleaseDate].Should().Be("released now"); properties[ReplicaInfoKeys.Dependencies].Should().Be("dep-a;dep-b"); - properties[ReplicaInfoKeys.Host].Should().Be("newHostName"); + properties[ReplicaInfoKeys.Host].Should().Be("newHostname"); } - [Test] - public void Should_build_url_from_parts() + [TestCase(null)] + [TestCase("newhostname")] + [TestCase("")] + public void Should_build_url_from_parts(string hostname) { var info = ReplicaInfoBuilder.Build( - setup => setup - .SetScheme("https") - .SetPort(123) - .SetUrlPath("vostok"), false) + setup => setup + .SetScheme("https") + .SetPort(123) + .SetUrlPath("vostok") + .SetVpnHostnameProvider(() => hostname), + false) .ReplicaInfo; - var host = EnvironmentInfo.Host.ToLowerInvariant(); + var host = string.IsNullOrEmpty(hostname) ? EnvironmentInfo.Host.ToLowerInvariant() : hostname; info.Replica.Should().Be($"https://{host}:123/vostok"); @@ -151,7 +156,8 @@ public void Should_add_properties() { builder.SetProperty("key1", "value1"); builder.SetProperty("key2", "value2"); - }, false); + }, + false); var properties = info.ReplicaInfo.Properties; properties["key1"].Should().Be("value1"); @@ -166,7 +172,8 @@ public void Should_rewrite_properties() { builder.SetProperty("key", "value1"); builder.SetProperty("key", "value2"); - }, false); + }, + false); var properties = info.ReplicaInfo.Properties; properties["key"].Should().Be("value2"); @@ -182,5 +189,40 @@ public void Should_rewrite_default_properties() info.ReplicaInfo.Replica.Should().Be($"{host}({Process.GetCurrentProcess().Id})"); info.ReplicaInfo.Properties[ReplicaInfoKeys.Replica].Should().Be("value"); } + + [Test] + public void Should_not_configure_hostname_when_uri_set() + { + var url = new UriBuilder + { + Scheme = "https", + Host = "github.com", + Port = 123, + Path = "vostok" + }.Uri; + + var info = ReplicaInfoBuilder.Build( + setup => setup + .SetUrl(url) + .SetVpnHostnameProvider(() => "newHostname"), + false + ); + + info.ReplicaInfo.Replica.Should().Be("https://github.com:123/vostok"); + } + + [Test] + public void Should_configure_hostname_when_uri_not_set() + { + var info = ReplicaInfoBuilder.Build( + setup => setup + .SetUrl(null) + .SetPort(123) + .SetVpnHostnameProvider(() => "newhostname"), + false + ); + + info.ReplicaInfo.Replica.Should().Be("http://newhostname:123/"); + } } } \ No newline at end of file diff --git a/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs b/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs index a2e301c..d942798 100644 --- a/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs +++ b/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs @@ -74,7 +74,7 @@ public interface IReplicaInfoBuilder /// Default value: null /// Should not be called in conjunction with . /// - IReplicaInfoBuilder SetHostnameProvider([CanBeNull] Func hostNameProvider); + IReplicaInfoBuilder SetVpnHostnameProvider([CanBeNull] Func vpnHostnameProvider); /// /// Sets build commit hash. diff --git a/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt b/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt index 09c08a7..58e6860 100644 --- a/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt +++ b/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt @@ -1 +1 @@ -Vostok.ServiceDiscovery.IReplicaInfoBuilder.SetHostnameProvider(System.Func hostNameProvider) -> Vostok.ServiceDiscovery.IReplicaInfoBuilder \ No newline at end of file +Vostok.ServiceDiscovery.IReplicaInfoBuilder.SetVpnHostnameProvider(System.Func vpnHostnameProvider) -> Vostok.ServiceDiscovery.IReplicaInfoBuilder \ No newline at end of file diff --git a/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs b/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs index c269660..43eadbb 100644 --- a/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs +++ b/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs @@ -34,14 +34,12 @@ internal class ReplicaInfoBuilder : IReplicaInfoBuilder private List dependencies; private TagCollection tags; - private bool useFQDN; - private Func hostNameProvider; + private Func vpnHostnameProvider; private ReplicaInfoBuilder(bool useFQDN) { environment = "default"; application = EnvironmentInfo.Application; - this.useFQDN = useFQDN; host = useFQDN ? EnvironmentInfo.FQDN : EnvironmentInfo.Host; processName = EnvironmentInfo.ProcessName; processId = EnvironmentInfo.ProcessId; @@ -61,11 +59,12 @@ public static ServiceBeaconInfo Build(ReplicaInfoSetup setup, bool useFQDN) public ServiceBeaconInfo Build() { - if (hostNameProvider != null) + var vpnHostname = vpnHostnameProvider.Invoke(); + if (!string.IsNullOrEmpty(vpnHostname)) { - host = hostNameProvider(useFQDN); + host = vpnHostname; } - + url ??= BuildUrl(); replica ??= url.ToString(); @@ -173,9 +172,9 @@ public IReplicaInfoBuilder SetUrlPath(string path) return this; } - public IReplicaInfoBuilder SetHostnameProvider(Func hostNameProvider) + public IReplicaInfoBuilder SetVpnHostnameProvider(Func vpnHostnameProvider) { - this.hostNameProvider = hostNameProvider; + this.vpnHostnameProvider = vpnHostnameProvider; return this; } From 68f6b6fa6f032c168710ed34b3a93c713635bf31 Mon Sep 17 00:00:00 2001 From: "kulbachnyi.v" Date: Fri, 29 Dec 2023 14:06:02 +0500 Subject: [PATCH 6/7] fix: refactored hostname provider --- .../ReplicaInfoBuilder_Tests.cs | 46 +++++++++++-------- .../IReplicaInfoBuilder.cs | 2 +- .../PublicAPI.Unshipped.txt | 2 +- Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs | 10 ++-- 4 files changed, 35 insertions(+), 25 deletions(-) diff --git a/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs b/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs index 815333c..fef0da7 100644 --- a/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs +++ b/Vostok.ServiceDiscovery.Tests/ReplicaInfoBuilder_Tests.cs @@ -64,7 +64,7 @@ public void Should_be_configurable() .SetReleaseDate("released now") .SetDependencies(new List {"dep-a", "dep-b"}) .SetTags(new TagCollection {"tag1", {"tag2", "value"}}) - .SetVpnHostnameProvider(() => "newHostname"), + .SetHostnameProvider(() => "newHostname"), false); info.ReplicaInfo.Environment.Should().Be("custom-environment"); @@ -88,21 +88,19 @@ public void Should_be_configurable() properties[ReplicaInfoKeys.Host].Should().Be("newHostname"); } - [TestCase(null)] - [TestCase("newhostname")] - [TestCase("")] - public void Should_build_url_from_parts(string hostname) + [Test] + public void Should_build_url_from_parts() { var info = ReplicaInfoBuilder.Build( setup => setup .SetScheme("https") .SetPort(123) .SetUrlPath("vostok") - .SetVpnHostnameProvider(() => hostname), + .SetHostnameProvider(() => "testhost"), false) .ReplicaInfo; - var host = string.IsNullOrEmpty(hostname) ? EnvironmentInfo.Host.ToLowerInvariant() : hostname; + var host = "testhost"; info.Replica.Should().Be($"https://{host}:123/vostok"); @@ -204,25 +202,37 @@ public void Should_not_configure_hostname_when_uri_set() var info = ReplicaInfoBuilder.Build( setup => setup .SetUrl(url) - .SetVpnHostnameProvider(() => "newHostname"), + .SetHostnameProvider(() => "newHostname"), false ); info.ReplicaInfo.Replica.Should().Be("https://github.com:123/vostok"); } - [Test] - public void Should_configure_hostname_when_uri_not_set() + [TestCase(null)] + [TestCase("newHostname")] + [TestCase("")] + public void Should_correctly_build_url_with_hostname_provider(string hostname) { var info = ReplicaInfoBuilder.Build( - setup => setup - .SetUrl(null) - .SetPort(123) - .SetVpnHostnameProvider(() => "newhostname"), - false - ); - - info.ReplicaInfo.Replica.Should().Be("http://newhostname:123/"); + setup => setup + .SetScheme("https") + .SetPort(123) + .SetHostnameProvider(() => hostname), + false) + .ReplicaInfo; + + var expectedHostname = string.IsNullOrEmpty(hostname) ? EnvironmentInfo.Host : hostname; + var host = expectedHostname.ToLowerInvariant(); + + info.Replica.Should().Be($"https://{host}:123/"); + + var properties = info.Properties; + + properties[ReplicaInfoKeys.Replica].Should().Be($"https://{host}:123/"); + + properties[ReplicaInfoKeys.Url].Should().BeEquivalentTo($"https://{host}:123/"); + properties[ReplicaInfoKeys.Host].Should().Be(expectedHostname); } } } \ No newline at end of file diff --git a/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs b/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs index d942798..bd559cf 100644 --- a/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs +++ b/Vostok.ServiceDiscovery/IReplicaInfoBuilder.cs @@ -74,7 +74,7 @@ public interface IReplicaInfoBuilder /// Default value: null /// Should not be called in conjunction with . /// - IReplicaInfoBuilder SetVpnHostnameProvider([CanBeNull] Func vpnHostnameProvider); + IReplicaInfoBuilder SetHostnameProvider([CanBeNull] Func vpnHostnameProvider); /// /// Sets build commit hash. diff --git a/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt b/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt index 58e6860..69cf9fd 100644 --- a/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt +++ b/Vostok.ServiceDiscovery/PublicAPI.Unshipped.txt @@ -1 +1 @@ -Vostok.ServiceDiscovery.IReplicaInfoBuilder.SetVpnHostnameProvider(System.Func vpnHostnameProvider) -> Vostok.ServiceDiscovery.IReplicaInfoBuilder \ No newline at end of file +Vostok.ServiceDiscovery.IReplicaInfoBuilder.SetHostnameProvider(System.Func vpnHostnameProvider) -> Vostok.ServiceDiscovery.IReplicaInfoBuilder \ No newline at end of file diff --git a/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs b/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs index 43eadbb..3e9c574 100644 --- a/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs +++ b/Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs @@ -34,7 +34,7 @@ internal class ReplicaInfoBuilder : IReplicaInfoBuilder private List dependencies; private TagCollection tags; - private Func vpnHostnameProvider; + private Func hostnameProvider; private ReplicaInfoBuilder(bool useFQDN) { @@ -59,14 +59,14 @@ public static ServiceBeaconInfo Build(ReplicaInfoSetup setup, bool useFQDN) public ServiceBeaconInfo Build() { - var vpnHostname = vpnHostnameProvider.Invoke(); + var vpnHostname = hostnameProvider?.Invoke(); if (!string.IsNullOrEmpty(vpnHostname)) { host = vpnHostname; } url ??= BuildUrl(); - replica ??= url.ToString(); + replica ??= url?.ToString() ?? $"{host}({EnvironmentInfo.ProcessId})"; if (url != null) { @@ -172,9 +172,9 @@ public IReplicaInfoBuilder SetUrlPath(string path) return this; } - public IReplicaInfoBuilder SetVpnHostnameProvider(Func vpnHostnameProvider) + public IReplicaInfoBuilder SetHostnameProvider(Func vpnHostnameProvider) { - this.vpnHostnameProvider = vpnHostnameProvider; + this.hostnameProvider = vpnHostnameProvider; return this; } From e99526f90d26b6b227dbdcadffd7b655c7012995 Mon Sep 17 00:00:00 2001 From: "kulbachnyi.v" Date: Wed, 7 Feb 2024 11:09:50 +0500 Subject: [PATCH 7/7] fix: update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index fc31c76..1296e3e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.1.22 (07-02-2024) + +Added method `SetHostnameProvider` for configuring hostname in `IReplicaInfoBuilder` + ## 0.1.21 (31-08-2022): Added missing `ExecutionContext.SuppressFlow` for long-running tasks.