Giter Club home page Giter Club logo

applicationinsights-kubernetes's Introduction

Microsoft Application Insights for Kubernetes

Nuget Downloads

Application Insights for Kubernetes enhances telemetries with K8s properties, works for .NET Core/.NET 6 applications in Kubernetes clusters.

Screenshot for Application Insights for Kubernetes enhanced telemetry

⚠️ Microsoft Application Insights for Kubernetes (this library) is designed to improve the functionality of Microsoft Application Insights. While it is possible to run Application Insights on a Kubernetes cluster without this library, it allows for Kubernetes-specific properties such as Pod-Name and Deployment to be included in all telemetry entries. Additionally, the library ensures that appropriate values are assigned, enabling advanced features like the Application Map to display multiple microservices or roles on a single Application Insights map.

Continuous Integration Status

Rolling Build Nightly Build
Rolling-Build Status Nightly-Build Status

Get Started

This is a quick guide for ASP.NET Core projects. If you want to run it in a worker, see the instructions in the Walk-through section.

Prerequisite

⚠️ For RBAC-enabled Kubernetes, make sure permissions are configured.

Instrument an ASP.NET Core application

  1. Add references to Application Insights SDK and Application Insights for Kubernetes by running:

    dotnet add package Microsoft.ApplicationInsights.AspNetCore
    dotnet add package Microsoft.ApplicationInsights.Kubernetes
  2. Enable Application Insights and Application Insights for Kubernetes Enricher in Startup.cs / Program.cs:

    public void ConfigureServices(IServiceCollection services)
    {
        ...
        services.AddApplicationInsightsTelemetry("----Your Application Insights Instrumentation Key ----");
        services.AddApplicationInsightsKubernetesEnricher();
        services.AddMvc();
        ...
    }
  3. Build the application in containers, then deploy the container with Kubernetes.

Notes: Those steps are not considered the best practice to set the instrumentation key for application insights. Refer to Enable Application Insights server-side telemetry for various options. Also, consider deploying Kubernetes Secrets to secure it. Refer to Deploy the application in Kubernetes for an example.

Walk-through with example code

Customize Configurations

Customize configurations are supported. There are several ways to customize the settings. For example:

  1. Using code:

    services.AddApplicationInsightsKubernetesEnricher(option=> {
        option.InitializationTimeout = TimeSpan.FromSeconds(15);
    });
  2. Using appsettings.json:

    {
        "Logging": {
            // ...
        },
        // Adding the following section to set the timeout to 15 seconds
        "AppInsightsForKubernetes": {
            "InitializationTimeout": "00:00:15"
        }
    }
  3. Using environment variables:

    AppInsightsForKubernetes__InitializationTimeout=3.1:12:15.34

    All the related configurations have to be put in a section named AppInsightsForKubernetes. The supported keys/values are listed below:

    Key Value/Types Default Value Description
    InitializationTimeout TimeSpan 00:02:00 Maximum time to wait for spinning up the container. Accepted format: [d.]hh:mm:ss[.fffffff].
    ClusterInfoRefreshInterval TimeSpan 00:10:00 For 3.x only. Get or sets how frequent to refresh the Kubernetes cluster properties.
    DisablePerformanceCounters Boolean false Deprecated. Sets to true to avoid adding performance counter telemetry initializer.

Tips: Refer to AppInsightsForKubernetesOptions.cs for the latest customization supported.

The configuration uses the ASP.NET Core conventions. Refer to Configuration in ASP.NET Core for more information.

Verify the cluster configuration (Linux Container only)

Use the troubleshooting image to verify the cluster is properly configured.

Learn more

Next step

Profile your application for performance improvement using Application Insights Profiler for Linux.

Contributing

Report issues

Please file bug, discussion or any other interesting topics in issues on GitHub.

Troubleshooting

Read the FAQ for common issues. When Microsoft.ApplicationInsights.Kubernetes doesn't work properly, you can turn on self-diagnostics to see the traces in Kubernetes' logs. Refer to How to enable self diagnostics for ApplicationInsights.Kubernetes for instructions.

