public void Test_CanUpdateMetric_Decrement(int times)
        {
            Faker faker =
                new Faker();

            AppMetricId[] targetMetricIds = AppMetricId
                                            .BuiltInAppMetricIds
                                            .ToArray();

            long initialValue = times * faker.Random
                                .Long(1, 100000);

            AppMetricsCollection metrics = new AppMetricsCollection(targetMetricIds
                                                                    .Select(mId => new AppMetric(mId, initialValue))
                                                                    .ToArray());

            for (int i = 0; i < times; i++)
            {
                foreach (AppMetricId metricId in targetMetricIds)
                {
                    metrics.UpdateMetric(metricId, m => m.Decrement());
                }
            }

            foreach (AppMetricId metricId in targetMetricIds)
            {
                Assert.AreEqual(initialValue - times, metrics.QueryMetric(metricId).Value);
            }
        }
        public void Test_CanUpdateMetric_Add(int times)
        {
            Faker faker =
                new Faker();

            AppMetricId[] targetMetricIds = AppMetricId
                                            .BuiltInAppMetricIds
                                            .ToArray();

            long expectedTotal = 0;

            AppMetricsCollection metrics = new AppMetricsCollection(targetMetricIds);

            for (int i = 0; i < times; i++)
            {
                long randomValToAdd = faker.Random.Long(0, 100000);

                foreach (AppMetricId metricId in targetMetricIds)
                {
                    metrics.UpdateMetric(metricId, m => m.Add(randomValToAdd));
                }

                expectedTotal += randomValToAdd;
            }

            foreach (AppMetricId metricId in targetMetricIds)
            {
                Assert.AreEqual(expectedTotal, metrics.QueryMetric(metricId).Value);
            }
        }
        private void IncrementDequeueCount(TimeSpan duration)
        {
            long durationMilliseconds = ( long )Math.Ceiling(duration
                                                             .TotalMilliseconds);

            mMetrics.UpdateMetric(AppMetricId.QueueConsumerDequeueCount,
                                  m => m.Increment());

            mMetrics.UpdateMetric(AppMetricId.QueueConsumerTotalDequeueDuration,
                                  m => m.Add(durationMilliseconds));

            mMetrics.UpdateMetric(AppMetricId.QueueConsumerMinimumDequeueDuration,
                                  m => m.Min(durationMilliseconds));

            mMetrics.UpdateMetric(AppMetricId.QueueConsumerMaximumDequeueDuration,
                                  m => m.Max(durationMilliseconds));
        }
Exemplo n.º 4
0
		private void UpdateTaskProcessingStats ( TaskExecutionResult result )
		{
			mMetrics.UpdateMetric( AppMetricId.WorkerProcessedPayloadCount,
				m => m.Increment() );

			mMetrics.UpdateMetric( AppMetricId.WorkerTotalProcessingTime,
				m => m.Add( result.ProcessingTimeMilliseconds ) );

			if ( result.ExecutedSuccessfully )
				mMetrics.UpdateMetric( AppMetricId.WorkerSuccessfulProcessedPayloadCount,
					m => m.Increment() );

			else if ( result.ExecutionFailed )
				mMetrics.UpdateMetric( AppMetricId.WorkerFailedProcessedPayloadCount,
					m => m.Increment() );

			else if ( result.ExecutionCancelled )
				mMetrics.UpdateMetric( AppMetricId.WorkerProcessingCancelledPayloadCount,
					m => m.Increment() );
		}
        public void Test_CanUpdateMetric_Increment(int times)
        {
            AppMetricId[] targetMetricIds = AppMetricId
                                            .BuiltInAppMetricIds
                                            .ToArray();

            AppMetricsCollection metrics = new AppMetricsCollection(targetMetricIds);

            for (int i = 0; i < times; i++)
            {
                foreach (AppMetricId metricId in targetMetricIds)
                {
                    metrics.UpdateMetric(metricId, m => m.Increment());
                }
            }

            foreach (AppMetricId metricId in targetMetricIds)
            {
                Assert.AreEqual(times, metrics.QueryMetric(metricId).Value);
            }
        }
        public void Test_CanUpdateMetric_ReplaceValue(int times)
        {
            Faker faker =
                new Faker();

            AppMetricId[] targetMetricIds = AppMetricId
                                            .BuiltInAppMetricIds
                                            .ToArray();

            AppMetricsCollection metrics = new AppMetricsCollection(targetMetricIds);

            for (int i = 0; i < times; i++)
            {
                foreach (AppMetricId metricId in targetMetricIds)
                {
                    long randomNewVal = faker.Random.Long();
                    metrics.UpdateMetric(metricId, m => m.Update(randomNewVal));

                    Assert.AreEqual(randomNewVal, metrics
                                    .QueryMetric(metricId)
                                    .Value);
                }
            }
        }
