-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop'
- Loading branch information
Showing
17 changed files
with
269 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/ApplicationInsights.Kubernetes/Debuggings/K8sDebuggingEnvironmentFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.ApplicationInsights.Kubernetes.Entities; | ||
|
||
namespace Microsoft.ApplicationInsights.Kubernetes.Debugging | ||
{ | ||
internal class K8sDebuggingEnvironmentFactory : IK8sEnvironmentFactory | ||
{ | ||
public Task<K8sEnvironment> CreateAsync(TimeSpan timeout) | ||
{ | ||
return Task.FromResult(new K8sEnvironment() | ||
{ | ||
ContainerID = KubeHttpDebuggingClientSettings.FakeContainerId, | ||
myContainerStatus = new ContainerStatus() | ||
{ | ||
ContainerID = KubeHttpDebuggingClientSettings.FakeContainerId, | ||
Image = nameof(ContainerStatus.Image), | ||
ImageID = nameof(ContainerStatus.ImageID), | ||
Name = nameof(ContainerStatus.Name), | ||
Ready = true, | ||
}, | ||
myDeployment = new K8sDeployment() | ||
{ | ||
Metadata = new K8sDeploymentMetadata() | ||
{ | ||
Labels = new Dictionary<string, string>() { { "app", "stub" } }, | ||
Name = nameof(K8sDeploymentMetadata.Name), | ||
Uid = nameof(K8sDeploymentMetadata.Uid), | ||
}, | ||
Spec = new K8sDeploymentSpec() | ||
{ | ||
Selector = new Selector() | ||
{ | ||
MatchLabels = new Dictionary<string, string>() { { "app", "stub" } }, | ||
}, | ||
}, | ||
}, | ||
myNode = new K8sNode() | ||
{ | ||
Metadata = new K8sNodeMetadata() | ||
{ | ||
Labels = new Dictionary<string, string>() { { "app", "stub" } }, | ||
Name = nameof(K8sNodeMetadata.Name), | ||
Uid = nameof(K8sNodeMetadata.Uid), | ||
}, | ||
Status = new K8sNodeStatus() | ||
{ | ||
}, | ||
}, | ||
myPod = new K8sPod() | ||
{ | ||
Metadata = new K8sPodMetadata() | ||
{ | ||
Uid = "StubPodId", | ||
Name = "StubPodName", | ||
Labels = new Dictionary<string, string>() { { "app", "stub" } }, | ||
} | ||
}, | ||
myReplicaSet = new K8sReplicaSet() | ||
{ | ||
Metadata = new K8sReplicaSetMetadata() | ||
{ | ||
Name = "StubReplicaName", | ||
} | ||
} | ||
}); | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/ApplicationInsights.Kubernetes/Debuggings/KubeDebuggingHttpClientSettings.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Net.Http; | ||
|
||
namespace Microsoft.ApplicationInsights.Kubernetes.Debugging | ||
{ | ||
internal class KubeHttpDebuggingClientSettings : IKubeHttpClientSettingsProvider | ||
{ | ||
public const string FakeContainerId = "F8E1C6FF-2217-4962-90FF-0D9195AF0785"; | ||
|
||
public string ContainerId => FakeContainerId; | ||
|
||
public string QueryNamespace => "063A30B8-6A62-4519-8BFE-0DE144B009A1"; | ||
|
||
public Uri ServiceBaseAddress => new Uri("http://localhost/stub"); | ||
|
||
public HttpMessageHandler CreateMessageHandler() | ||
{ | ||
return null; | ||
} | ||
|
||
public string GetToken() | ||
{ | ||
return null; | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/ApplicationInsights.Kubernetes/Debuggings/KubernetesDebuggingServiceCollectionBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
using System; | ||
using Microsoft.Extensions.DependencyInjection; | ||
|
||
namespace Microsoft.ApplicationInsights.Kubernetes.Debugging | ||
{ | ||
public sealed class KubernetesDebuggingServiceCollectionBuilder : KubernetesServiceCollectionBuilder | ||
{ | ||
#region Singleton | ||
private KubernetesDebuggingServiceCollectionBuilder() { } | ||
private static KubernetesDebuggingServiceCollectionBuilder _instance = new KubernetesDebuggingServiceCollectionBuilder(); | ||
|
||
[Obsolete("This instance is used only for debugging. Never use this in production!", false)] | ||
public static KubernetesDebuggingServiceCollectionBuilder Instance => _instance; | ||
#endregion | ||
|
||
protected override void InjectChangableServices(IServiceCollection serviceCollection) | ||
{ | ||
serviceCollection.AddSingleton<IKubeHttpClientSettingsProvider, KubeHttpDebuggingClientSettings>(); | ||
serviceCollection.AddSingleton<IK8sEnvironmentFactory, K8sDebuggingEnvironmentFactory>(); | ||
} | ||
} | ||
} |
17 changes: 9 additions & 8 deletions
17
src/ApplicationInsights.Kubernetes/Extensions/ApplicationInsightsExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/ApplicationInsights.Kubernetes/Extensions/IKubernetesServiceCollectionBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public interface IKubernetesServiceCollectionBuilder | ||
{ | ||
IServiceCollection InjectServices(IServiceCollection serviceCollection); | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/ApplicationInsights.Kubernetes/Extensions/KubernetesServiceCollectionBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using Microsoft.ApplicationInsights.Kubernetes; | ||
using Microsoft.Extensions.Logging; | ||
|
||
namespace Microsoft.Extensions.DependencyInjection | ||
{ | ||
public class KubernetesServiceCollectionBuilder : IKubernetesServiceCollectionBuilder | ||
{ | ||
/// <summary> | ||
/// Inject Kubernetes related service into the service collection. | ||
/// </summary> | ||
/// <param name="serviceCollection"></param> | ||
/// <returns></returns> | ||
public IServiceCollection InjectServices(IServiceCollection serviceCollection) | ||
{ | ||
IServiceCollection services = serviceCollection ?? new ServiceCollection(); | ||
InjectCommonServices(services); | ||
|
||
InjectChangableServices(services); | ||
|
||
return services; | ||
} | ||
|
||
private static void InjectCommonServices(IServiceCollection serviceCollection) | ||
{ | ||
// According to the code, adding logging will not overwrite existing logging classes | ||
// https://github.com/aspnet/Logging/blob/c821494678a30c323174bea8056f43b93a3ca6f4/src/Microsoft.Extensions.Logging/LoggingServiceCollectionExtensions.cs | ||
// Becuase it uses 'TryAdd()' extenion method on service collection. | ||
serviceCollection.AddLogging(); | ||
|
||
serviceCollection.AddSingleton<KubeHttpClientFactory>(); | ||
serviceCollection.AddSingleton<K8sQueryClientFactory>(); | ||
} | ||
|
||
protected virtual void InjectChangableServices(IServiceCollection serviceCollection) | ||
{ | ||
serviceCollection.AddSingleton<IKubeHttpClientSettingsProvider>(p => new KubeHttpClientSettingsProvider(logger: p.GetService<ILogger<KubeHttpClientSettingsProvider>>())); | ||
serviceCollection.AddSingleton<IK8sEnvironmentFactory, K8sEnvironmentFactory>(); | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/ApplicationInsights.Kubernetes/Interfaces/IK8sEnvironmentFactory.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.ApplicationInsights.Kubernetes | ||
{ | ||
internal interface IK8sEnvironmentFactory | ||
{ | ||
Task<K8sEnvironment> CreateAsync(TimeSpan timeout); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.