Skip to content

Commit

Permalink
Add CDN exp
Browse files Browse the repository at this point in the history
  • Loading branch information
AmelBawa-msft committed Dec 3, 2024
1 parent f95c26c commit 1d7fcd0
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
12 changes: 11 additions & 1 deletion src/AppInstallerCommonCore/Experiment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,19 @@ namespace AppInstaller::Settings
}
}

// Define static members
std::map<Experiment::Key, bool> 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)
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerCommonCore/Public/AppInstallerTelemetry.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/AppInstallerCommonCore/Public/winget/Experiment.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ namespace AppInstaller::Settings
Utility::LocIndView m_jsonName;
std::string_view m_link;
std::string m_key;
static std::map<Key, bool> m_isEnabledCache;
static std::mutex m_mutex;
};
}
18 changes: 15 additions & 3 deletions src/AppInstallerRepositoryCore/SourceList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include <winget/AdminSettings.h>
#include <winget/Certificates.h>
#include <winget/Experiment.h>
#include <CertificateResources.h>

using namespace AppInstaller::Settings;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand All @@ -278,7 +290,7 @@ namespace AppInstaller::Repository

std::optional<WellKnownSource> 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;
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 1d7fcd0

Please sign in to comment.