Skip to content

Commit

Permalink
Update logging a bit (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaomi7732 authored Jun 10, 2024
1 parent 80439e5 commit f610fc4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ public bool TryBackFillContainerId(V1Pod pod, out V1ContainerStatus? containerSt
_logger.LogDebug(FormattableString.Invariant($"Select container by environment variable containerName: {containerName}"));
containerStatus = containerStatuses.FirstOrDefault(c => string.Equals(c.Name, containerName, StringComparison.Ordinal));
if (containerStatus is not null)
{
{
_logger.LogDebug(FormattableString.Invariant($"Selected container by container.name property container id: {containerStatus.ContainerID}"));
}

}
if (containerStatus is not null)
{
_logger.LogInformation(FormattableString.Invariant($"Selected container {containerStatus.Name} container id: {containerStatus.ContainerID}"));
_logger.LogInformation(FormattableString.Invariant($"Selected container id: {containerStatus.ContainerID}, name: {containerStatus.Name}"));

using (IServiceScope scope = _serviceScopeFactory.CreateScope())
{
Expand All @@ -96,7 +96,7 @@ private bool TryGetContainerId(out string? containerId)
{
if (provider.TryGetMyContainerId(out containerId))
{
_logger.LogInformation(FormattableString.Invariant($"Get container id by provider: {containerId}"));
_logger.LogInformation(FormattableString.Invariant($"Got container id {containerId} by provider: {provider.GetType().Name}"));
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,15 +59,17 @@ public async Task<bool> IsContainerReadyAsync(CancellationToken cancellationToke
return null;
}

// If there's no container id provided by the container id holder, at this moment, try backfill
// Container Id is null. There's no container id provided by the container id holder, try backfill.

// Give out warnings on Linux in case the auto detect has a bug.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
_logger.LogWarning("Can't fetch container id. Container id info will be missing. Please file an issue at https://github.com/microsoft/ApplicationInsights-Kubernetes/issues.");
_logger.LogWarning("Failed to auto detect container id. Will try back-filling. Please file an issue at https://github.com/microsoft/ApplicationInsights-Kubernetes/issues for investigation.");
}

if (_containerIdHolder.TryBackFillContainerId(myPod, out V1ContainerStatus? inferredContainerStatus))
{
_logger.LogInformation("Backfill container id succeeded. Container id: {0}", inferredContainerStatus?.ContainerID ?? "Empty");
// Back fill success, return the status.
return inferredContainerStatus;
}
Expand All @@ -84,7 +86,7 @@ private bool IsContainerStatusReady(V1ContainerStatus containerStatus)

public async Task<V1ContainerStatus?> WaitContainerReadyAsync(CancellationToken cancellationToken)
{
while(true)
while (true)
{
cancellationToken.ThrowIfCancellationRequested();

Expand Down

0 comments on commit f610fc4

Please sign in to comment.