Closed qbdev-kr closed 1 year ago
@xiaomi7732 . Tagging you as I saw you made a recent PR to another example in this repo.
Hey, @qbdev-kr I'll help troubleshoot. I have several questions after reading the code, could you please help me understand them:
services.AddApplicationInsightsKubernetesEnricher(diagnosticLogLevel: LogLevel.Trace); // Use trace level than information level.
⚠️ You might have access tokens displayed in your logs, please redact before posting.
BTW, due to a recent change, you do NOT need the observer to turn on diagnostic traces any more, so you could remove these lines if you are using 3.0+ (or even later version in 2.x)
// These are deprecated in the later versions
var observer = new ApplicationInsightsKubernetesDiagnosticObserver(DiagnosticLogLevel.Trace);
ApplicationInsightsKubernetesDiagnosticSource.Instance.Observable.SubscribeWithAdapter(observer);
// Set the log level in `AddApplicationInsightsKubernetesEnricher` instead, which you already did.
Hi @xiaomi7732 Thank you for your fast response. I have included some info below.
Packages Info:
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging.ApplicationInsights" Version="2.21.0" />
<PackageReference Include="Microsoft.ApplicationInsights.Kubernetes" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="6.0.0" />
<PackageReference Include="Microsoft.ApplicationInsights" Version="2.21.0" />
Building a simple console application to consume data from cosmosDB client and loading data back into CosmosDB with some changes. Using Microsoft.Azure.Cosmos for this. Does not use a hosting technology like ASP.NET core or Worker service - No. This console application is kicked off like a cron job in AKS but it shouldn't matter.
Setting Diagnostic level to trace and redacting some internal logs and i will share here shortly.
I have removed the DiagnosticObserver code lines as the ApplicationInsights.Kubernetes package is 3.0
Still waiting for the log to confirm, but here's my I hunch: there's a design hole in 3.x that we are relying on the HostedService to bootstrap the fetch of K8s info.
And the console application by default doesn't have a host to start the backend services - thus nothing triggers the fetch of the k8s info.
I'll do some quick checks while waiting for the logs to confirm. Thank you @qbdev-kr for the report.
@xiaomi7732 - Logs From the Pod the job is running in. The console app is executed like a cron job on demand.
Is there something specific I can look into? Will it help if I call a http end point and we see some logs that way?
PS C:\Windows\system32> kubectl -n kube-system logs -f
I redacted all code and put this log in a loop like this and it throws an exception when iterator limit is reached.
IServiceProvider serviceProvider = services.BuildServiceProvider();
ILogger<Program> logger = serviceProvider.GetRequiredService<ILogger<Program>>();
try
{
logger.LogInformation("[DEMO] Skip Setting Config Variable ...");
// redacted
int count = 0;
int maxCount = 20;
await Task.Delay(TimeSpan.FromSeconds(30));
// for loop in-place of redacted code
for (int i =0; i<= maxCount; i++)
{
count++;
if (count > maxCount)
throw new Exception("[DEMO] Forced Exception by User - Testing Kubernetes of type K8s");
logger.LogInformation("[DEMO] Info Logged is made by User");
channel.Flush();
await Task.Delay(TimeSpan.FromSeconds(15));
}
}
catch (Exception ex)
{
logger.LogError(ex, "[DEMO] Application failed");
Thread.Sleep(35000);
}
finally
{
logger.LogInformation("[Demo] Job end.");
channel.Flush();
Thread.Sleep(10000);
}
@xiaomi7732 Would it help if I use a HostBuilder to instantiate the DI steps and run the Host Async? Is that what you meant in your earlier comment.
@qbdev-kr I see.
It is a bug that the background service to fetch k8s info was never bootstrapped. Let me see how to support the console application.
I see several approaches for you:
Worker
:
I'll use this issue as the bug tracking and I'll keep it open until the issue is addressed.
@xiaomi7732 , Thank you for giving direction and tracking this. I have some follow up questions,
Microsoft.ApplicationInsights.Kubernetes.2.x
doesn't require hosted service;Hey @qbdev-kr,
The fix is available now. Please follow this updated example: Program.cs, specifically, call serviceProvider.StartApplicationInsightsKubernetesEnricher()
after you call services.AddApplicationInsightsKubernetesEnricher()
.
I tested it locally and it worked for me. Please give it a try. At the same time, let me know if there's any feedback or any change you want.
Package: https://www.nuget.org/packages/Microsoft.ApplicationInsights.Kubernetes/3.1.0-beta2
@xiaomi7732 Thank you so much.
I will add this package and share the results with you.
Hi @xiaomi7732, Thank you so much for the suggested change. I Can confirm, after including the change below and using the 3.1.0-beta2 package
serviceProvider.StartApplicationInsightsKubernetesEnricher()
the Enriched Kubernetes data is populating under custom Dimension.
These are the kubectl logs =>
Thank you for your help, I wanted to ask if you know, how can I see the replicaSet and the deployment name property? I see all but these two.
Cool. Thanks for getting back and confirming the fix. A quick thing to check is cluster role binding. See docs here: https://github.com/microsoft/ApplicationInsights-Kubernetes/blob/develop/docs/configure-rbac-permissions.md
I'll close this issue since this topic is completed. Feel free to file another issue if you would like to have another troubleshooting for replicaSet/deployment name after you confirm the proper rbac permissions are granted.
@xiaomi7732 , I noticed the package I was using per recommendation is deprecated, are the changes now part of a different package version?
https://www.nuget.org/packages/Microsoft.ApplicationInsights.Kubernetes/3.1.0-beta2
Yes, it is out of beta now: https://www.nuget.org/packages/Microsoft.ApplicationInsights.Kubernetes/3.1.0.
Just in case, we go with semver. And by the rule: 3.0.0 < 3.1.0-betaN < 3.1.0.
@xiaomi7732, Thank you for the update and your Contribution!
Goal
I want to be able to see Enriched Kubernetes Info coming into App Insights
Issue Summary
I consistently am seeing the trace,
Application Insights for Kubernetes telemetry initializer is used but the content has not ready yet.![image](https://user-images.githubusercontent.com/114493252/197005241-097f3b03-8fa5-463d-8897-311067bfcbc7.png)
What I have done
I have used https://github.com/microsoft/ApplicationInsights-Kubernetes/issues/187 to help me out by adding delay etc. But that has not helped me and i am also deploying to AKS.
AKS
AKS is used to host a docker image from this code. The console app is calling an await method to run some ETL process and the total job completes in 2 minutes.
Usage
The code snipper example below is identical to the BasicConsoleAppILoggerApplication in .NET 6 console application with all needed packages installed.