Add AWSAttribution feature (#1164)

* LYN-3601: Provide skeleton classes for AWS Attribution (#31)

Provide skeleton classes for AWS Attribution, along with some basic unit tests

* Add AWS Attribution UI and settings (#56)

* Adding AWS Attributions UX and corresponding editor preference s setting

* Fix serialized field description

* Fixed update frequency to be  a day

* Handling editor startup with default values for AWSAttribution

* Add missing header and remove AWSCoreSystemComponentMock fron test

* Generate and post AWSAttribution metric (#69)

* Adding AWS Attribution Api service job

* Adding support for config endpoint override

* Update Api endpoint formatting, fix default region

* Remove extra header

* Fixes for link issues

* Fix Unittest namespace

* Instantiating AWSAttributionSystemComponent in AWS.Editor module

* Update AttributionMetric with engine version and AWS enabled gems (#77)

* Update AttributionMetric with engine version and AWS enabled gems

* Fix warnings

* Undoing accidental change

* Saving level PrefabLevel_OpensLevelWithEntities

* Remove overriding editorprefrences.setreg

* Revert "Saving level PrefabLevel_OpensLevelWithEntities"

This reverts commit 529af70c55ece70fc6bc29ceb83bef60413713a3.

* Move AWS preferences to its own temp settings file

* Undo accidental file add

* Add missing string params in warning messages

Co-authored-by: Pip Potter <61438964+lmbr-pip@users.noreply.github.com>
This commit is contained in:
amzn-hdoke
2021-06-04 20:48:35 -07:00
committed by GitHub
parent 2ba6300a45
commit bf29b27937
27 changed files with 1732 additions and 5 deletions
@@ -35,6 +35,7 @@
#include "EditorPreferencesPageViewportMovement.h"
#include "EditorPreferencesPageViewportDebug.h"
#include "EditorPreferencesPageExperimentalLighting.h"
#include "EditorPreferencesPageAWS.h"
#include "LyViewPaneNames.h"
AZ_PUSH_DISABLE_DLL_EXPORT_MEMBER_WARNING
@@ -72,6 +73,7 @@ EditorPreferencesDialog::EditorPreferencesDialog(QWidget* pParent)
CEditorPreferencesPage_ViewportMovement::Reflect(*serializeContext);
CEditorPreferencesPage_ViewportDebug::Reflect(*serializeContext);
CEditorPreferencesPage_ExperimentalLighting::Reflect(*serializeContext);
CEditorPreferencesPage_AWS::Reflect(*serializeContext);
}
}
@@ -0,0 +1,151 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include "EditorDefs.h"
#include "EditorPreferencesPageAWS.h"
// AzCore
#include <AzCore/Serialization/EditContext.h>
#include <AzCore/Settings/SettingsRegistryMergeUtils.h>
#include <AzCore/Jobs/JobFunction.h>
void CEditorPreferencesPage_AWS::Reflect(AZ::SerializeContext& serialize)
{
serialize.Class<UsageOptions>()
->Version(1)
->Field("AWSAttributionEnabled", &UsageOptions::m_awsAttributionEnabled);
serialize.Class<CEditorPreferencesPage_AWS>()
->Version(1)
->Field("UsageOptions", &CEditorPreferencesPage_AWS::m_usageOptions);
AZ::EditContext* editContext = serialize.GetEditContext();
if (editContext)
{
editContext->Class<UsageOptions>("Options", "")
->DataElement(AZ::Edit::UIHandlers::CheckBox, &UsageOptions::m_awsAttributionEnabled, "Send Metrics usage to AWS",
"Reports Gem usage to AWS on Editor launch");
editContext->Class<CEditorPreferencesPage_AWS>("AWS Preferences", "AWS Preferences")
->ClassElement(AZ::Edit::ClassElements::EditorData, "")
->Attribute(AZ::Edit::Attributes::Visibility, AZ_CRC("PropertyVisibility_ShowChildrenOnly", 0xef428f20))
->DataElement(AZ::Edit::UIHandlers::Default, &CEditorPreferencesPage_AWS::m_usageOptions, "AWS Usage Data", "AWS Usage Options");
}
}
CEditorPreferencesPage_AWS::CEditorPreferencesPage_AWS()
{
m_settingsRegistry = AZStd::make_unique<AZ::SettingsRegistryImpl>();
InitializeSettings();
// TODO Update with AWS svg.
m_icon = QIcon(":/res/AWS_preferences_icon.svg");
}
CEditorPreferencesPage_AWS::~CEditorPreferencesPage_AWS()
{
m_settingsRegistry.reset();
}
const char* CEditorPreferencesPage_AWS::GetTitle()
{
return "AWS";
}
QIcon& CEditorPreferencesPage_AWS::GetIcon()
{
return m_icon;
}
void CEditorPreferencesPage_AWS::OnApply()
{
m_settingsRegistry->Set(AWSAttributionEnabledKey, m_usageOptions.m_awsAttributionEnabled);
SaveSettingsRegistryFile();
}
const CEditorPreferencesPage_AWS::UsageOptions& CEditorPreferencesPage_AWS::GetUsageOptions()
{
return m_usageOptions;
}
void CEditorPreferencesPage_AWS::SaveSettingsRegistryFile()
{
AZ::Job* job = AZ::CreateJobFunction(
[this]()
{
AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance();
AZ_Assert(fileIO, "File IO is not initialized.");
// Resolve path to editor_aws_preferences.setreg
AZStd::string editorPreferencesFilePath =
AZStd::string::format("@user@/%s/%s", AZ::SettingsRegistryInterface::RegistryFolder, EditorAWSPreferencesFileName);
AZStd::array<char, AZ::IO::MaxPathLength> resolvedPath{};
fileIO->ResolvePath(editorPreferencesFilePath.c_str(), resolvedPath.data(), resolvedPath.size());
AZ::SettingsRegistryMergeUtils::DumperSettings dumperSettings;
dumperSettings.m_prettifyOutput = true;
dumperSettings.m_jsonPointerPrefix = AWSAttributionSettingsPrefixKey;
AZStd::string stringBuffer;
AZ::IO::ByteContainerStream stringStream(&stringBuffer);
if (!AZ::SettingsRegistryMergeUtils::DumpSettingsRegistryToStream(
*m_settingsRegistry, AWSAttributionSettingsPrefixKey, stringStream, dumperSettings))
{
AZ_Warning(
"AWSAttributionManager", false, R"(Unable to save changes to the Editor AWS Preferences registry file at "%s"\n)",
resolvedPath.data());
return;
}
bool saved{};
constexpr auto configurationMode =
AZ::IO::SystemFile::SF_OPEN_CREATE | AZ::IO::SystemFile::SF_OPEN_CREATE_PATH | AZ::IO::SystemFile::SF_OPEN_WRITE_ONLY;
if (AZ::IO::SystemFile outputFile; outputFile.Open(resolvedPath.data(), configurationMode))
{
saved = outputFile.Write(stringBuffer.data(), stringBuffer.size()) == stringBuffer.size();
}
AZ_Warning(
"AWSAttributionManager", saved, R"(Unable to save Editor AWS Preferences registry file to path "%s"\n)",
editorPreferencesFilePath.c_str());
},
true);
job->Start();
}
void CEditorPreferencesPage_AWS::InitializeSettings()
{
AZ::IO::FileIOBase* fileIO = AZ::IO::FileIOBase::GetInstance();
AZ_Assert(fileIO, "File IO is not initialized.");
// Resolve path to editor_aws_preferences.setreg
AZStd::string editorAWSPreferencesFilePath =
AZStd::string::format("@user@/%s/%s", AZ::SettingsRegistryInterface::RegistryFolder, EditorAWSPreferencesFileName);
AZStd::array<char, AZ::IO::MaxPathLength> resolvedPathAWSPreference{};
if (!fileIO->ResolvePath(editorAWSPreferencesFilePath.c_str(), resolvedPathAWSPreference.data(), resolvedPathAWSPreference.size()))
{
AZ_Warning("AWSAttributionManager", false, "Error resolving path %s", resolvedPathAWSPreference.data());
return;
}
if (fileIO->Exists(resolvedPathAWSPreference.data()))
{
m_settingsRegistry->MergeSettingsFile(resolvedPathAWSPreference.data(), AZ::SettingsRegistryInterface::Format::JsonMergePatch, "");
}
if (!m_settingsRegistry->Get(m_usageOptions.m_awsAttributionEnabled, AWSAttributionEnabledKey))
{
// If key is missing default to on.
m_usageOptions.m_awsAttributionEnabled = true;
}
}
@@ -0,0 +1,60 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include "Include/IPreferencesPage.h"
#include <AzCore/Serialization/SerializeContext.h>
#include <AzCore/Settings/SettingsRegistryImpl.h>
#include <AzCore/RTTI/RTTI.h>
#include <QIcon>
class CEditorPreferencesPage_AWS
: public IPreferencesPage
{
public:
AZ_RTTI(CEditorPreferencesPage_AWS, "{51FB9557-ABA3-4FD7-803A-1784F5B06F5F}", IPreferencesPage)
static void Reflect(AZ::SerializeContext& serialize);
CEditorPreferencesPage_AWS();
virtual ~CEditorPreferencesPage_AWS();
// IPreferencesPage interface methods.
virtual const char* GetCategory() override { return "AWS"; }
virtual const char* GetTitle() override;
virtual QIcon& GetIcon() override;
virtual void OnApply() override;
virtual void OnCancel() override {}
virtual bool OnQueryCancel() override { return true; }
protected:
struct UsageOptions
{
AZ_TYPE_INFO(UsageOptions, "{2B7D9B19-D13B-4E54-B724-B2FD8D0828B3}")
bool m_awsAttributionEnabled;
};
const UsageOptions& GetUsageOptions();
private:
void InitializeSettings();
void SaveSettingsRegistryFile();
UsageOptions m_usageOptions;
QIcon m_icon;
AZStd::unique_ptr<AZ::SettingsRegistryImpl> m_settingsRegistry;
static constexpr char AWSAttributionEnabledKey[] = "/Amazon/AWS/Preferences/AWSAttributionEnabled";
static constexpr char EditorPreferencesFileName[] = "editorpreferences.setreg";
static constexpr char EditorAWSPreferencesFileName[] = "editor_aws_preferences.setreg";
static constexpr char AWSAttributionSettingsPrefixKey[] = "/Amazon/AWS/Preferences";
};
+1
View File
@@ -143,6 +143,7 @@
<file>res/Camera.svg</file>
<file>res/Debug.svg</file>
<file>res/Experimental.svg</file>
<file>res/AWS_preferences_icon.svg</file>
<file>res/Files.svg</file>
<file>res/Gizmos.svg</file>
<file>res/Global.svg</file>
@@ -15,6 +15,8 @@
#include "PreferencesStdPages.h"
#include <AzToolsFramework/Entity/EditorEntityHelpers.h>
// Editor
#include "EditorPreferencesPageGeneral.h"
#include "EditorPreferencesPageFiles.h"
@@ -23,6 +25,7 @@
#include "EditorPreferencesPageViewportMovement.h"
#include "EditorPreferencesPageViewportDebug.h"
#include "EditorPreferencesPageExperimentalLighting.h"
#include "EditorPreferencesPageAWS.h"
//////////////////////////////////////////////////////////////////////////
@@ -42,6 +45,11 @@ CStdPreferencesClassDesc::CStdPreferencesClassDesc()
};
m_pageCreators.push_back([]() { return new CEditorPreferencesPage_ExperimentalLighting(); });
if (AzToolsFramework::IsComponentWithServiceRegistered(AZ_CRC_CE("AWSCoreEditorService")))
{
m_pageCreators.push_back([]() { return new CEditorPreferencesPage_AWS(); });
}
}
HRESULT CStdPreferencesClassDesc::QueryInterface(const IID& riid, void** ppvObj)
@@ -586,6 +586,8 @@ set(FILES
EditorPreferencesPageViewportDebug.cpp
EditorPreferencesPageExperimentalLighting.h
EditorPreferencesPageExperimentalLighting.cpp
EditorPreferencesPageAWS.h
EditorPreferencesPageAWS.cpp
EditorPreferencesDialog.h
EditorPreferencesDialog.cpp
EditorPreferencesDialog.ui
@@ -0,0 +1,3 @@
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M21.4629 11.2764C20.6447 10.508 19.5748 10.0719 18.4419 10.0719C17.8965 10.0719 17.351 10.1758 16.8475 10.3834C16.5748 9.26204 15.9664 8.2237 15.1063 7.37226C13.8685 6.16779 12.6717 5.47607 10.4147 5.47607C7.92095 5.47607 6.586 6.16779 5.32725 7.37226C4.08949 8.57673 3.30673 10.1907 3.30673 11.8935C3.30673 12.1635 3.32771 12.4335 3.34869 12.7035C2.84519 12.8281 2.49509 13.0831 2.13844 13.4362C1.57201 13.9761 1.25732 14.7029 1.25732 15.4713C1.25732 17.1534 2.66292 18.5032 4.3832 18.5032L18.2741 18.524C20.7286 18.524 22.7426 16.5927 22.7426 14.2045C22.7217 13.1039 22.2811 12.0656 21.4629 11.2764ZM17.2975 16.6659L4.65419 16.6867C3.62622 16.6867 3.45969 16.0387 3.37771 15.6437C3.30673 15.3017 3.37861 14.7882 3.53455 14.5799C3.74825 14.2944 4.10093 14.1649 4.5273 14.1216C4.76182 14.0979 5.1687 14.0552 5.32721 13.8355C5.43211 13.6901 5.47406 13.5032 5.45308 13.3163C5.36917 12.901 5.32721 12.5272 5.32721 12.1119C5.32721 10.7413 5.6315 9.73925 6.63849 8.76321C7.64549 7.78717 8.98815 7.24724 10.4147 7.24724C11.8413 7.24724 12.9769 7.56395 13.9839 8.53999C14.865 9.39143 15.3895 10.4921 15.5154 11.655C15.5363 11.8627 15.6622 12.0703 15.872 12.1534C16.0608 12.2365 16.3126 12.2365 16.4804 12.1119C17.6342 11.3643 18.848 11.1981 19.876 12.1742C20.4424 12.7141 20.7426 13.4362 20.7426 14.2045C20.7426 15.9074 19.0808 16.6659 17.2975 16.6659Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 1.4 KiB