Exemplo n.º 1
0
		public void FindLastMessage_LastMessageIsAfterNow()
		{
			var lastEntryPK = AzureDiagnosticsUtils.FindLastMessagePartitionKey(
				new AzureDiagnosticLogsTableMock().Add(TestEventTimestampFromMinutes(1), "hey").Add(TestEventTimestampFromMinutes(10), "there"),
				new DateTime(TestEventTimestampFromMinutes(7), DateTimeKind.Utc));
			Assert.AreEqual(AzureDiagnosticsUtils.EventTickCountToEventPartitionKey(TestEventTimestampFromMinutes(10)), lastEntryPK.ToString());
		}
Exemplo n.º 2
0
		static void FindDateBoundTest(ValueBound bound, long dateTicks, 
			string expectedMessage, EntryPartition? searchRangeBegin = null, EntryPartition? searchRangeEnd = null)
		{
			var entry = AzureDiagnosticsUtils.FindDateBound(
				new AzureDiagnosticLogsTableMock()
					.Add(TestEventTimestampFromMinutes(1), "1")
					.Add(TestEventTimestampFromMinutes(1) + 2, "1+2")
					.Add(TestEventTimestampFromMinutes(1) + 2, "1+2.2")
					.Add(TestEventTimestampFromMinutes(1) + 3, "1+3")
					.Add(TestEventTimestampFromMinutes(1) + 10, "1+10")
					.Add(TestEventTimestampFromMinutes(2), "2")
					.Add(TestEventTimestampFromMinutes(3) + 100, "3+100")
					.Add(TestEventTimestampFromMinutes(3) + 200, "3+200")
					.Add(TestEventTimestampFromMinutes(3) + 300, "3+300")
					.Add(TestEventTimestampFromMinutes(3) + 300, "3+300.2")
					.Add(TestEventTimestampFromMinutes(1000) + 10, "1000+10")
					.Add(TestEventTimestampFromMinutes(1000) + 20, "1000+20")
					.Add(TestEventTimestampFromMinutes(100000), "100000")
					.Add(TestEventTimestampFromMinutes(100000) + 100, "100000+100"),
				new DateTime(dateTicks, DateTimeKind.Utc), bound, 
					searchRangeBegin.GetValueOrDefault(EntryPartition.MinValue), 
					searchRangeEnd.GetValueOrDefault(EntryPartition.MaxValue), 
					CancellationToken.None);
			if (expectedMessage == null)
			{
				Assert.IsTrue(!entry.HasValue);
			}
			else
			{
				Assert.IsTrue(entry.HasValue);
				Assert.AreEqual(expectedMessage, (entry.Value.Entry as WADLogsTableEntry).Message);
			}
		}
Exemplo n.º 3
0
		public void EventTickCountToEventPartitionKeyTest()
		{
			// sample numbers are taken from read WADLogsTable

			Assert.AreEqual("0634923055200000000", AzureDiagnosticsUtils.EventTickCountToEventPartitionKey(634923055356353096));
			Assert.AreEqual("0634904775000000000", AzureDiagnosticsUtils.EventTickCountToEventPartitionKey(634904775152901748));
			Assert.AreEqual("0634903933800000000", AzureDiagnosticsUtils.EventTickCountToEventPartitionKey(634903934382982291));
		}
Exemplo n.º 4
0
		public void FindLastMessage_ManyMessagesAtTheSameSecond()
		{
			var lastEntryPK = AzureDiagnosticsUtils.FindLastMessagePartitionKey(
				new AzureDiagnosticLogsTableMock()
					.Add(TestEventTimestampFromMinutes(2), "hey")
					.Add(TestEventTimestampFromMinutes(9), "there")
					.Add(TestEventTimestampFromMinutes(9)+1, "there2")
					.Add(TestEventTimestampFromMinutes(9)+2, "there3"),
				new DateTime(TestEventTimestampFromMinutes(15), DateTimeKind.Utc));
			Assert.AreEqual(AzureDiagnosticsUtils.EventTickCountToEventPartitionKey(TestEventTimestampFromMinutes(9)), lastEntryPK.ToString());
		}
Exemplo n.º 5
0
			static WADLogsTableEntry MakeWADEntry(KeyValuePair<long, string> entry)
			{
				if (entry.Value == null)
					return null;
				return new WADLogsTableEntry()
				{
					PartitionKey = AzureDiagnosticsUtils.EventTickCountToEventPartitionKey(entry.Key),
					EventTickCount = entry.Key,
					Timestamp = new DateTime(entry.Key, DateTimeKind.Utc),
					Message = entry.Value
				};
			}
