Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplifying perf improvement PR #199

Merged
merged 2 commits into from
Jun 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,18 @@ protected virtual IEnumerable<JToken> MatchTypeTokens(JObject token)
EnsureArg.IsNotNull(token, nameof(token));
var evaluator = CreateRequiredExpressionEvaluator(Template.TypeMatchExpression, nameof(Template.TypeMatchExpression));

JObject tokenClone = null;

foreach (var extractedToken in evaluator.SelectTokens(token))
{
// Add the extracted data as an element of the original data.
// This allows subsequent expressions access to data from the original event data
if (tokenClone == null)
{
tokenClone = new JObject(token);
}

var tokenClone = token.DeepClone() as JObject;
tokenClone.Remove(MatchedToken);
tokenClone.Add(MatchedToken, extractedToken);
yield return tokenClone;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -117,10 +118,19 @@ private async Task StartConsumer(ISourceBlock<EventData> producer, IEnumerableAs

try
{
var stopWatch = new Stopwatch();
stopWatch.Start();
foreach (var measurement in _contentTemplate.GetMeasurements(token))
{
measurement.IngestionTimeUtc = evt.SystemProperties.EnqueuedTimeUtc;
createdMeasurements.Add((partitionId, measurement));

stopWatch.Stop();
_log.LogMetric(
IomtMetrics.NormalizedEventGenerationTimeMs(partitionId),
stopWatch.ElapsedMilliseconds);
stopWatch.Reset();
stopWatch.Start();
}
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ private IomtMetricDefinition(string metricName)

public static IomtMetricDefinition NormalizedEvent { get; } = new IomtMetricDefinition(nameof(NormalizedEvent));

public static IomtMetricDefinition NormalizedEventGenerationTimeMs { get; } = new IomtMetricDefinition(nameof(NormalizedEventGenerationTimeMs));

public static IomtMetricDefinition Measurement { get; } = new IomtMetricDefinition(nameof(Measurement));

public static IomtMetricDefinition MeasurementGroup { get; } = new IomtMetricDefinition(nameof(MeasurementGroup));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,5 +159,16 @@ public static Metric HandledException(string exceptionName, string connectorStag
{
return exceptionName.ToErrorMetric(connectorStage, ErrorType.GeneralError, ErrorSeverity.Critical);
}

/// <summary>
/// The time it takes to generate a Normalized Event.
/// </summary>
/// <param name="partitionId">The partition id of the events being consumed from the event hub partition </param>
public static Metric NormalizedEventGenerationTimeMs(string partitionId = null)
{
return IomtMetricDefinition.NormalizedEventGenerationTimeMs
.CreateBaseMetric(Category.Traffic, ConnectorOperation.Normalization)
.AddDimension(_partitionDimension, partitionId);
}
}
}