public void QuickPulseServiceClientSubmitsTopCpuProcessesToService() { // ARRANGE var now = DateTimeOffset.UtcNow; var ikey = "some ikey"; var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, new Clock(), true); var cpuData = new[] { Tuple.Create("Process1", 1), Tuple.Create("Process2", 2) }; var sample = new QuickPulseDataSample( new QuickPulseDataAccumulator { StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, double> >(), cpuData, false); // ACT serviceClient.SubmitSamples(new[] { sample }, ikey); // ASSERT this.listener.Stop(); Assert.AreEqual(1, this.samples.Count); Assert.AreEqual(2, this.samples[0].Item2.TopCpuProcesses.Count()); Assert.AreEqual("Process1", this.samples[0].Item2.TopCpuProcesses[0].ProcessName); Assert.AreEqual(1, this.samples[0].Item2.TopCpuProcesses[0].CpuPercentage); Assert.AreEqual("Process2", this.samples[0].Item2.TopCpuProcesses[1].ProcessName); Assert.AreEqual(2, this.samples[0].Item2.TopCpuProcesses[1].CpuPercentage); }
public void QuickPulseServiceClientFillsInSampleWeightWhenSubmittingToService() { // ARRANGE var now = DateTimeOffset.UtcNow; var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, new Clock()); var sample1 = new QuickPulseDataSample( new QuickPulseDataAccumulator { AIRequestCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(3, 10000), StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, float> >()); var sample2 = new QuickPulseDataSample( new QuickPulseDataAccumulator { AIDependencyCallCountAndDurationInTicks = QuickPulseDataAccumulator.EncodeCountAndDuration(4, 10000), StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, float> >()); // ACT serviceClient.SubmitSamples(new[] { sample1, sample2 }, string.Empty); // ASSERT this.listener.Stop(); Assert.AreEqual(3, this.samples[0].Item2.Metrics.Single(m => m.Name == @"\ApplicationInsights\Request Duration").Weight); Assert.AreEqual(4, this.samples[1].Item2.Metrics.Single(m => m.Name == @"\ApplicationInsights\Dependency Call Duration").Weight); }
public void QuickPulseServiceClientFillsInTelemetryDocumentsWhenSubmittingToService() { // ARRANGE var now = DateTimeOffset.UtcNow; var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, new Clock(), false); var properties = new Dictionary <string, string>() { { "Prop1", "Val1" } }; var sample = new QuickPulseDataSample( new QuickPulseDataAccumulator { StartTimestamp = now, EndTimestamp = now.AddSeconds(1), TelemetryDocuments = new ConcurrentStack <ITelemetryDocument>( new ITelemetryDocument[] { new RequestTelemetryDocument() { Name = "Request1", Properties = properties.ToArray() }, new DependencyTelemetryDocument() { Name = "Dependency1", Properties = properties.ToArray() }, new ExceptionTelemetryDocument() { Exception = "Exception1", Properties = properties.ToArray() } }) }, new Dictionary <string, Tuple <PerformanceCounterData, double> >(), Enumerable.Empty <Tuple <string, int> >(), false); // ACT serviceClient.SubmitSamples(new[] { sample }, string.Empty); // ASSERT this.listener.Stop(); Assert.AreEqual("Request1", ((RequestTelemetryDocument)this.samples[0].Item2.Documents[0]).Name); Assert.AreEqual("Prop1", ((RequestTelemetryDocument)this.samples[0].Item2.Documents[0]).Properties.First().Key); Assert.AreEqual("Val1", ((RequestTelemetryDocument)this.samples[0].Item2.Documents[0]).Properties.First().Value); Assert.AreEqual("Dependency1", ((DependencyTelemetryDocument)this.samples[0].Item2.Documents[1]).Name); Assert.AreEqual("Prop1", ((DependencyTelemetryDocument)this.samples[0].Item2.Documents[1]).Properties.First().Key); Assert.AreEqual("Val1", ((DependencyTelemetryDocument)this.samples[0].Item2.Documents[1]).Properties.First().Value); Assert.AreEqual("Exception1", ((ExceptionTelemetryDocument)this.samples[0].Item2.Documents[2]).Exception); Assert.AreEqual("Prop1", ((ExceptionTelemetryDocument)this.samples[0].Item2.Documents[2]).Properties.First().Key); Assert.AreEqual("Val1", ((ExceptionTelemetryDocument)this.samples[0].Item2.Documents[2]).Properties.First().Value); }
public void QuickPulseServiceClientInterpretsSubmitSamplesResponseCorrectlyWhenHeaderMissing() { // ARRANGE var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, new Clock()); // ACT this.submitResponse = r => { }; bool?response = serviceClient.SubmitSamples(new QuickPulseDataSample[] { }, string.Empty); // ASSERT this.listener.Stop(); Assert.IsNull(response); }
public void QuickPulseServiceClientInterpretsSubmitSamplesResponseCorrectlyWhenHeaderFalse() { // ARRANGE var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, new Clock()); // ACT this.submitResponse = r => { r.AddHeader("x-ms-qps-subscribed", false.ToString()); }; bool?response = serviceClient.SubmitSamples(new QuickPulseDataSample[] { }, string.Empty); // ASSERT this.listener.Stop(); Assert.IsFalse(response.Value); }
public void QuickPulseServiceClientInterpretsSubmitSamplesResponseCorrectlyWhenHeaderInvalid() { // ARRANGE var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, new Clock(), false); // ACT this.submitResponse = r => { r.AddHeader(QuickPulseConstants.XMsQpsSubscribedHeaderName, "bla"); }; bool?response = serviceClient.SubmitSamples(new QuickPulseDataSample[] { }, string.Empty); // ASSERT this.listener.Stop(); Assert.IsNull(response); }
public void QuickPulseServiceClientSetsTransmissionTimeCorrectly() { // ARRANGE var dummy = new Dictionary <string, Tuple <PerformanceCounterData, double> >(); var dummy2 = Enumerable.Empty <Tuple <string, int> >(); var timeProvider = new ClockMock(); var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, timeProvider, false); var sample1 = new QuickPulseDataSample( new QuickPulseDataAccumulator { StartTimestamp = timeProvider.UtcNow.AddSeconds(-1), EndTimestamp = timeProvider.UtcNow }, dummy, dummy2, false); timeProvider.FastForward(TimeSpan.FromSeconds(1)); var sample2 = new QuickPulseDataSample( new QuickPulseDataAccumulator { StartTimestamp = timeProvider.UtcNow.AddSeconds(-1), EndTimestamp = timeProvider.UtcNow }, dummy, dummy2, false); timeProvider.FastForward(TimeSpan.FromSeconds(1)); var sample3 = new QuickPulseDataSample( new QuickPulseDataAccumulator { StartTimestamp = timeProvider.UtcNow.AddSeconds(-1), EndTimestamp = timeProvider.UtcNow }, dummy, dummy2, false); // ACT timeProvider.FastForward(TimeSpan.FromSeconds(5)); serviceClient.SubmitSamples(new[] { sample1, sample2, sample3 }, string.Empty); // ASSERT this.listener.Stop(); Assert.AreEqual(3, this.samples.Count); Assert.IsTrue((timeProvider.UtcNow - this.samples[0].Item1).Duration() < TimeSpan.FromMilliseconds(1)); Assert.IsTrue((timeProvider.UtcNow - this.samples[1].Item1).Duration() < TimeSpan.FromMilliseconds(1)); Assert.IsTrue((timeProvider.UtcNow - this.samples[2].Item1).Duration() < TimeSpan.FromMilliseconds(1)); Assert.IsTrue(this.samples.All(s => (s.Item2.Timestamp - timeProvider.UtcNow).Duration() > TimeSpan.FromSeconds(1))); }
public void QuickPulseServiceClientSubmitsSamplesToService() { // ARRANGE var now = DateTimeOffset.UtcNow; var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, new Clock(), false); var sample1 = new QuickPulseDataSample( new QuickPulseDataAccumulator { AIRequestSuccessCount = 5, StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, double> >(), Enumerable.Empty <Tuple <string, int> >(), false); var sample2 = new QuickPulseDataSample( new QuickPulseDataAccumulator { AIDependencyCallSuccessCount = 10, StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, double> >(), Enumerable.Empty <Tuple <string, int> >(), false); var sample3 = new QuickPulseDataSample( new QuickPulseDataAccumulator { AIExceptionCount = 15, StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, double> >(), Enumerable.Empty <Tuple <string, int> >(), false); // ACT bool?sendMore = serviceClient.SubmitSamples(new[] { sample1, sample2, sample3 }, string.Empty); // ASSERT this.listener.Stop(); Assert.AreEqual(true, sendMore); Assert.AreEqual(3, this.samples.Count); Assert.AreEqual(5, this.samples[0].Item2.Metrics.Single(m => m.Name == @"\ApplicationInsights\Requests Succeeded/Sec").Value); Assert.AreEqual(10, this.samples[1].Item2.Metrics.Single(m => m.Name == @"\ApplicationInsights\Dependency Calls Succeeded/Sec").Value); Assert.AreEqual(15, this.samples[2].Item2.Metrics.Single(m => m.Name == @"\ApplicationInsights\Exceptions/Sec").Value); }
public void QuickPulseServiceClientRoundsSampleValuesWhenSubmittingToService() { // ARRANGE var now = DateTimeOffset.UtcNow; var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, new Clock()); var sample1 = new QuickPulseDataSample( new QuickPulseDataAccumulator { AIRequestSuccessCount = 1, StartTimestamp = now, EndTimestamp = now.AddSeconds(3) }, new Dictionary <string, Tuple <PerformanceCounterData, float> >()); // ACT serviceClient.SubmitSamples(new[] { sample1 }, string.Empty); // ASSERT this.listener.Stop(); Assert.AreEqual(0.3333, this.samples[0].Item2.Metrics.Single(m => m.Name == @"\ApplicationInsights\Requests Succeeded/Sec").Value); }
public void QuickPulseServiceClientDoesNotRetrySubmitSamples() { // ARRANGE var serviceClient = new QuickPulseServiceClient( this.serviceEndpoint, string.Empty, string.Empty, new Clock(), TimeSpan.FromMilliseconds(50)); this.emulateTimeout = true; // ACT serviceClient.SubmitSamples(new QuickPulseDataSample[] { }, string.Empty); // ASSERT this.listener.Stop(); Assert.AreEqual(1, this.submitCount); }
public void QuickPulseServiceClientSubmitsInstrumentationKeyToService() { // ARRANGE var now = DateTimeOffset.UtcNow; var ikey = "some ikey"; var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, new Clock()); var sample = new QuickPulseDataSample( new QuickPulseDataAccumulator { StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, float> >()); // ACT serviceClient.SubmitSamples(new[] { sample }, ikey); // ASSERT this.listener.Stop(); Assert.AreEqual(1, this.samples.Count); Assert.AreEqual(ikey, this.samples[0].Item2.InstrumentationKey); }
public void QuickPulseServiceClientSubmitsMachineNameToServiceWithSubmitSamples() { // ARRANGE var now = DateTimeOffset.UtcNow; var machineName = "this machine"; var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, machineName, string.Empty, new Clock()); var sample = new QuickPulseDataSample( new QuickPulseDataAccumulator { StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, float> >()); // ACT serviceClient.SubmitSamples(new[] { sample }, string.Empty); // ASSERT this.listener.Stop(); Assert.AreEqual(1, this.samples.Count); Assert.AreEqual(machineName, this.samples[0].Item2.MachineName); }
public void QuickPulseServiceClientSubmitsVersionToServiceWithSubmitSamples() { // ARRANGE var now = DateTimeOffset.UtcNow; var version = "this version"; var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, version, new Clock()); var sample = new QuickPulseDataSample( new QuickPulseDataAccumulator { StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, float> >()); // ACT serviceClient.SubmitSamples(new[] { sample }, string.Empty); // ASSERT this.listener.Stop(); Assert.AreEqual(1, this.samples.Count); Assert.AreEqual(version, this.samples[0].Item2.Version); Assert.AreEqual(MonitoringDataPoint.CurrentInvariantVersion, this.samples[0].Item2.InvariantVersion); }
public void QuickPulseServiceClientSubmitsTransmissionTimeToServiceWithSubmitSamples() { // ARRANGE var timeProvider = new ClockMock(); var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, timeProvider, false); var sample = new QuickPulseDataSample( new QuickPulseDataAccumulator { StartTimestamp = timeProvider.UtcNow, EndTimestamp = timeProvider.UtcNow.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, double> >(), Enumerable.Empty <Tuple <string, int> >(), false); // ACT serviceClient.SubmitSamples(new[] { sample }, string.Empty); // ASSERT this.listener.Stop(); Assert.AreEqual(1, this.samples.Count); Assert.AreEqual(timeProvider.UtcNow.Ticks, this.samples[0].Item1.Ticks); }
public void QuickPulseServiceClientSubmitsStreamIdToServiceWithSubmitSamples() { // ARRANGE var now = DateTimeOffset.UtcNow; var streamId = "this stream"; var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, streamId, string.Empty, string.Empty, new Clock(), false); var sample = new QuickPulseDataSample( new QuickPulseDataAccumulator { StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, double> >(), Enumerable.Empty <Tuple <string, int> >(), false); // ACT serviceClient.SubmitSamples(new[] { sample }, string.Empty); // ASSERT this.listener.Stop(); Assert.AreEqual(1, this.samples.Count); Assert.AreEqual(streamId, this.samples[0].Item2.StreamId); }
public void QuickPulseServiceClientSubmitsTopCpuProcessesAccessDeniedToService() { // ARRANGE var now = DateTimeOffset.UtcNow; var ikey = "some ikey"; var serviceClient = new QuickPulseServiceClient(this.serviceEndpoint, string.Empty, string.Empty, string.Empty, string.Empty, new Clock(), true); var sample = new QuickPulseDataSample( new QuickPulseDataAccumulator { StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, double> >(), new Tuple <string, int>[] { }, true); // ACT serviceClient.SubmitSamples(new[] { sample }, ikey); // ASSERT this.listener.Stop(); Assert.AreEqual(1, this.samples.Count); Assert.IsTrue(this.samples[0].Item2.TopCpuDataAccessDenied); }