From 1d7fcd0d1214a70499dbc0c47aecf6ef5fc5e44b Mon Sep 17 00:00:00 2001 From: AmirMS <104940545+AmelBawa-msft@users.noreply.github.com> Date: Mon, 2 Dec 2024 17:07:09 -0800 Subject: [PATCH] Add CDN exp --- src/AppInstallerCommonCore/Experiment.cpp | 12 +++++++++++- .../Public/AppInstallerTelemetry.h | 2 ++ .../Public/winget/Experiment.h | 2 ++ src/AppInstallerRepositoryCore/SourceList.cpp | 18 +++++++++++++++--- 4 files changed, 30 insertions(+), 4 deletions(-) diff --git a/src/AppInstallerCommonCore/Experiment.cpp b/src/AppInstallerCommonCore/Experiment.cpp index 64eac7bc38..b934df5216 100644 --- a/src/AppInstallerCommonCore/Experiment.cpp +++ b/src/AppInstallerCommonCore/Experiment.cpp @@ -45,9 +45,19 @@ namespace AppInstaller::Settings } } + // Define static members + std::map Experiment::m_isEnabledCache; + std::mutex Experiment::m_mutex; + bool Experiment::IsEnabled(Key key) { - return IsEnabledInternal(key, User()); + std::lock_guard lock(m_mutex); + if (m_isEnabledCache.find(key) == m_isEnabledCache.end()) + { + m_isEnabledCache[key] = IsEnabledInternal(key, User()); + } + + return m_isEnabledCache[key]; } Experiment Experiment::GetExperiment(Key key) diff --git a/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h b/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h index 9d7452e0ff..1ff5962426 100644 --- a/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h +++ b/src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h @@ -128,6 +128,8 @@ namespace AppInstaller::Logging // LogNonFatalDOError std::string DOUrl; HRESULT DOHResult = S_OK; + + // TODO Add experiments telemetry }; // This type contains the registration lifetime of the telemetry trace logging provider. diff --git a/src/AppInstallerCommonCore/Public/winget/Experiment.h b/src/AppInstallerCommonCore/Public/winget/Experiment.h index 37f10cb8b8..ea6ac149ea 100644 --- a/src/AppInstallerCommonCore/Public/winget/Experiment.h +++ b/src/AppInstallerCommonCore/Public/winget/Experiment.h @@ -36,5 +36,7 @@ namespace AppInstaller::Settings Utility::LocIndView m_jsonName; std::string_view m_link; std::string m_key; + static std::map m_isEnabledCache; + static std::mutex m_mutex; }; } diff --git a/src/AppInstallerRepositoryCore/SourceList.cpp b/src/AppInstallerRepositoryCore/SourceList.cpp index 1eb0e8ba95..37fa778dbe 100644 --- a/src/AppInstallerRepositoryCore/SourceList.cpp +++ b/src/AppInstallerRepositoryCore/SourceList.cpp @@ -8,6 +8,7 @@ #include #include +#include #include using namespace AppInstaller::Settings; @@ -36,6 +37,7 @@ namespace AppInstaller::Repository constexpr std::string_view s_Source_WingetCommunityDefault_Name = "winget"sv; constexpr std::string_view s_Source_WingetCommunityDefault_Arg = "https://cdn.winget.microsoft.com/cache"sv; + constexpr std::string_view s_Source_WingetCommunityExperimental_Arg = "https://cdn2.winget.microsoft.com/cache"sv; constexpr std::string_view s_Source_WingetCommunityDefault_Data = "Microsoft.Winget.Source_8wekyb3d8bbwe"sv; constexpr std::string_view s_Source_WingetCommunityDefault_Identifier = "Microsoft.Winget.Source_8wekyb3d8bbwe"sv; @@ -207,6 +209,16 @@ namespace AppInstaller::Repository { return details.IsTombstone || details.Origin == SourceOrigin::Metadata || !details.IsVisible; } + + std::string_view GetWingetCommunitySource() + { + if (Settings::Experiment::IsEnabled(Settings::Experiment::Key::CDN)) + { + return s_Source_WingetCommunityExperimental_Arg; + } + + return s_Source_WingetCommunityDefault_Arg; + } } void SourceDetailsInternal::CopyMetadataFieldsTo(SourceDetailsInternal& target) @@ -251,7 +263,7 @@ namespace AppInstaller::Repository switch (source) { case WellKnownSource::WinGet: - return s_Source_WingetCommunityDefault_Arg; + return GetWingetCommunitySource(); case WellKnownSource::MicrosoftStore: return s_Source_MSStoreDefault_Arg; case WellKnownSource::DesktopFrameworks: @@ -278,7 +290,7 @@ namespace AppInstaller::Repository std::optional CheckForWellKnownSourceMatch(std::string_view name, std::string_view arg, std::string_view type) { - if (name == s_Source_WingetCommunityDefault_Name && arg == s_Source_WingetCommunityDefault_Arg && type == Microsoft::PreIndexedPackageSourceFactory::Type()) + if (name == s_Source_WingetCommunityDefault_Name && arg == GetWingetCommunitySource() && type == Microsoft::PreIndexedPackageSourceFactory::Type()) { return WellKnownSource::WinGet; } @@ -306,7 +318,7 @@ namespace AppInstaller::Repository details.Origin = SourceOrigin::Default; details.Name = s_Source_WingetCommunityDefault_Name; details.Type = Microsoft::PreIndexedPackageSourceFactory::Type(); - details.Arg = s_Source_WingetCommunityDefault_Arg; + details.Arg = GetWingetCommunitySource(); details.Data = s_Source_WingetCommunityDefault_Data; details.Identifier = s_Source_WingetCommunityDefault_Identifier; details.TrustLevel = SourceTrustLevel::Trusted | SourceTrustLevel::StoreOrigin;