Developing

Please refer the Develop Guide.


This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

applicationinsights-kubernetes's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

applicationinsights-kubernetes's Issues

Name for the method of EnableK8s()

In the pull request #60 , @nizarq think EnableK8s() is not a good name for API because K8s is not as official as Kubernetes.
Anyone think it bothers or not? Please suggest a better name if you agree. Let's make decision before it goes public - it will be way easier we change it for now.
Suggestion from @nizarq: EnableApplicationInsightsFoKubernetes()

Give the project a new name

aikubequery looks more like a codename. Let's give the project a new name like: ApplicationInsights.Kubernetes.

Verify the building system is still OK with the naming change.

When will be beta2 release?

Hello,
latest release on a nuget was in May 2017. As I can see we have some changes. Maybe it's time to release some beta2 version for dev who already invest sometime and tested this package in their apps earlier?

Daemonset/sidecar container?

So at the outset, I have only basic understanding of appinsights's data model. However, I'm currently working on porting a relatively mid sized codebase to .net core with the aim to run it on k8s. Also, I've just landed on your repo from google and a quick read through isn't very informative - however, it did bring up a question.

The question I have is that would it be possible to explore running this as a sidecar/daemonset in k8s - so that the actual code doesn't have to deal with keeping a buffer/flush it's log etc. Even better if this can also take an eventflow config and be responsible for pushing AI telemetry reliably.

Bump up .NET Core 1.x version from 1.3 to 1.6

The scenario of AI.K8s only works when AI.DependencyCollector 2.4 or above is there. Since AI.DependencyCollector 2.4 targets minimum of .netstandard 1.6, it doesn't make sense for AI.K8s to target framework lower than 1.6.
Besides, at this point, .netstandard 2.0 is available and 1.6 of .netstnadard shall become the stable version of .netstandard 1.x.

Application Insights Kubernetes failed to start.

I integrated application insights kubernetes plugin in my ASP.NET core web api project and deployed it on a kubernetes, but there was no metrics/stats on app-insights dashboard related to kubernetes. Then I enabled self diagnostics for ApplicationInsights.Kubernetes (link) and checked the logs and found that it throws an exception and then fails to start:

PS C:\WINDOWS\system32> kubectl logs todoappcore-1886517599-52jfh
info: K8sEnvInitializer[0]
      ApplicationInsights.Kubernetes.Version:1.0.0-beta1
crit: Microsoft.ApplicationInsights.Kubernetes.K8sEnvironment[0]
      System.InvalidCastException: Can't figure out docker id. Input: 11:blkio:/kubepods/besteffort/podaf692797-a1d6-11e7-a192-00155da0364d/3a65f1c8605ac1121e9a7002e7319a6929d8dee4c29b582e86d01d1e64d93a32
      10:net_cls:/kubepods/besteffort/podaf692797-a1d6-11e7-a192-00155da0364d/3a65f1c8605ac1121e9a7002e7319a6929d8dee4c29b582e86d01d1e64d93a32
      9:pids:/kubepods/besteffort/podaf692797-a1d6-11e7-a192-00155da0364d/3a65f1c8605ac1121e9a7002e7319a6929d8dee4c29b582e86d01d1e64d93a32
      8:memory:/kubepods/besteffort/podaf692797-a1d6-11e7-a192-00155da0364d/3a65f1c8605ac1121e9a7002e7319a6929d8dee4c29b582e86d01d1e64d93a32
      7:freezer:/kubepods/besteffort/podaf692797-a1d6-11e7-a192-00155da0364d/3a65f1c8605ac1121e9a7002e7319a6929d8dee4c29b582e86d01d1e64d93a32
      6:cpuset:/kubepods/besteffort/podaf692797-a1d6-11e7-a192-00155da0364d/3a65f1c8605ac1121e9a7002e7319a6929d8dee4c29b582e86d01d1e64d93a32
      5:devices:/kubepods/besteffort/podaf692797-a1d6-11e7-a192-00155da0364d/3a65f1c8605ac1121e9a7002e7319a6929d8dee4c29b582e86d01d1e64d93a32
      4:hugetlb:/kubepods/besteffort/podaf692797-a1d6-11e7-a192-00155da0364d/3a65f1c8605ac1121e9a7002e7319a6929d8dee4c29b582e86d01d1e64d93a32
      3:cpu,cpuacct:/kubepods/besteffort/podaf692797-a1d6-11e7-a192-00155da0364d/3a65f1c8605ac1121e9a7002e7319a6929d8dee4c29b582e86d01d1e64d93a32
      2:perf_event:/kubepods/besteffort/podaf692797-a1d6-11e7-a192-00155da0364d/3a65f1c8605ac1121e9a7002e7319a6929d8dee4c29b582e86d01d1e64d93a32
      1:name=systemd:/kubepods/besteffort/podaf692797-a1d6-11e7-a192-00155da0364d/3a65f1c8605ac1121e9a7002e7319a6929d8dee4c29b582e86d01d1e64d93a32
      . Pattern: cpu.+docker/(.*)$
         at Microsoft.ApplicationInsights.Kubernetes.KubeHttpClientSettingsProvider.FetchContainerId(String pathToCGroup)
         at Microsoft.ApplicationInsights.Kubernetes.KubeHttpClientSettingsProvider..ctor(ILoggerFactory loggerFactory, String pathToToken, String pathToCert, String pathToNamespace, String pathToCGroup, String
kubernetesServiceHost, String kubernetesServicePort)
         at Microsoft.ApplicationInsights.Kubernetes.K8sEnvironment.<CreateAsync>d__11.MoveNext()
fail: K8sEnvInitializer[0]
      Application Insights Kubernetes failed to start.
dbug: Microsoft.AspNetCore.Hosting.Internal.WebHost[3]
      Hosting starting
dbug: Microsoft.AspNetCore.Hosting.Internal.WebHost[4]
      Hosting started
Hosting environment: Production
Content root path: /app
Now listening on: http://+:80
Application started. Press Ctrl+C to shut down.

I have tried on a minikube cluster (kubernetes 1.7.0) and also tried on kubernetes cluster 1.6.6 on Azure Container Service as well.

Refactor the initialize process

  • Expose the initializer
  • Allow user to enable AI.K8s before or after user calls UseAI() or registered the service by themselves.

Update FxCop version

The referenced FxCop analyzer is out of date and is causing a lot of warnings. (1000+).
Bump up version to provide better code analysis experience.

Investigate exclude http request to K8s proxy being self-tracked

AI.K8s uses http requests to fetch K8s properties. These http requests are also recorded by AI sdk automatically, which usually is a noise to end user.
Investigate to see if we can provide an option to allow user to opt in these requests when only necessary.

HttpGet Readiness Probe causes a deadlock

I am using https://github.com/dotnet-architecture/HealthChecks.
When an HttpGet Readiness Probe is configured, either Application Insights Kubernetes fails to start, or the pod never gets to Ready.

Steps to reproduce:

add this to deployment.yaml:

readinessProbe:
  httpGet:
    path: /hc
    port: 80
    scheme: HTTP
  initialDelaySeconds: 130 #(10 seconds more than the default timeout)
  periodSeconds: 10
  failureThreshold: 10
  timeoutSeconds: 10

This will cause the pod to be ready after 130 seconds, but the logs show:

fail: Microsoft.ApplicationInsights.Kubernetes.K8sEnvironment[0]
Kubernetes info is not available within given time of 120000 ms.
fail: K8sEnvInitializer[0]
Application Insights Kubernetes failed to start.

When the probe is defined like this:

readinessProbe:
  httpGet:
    path: /hc
    port: 80
    scheme: HTTP
  initialDelaySeconds: 10 #(start probing after 10 seconds))
  periodSeconds: 10
  failureThreshold: 10
  timeoutSeconds: 10

