Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating logging a bit #364

Merged
merged 1 commit into from
Jun 10, 2024
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
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
Loading