Exemplo n.º 7
0
 private void IncrementPerfMonPostCount()
 {
     mMetrics.UpdateMetric(AppMetricId.PerfMonReportPostCount,
                           m => m.Increment());
 }
Exemplo n.º 8
0
 private void IncrementListenerReconnectCount()
 {
     mMetrics.UpdateMetric(AppMetricId.ListenerReconnectCount,
                           m => m.Increment());
 }
Exemplo n.º 9
0
 private void IncrementPostResultCount()
 {
     mMetrics.UpdateMetric(AppMetricId.ResultQueueResultPostCount,
                           m => m.Increment());
 }
Exemplo n.º 10
0
        private async Task PollForQueuedTasksAsync()
        {
            CancellationToken stopToken = mStopTokenSource
                                          .Token;

            //Check cancellation token before starting
            //	the polling loop
            if (stopToken.IsCancellationRequested)
            {
                return;
            }

            while (true)
            {
                try
                {
                    //Check for token cancellation at the beginning of the loop
                    stopToken.ThrowIfCancellationRequested();

                    //If the buffer is full, we wait for some space to become available,
                    //  since, even if we can dequeue an task,
                    //  we won't have anywhere to place it yet and we
                    //  may be needlessly helding a lock to that task
                    if (mTaskBuffer.IsFull)
                    {
                        mLogger.Debug("Task buffer is full. Waiting for available space...");
                        mMetrics.UpdateMetric(AppMetricId.PollerWaitForBufferSpaceCount, m => m.Increment());
                        await mWaitForClearToAddToBuffer.ToTask();
                    }

                    //It may be that the wait handle was signaled
                    //  as part of the Stop operation,
                    //  so we need to check for that as well.
                    stopToken.ThrowIfCancellationRequested();

                    //Attempt to dequeue and then check cancellation
                    IQueuedTaskToken queuedTaskToken = await mTaskQueueConsumer
                                                       .DequeueAsync(mRequiredPayloadTypes);

                    //Before posting the token to the buffer,
                    //	check if cancellation was requested
                    stopToken.ThrowIfCancellationRequested();

                    if (queuedTaskToken != null)
                    {
                        //If we have found a token, attempt to set it as started
                        //	 and only then add it to buffer for processing.
                        //If not, dispose and discard the token
                        mLogger.DebugFormat("Task found with id = {0}, type = {1}. Acquiring reservation...",
                                            queuedTaskToken.DequeuedTask.Id,
                                            queuedTaskToken.DequeuedTask.Type);

                        mMetrics.UpdateMetric(AppMetricId.PollerDequeueCount, m => m.Increment());
                        mTaskBuffer.TryAddNewTask(queuedTaskToken);
                    }
                    else
                    {
                        //If there is no task available in the queue, begin waiting for
                        //  a notification of new added tasks
                        mLogger.Debug("No task dequeued when polled. Waiting for available task...");
                        mMetrics.UpdateMetric(AppMetricId.PollerWaitForDequeueCount, m => m.Increment());
                        await mWaitForClearToDequeue.ToTask();
                    }

                    //It may be that the wait handle was signaled
                    //  as part of the Stop operation,
                    //  so we need to check for that as well.
                    stopToken.ThrowIfCancellationRequested();

                    //Finally, reset all the handles, at the end of the loop
                    mWaitForClearToAddToBuffer.Reset();
                    mWaitForClearToDequeue.Reset();
                }
                catch (OperationCanceledException)
                {
                    mLogger.Debug("Stop requested. Breaking polling loop...");
                    break;
                }
            }

            mTaskBuffer.CompleteAdding();
        }
Exemplo n.º 11
0
 private void IncrementTimesFilled()
 {
     mMetrics.UpdateMetric(AppMetricId.BufferTimesFilled,
                           m => m.Increment());
 }