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

Include umbraco-package.json manifests in telemetry data #16430

Merged
merged 4 commits into from
May 31, 2024

Conversation

ronaldbarendse
Copy link
Contributor

Prerequisites

  • I have added steps to test this contribution in the description below

Description

PR #15744 removed the legacy package manifest parser, but also removed the code from PackagingService that returned the combined the package migrations and manifests. This data is used in the telemetry service to report the installed packages (if the consent level of the installation is set to Basic or Detailed and the package hasn't opted-out), which is mainly used in the Marketplace to sort the packages by most active installs.

Another important detail that was missing, is being able to specify the (NuGet) package ID in the manifest, so the Marketplace can do a 1:1 match when aggregating the data.

Besides re-introducing the package manifests as installed packages and adding the package ID, I've ensured the ID is also exposed in the Management API endpoints. E.g. the umbraco/management/api/v1/manifest/manifest endpoint now returns:

[
  {
    "name": "@umbraco-cms/backoffice",
    "id": null,
    "version": "14.0.0-rc2",
    "extensions": []
  },
  {
    "name": "Test",
    "id": "Umbraco.Cms.Test",
    "version": "14.0.0",
    "extensions": []
  }
]

Testing can be done by adding a umbraco-package.json file to e.g. wwwroot\App_Plugins\Test:

{
  "name": "Test",
  "id": "Umbraco.Cms.Test",
  "version": "14.0.0",
  "extensions": []
}

And then making sure this is included in ReportSiteJob.RunJobAsync() (update Delay to 0 and add a breakpoint to this method) and the package ID is exposed in the Management API (all Manifest endpoints).

@ronaldbarendse
Copy link
Contributor Author

The backoffice UI will still need to be updated to show the package ID, as that's currently missing:

Installed packages v14

Comparing it to v13, the package name is more visible/prominent and the version has a label, so maybe the styling could be slightly updated as well:

Installed packages v13

@Zeegaan
Copy link
Member

Zeegaan commented May 28, 2024

Heyo 👋
This won't make it in 14.0.0 sadly, so you'll need to fix the breaking changes in IPackagingService, should be fairly simple using Default implementation 😁

@@ -155,7 +183,8 @@ public async Task<PagedModel<PackageDefinition>> GetCreatedPackagesAsync(int ski
using ICoreScope scope = _coreScopeProvider.CreateCoreScope(autoComplete: true);
PackageDefinition[] packages = _createdPackages.GetAll().WhereNotNull().ToArray();
var pagedModel = new PagedModel<PackageDefinition>(packages.Length, packages.Skip(skip).Take(take));
return await Task.FromResult(pagedModel);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed we have quite a few occurrences of await Task.FromResult() spread throughout the codebase, which seems wasteful, as it wraps the result and adds an additional await (with all the extra async state machine code that's generated by the compiler)...

@ronaldbarendse
Copy link
Contributor Author

Heyo 👋 This won't make it in 14.0.0 sadly, so you'll need to fix the breaking changes in IPackagingService, should be fairly simple using Default implementation 😁

I've avoided any breaking changes now and added comments to highlight some additional bugs/issues that are fixed in this PR. Would be great if we can ship this in a patch, instead of waiting for the next minor 😇

@Zeegaan Zeegaan changed the base branch from release/14.0 to v14/dev May 30, 2024 08:56
@ronaldbarendse
Copy link
Contributor Author

ronaldbarendse commented May 30, 2024

To help testing out the changes, you can put this composer/component in your project and check out the logged messages:

using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Telemetry;

internal sealed class LogPackageTelemetryComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.AddComponent<LogPackageTelemetryComponent>();
    }

    private sealed class LogPackageTelemetryComponent : IComponent
    {
        private readonly ITelemetryService _telemetryService;
        private readonly ILogger<LogPackageTelemetryComponent> _logger;

        public LogPackageTelemetryComponent(ITelemetryService telemetryService, ILogger<LogPackageTelemetryComponent> logger)
        {
            _telemetryService = telemetryService;
            _logger = logger;
        }

        public void Initialize()
        {
            var telemetryReportData = _telemetryService.GetTelemetryReportDataAsync().GetAwaiter().GetResult();
            if (telemetryReportData?.Packages is not null)
            {
                foreach (var packageTelemetry in telemetryReportData.Packages)
                {
                    _logger.LogInformation(
                        "Package telemetry for {PackageName} ({PackageId}) {PackageVersion}",
                        packageTelemetry.Name,
                        packageTelemetry.Id,
                        packageTelemetry.Version);
                }
            }
        }

        public void Terminate()
        { }
    }
}

On a side note: this does highlight the fact we don't have an IAsyncComponent 😇

@Zeegaan
Copy link
Member

Zeegaan commented May 31, 2024

Looks good, tests good 🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants