Skip to content

Commit

Permalink
New improvements for 0.1.9 (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
tonyredondo committed Oct 17, 2023
1 parent 07ddf29 commit eab9358
Show file tree
Hide file tree
Showing 11 changed files with 311 additions and 77 deletions.
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.1.8</Version>
<Version>0.1.9</Version>
<Authors>Tony Redondo, Grégory Léocadie</Authors>
<TargetFrameworks>net6.0;net7.0;net8.0</TargetFrameworks>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
125 changes: 113 additions & 12 deletions src/TimeItSharp.Common/Configuration/Builder/ConfigBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,17 +86,6 @@ public ConfigBuilder WithDatadog(bool enabled)
return this;
}

/// <summary>
/// Sets if the metrics importer should be enabled or not
/// </summary>
/// <param name="enabled">True if the metrics importer is enabled; false if disabled</param>
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithMetrics(bool enabled)
{
_configuration.EnableMetrics = enabled;
return this;
}

#endregion

#region Scenarios
Expand Down Expand Up @@ -134,14 +123,36 @@ public ConfigBuilder WithScenario(Func<ScenarioBuilder, ScenarioBuilder> scenari

#endregion

/// <summary>
/// Sets if the runtime metrics importer should be enabled or not
/// </summary>
/// <param name="enabled">True if the metrics importer is enabled; false if disabled</param>
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithMetrics(bool enabled)
{
_configuration.EnableMetrics = enabled;
return this;
}

/// <summary>
/// Sets the process name to collect runtime metrics
/// </summary>
/// <param name="processName">Process name</param>
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithMetricsProcessName(string processName)
{
_configuration.MetricsProcessName = processName;
return this;
}

/// <summary>
/// Sets the name of the configuration
/// </summary>
/// <param name="name">Name of the configuration</param>
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithName(string name)
{
_configuration.FileName = name;
_configuration.Name = name;
return this;
}

Expand Down Expand Up @@ -180,6 +191,17 @@ public ConfigBuilder ClearExporters()
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithExporter(AssemblyLoadInfo exporter)
{
// Check if exporter is already there.
foreach (var existingExporter in _configuration.Exporters)
{
if (existingExporter.Name == exporter.Name &&
existingExporter.FilePath == exporter.FilePath &&
existingExporter.Type == exporter.Type)
{
return this;
}
}

_configuration.Exporters.Add(exporter);
return this;
}
Expand All @@ -202,6 +224,15 @@ public ConfigBuilder WithExporter(params AssemblyLoadInfo[] exporters)
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithExporter(string exporterName)
{
// Check if exporter is already there.
foreach (var exporter in _configuration.Exporters)
{
if (exporter.Name == exporterName)
{
return this;
}
}

_configuration.Exporters.Add(new AssemblyLoadInfo
{
Name = exporterName
Expand All @@ -228,6 +259,16 @@ public ConfigBuilder WithExporter<T>()
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithExporter(Type exporterType)
{
// Check if exporter is already there.
foreach (var exporter in _configuration.Exporters)
{
if (exporter.FilePath == exporterType.Assembly.Location &&
exporter.Type == exporterType.FullName)
{
return this;
}
}

_configuration.Exporters.Add(new AssemblyLoadInfo
{
FilePath = exporterType.Assembly.Location,
Expand Down Expand Up @@ -291,6 +332,17 @@ public ConfigBuilder ClearAssertors()
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithAssertor(AssemblyLoadInfo assertor)
{
// Check if assertor is already there.
foreach (var existing in _configuration.Assertors)
{
if (existing.Name == assertor.Name &&
existing.FilePath == assertor.FilePath &&
existing.Type == assertor.Type)
{
return this;
}
}

_configuration.Assertors.Add(assertor);
return this;
}
Expand All @@ -313,6 +365,15 @@ public ConfigBuilder WithAssertor(params AssemblyLoadInfo[] assertors)
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithAssertor(string assertorName)
{
// Check if assertors is already there.
foreach (var exiting in _configuration.Assertors)
{
if (exiting.Name == assertorName)
{
return this;
}
}

_configuration.Assertors.Add(new AssemblyLoadInfo
{
Name = assertorName
Expand All @@ -339,6 +400,16 @@ public ConfigBuilder WithAssertor<T>()
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithAssertor(Type assertorType)
{
// Check if assertors is already there.
foreach (var existing in _configuration.Assertors)
{
if (existing.FilePath == assertorType.Assembly.Location &&
existing.Type == assertorType.FullName)
{
return this;
}
}

_configuration.Assertors.Add(new AssemblyLoadInfo
{
FilePath = assertorType.Assembly.Location,
Expand Down Expand Up @@ -397,6 +468,17 @@ public ConfigBuilder ClearServices()
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithService(AssemblyLoadInfo service)
{
// Check if service is already there.
foreach (var existing in _configuration.Services)
{
if (existing.Name == service.Name &&
existing.FilePath == service.FilePath &&
existing.Type == service.Type)
{
return this;
}
}

_configuration.Services.Add(service);
return this;
}
Expand All @@ -419,6 +501,15 @@ public ConfigBuilder WithService(params AssemblyLoadInfo[] services)
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithService(string serviceName)
{
// Check if service is already there.
foreach (var exiting in _configuration.Services)
{
if (exiting.Name == serviceName)
{
return this;
}
}

_configuration.Services.Add(new AssemblyLoadInfo
{
Name = serviceName
Expand All @@ -445,6 +536,16 @@ public ConfigBuilder WithService<T>()
/// <returns>Configuration builder instance</returns>
public ConfigBuilder WithService(Type serviceType)
{
// Check if services is already there.
foreach (var existing in _configuration.Services)
{
if (existing.FilePath == serviceType.Assembly.Location &&
existing.Type == serviceType.FullName)
{
return this;
}
}

_configuration.Services.Add(new AssemblyLoadInfo
{
FilePath = serviceType.Assembly.Location,
Expand Down
10 changes: 10 additions & 0 deletions src/TimeItSharp.Common/Configuration/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public class Config : ProcessData

[JsonIgnore]
public string FileName { get; set; }

[JsonIgnore]
public string Name { get; set; }

[JsonPropertyName("warmUpCount")]
public int WarmUpCount { get; set; }
Expand All @@ -25,6 +28,9 @@ public class Config : ProcessData

[JsonPropertyName("enableMetrics")]
public bool EnableMetrics { get; set; }

[JsonPropertyName("metricsProcessName")]
public string MetricsProcessName { get; set; }

[JsonPropertyName("scenarios")]
public List<Scenario> Scenarios { get; set; }
Expand All @@ -46,10 +52,12 @@ public Config()
FilePath = string.Empty;
Path = string.Empty;
FileName = string.Empty;
Name = string.Empty;
WarmUpCount = 0;
Count = 0;
EnableDatadog = false;
EnableMetrics = true;
MetricsProcessName = string.Empty;
Scenarios = new();
JsonExporterFilePath = string.Empty;
Exporters = new();
Expand Down Expand Up @@ -92,10 +100,12 @@ public static Config LoadConfiguration(string filePath)
FilePath = FilePath,
Path = Path,
FileName = FileName,
Name = Name,
WarmUpCount = WarmUpCount,
Count = Count,
EnableDatadog = EnableDatadog,
EnableMetrics = EnableMetrics,
MetricsProcessName = MetricsProcessName,
Scenarios = Scenarios.Select(i => i.Clone()).ToList(),
JsonExporterFilePath = JsonExporterFilePath,
Exporters = Exporters.Select(i => i.Clone()).ToList(),
Expand Down
Loading

0 comments on commit eab9358

Please sign in to comment.