This repository has been archived by the owner on Jul 30, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add telemetry around report generation in Search.GenerateAuxiliaryData (
#740) Address NuGet/Engineering#2327
- Loading branch information
1 parent
e8101f6
commit f9f08ff
Showing
9 changed files
with
135 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/Search.GenerateAuxiliaryData/Telemetry/ITelemetryService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
||
namespace Search.GenerateAuxiliaryData.Telemetry | ||
{ | ||
public interface ITelemetryService | ||
{ | ||
void TrackExporterDuration(string exporter, string report, TimeSpan duration, bool success); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/Search.GenerateAuxiliaryData/Telemetry/TelemetryService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using NuGet.Services.Logging; | ||
|
||
namespace Search.GenerateAuxiliaryData.Telemetry | ||
{ | ||
public class TelemetryService : ITelemetryService | ||
{ | ||
private const string Prefix = "Search.GenerateAuxiliaryData."; | ||
|
||
private readonly ITelemetryClient _telemetryClient; | ||
|
||
public TelemetryService(ITelemetryClient telemetryClient) | ||
{ | ||
_telemetryClient = telemetryClient; | ||
} | ||
|
||
public void TrackExporterDuration(string exporter, string report, TimeSpan duration, bool success) | ||
{ | ||
_telemetryClient.TrackMetric( | ||
Prefix + "ExporterDurationMs", | ||
duration.TotalMilliseconds, | ||
new Dictionary<string, string> | ||
{ | ||
{ "Exporter", exporter }, | ||
{ "Report", report }, | ||
{ "Success", success.ToString() }, | ||
}); | ||
} | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
tests/Tests.Search.GenerateAuxiliaryData/Telemetry/TelemetryServiceFacts.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
using System.Collections.Concurrent; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Moq; | ||
using NuGet.Services.Logging; | ||
using Search.GenerateAuxiliaryData.Telemetry; | ||
using Xunit; | ||
|
||
namespace Tests.Search.GenerateAuxiliaryData.Telemetry | ||
{ | ||
public class TelemetryServiceFacts | ||
{ | ||
public class TrackExporterDuration : BaseFacts | ||
{ | ||
[Fact] | ||
public void EmitsExpectedMetric() | ||
{ | ||
Target.TrackExporterDuration( | ||
"TheExporter", | ||
"TheReport", | ||
TimeSpan.FromMilliseconds(1234), | ||
success: true); | ||
|
||
TelemetryClient.Verify( | ||
x => x.TrackMetric( | ||
"Search.GenerateAuxiliaryData.ExporterDurationMs", | ||
1234, | ||
It.IsAny<IDictionary<string, string>>()), | ||
Times.Once); | ||
|
||
var properties = Assert.Single(Properties); | ||
Assert.Equal(new[] { "Exporter", "Report", "Success" }, properties.Keys.OrderBy(x => x).ToArray()); | ||
Assert.Equal("TheExporter", properties["Exporter"]); | ||
Assert.Equal("TheReport", properties["Report"]); | ||
Assert.Equal("True", properties["Success"]); | ||
} | ||
} | ||
|
||
public abstract class BaseFacts | ||
{ | ||
public BaseFacts() | ||
{ | ||
TelemetryClient = new Mock<ITelemetryClient>(); | ||
Properties = new ConcurrentQueue<IDictionary<string, string>>(); | ||
|
||
TelemetryClient | ||
.Setup(x => x.TrackMetric(It.IsAny<string>(), It.IsAny<double>(), It.IsAny<IDictionary<string, string>>())) | ||
.Callback<string, double, IDictionary<string, string>>((_, __, p) => Properties.Enqueue(p)); | ||
|
||
Target = new TelemetryService(TelemetryClient.Object); | ||
} | ||
|
||
public Mock<ITelemetryClient> TelemetryClient { get; } | ||
public ConcurrentQueue<IDictionary<string, string>> Properties { get; } | ||
public TelemetryService Target { get; } | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters