Skip to content

Commit

Permalink
fix: updated ReplicaInfoBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
kulbachnyi.v committed Dec 25, 2023
1 parent bcf42dd commit fd161de
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Vostok.ServiceDiscovery/ReplicaInfoBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string> properties = new Dictionary<string, string>();

private string host;
private string processName;

private string environment;
Expand All @@ -34,13 +34,15 @@ internal class ReplicaInfoBuilder : IReplicaInfoBuilder
private List<string> dependencies;
private TagCollection tags;

private bool useFQDN;
private Func<bool, string> 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;
Expand All @@ -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)
{
Expand Down

0 comments on commit fd161de

Please sign in to comment.