public TelemetryKeyCache(IOptions <AppInsightsForKubernetesOptions> options) { _options = options?.Value ?? throw new System.ArgumentNullException(nameof(options)); if (_options.TelemetryKeyProcessor != null) { _telemetryKeyCache = new ConcurrentDictionary <string, string>(); } }
public void ShouldAlterKeyNameWhenSet(string input, string expected) { AppInsightsForKubernetesOptions opts = new AppInsightsForKubernetesOptions(); opts.TelemetryKeyProcessor = (key) => key.Replace('.', '_'); IOptions <AppInsightsForKubernetesOptions> options = Options.Create <AppInsightsForKubernetesOptions>(opts); TelemetryKeyCache keyCache = new TelemetryKeyCache(options); string actual = keyCache.GetProcessedKey(input); Assert.Equal(expected, actual); }
public void ReturnsOriginalWhenProcessorNotSet() { string input = "abc.def"; string expected = input; AppInsightsForKubernetesOptions opts = new AppInsightsForKubernetesOptions(); opts.TelemetryKeyProcessor = null; // Making sure it is null. IOptions <AppInsightsForKubernetesOptions> options = Options.Create <AppInsightsForKubernetesOptions>(opts); TelemetryKeyCache keyCache = new TelemetryKeyCache(options); string actual = keyCache.GetProcessedKey(input); Assert.Equal(expected, actual); }
public void AllowsRemoveDot() { string input = "abc.def"; string expected = "abcdef"; AppInsightsForKubernetesOptions opts = new AppInsightsForKubernetesOptions(); opts.TelemetryKeyProcessor = (key) => key.Replace(".", string.Empty); // Remove dot(.) IOptions <AppInsightsForKubernetesOptions> options = Options.Create <AppInsightsForKubernetesOptions>(opts); TelemetryKeyCache keyCache = new TelemetryKeyCache(options); string actual = keyCache.GetProcessedKey(input); Assert.Equal(expected, actual); }
public void AllowsMoreThanJustReplaceDot() { string input = "abc.def"; string expected = "\"abc.def\""; AppInsightsForKubernetesOptions opts = new AppInsightsForKubernetesOptions(); opts.TelemetryKeyProcessor = (key) => $@"""{key}"""; // Add quotes IOptions <AppInsightsForKubernetesOptions> options = Options.Create <AppInsightsForKubernetesOptions>(opts); TelemetryKeyCache keyCache = new TelemetryKeyCache(options); string actual = keyCache.GetProcessedKey(input); Assert.Equal(expected, actual); }
public KubernetesTelemetryInitializer( IK8sEnvironmentFactory k8sEnvFactory, IOptions <AppInsightsForKubernetesOptions> options, SDKVersionUtils sdkVersionUtils, ITelemetryKeyCache telemetryKeyCache) { _k8sEnvironment = null; // Options can't be null. Debug.Assert(options != null, "Options can't be null."); _options = Arguments.IsNotNull(options?.Value, nameof(options)); _logger.LogDebug(@"Initialize Application Insights for Kubernetes telemetry initializer with Options: {0}", JsonConvert.SerializeObject(_options)); _telemetryKeyCache = telemetryKeyCache ?? throw new ArgumentNullException(nameof(telemetryKeyCache)); _sdkVersionUtils = Arguments.IsNotNull(sdkVersionUtils, nameof(sdkVersionUtils)); _timeoutAt = DateTime.Now.Add(_options.InitializationTimeout); _k8sEnvFactory = Arguments.IsNotNull(k8sEnvFactory, nameof(k8sEnvFactory)); _ = SetK8sEnvironment(); }