Ejemplo n.º 1
0
        public async Task GivenEventsArray_CalculateEventStats_ThenEventStatsReturned_Test()
        {
            // 22 bytes
            var body = Encoding.UTF8.GetBytes("22 characters to bytes");
            var evt  = new EventData(body);

            // 93 bytes on Linux, 94 bytes on Windows
            evt.SystemProperties = new SystemPropertiesCollection(1, DateTime.MinValue, "1", "1");

            // 14 bytes
            evt.Properties["7 chars"] = "7 chars";

            // 14 bytes
            evt.SystemProperties.TryAdd("7 chars", "7 chars");

            var evtBatch = new EventData[] { evt };
            IEventProcessingMeter meter = new EventProcessingMeter();
            var stats = await meter.CalculateEventStats(evtBatch);

            // DateTime.MinValue = "01/01/0001 00:00:00" on Linux
            // DateTime.MinValue = "1/1/0001 12:00:00 AM" on Windows
            if (DateTime.MinValue.ToString() == "01/01/0001 00:00:00")
            {
                Assert.Equal(143, stats.TotalEventsProcessedBytes); // 22 + 93 + 14 + 14 = 143
            }
            else
            {
                Assert.Equal(144, stats.TotalEventsProcessedBytes); // 22 + 94 + 14 + 14 = 144
            }
        }
Ejemplo n.º 2
0
        public async Task NormalizeDeviceData(
            [EventHubTrigger("input", Connection = "InputEventHub")] EventData[] events,
            [EventHubMeasurementCollector("output", Connection = "OutputEventHub")] IAsyncCollector <IMeasurement> output,
            [Blob("template/%Template:DeviceContent%", FileAccess.Read)] string templateDefinitions,
            [DeviceDataNormalization] IOptions <NormalizationServiceOptions> normalizationSettings)
        {
            try
            {
                EnsureArg.IsNotNull(templateDefinitions, nameof(templateDefinitions));
                EnsureArg.IsNotNull(events, nameof(events));
                EnsureArg.IsNotNull(normalizationSettings, nameof(normalizationSettings));

                var templateContext = _collectionContentTemplateFactory.Create(templateDefinitions);
                templateContext.EnsureValid();
                var template = templateContext.Template;

                _logger.LogMetric(
                    IomtMetrics.DeviceEvent(),
                    events.Length);

                IDataNormalizationService <EventData, IMeasurement> dataNormalizationService = new MeasurementEventNormalizationService(_logger, template, _exceptionTelemetryProcessor);
                await dataNormalizationService.ProcessAsync(events, output).ConfigureAwait(false);

                if (normalizationSettings.Value.LogDeviceIngressSizeBytes)
                {
                    IEventProcessingMeter meter = new EventProcessingMeter();
                    var eventStats = await meter.CalculateEventStats(events);

                    _logger.LogMetric(
                        IomtMetrics.DeviceIngressSizeBytes(),
                        eventStats.TotalEventsProcessedBytes);
                }
            }
            catch (Exception ex)
            {
                _logger.LogMetric(
                    IomtMetrics.UnhandledException(ex.GetType().Name, ConnectorOperation.Normalization),
                    1);
                throw;
            }
        }
Ejemplo n.º 3
0
        public async Task GivenEventsArray_CalculateEventStats_ThenEventStatsReturned_Test()
        {
            // 22 bytes
            var body = Encoding.UTF8.GetBytes("22 characters to bytes");
            var evt  = new EventData(body);

            // 94 bytes
            evt.SystemProperties = new SystemPropertiesCollection(1, DateTime.MinValue, "1", "1");

            // 14 bytes
            evt.Properties["7 chars"] = "7 chars";

            // 14 bytes
            evt.SystemProperties.TryAdd("7 chars", "7 chars");

            var evtBatch = new EventData[] { evt };
            IEventProcessingMeter meter = new EventProcessingMeter();
            var stats = await meter.CalculateEventStats(evtBatch);

            // 22 + 94 + 14 + 14 = 144
            Assert.Equal(144, stats.TotalEventsProcessedBytes);
        }