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

Add telemetry for HTTP resources that have an HTTPS source #6022

Closed
wants to merge 5 commits into from
Closed
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 @@ -4,6 +4,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Protocol.Core.Types;

namespace NuGet.Protocol
Expand Down Expand Up @@ -32,7 +33,18 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceReposito

// If index.json contains a flat container resource use that to directly
// construct package download urls.
var packageBaseAddress = serviceIndex.GetServiceEntryUri(ServiceTypes.PackageBaseAddress)?.AbsoluteUri;
var uri = serviceIndex.GetServiceEntryUri(ServiceTypes.PackageBaseAddress);
var packageBaseAddress = uri?.AbsoluteUri;

if (uri != null &&
source.PackageSource.IsHttps &&
uri?.Scheme == Uri.UriSchemeHttp &&
uri?.Scheme != Uri.UriSchemeHttps)
{
// Telemetry for HTTPS sources that have an HTTP resource
var telemetry = new ServiceIndexEntryTelemetry(1, "RestorePackageSourceSummary");
TelemetryActivity.EmitTelemetryEvent(telemetry);
}

if (packageBaseAddress != null)
{
Expand All @@ -49,5 +61,13 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceReposito

return new Tuple<bool, INuGetResource>(curResource != null, curResource);
}

private class ServiceIndexEntryTelemetry : TelemetryEvent
{
public ServiceIndexEntryTelemetry(int NumSourceWithHttpResource, string eventName) : base(eventName)
{
this["NumHTTPDownloadResourceWithHTTPSSource"] = NumSourceWithHttpResource;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Protocol.Core.Types;
using NuGet.Protocol.Resources;

Expand All @@ -31,6 +32,16 @@ public OwnerDetailsUriResourceV3Provider()
{
Uri? uriTemplate = serviceIndex.GetServiceEntryUri(ServiceTypes.OwnerDetailsUriTemplate);

if (uriTemplate != null &&
source.PackageSource.IsHttps &&
uriTemplate?.Scheme == Uri.UriSchemeHttp &&
uriTemplate?.Scheme != Uri.UriSchemeHttps)
{
// Telemetry for HTTPS sources that have an HTTP resource
var telemetry = new ServiceIndexEntryTelemetry(1, "RestorePackageSourceSummary");
TelemetryActivity.EmitTelemetryEvent(telemetry);
}

if (uriTemplate != null)
{
resource = OwnerDetailsUriTemplateResourceV3.CreateOrNull(uriTemplate);
Expand All @@ -39,5 +50,13 @@ public OwnerDetailsUriResourceV3Provider()

return new Tuple<bool, INuGetResource?>(resource != null, resource);
}

private class ServiceIndexEntryTelemetry : TelemetryEvent
{
public ServiceIndexEntryTelemetry(int NumSourceWithHttpResource, string eventName) : base(eventName)
{
this["NumHTTPOwnerDetailsUriResourceWithHTTPSSource"] = NumSourceWithHttpResource;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Protocol.Core.Types;

namespace NuGet.Protocol
Expand All @@ -24,10 +25,29 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceReposito
if (serviceIndex != null)
{
var uri = serviceIndex.GetServiceEntryUri(ServiceTypes.PackageDetailsUriTemplate);

if (uri != null &&
source.PackageSource.IsHttps &&
uri?.Scheme == Uri.UriSchemeHttp &&
uri?.Scheme != Uri.UriSchemeHttps)
{
// Telemetry for HTTPS sources that have an HTTP resource
var telemetry = new ServiceIndexEntryTelemetry(1, "RestorePackageSourceSummary");
TelemetryActivity.EmitTelemetryEvent(telemetry);
}

resource = PackageDetailsUriResourceV3.CreateOrNull(uri?.OriginalString);
}

return new Tuple<bool, INuGetResource>(resource != null, resource);
}

private class ServiceIndexEntryTelemetry : TelemetryEvent
{
public ServiceIndexEntryTelemetry(int NumSourceWithHttpResource, string eventName) : base(eventName)
{
this["NumHTTPPackageDetailsUriResourceWithHTTPSSource"] = NumSourceWithHttpResource;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Protocol.Core.Types;

namespace NuGet.Protocol
Expand All @@ -30,6 +31,16 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(
{
var baseUrl = serviceIndex.GetServiceEntryUri(ServiceTypes.PackagePublish);

if (baseUrl != null &&
source.PackageSource.IsHttps &&
baseUrl?.Scheme == Uri.UriSchemeHttp &&
baseUrl?.Scheme != Uri.UriSchemeHttps)
{
// Telemetry for HTTPS sources that have an HTTP resource
var telemetry = new ServiceIndexEntryTelemetry(1, "RestorePackageSourceSummary");
TelemetryActivity.EmitTelemetryEvent(telemetry);
}

HttpSource httpSource = null;
var sourceUri = baseUrl?.AbsoluteUri;
if (!string.IsNullOrEmpty(sourceUri))
Expand All @@ -52,5 +63,13 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(
var result = new Tuple<bool, INuGetResource>(packageUpdateResource != null, packageUpdateResource);
return result;
}

private class ServiceIndexEntryTelemetry : TelemetryEvent
{
public ServiceIndexEntryTelemetry(int NumSourceWithHttpResource, string eventName) : base(eventName)
{
this["NumPackageUpdateResourceWithHTTPSSource"] = NumSourceWithHttpResource;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Protocol.Core.Types;

namespace NuGet.Protocol
Expand All @@ -27,6 +28,16 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceReposito
//This will come back as null if there are no matching RegistrationsBaseUrl types
var baseUrl = serviceIndex.GetServiceEntryUri(ServiceTypes.RegistrationsBaseUrl);

if (baseUrl != null &&
source.PackageSource.IsHttps &&
baseUrl?.Scheme == Uri.UriSchemeHttp &&
baseUrl?.Scheme != Uri.UriSchemeHttps)
{
// Telemetry for HTTPS sources that have an HTTP resource
var telemetry = new ServiceIndexEntryTelemetry(1, "RestorePackageSourceSummary");
TelemetryActivity.EmitTelemetryEvent(telemetry);
}

if (baseUrl != null)
{
var httpSourceResource = await source.GetResourceAsync<HttpSourceResource>(token);
Expand All @@ -38,5 +49,13 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceReposito

return new Tuple<bool, INuGetResource>(regResource != null, regResource);
}

private class ServiceIndexEntryTelemetry : TelemetryEvent
{
public ServiceIndexEntryTelemetry(int NumSourceWithHttpResource, string eventName) : base(eventName)
{
this["NumHTTPRegistrationResourceWithHTTPSSource"] = NumSourceWithHttpResource;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Protocol.Core.Types;

namespace NuGet.Protocol
Expand All @@ -23,13 +24,32 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceReposito
var serviceIndex = await source.GetResourceAsync<ServiceIndexResourceV3>(token);
if (serviceIndex != null)
{
var uriTemplate = serviceIndex.GetServiceEntryUri(ServiceTypes.ReportAbuse)?.AbsoluteUri;
var uri = serviceIndex.GetServiceEntryUri(ServiceTypes.ReportAbuse);
var uriTemplate = uri?.AbsoluteUri;

if (uri != null &&
source.PackageSource.IsHttps &&
uri?.Scheme == Uri.UriSchemeHttp &&
uri?.Scheme != Uri.UriSchemeHttps)
{
// Telemetry for HTTPS sources that have an HTTP resource
var telemetry = new ServiceIndexEntryTelemetry(1, "RestorePackageSourceSummary");
TelemetryActivity.EmitTelemetryEvent(telemetry);
}

// construct a new resource
resource = new ReportAbuseResourceV3(uriTemplate);
}

return new Tuple<bool, INuGetResource>(resource != null, resource);
}

private class ServiceIndexEntryTelemetry : TelemetryEvent
{
public ServiceIndexEntryTelemetry(int NumSourceWithHttpResource, string eventName) : base(eventName)
{
this["NumHTTPReportAbuseResourceWithHTTPSSource"] = NumSourceWithHttpResource;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Protocol.Core.Types;

namespace NuGet.Protocol
Expand All @@ -27,6 +28,16 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceReposito
{
var baseUrl = serviceIndex.GetServiceEntryUri(ServiceTypes.SymbolPackagePublish);

if (baseUrl != null &&
source.PackageSource.IsHttps &&
baseUrl?.Scheme == Uri.UriSchemeHttp &&
baseUrl?.Scheme != Uri.UriSchemeHttps)
{
// Telemetry for HTTPS sources that have an HTTP resource
var telemetry = new ServiceIndexEntryTelemetry(1, "RestorePackageSourceSummary");
TelemetryActivity.EmitTelemetryEvent(telemetry);
}

HttpSource httpSource = null;
var sourceUri = baseUrl?.AbsoluteUri;
if (!string.IsNullOrEmpty(sourceUri))
Expand All @@ -43,5 +54,13 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(SourceReposito
var result = new Tuple<bool, INuGetResource>(symbolPackageUpdateResource != null, symbolPackageUpdateResource);
return result;
}

private class ServiceIndexEntryTelemetry : TelemetryEvent
{
public ServiceIndexEntryTelemetry(int NumSourceWithHttpResource, string eventName) : base(eventName)
{
this["NumHTTPSymbolPackageUpdateResourceWithHTTPSSource"] = NumSourceWithHttpResource;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ public override async Task<Tuple<bool, INuGetResource>> TryCreate(
if (serviceIndex != null)
{
var baseUrl = serviceIndex.GetServiceEntryUri(ServiceTypes.LegacyGallery);

if (baseUrl != null &&
source.PackageSource.IsHttps &&
baseUrl?.Scheme == Uri.UriSchemeHttp &&
baseUrl?.Scheme != Uri.UriSchemeHttps)
{
// Telemetry for HTTPS sources that have an HTTP resource
var telemetry = new ServiceIndexEntryTelemetry(1, "RestorePackageSourceSummary");
TelemetryActivity.EmitTelemetryEvent(telemetry);
}

if (baseUrl != null)
{
var httpSource = await source.GetResourceAsync<HttpSourceResource>(token);
Expand All @@ -45,5 +56,13 @@ await ODataServiceDocumentUtils.CreateODataServiceDocumentResourceV2(
var result = new Tuple<bool, INuGetResource>(resource != null, resource);
return result;
}

private class ServiceIndexEntryTelemetry : TelemetryEvent
{
public ServiceIndexEntryTelemetry(int NumSourceWithHttpResource, string eventName) : base(eventName)
{
this["NumHTTPV3FeedListResourceWithHTTPSSource"] = NumSourceWithHttpResource;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Threading;
using System.Threading.Tasks;
using NuGet.Common;
using NuGet.Protocol.Core.Types;
using NuGet.Protocol.Resources;

Expand All @@ -26,6 +27,17 @@ public VulnerabilityInfoResourceV3Provider()
{
var serviceIndexResource = await source.GetResourceAsync<ServiceIndexResourceV3>(token);
Uri? baseUri = serviceIndexResource?.GetServiceEntryUri(ServiceTypes.VulnerabilityInfo);

if (baseUri != null &&
source.PackageSource.IsHttps &&
baseUri?.Scheme == Uri.UriSchemeHttp &&
baseUri?.Scheme != Uri.UriSchemeHttps)
{
// Telemetry for HTTPS sources that have an HTTP resource
var telemetry = new ServiceIndexEntryTelemetry(1, "RestorePackageSourceSummary");
TelemetryActivity.EmitTelemetryEvent(telemetry);
}

if (baseUri != null)
{
var resource = new VulnerabilityInfoResourceV3(source);
Expand All @@ -34,5 +46,13 @@ public VulnerabilityInfoResourceV3Provider()

return new Tuple<bool, INuGetResource?>(false, null);
}

private class ServiceIndexEntryTelemetry : TelemetryEvent
{
public ServiceIndexEntryTelemetry(int NumSourceWithHttpResource, string eventName) : base(eventName)
{
this["NumHTTPVulnerabilityInfoResourceWithHTTPSSource"] = NumSourceWithHttpResource;
}
}
}
}
Loading