Comments (15)
Pod can be recreate with the same name, but there can only be one with the same name at a time. Object Names and IDs
If I tested it right... if Container Id missing then Application Insight not showing "Cloud Role Name".
But is show and populate this custom properties
Kubernetes.Node.Name
Kubernetes.Pod.Name
Kubernetes.Pod.Namespace
Kubernetes.Node.ID
Kubernetes.Deployment.Name
Kubernetes.Pod.ID
Kubernetes.ReplicaSet.Name
Kubernetes.Pod.Labels
from applicationinsights-kubernetes.
@TTmaister your change has been released:
https://www.nuget.org/packages/Microsoft.ApplicationInsights.Kubernetes/6.1.1-beta2
Let me know if that unblocks you. Thank you for your contribution!
Works as expected.
- One container no need for environment variable to get "Cloud Role Name" visible.
- More than one container and ContainerName environment variable is not present "Cloud Role Name" not visible.
- Multiple containers and ContainerName environment variable is preset "Cloud Role Name" visible.
@xiaomi7732 Maybe this should be documented to project readme.
from applicationinsights-kubernetes.
Hey @Ismael-Pep, thanks for the inquiry. Here's the new package is released today:
https://www.nuget.org/packages/Microsoft.ApplicationInsights.Kubernetes/6.1.1
from applicationinsights-kubernetes.
Hi @TTmaister, this is a known issue because of the implementations of docker engines. There has been a related issue #290.
Please check out the design doc here for the container id providers: https://github.com/microsoft/ApplicationInsights-Kubernetes/wiki/Design-for-ContainerIdProviders
That said, 2 questions for you:
-
Is the container id anywhere in the
mountinfo
you shared? If it is, we might be able to append another container id providers for your case. -
Is it possible for you to set up the environment variable for container id as mentioned in the design doc to workaround the issue? For example:
ContainerId=my-container-id
.
Any proposal for how to make this more adaptive is super-welcome!
BTW, just FYI, here's a lengthy stackoverflow discussion on the topic:
https://stackoverflow.com/questions/20995351/how-can-i-get-docker-linux-container-information-from-within-the-container-itsel/72565733#72565733
And an open standard issue:
opencontainers/runtime-spec#1105
from applicationinsights-kubernetes.
-
Container ID was 34bc656c1739fe713a867e18cc307f96e6fcba3cf89755db31b3c837f9d137f5. The answer is that there is no container id visible in mountinfo.
-
Possibly I can set the container id in the environment variables, but I don't know how to do it in the Kubernetes Deployment yaml so that each pod has its own ID. Does it have to be the same as what the Kubernetes Api provides.
from applicationinsights-kubernetes.
Hey @TTmaister, thanks for providing the information. Unfortunately, without container id anywhere in the container, we won't have the magic to somehow make it available.
Manually set the environment would probably be the only way that will provide full enhancement.
I don't know what will happen if you set container id to a mismatched value. That is an interesting idea. I assume you could set the environment variable to a random value for identification of the instances, but will it provide too much value? (pods comes and goes, and if the container id is random, why bother?)
That said, could you please help me understand what the telemetry looks like on your end? I assume container id missing but everything else, like podName
, node
info should be there on the events, does that align with what you see?
from applicationinsights-kubernetes.
Application Insight is missing all the data brought by the plugin. I can see in Application Insight that the POD requests information about the POD from the Kubernetes API and gets the response http200.
from applicationinsights-kubernetes.
Hey @xiaomi7732
Does it make any sense to change the ContainerIdHolder class to be able to parse the ContainerName variable from the environment variables.
And then filtter ContainerStatus by ContainerName
if (containerStatuses is not null && containerStatuses.Count > 1)
{
string? containerName = Environment.GetEnvironmentVariable("ContainerName");
containerStatus = containerStatuses.FirstOrDefault(c => c.Name == containerName);
_logger.LogInformation(FormattableString.Invariant($"Use the only container inside the pod for container id: {containerStatus.ContainerID}"));
using (IServiceScope scope = _serviceScopeFactory.CreateScope())
{
IContainerIdNormalizer normalizer = scope.ServiceProvider.GetRequiredService<IContainerIdNormalizer>();
if (normalizer.TryNormalize(containerStatus.ContainerID, out string? normalizedContainerId))
{
_containerId = normalizedContainerId;
return true;
}
}
_logger.LogError(FormattableString.Invariant($"Normalization failed for container id: {containerStatus.ContainerID}"));
}
ContinerName can be defined as environment variable Kubernetes Deployment yaml.
env:
- name: ContainerName
valueFrom:
fieldRef:
fieldPath: metadata.labels['app']
Or some other label. We have set "app" label for all deployments.
from applicationinsights-kubernetes.
Hi @TTmaister, using ContainerName
for matching seem like an approach. I think we should peruse it when time permits. Do you know is pod name always unique?
With regarding what is going on, I think I see it. Container id was supposed to be optional, but it is required - in between several iterations to support .NET 6 and the latest K8s SDK. See below for the details:
It was like this, there had been a note to allow empty container id.
// Notes: It is still possible for the optional container id to be empty at this point, the following method needs to handle the case.
if (!await SpinWaitContainerReadyAsync(timeoutAt, queryClient, myPod, containerId, cancellationToken).ConfigureAwait(false))
{
_logger.LogError(Invariant($"Kubernetes info is not available before the timeout at {timeoutAt}."));
return null;
}
And in the implementation, this is the logic to allow empty container id:
if (!string.IsNullOrEmpty(myContainerId))
{
// Check targeted container status
readyToGo = IsContainerReady(podInfo.GetContainerStatus(myContainerId));
}
else
{
_logger.LogWarning("No container id available. Fallback to use the any container for status checking.");
readyToGo = podInfo.GetAllContainerStatus().Any(s => IsContainerReady(s));
}
And it is like this now, meaning optional container id is not allowed:
public async Task<bool> IsContainerReadyAsync(CancellationToken cancellationToken)
{
V1ContainerStatus? myContainerStatus = await GetMyContainerStatusAsync(cancellationToken).ConfigureAwait(false);
if (myContainerStatus is not null)
{
return IsContainerStatusReady(myContainerStatus);
}
return false;
}
That doesn't agree with the design that I shared earlier and shall be treated as a bug. Will it unblock you if I make it optional again?
from applicationinsights-kubernetes.
That is correct. FYI, the line of code:
from applicationinsights-kubernetes.
I think there could be 2 fixes:
And I inspected various options to back fill container id, and I think using container name is a very good idea. It might worth a bit documentation but could be useful as an alternative to container ids.
@TTmaister are you interested to submit a PR for it? Or I can prepare a PR if you don't have the time.
BTW, if you are interested, please fork this repository, and branching off your own fork since this repository has been locked down and nobody could PR into it directly. :-)
from applicationinsights-kubernetes.
@TTmaister your change has been released:
https://www.nuget.org/packages/Microsoft.ApplicationInsights.Kubernetes/6.1.1-beta2
Let me know if that unblocks you. Thank you for your contribution!
from applicationinsights-kubernetes.
@TTmaister, thanks for the verification! I will update the wiki. I'll keep this issue open until the stable version of 6.1.1 got released.
from applicationinsights-kubernetes.
A FAQ is added:
https://github.com/microsoft/ApplicationInsights-Kubernetes/wiki/FAQ, pointing to the wiki: How to set container name manually.
from applicationinsights-kubernetes.
Is there an Eta on when the version 6.1.1 will be released?, Thx!
from applicationinsights-kubernetes.
Related Issues (20)
- [Investigation] Make calling into ExecuteAsync idempotent HOT 2
- Compliance: Unit test SDK depends on Newtonsoft.Json 9.0.1 HOT 2
- AKS no telemetry HOT 3
- Upgrade KubernetesClient to >= 10.0.16 to remove dependency on System.IO.Abstractions HOT 16
- backlog
- Add wiki for supporting Azure Function in K8s HOT 1
- Use AKS instead of local kubernetes - How HOT 4
- No insight output as indicated in Zero Code light up Example HOT 4
- Can I use DefaultAzureCredential with Zero User Code Lightup? HOT 5
- Enhancement: Capture container image name HOT 6
- Investigation: Using a label to locate the current container HOT 1
- Decouple Enhancement and container readiness HOT 2
- Cannot get pod info because of proxy configuration HOT 9
- As of now the package doesn HOT 1
- As of now the package doesn't seem to add the properties anymore? HOT 3
- Can't register Enrichers when using KeyedServices HOT 1
- Upgrade of `KubernetesClient` dependency HOT 18
- how to customize k8s properties name HOT 3
- Warning in pod logs re failed to get container id HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from applicationinsights-kubernetes.