the pod never reaches ready state and gives an error:

Readiness probe failed: Get http://xx.xxx.x.122:80/hc: dial tcp xx.xxx.x.122:80: getsockopt: connection refused

The logs show that the application never initialises further than this message:

trce: Microsoft.ApplicationInsights.Kubernetes.KubeHttpClientSettingsProvider[0]
System.Security.Cryptography.X509Certificates.X509Chain
trce: Microsoft.ApplicationInsights.Kubernetes.KubeHttpClientSettingsProvider[0]
RemoteCertificateChainErrors
trce: Microsoft.ApplicationInsights.Kubernetes.KubeHttpClientSettingsProvider[0]
ServerCert:
[Subject]
CN=apiserver

[Issuer]
CN=acsk8sca

[Serial Number]
XXXXXXXXXXXXX

[Not Before]
10/26/2017 00:00:00

[Not After]
10/26/2019 00:00:00

[Thumbprint]
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

dbug: Microsoft.ApplicationInsights.Kubernetes.KubeHttpClientSettingsProvider[0]
Issuer validation passed: CN=acsk8sca
dbug: Microsoft.ApplicationInsights.Kubernetes.KubeHttpClientSettingsProvider[0]
Server certificate validate date verification passed.
dbug: Microsoft.ApplicationInsights.Kubernetes.KubeHttpClientSettingsProvider[0]
Server certification custom validation successed.

A possible solution might be to wrap the initialisation in a Task.Run(), as is done for retrieving the version info in KubernetesModule.EnableKubernetes

Multi-targeting .NET Standard 1.3 and .NET Standard 2.0

Although .NET Standard 2.0 project shall be able to reference .NET Standard 1.3 implementations, it is beneficial to multi-targeting both .NET Standard 1.3 & .NET Standard 2.0 to make use of the new sets of APIs. This need to be done prior to supporting the new configuration settings in ASP.NET Core 2.0 applications.

Verify the telemetry initializer logic

When the data exists on the telemetry object already, is the last hit win or the first hit win? Refer to other telemetry initializers and fix when necessary.

Simply ms-build properties

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <!-- This variable for the package version is redundant -->
    <CIPackageVersion Condition=" '$(CIPackageVersion)' == ''">1.0.0-dev</CIPackageVersion>
    <!-- ... -->
    <Version>$(CIPackageVersion)</Version>
  • Remove the property.
  • Provide a better default value for version - maybe include yyyyMMdd that the local package can easily be identified.
  • Update CI to set the new variable.

Refactor the list entity

All list entities can be merged using generics.

  • EntityList : IEnumerable should do.

  • In the http client, we accepts parameter like GetAsync serialize the object into EntityList, return it as IEnumerable.

  • Unit tests.

Build a good README.md

  • Add badge for both rolling build and nightly build
  • Add get started section
  • Add contribution section

Unable to enable self diagnostics for ApplicationInsights.Kubernetes in ASP.NET Core 2.0

I am trying to configure ApplicationInsights Kubernetes plugin in my ASP.NET Core 2.0 application. I have followed the instructions and deployed the container image to kubernetes cluster (Azure Kubernetes Service with kubernetes 1.8.1 as well as on minikube with kubernetes 1.8.0). But I am unable to get any kubernetes related stats in the app-insights portal. I am trying to enable self diagnostics for ApplicationInsights.Kubernetes using the instructions here but its giving me error on line:

.ConfigureLogging(f => f.AddConsole(LogLevel.Trace))

The error is:
Error CS1503 Argument 2: cannot convert from 'Microsoft.Extensions.Logging.LogLevel' to 'System.Action<Microsoft.Extensions.Logging.Console.ConsoleLoggerOptions>'

It seems like the .net core 2.0 packages does not have these functions to add console. I have added below lines but still no kubernetes logs and no stats on app insight portal.

.ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Trace))

What could be the issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.