Exemplo n.º 6
0
			public IEnumerable<AzureDiagnosticLogEntry> GetEntriesInRange(string beginPartitionKey, string endPartitionKey, int? limit)
			{
				EnsureCompleted();
				var x =
					from entry in entries
					let pk = AzureDiagnosticsUtils.EventTickCountToEventPartitionKey(entry.Key)
					where string.Compare(pk, beginPartitionKey) >= 0 && string.Compare(pk, endPartitionKey) < 0
					select MakeWADEntry(entry);
				if (limit != null)
					x = x.Take(limit.Value);
				return x;
			}
Exemplo n.º 7
0
		public void FindDateBound_LowerBound_BugFromRealLogs2()
		{
			var tableMock = new AzureDiagnosticLogsTableMock()
					.Add(634929032152764926, "1")
					.Add(634929034677682953, "2")
					.Add(634929034680972605, "3")
					.Add(634931678260882377, "4");
			var bound = AzureDiagnosticsUtils.FindDateBound(tableMock, new DateTime(634929213420972605, DateTimeKind.Utc),
				ValueBound.Lower,
				new EntryPartition(0634929031800000000), new EntryPartition(0634932574800000000), CancellationToken.None);
			Assert.IsTrue(bound.HasValue && (bound.Value.Entry as WADLogsTableEntry).Message == "4");
		}
Exemplo n.º 8
0
		public void LoadMessagesRange_EntriesAlreadySortedWithingPartitions()
		{
			var msgs = AzureDiagnosticsUtils.LoadWADLogsTableMessagesRange(
				new AzureDiagnosticLogsTableMock()
					.Add(TestEventTimestampFromMinutes(2), "1")
					.Add(TestEventTimestampFromMinutes(2) + 1, "2")
					.Add(TestEventTimestampFromMinutes(3), "3")
					.Add(TestEventTimestampFromMinutes(3) + 1, "4"),
				new LogJoint.LogSourceThreads(), EntryPartition.MinValue, EntryPartition.MaxValue, null).ToArray();
			var str = string.Join("|", msgs.Select(m => m.Text.ToString()).ToArray());
			Assert.AreEqual("1|2|3|4", str);
		}
Exemplo n.º 9
0
        public void TestAccount(StorageAccount account)
        {
            try
            {
                var table = AzureDiagnosticLogsTable <AzureDiagnosticLogEntry> .CreateTable(account, "WADLogsTable");

                AzureDiagnosticsUtils.FindFirstMessagePartitionKey(table);
            }
            catch (Exception exception)
            {
                RethrowStorageExceptionWithUserFriendlyMessage(exception);
                throw;
            }
        }
Exemplo n.º 10
0
 protected override void LiveLogListen(CancellationToken stopEvt, LiveLogXMLWriter output)
 {
     using (host.Trace.NewFrame)
     {
         try
         {
             if (azureConnectParams.Mode == AzureConnectionParams.LoadMode.FixedRange)
             {
                 ReportBackgroundActivityStatus(true);
                 foreach (var entry in AzureDiagnosticsUtils.LoadEntriesRange(
                              table, new EntryPartition(azureConnectParams.From.Ticks), new EntryPartition(azureConnectParams.Till.Ticks), null, stopEvt))
                 {
                     WriteEntry(entry.Entry, output);
                     if (stopEvt.IsCancellationRequested)
                     {
                         return;
                     }
                 }
                 ReportBackgroundActivityStatus(false);
                 return;
             }
             else if (azureConnectParams.Mode == AzureConnectionParams.LoadMode.Recent)
             {
                 ReportBackgroundActivityStatus(true);
                 var lastPartition = AzureDiagnosticsUtils.FindLastMessagePartitionKey(table, DateTime.UtcNow, stopEvt);
                 if (lastPartition.HasValue)
                 {
                     var firstPartition = new EntryPartition(lastPartition.Value.Ticks + azureConnectParams.Period.Ticks);
                     foreach (var entry in AzureDiagnosticsUtils.LoadEntriesRange(table, firstPartition, EntryPartition.MaxValue, null, stopEvt))
                     {
                         WriteEntry(entry.Entry, output);
                         stopEvt.ThrowIfCancellationRequested();
                     }
                 }
                 ReportBackgroundActivityStatus(false);
                 return;
             }
         }
         catch (OperationCanceledException e)
         {
             host.Trace.Error(e, "WAD live log thread cancelled");
         }
         catch (Exception e)
         {
             host.Trace.Error(e, "WAD live log thread failed");
         }
     }
 }
Exemplo n.º 11
0
			public AzureDiagnosticLogEntry GetFirstEntryOlderThan(string partitionKey)
			{
				EnsureCompleted();
				return MakeWADEntry(entries.FirstOrDefault(entry => 
					string.Compare(AzureDiagnosticsUtils.EventTickCountToEventPartitionKey(entry.Key), partitionKey) > 0));
			}
Exemplo n.º 12
0
 public static int Distance(EntryPartition begin, EntryPartition end)
 {
     return(AzureDiagnosticsUtils.TicksToMinutes(end.Ticks - begin.Ticks));
 }