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

Adding the client code for supporting experiments #5034

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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 @@ -375,7 +375,7 @@
<Filter>Source Files\Common</Filter>
</ClCompile>
<ClCompile Include="Experiment.cpp">
<Filter>Source Files\Repository</Filter>
<Filter>Source Files\Common</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
Expand Down
1 change: 0 additions & 1 deletion src/AppInstallerCLITests/Experiment.cpp
AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
Expand Down
9 changes: 4 additions & 5 deletions src/AppInstallerCommonCore/AppInstallerTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#define AICLI_TraceLoggingStringView(_sv_,_name_) TraceLoggingCountedUtf8String(_sv_.data(), static_cast<ULONG>(_sv_.size()), _name_)
#define AICLI_TraceLoggingWStringView(_sv_,_name_) TraceLoggingCountedWideString(_sv_.data(), static_cast<ULONG>(_sv_.size()), _name_)
#define AICLI_TraceLoggingJsonWString(_sv_, _name_) TraceLoggingPackedFieldEx(_sv_.c_str(), static_cast<ULONG>((_sv_.size() + 1) * sizeof(wchar_t)), TlgInUNICODESTRING, TlgOutJSON, _name_)
#define AICLI_TraceLoggingJsonString(_sv_, _name_) TraceLoggingPackedFieldEx(_sv_.c_str(), static_cast<ULONG>((_sv_.size() + 1) * sizeof(char)), TlgInUNICODESTRING, TlgOutJSON, _name_)

#define AICLI_TraceLoggingWriteActivity(_eventName_,...) TraceLoggingWriteActivity(\
g_hTraceProvider,\
Expand Down Expand Up @@ -81,7 +80,7 @@ namespace AppInstaller::Logging
}
}

std::string GetExperimentsJson(const std::map<Experiment::Key, ExperimentState>& experiments)
std::wstring GetExperimentsJson(const std::map<Experiment::Key, ExperimentState>& experiments)
{
Json::Value root;
for (const auto& experiment : experiments)
Expand All @@ -91,7 +90,7 @@ namespace AppInstaller::Logging
}

Json::StreamWriterBuilder builder;
return Json::writeString(builder, root);
return Utility::ConvertToUTF16(Json::writeString(builder, root));
}
}

