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

Log Com invocation startup telemetry and delay auto update time when invoked from explorer #3665

Merged
merged 9 commits into from
Sep 26, 2023

Conversation

yao-msft
Copy link
Contributor

@yao-msft yao-msft commented Sep 24, 2023

  • Add telemetry event for PackageManager class creation
  • Delay source update time to 7 days by default when invoked from explorer
  • Also fixes Source agreements related crash found when doing the above work
Microsoft Reviewers: Open in CodeFlow

@yao-msft yao-msft requested a review from a team as a code owner September 24, 2023 22:16
try
{
auto [hrGetCallerId, callerProcessId] = GetCallerProcessId();
THROW_IF_FAILED(hrGetCallerId);
Copy link
Member

Choose a reason for hiding this comment

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

Don't use exceptions for control flow.

try
// OutOfProc case, we check for explorer.exe
auto callerNameWide = AppInstaller::Utility::ConvertToUTF16(GetCallerName());
auto processName = AppInstaller::Utility::ConvertToUTF8(std::filesystem::path{ callerNameWide }.filename().wstring());
Copy link
Member

Choose a reason for hiding this comment

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

Please move this detection to a shared utility function as I suspect we will need it again (and I want to make it very explicit that we are doing this).

At the same time, wrap it in a try/catch so that we can ensure that an unexpected caller value being set doesn't blow up path parsing or something. The values we are targeting should be ok, and so any exception can be treated as not the case we are looking for.

source = m_sourceReference;
source.SetCaller(GetCallerName());
source.SetCaller(callerName);
Copy link
Member

Choose a reason for hiding this comment

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

Don't you need to call SetBackgroundUpdateInterval here? I'm not seeing it being set anywhere else...

{
// See if caller name is set by caller
static auto callerName = GetComCallerName("");
static constexpr winrt::Windows::Foundation::TimeSpan s_PackageCatalogUpdateIntervalDelay = 168h; //1 week
Copy link
Member

Choose a reason for hiding this comment

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

We might want to randomize this a bit as well, at least + 0/24 hours (worth of seconds or smaller) but maybe even up to a week extra. That will hopefully prevent this from causing time based scheduled tasks to align on updates.

@@ -143,4 +145,26 @@ namespace winrt::Microsoft::Management::Deployment::implementation

return callerName;
}

bool ShouldDelayBackgroundUpdateByCaller()
Copy link
Member

Choose a reason for hiding this comment

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

I really meant with a name that was like IsBackgroundProcessForPolicy or something.

m_packageCatalogBackgroundUpdateInterval = s_PackageCatalogUpdateIntervalDelay;
// Add a bit of randomness to the default interval time
std::default_random_engine randomEngine(std::random_device{}());
std::uniform_int_distribution<long long> distribution(0, 168);
Copy link
Member

Choose a reason for hiding this comment

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

We really want to spread this out, so multiple this by 3600 for second resolution.

auto previousThreadGlobals = m_threadGlobals.SetForCurrentThread();
// Immediately reset as we only want the thread globals for logging within this object.
previousThreadGlobals.reset();
m_threadGlobals.GetTelemetryLogger().SetCaller(GetCallerName());
Copy link
Member

Choose a reason for hiding this comment

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

Make sure that this doesn't send a summary event. There is a bool that disables it as I remember.

@github-actions

This comment has been minimized.

@JohnMcPMS JohnMcPMS merged commit 804c125 into microsoft:master Sep 26, 2023
8 checks passed
@yao-msft yao-msft deleted the reducetraffic branch September 26, 2023 16:36
JohnMcPMS pushed a commit to JohnMcPMS/winget-cli that referenced this pull request Sep 27, 2023
…invoked from explorer (microsoft#3665)

- Add telemetry event for PackageManager class creation
- Delay source update time to 7 days by default when invoked from explorer
- Also fixes Source agreements related crash found when doing the above work
JohnMcPMS added a commit that referenced this pull request Sep 27, 2023
…invoked from explorer (#3665) (#3684)

- Add telemetry event for PackageManager class creation
- Delay source update time to 7 days by default when invoked from explorer
- Also fixes Source agreements related crash found when doing the above work

Co-authored-by: yao-msft <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants