8000 add configurable maintenance event to local agent by tculotta · Pull Request #180 · PlayFab/MpsAgent · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add configurable maintenance event to local agent #180

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

Merged
merged 8 commits into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions AgentInterfaces/MaintenanceSchedule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class MaintenanceEvent

public DateTime? NotBefore { get; set; }

public string Description { get; set; }
Copy link
Contributor

Choose a reason for hiding this comment

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

any idea why this wasn't there originally?


public string EventSource { get; set; }

public int DurationInSeconds { get; set; }
Expand Down
3 changes: 3 additions & 0 deletions LocalMultiplayerAgent.UnitTest/ControllerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ public async Task ValidateStandingByToInitializingThrows()

string sessionHostId = "testSessionHostId";

// Settings is accessed in the heartbeat endpoint
Globals.Settings = new();

// send the first heartbeat with "StandingBy"
SessionHostHeartbeatInfo heartbeat = new SessionHostHeartbeatInfo()
{
Expand Down
8 changes: 8 additions & 0 deletions LocalMultiplayerAgent/Config/MultiplayerSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public class MultiplayerSettings

public int NumHeartBeatsForTerminateResponse { get; set; }

public int NumHeartBeatsForMaintenanceEventResponse { get; set; }

public bool RunContainer { get; set; }

public string OutputFolder { get; set; }
Expand All @@ -49,6 +51,12 @@ public class MultiplayerSettings

public IDictionary<string, string> DeploymentMetadata { get; set; }

public string MaintenanceEventType { get; set; }

public string MaintenanceEventStatus { get; set; }

public string MaintenanceEventSource { get; set; }

public SessionHostsStartInfo ToSessionHostsStartInfo()
{
// Clear mount path in process based, otherwise, agent will kick into back-compat mode and try to strip the
Expand Down
6 changes: 6 additions & 0 deletions LocalMultiplayerAgent/Config/MultiplayerSettingsValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ public bool IsValid(bool createBuild = false)
Console.WriteLine("NumHeartBeatsForTerminateResponse must be greater than NumHeartBeatsForActivateResponse. Ideally more than 1, since you would like the server to be alive for a few seconds");
isSuccess = false;
}

if (_settings.NumHeartBeatsForTerminateResponse < _settings.NumHeartBeatsForMaintenanceEventResponse)
{
Console.WriteLine("NumHeartBeatsForMaintenanceEventResponse must be less than or equal to NumHeartBeatsForTerminateResponse.");
isSuccess = false;
}
}

if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
Expand Down
34 changes: 32 additions & 2 deletions LocalMultiplayerAgent/Controllers/SessionHostController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace LocalMultiplayerAgent.Controllers
using Microsoft.Azure.Gaming.VmAgent.Model;
using Microsoft.Extensions.Hosting;
using Instrumentation;
using System.Collections.Generic;

public class SessionHostController : Controller
{
Expand Down Expand Up @@ -54,6 +55,7 @@ public async Task<IActionResult> ProcessHeartbeat(string sessionHostId,
Operation op = Operation.Continue;
SessionConfig config = null;
Console.WriteLine($"CurrentGameState: {heartbeatRequest.CurrentGameState}");
bool sendMaintenanceEvent = false;

if(!ValidateSessionHostStatusTransition(previousSessionHostStatus, currentGameState))
{
Expand All @@ -78,22 +80,50 @@ public async Task<IActionResult> ProcessHeartbeat(string sessionHostId,
config = Globals.SessionConfig;
}

sendMaintenanceEvent = (numHeartBeats == Globals.Settings.NumHeartBeatsForMaintenanceEventResponse);

HeartBeatsCount[sessionHostId]++;
}
else
{
sendMaintenanceEvent = (Globals.Settings.NumHeartBeatsForMaintenanceEventResponse == 1);
HeartBeatsCount.TryAdd(sessionHostId, 1);
}

previousSessionHostStatus = currentGameState;

return Ok(new SessionHostHeartbeatInfo
SessionHostHeartbeatInfo heartbeatResponse = new SessionHostHeartbeatInfo
{
CurrentGameState = currentGameState,
NextHeartbeatIntervalMs = DefaultHeartbeatIntervalMs,
Operation = op,
SessionConfig = config
});
};

if (_wasGsdkVersionLogged && sendMaintenanceEvent)
{
heartbeatResponse.MaintenanceSchedule = new()
{
DocumentIncarnation = "1",
MaintenanceEvents = new List<MaintenanceEvent>()
{
new()
{
EventId = Guid.NewGuid().ToString(),
EventType = Globals.Settings.MaintenanceEventType,
ResourceType = "VirtualMachine",
AffectedResources = new List<string>() { "vmId" },
EventStatus = Globals.Settings.MaintenanceEventStatus,
NotBefore = DateTime.UtcNow.AddMinutes(5),
Description = $"Scheduled {Globals.Settings.MaintenanceEventType} event for VM",
EventSource = Globals.Settings.MaintenanceEventSource,
DurationInSeconds = 300
}
}
};
}

return Ok(heartbeatResponse);
}

private static bool _wasGsdkVersionLogged = false;
Expand Down
5 changes: 5 additions & 0 deletions LocalMultiplayerAgent/MultiplayerSettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@
"RunContainer": false,
"OutputFolder": "",
"NumHeartBeatsForActivateResponse": 10,
"NumHeartBeatsForMaintenanceEventResponse": 0, // a value < 1 will disable the maintenance event
"NumHeartBeatsForTerminateResponse": 60,
"AgentListeningPort": 56001,
// Valid maintenance event values are explained here: https://learn.microsoft.com/azure/virtual-machines/windows/scheduled-events#event-properties
"MaintenanceEventType": "Reboot",
"MaintenanceEventStatus": "Scheduled",
"MaintenanceEventSource": "Platform",
"AssetDetails": [
{
"MountPath": "C:\\Assets",
Expand Down
0