Expand Down Expand Up @@ -870,8 +869,8 @@ namespace AppInstaller::Logging
AICLI_TraceLoggingStringView(m_summary.RepairExecutionType, "RepairExecutionType"),
TraceLoggingUInt32(m_summary.RepairErrorCode, "RepairErrorCode"),
TelemetryPrivacyDataTag(PDT_ProductAndServicePerformance | PDT_ProductAndServiceUsage | PDT_SoftwareSetupAndInventory),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES),
AICLI_TraceLoggingJsonString(experimentsJson, "ExperimentsJson"));
AICLI_TraceLoggingJsonWString(experimentsJson, "ExperimentsJson"),
TraceLoggingKeyword(MICROSOFT_KEYWORD_MEASURES));
}
}
}
Expand Down
31 changes: 13 additions & 18 deletions src/AppInstallerCommonCore/Experiment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,30 @@ namespace AppInstaller::Settings
{
ExperimentState GetExperimentStateInternal(Experiment::Key key, const UserSettings& userSettings)
{
if (key == Experiment::Key::None)
{
return { true, ExperimentToggleSource::Default };
}

if (!GroupPolicies().IsEnabled(TogglePolicy::Policy::Experiments))
{
AICLI_LOG(Core, Info, <<
"Experiment " << Experiment::GetExperiment(key).Name() <<
AICLI_LOG(Core, Info, << "Experiment " << Experiment::GetExperiment(key).Name() <<
" is disabled due to group policy: " << TogglePolicy::GetPolicy(TogglePolicy::Policy::Experiments).RegValueName());
return { false, ExperimentToggleSource::Policy };
AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved
}

auto experiments = userSettings.Get<Setting::Experiments>();
if (key == Experiment::Key::None)
AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved
{
return { false, ExperimentToggleSource::Default };
}

auto experiment = Experiment::GetExperiment(key);
AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved
auto userSettingsExperiments = userSettings.Get<Setting::Experiments>();
auto jsonName = std::string(experiment.JsonName());
if (experiments.find(jsonName) != experiments.end())
if (userSettingsExperiments.find(jsonName) != userSettingsExperiments.end())
{
auto isEnabled = experiments[jsonName];
AICLI_LOG(Core, Info, <<
"Experiment " << Experiment::GetExperiment(key).Name() <<
" is set to " << isEnabled << " in user settings");
auto isEnabled = userSettingsExperiments[jsonName];
AICLI_LOG(Core, Info, << "Experiment " << experiment.Name() << " is set to " << (isEnabled ? "true" : "false") << " in user settings");
return { isEnabled, ExperimentToggleSource::UserSetting };
}

auto isEnabled = AppInstaller::Experiment::IsEnabled(experiment.GetKey());
AICLI_LOG(Core, Info, <<
"Experiment " << Experiment::GetExperiment(key).Name() <<
" is set to " << isEnabled);
AICLI_LOG(Core, Info, << "Experiment " << experiment.Name() << " is set to " << (isEnabled ? "true" : "false"));
return { isEnabled, ExperimentToggleSource::Default };
}

Expand Down Expand Up @@ -85,7 +80,7 @@ namespace AppInstaller::Settings
switch (key)
{
case Key::CDN:
return Experiment{ "CDN experiment", "CDN", "https://aka.ms/winget-settings", "CDN"};
return Experiment{ "winget source CDN experiment", "CDN", "https://aka.ms/winget-settings", "CDN"};
#ifndef AICLI_DISABLE_TEST_HOOKS
case Key::TestExperiment:
return Experiment{ "Test experiment", "TestExperiment", "https://aka.ms/winget-settings", "TestExperiment" };
Expand All @@ -99,7 +94,7 @@ namespace AppInstaller::Settings
{
std::vector<Experiment> result;

for (Key_t i = 0x1; i < static_cast<Key_t>(Key::Max); i = i << 1)
for (Key_t i = 0x1; i < static_cast<Key_t>(Key::Max); ++i)
{
result.emplace_back(GetExperiment(static_cast<Key>(i)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ namespace AppInstaller::Logging
std::string DOUrl;
HRESULT DOHResult = S_OK;

// LogExperiment
std::map<Settings::Experiment::Key, Settings::ExperimentState> Experiments;
AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved
};

Expand Down
20 changes: 10 additions & 10 deletions src/AppInstallerCommonCore/Public/winget/Experiment.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ namespace AppInstaller::Settings
enum ExperimentToggleSource
{
Default = 0,
Policy = 1,
UserSetting = 2,
Policy,
UserSetting,
};

struct ExperimentState
Expand All @@ -30,8 +30,8 @@ namespace AppInstaller::Settings
{
enum class Key : unsigned
{
None = 0x0,
CDN = 0x1,
None = 0,
CDN,
Max,

#ifndef AICLI_DISABLE_TEST_HOOKS
Expand All @@ -41,23 +41,23 @@ namespace AppInstaller::Settings

using Key_t = std::underlying_type_t<Key>;

Experiment(std::string_view name, std::string_view jsonName, std::string_view link, std::string key) :
m_name(name), m_jsonName(jsonName), m_link(link), m_key(key) {}
Experiment(std::string name, std::string jsonName, std::string link, std::string key) :
m_name(std::move(name)), m_jsonName(jsonName), m_link(std::move(link)), m_key(std::move((key))) {}
AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved

static ExperimentState GetState(Key feature);
static ExperimentState GetStateInternal(Key feature);
Copy link
Member

Choose a reason for hiding this comment

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

What makes it internal if it is public?

static Experiment GetExperiment(Key key);
static std::vector<Experiment> GetAllExperiments();

std::string_view Name() const { return m_name; }
std::string Name() const { return m_name; }
AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved
Utility::LocIndView JsonName() const { return m_jsonName; }
std::string_view Link() const { return m_link; }
std::string Link() const { return m_link; }
std::string GetKey() const { return m_key; }

private:
std::string_view m_name;
std::string m_name;
Utility::LocIndView m_jsonName;
AmelBawa-msft marked this conversation as resolved.
Show resolved Hide resolved
std::string_view m_link;
std::string m_link;
std::string m_key;
};
}
5 changes: 3 additions & 2 deletions src/AppInstallerSharedLib/JsonUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,10 @@ namespace AppInstaller::JSON
{
for (const auto& entry : node.getMemberNames())
{
if (node[entry].isBool())
auto& value = node[entry];
if (value.isBool())
{
result[entry] = node[entry].asBool();
result[entry] = value.asBool();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerSharedLib/Public/winget/JsonUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace AppInstaller::JSON
std::optional<std::vector<std::string>> GetValue<std::vector<std::string>>(const Json::Value& node);

template<>
std::optional<std::map<std::string, bool>> GetValue(const Json::Value& node);
std::optional<std::map<std::string, bool>> GetValue<std::map<std::string, bool>>(const Json::Value& node);

#ifndef WINGET_DISABLE_FOR_FUZZING
// For cpprestsdk JSON
Expand Down
Loading