Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Add events #354

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions Services/Diagnostics/DiagnosticsLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface IDiagnosticsLogger

void LogServiceHeartbeat();

void LogEvent(string eventName, string message);

void LogServiceError(
string message,
string exceptionMessage = "",
Expand Down Expand Up @@ -75,6 +77,12 @@ public void LogServiceHeartbeat()
this.PostRequest(this.diagnosticsEndpoint, jsonStruct);
}

public void LogEvent(string eventName, string message)
{
var jsonStruct = new JsonStruct(eventName + message, null);
this.PostRequest(this.diagnosticsEndpoint, jsonStruct);
}

public void LogServiceError(
string message,
string exceptionMessage = "",
Expand Down
35 changes: 35 additions & 0 deletions Services/Simulations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ public class Simulations : ISimulations
private const int DEVICES_PER_MODEL_IN_DEFAULT_TEMPLATE = 1;

private readonly IServicesConfig config;
private readonly IDiagnosticsLogger logDiagnostics;
private readonly IDeviceModels deviceModels;
private readonly IStorageAdapterClient storageAdapterClient;
private readonly IEngine mainStorage;
Expand Down Expand Up @@ -309,6 +310,15 @@ public async Task<Models.Simulation> UpsertAsync(Models.Simulation simulation, b
if (simulationIsRestarting)
{
simulation = await this.ResetSimulationStatisticsAsync(simulation);

simulation = await this.ResetSimulationStatisticsAsync(simulation);

Choose a reason for hiding this comment

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

duplicate statement!!

Suggested change
simulation = await this.ResetSimulationStatisticsAsync(simulation);

Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("SimulationId", simulation.Id);
data.Add("StartTime", simulation.StartTime != null ? simulation.StartTime.ToString() : null);
data.Add("DeviceModels", simulation.DeviceModels != null ? simulation.DeviceModels.ToString() : null);
data.Add("CustomDeviceModels", simulation.CustomDevices != null ? simulation.CustomDevices.ToString() : null);

this.diagnosticsLogger.LogEvent("SimulationStart", data.ToString());
}
else if (simulationIsStopping)
{
Expand All @@ -318,6 +328,15 @@ public async Task<Models.Simulation> UpsertAsync(Models.Simulation simulation, b
// This boolean triggers the deletion of partitions from the storage
// in the partitioning agent.
simulation.PartitioningComplete = false;

Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("SimulationId", simulation.Id);
data.Add("StopTime", simulation.StoppedTime != null ? simulation.StoppedTime.ToString() : null);
data.Add("DeviceModels", simulation.DeviceModels != null ? simulation.DeviceModels.ToString() : null);
data.Add("CustomDeviceModels", simulation.CustomDevices != null ? simulation.CustomDevices.ToString() : null);
data.Add("Statistics", simulation.Statistics != null ? simulation.Statistics.ToString() : null);

this.diagnosticsLogger.LogEvent("SimulationStop", data.ToString());
}

return await this.SaveAsync(simulation, simulation.ETag);
Expand Down Expand Up @@ -357,6 +376,13 @@ public async Task<Models.Simulation> MergeAsync(SimulationPatch patch)
if (simulationIsRestarting)
{
simulation = await this.ResetSimulationStatisticsAsync(simulation);
Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("SimulationId", simulation.Id);
data.Add("StartTime", simulation.StartTime != null ? simulation.StartTime.ToString() : null);
data.Add("DeviceModels", simulation.DeviceModels != null ? simulation.DeviceModels.ToString() : null);
data.Add("CustomDeviceModels", simulation.CustomDevices != null ? simulation.CustomDevices.ToString() : null);

this.diagnosticsLogger.LogEvent("SimulationRestart", data.ToString());
}
else if (simulationIsStopping)
{
Expand All @@ -367,6 +393,15 @@ public async Task<Models.Simulation> MergeAsync(SimulationPatch patch)
// in the partitioning agent.
simulation.PartitioningComplete = false;

Dictionary<string, string> data = new Dictionary<string, string>();
data.Add("SimulationId", simulation.Id);
data.Add("StopTime", simulation.StoppedTime != null ? simulation.StoppedTime.ToString() : null);
data.Add("DeviceModels", simulation.DeviceModels != null ? simulation.DeviceModels.ToString() : null);
data.Add("CustomDeviceModels", simulation.CustomDevices != null ? simulation.CustomDevices.ToString() : null);
data.Add("Statistics", simulation.Statistics != null ? simulation.Statistics.ToString() : null);

this.diagnosticsLogger.LogEvent("SimulationStop", data.ToString());

// Reset active device count to 0
await this.ResetActiveDevicesStatistics(simulation);
}
Expand Down
4 changes: 0 additions & 4 deletions SimulationAgent/Agent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,6 @@ private async Task CreateSimulationManagersAsync(IEnumerable<Simulation> activeS
this.deviceReplayActors);

this.simulationManagers[simulation.Id] = manager;

var msg = "New simulation manager created";
this.log.Info(msg, () => new { SimulationId = simulation.Id });
this.logDiagnostics.LogServiceStart(msg);
}
catch (Exception e)
{
Expand Down