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

Various changes to enable FIO and PostgreSQL tests in (Docker/ACI) container #435

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
7 changes: 3 additions & 4 deletions src/VirtualClient/VirtualClient.Contracts/DiskExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace VirtualClient.Contracts
using System.Text.RegularExpressions;

/// <summary>
///
///
/// </summary>
public static class DiskExtensions
{
Expand Down Expand Up @@ -42,11 +42,10 @@ public static string GetPreferredAccessPath(this Disk disk, PlatformID platform)
path = "/";

}
else if (platform == PlatformID.Unix && disk.IsOperatingSystem())
else if (platform == PlatformID.Win32NT && disk.IsOperatingSystem())
{
// If it is OS disk, test on OS partition
path = disk.Volumes.Where(v => v.IsOperatingSystem()).FirstOrDefault().AccessPaths.FirstOrDefault();

}
else
{
Expand Down Expand Up @@ -178,7 +177,7 @@ public static long SizeInBytes(this Disk disk, PlatformID platform)
else
{
result = disk.Volumes.Sum(v => v.SizeInBytes(platform));
}
}
}

return result;
Expand Down
20 changes: 13 additions & 7 deletions src/VirtualClient/VirtualClient.Core/DependencyFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,13 @@ public static IBlobManager CreateBlobManager(DependencyStore dependencyStore)
/// <param name="logger">A logger for capturing disk management telemetry.</param>
public static DiskManager CreateDiskManager(PlatformID platform, Microsoft.Extensions.Logging.ILogger logger = null)
{
if (PlatformSpecifics.IsRunningInContainer())
{
return new DummyDiskManager(platform, logger);
}

DiskManager manager = null;

switch (platform)
{
case PlatformID.Win32NT:
Expand Down Expand Up @@ -326,8 +332,8 @@ public static IEnumerable<ILoggerProvider> CreateFileLoggerProviders(string logF

// Metrics/Results
ILoggerProvider metricsLoggerProvider = DependencyFactory.CreateFileLoggerProvider(
Path.Combine(logFileDirectory, settings.MetricsFileName),
TimeSpan.FromSeconds(3),
Path.Combine(logFileDirectory, settings.MetricsFileName),
TimeSpan.FromSeconds(3),
LogLevel.Trace,
new SerilogJsonTextFormatter(propertiesToExcludeForMetrics)).HandleMetrics();

Expand All @@ -336,16 +342,16 @@ public static IEnumerable<ILoggerProvider> CreateFileLoggerProviders(string logF

// Metrics/Results in CSV Format
ILoggerProvider metricsCsvLoggerProvider = DependencyFactory.CreateCsvFileLoggerProvider(
Path.Combine(logFileDirectory,
Path.Combine(logFileDirectory,
settings.MetricsCsvFileName)).HandleMetrics();

VirtualClientRuntime.CleanupTasks.Add(new Action_(() => metricsCsvLoggerProvider.Dispose()));
loggerProviders.Add(metricsCsvLoggerProvider);

// System Events
ILoggerProvider eventsLoggerProvider = DependencyFactory.CreateFileLoggerProvider(
Path.Combine(logFileDirectory, settings.EventsFileName),
TimeSpan.FromSeconds(5),
Path.Combine(logFileDirectory, settings.EventsFileName),
TimeSpan.FromSeconds(5),
LogLevel.Trace,
new SerilogJsonTextFormatter(propertiesToExcludeForEvents)).HandleSystemEvents();

Expand Down Expand Up @@ -670,7 +676,7 @@ public static VirtualClientProxyApiClient CreateVirtualClientProxyApiClient(Uri
public static void FlushTelemetry(TimeSpan? timeout = null)
{
Parallel.ForEach(DependencyFactory.telemetryChannels, channel => channel.Flush(timeout));
}
}

/// <summary>
/// Applies a filter to the logger generated by the provider that will handle the logging
Expand Down Expand Up @@ -708,4 +714,4 @@ internal static ILoggerProvider HandleTraces(this ILoggerProvider loggerProvider
return loggerProvider.WithFilter((eventId, logLevel, state) => (LogType)eventId.Id <= LogType.Error);
}
}
}
}
97 changes: 97 additions & 0 deletions src/VirtualClient/VirtualClient.Core/DummyDiskManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace VirtualClient
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using Polly;
using VirtualClient.Common;
using VirtualClient.Common.Extensions;
using VirtualClient.Common.Telemetry;
using VirtualClient.Contracts;

/// <summary>
/// A DiskManager that simply presents a OS disk, and does not try to do any
/// discovery. Useful in containers.
/// </summary>
public class DummyDiskManager : DiskManager
{
private readonly DiskVolume volume;
private readonly Disk disk;

/// <summary>
/// Create a new <see cref="DummyDiskManager"/> instance.
/// </summary>
/// <param name="platform"></param>
/// <param name="logger"></param>
public DummyDiskManager(PlatformID platform, ILogger logger = null)
: base(logger)
{
string defaultMountPath = platform == PlatformID.Win32NT ? "C:\\" : "/";
string devicePath = platform == PlatformID.Win32NT ? "C:\\" : "/dev/sda";

var volumeProps = new Dictionary<string, IConvertible>();

// TODO: determine size with `df` or whatever on Windows

if (platform == PlatformID.Win32NT)
{
volumeProps.Add(Disk.WindowsDiskProperties.Info, "Boot");
volumeProps.Add(Disk.WindowsDiskProperties.Size, 1ul << 30);
}
else
{
volumeProps.Add(Disk.UnixDiskProperties.Size, 1ul << 30);
}

this.volume = new DiskVolume(0, devicePath, new[] { defaultMountPath }, volumeProps);
this.disk = new Disk(0, devicePath, new[] { this.volume });
}

/// <summary>
/// Get the set of disks.
/// </summary>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override Task<IEnumerable<Disk>> GetDisksAsync(CancellationToken cancellationToken)
{
return Task.FromResult<IEnumerable<Disk>>(new[] { this.disk });
}

/// <summary>
/// No-op
/// </summary>
/// <param name="disk"></param>
/// <param name="partitionType"></param>
/// <param name="fileSystemType"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
public override Task FormatDiskAsync(Disk disk, PartitionType partitionType, FileSystemType fileSystemType, CancellationToken cancellationToken)
{
return Task.CompletedTask;
}

/// <summary>
/// No-op
/// </summary>
/// <param name="volume"></param>
/// <param name="mountPoint"></param>
/// <param name="cancellationToken"></param>
/// <returns></returns>
/// <exception cref="ArgumentException"></exception>
public override Task CreateMountPointAsync(DiskVolume volume, string mountPoint, CancellationToken cancellationToken)
{
if (volume != this.volume)
{
throw new ArgumentException("Invalid volume provided to DummyDiskManager::CreateMountPointAsync");
}

return Task.CompletedTask;
}
}
}
8 changes: 8 additions & 0 deletions src/VirtualClient/VirtualClient.Core/UnixFirewallManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace VirtualClient
using VirtualClient.Common;
using VirtualClient.Common.Extensions;
using VirtualClient.Common.Platform;
using VirtualClient.Contracts;

/// <summary>
/// Provides methods for managing Unix/Linux system/OS firewall operations.
Expand Down Expand Up @@ -45,6 +46,13 @@ public override Task EnableInboundAppAsync(FirewallEntry firewallEntry, Cancella
public async override Task EnableInboundConnectionAsync(FirewallEntry firewallEntry, CancellationToken cancellationToken)
{
firewallEntry.ThrowIfNull(nameof(firewallEntry));

if (PlatformSpecifics.IsRunningInContainer())
{
// Can't set iptables from within a container.
return;
}

if (!cancellationToken.IsCancellationRequested)
{
string ports = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace VirtualClient.Dependencies
{
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
Expand Down Expand Up @@ -78,6 +79,17 @@ public string DiskFilter
}
}

/// <summary>
/// Directory for the PostgreSQL database within the disk.
/// </summary>
public string DataDirectory
{
get
{
return this.Parameters.GetValue<string>(nameof(this.DataDirectory), string.Empty);
}
}

/// <summary>
/// Database Name to create and utilize
/// </summary>
Expand Down Expand Up @@ -108,8 +120,15 @@ public string SuperUserPassword
{
get
{
byte[] hashBytes = SHA256.HashData(Encoding.UTF8.GetBytes(this.ExperimentId));
return Convert.ToBase64String(hashBytes);
if (this.Parameters.ContainsKey(nameof(this.SuperUserPassword)))
{
return this.Parameters.GetValue<string>(nameof(this.SuperUserPassword));
}
else
{
byte[] hashBytes = SHA256.HashData(Encoding.UTF8.GetBytes(this.ExperimentId));
return Convert.ToBase64String(hashBytes);
}
}
}

Expand Down Expand Up @@ -267,7 +286,18 @@ private async Task<string> GetPostgreSQLInnodbDirectoriesAsync(CancellationToken

foreach (Disk disk in disksToTest)
{
diskPaths += $"{disk.GetPreferredAccessPath(this.Platform)};";
string path = disk.GetPreferredAccessPath(this.Platform);

if (!string.IsNullOrEmpty(this.DataDirectory))
{
path = Path.Join(path, this.DataDirectory);
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
}

diskPaths += $"{path};";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"Parameters": {
"DatabaseName": "hammerdb_tpcc",
"DiskFilter": "osdisk:false&sizegreaterthan:256g",
"DataDirectory": "",
"Port": "5432",
"VirtualUsers": "{calculate({LogicalCoreCount})}",
"WarehouseCount": "{calculate({SystemMemoryMegabytes} * 15 / 800)}",
Expand Down Expand Up @@ -49,14 +50,16 @@
"Type": "FormatDisks",
"Parameters": {
"Scenario": "FormatDisks",
"Role": "Server"
"Role": "Server",
"DiskFilter": "$.Parameters.DiskFilter"
}
},
{
"Type": "MountDisks",
"Parameters": {
"Scenario": "CreateMountPoints",
"Role": "Server"
"Role": "Server",
"DiskFilter": "$.Parameters.DiskFilter"
}
},
{
Expand Down Expand Up @@ -129,7 +132,8 @@
"DiskFilter": "$.Parameters.DiskFilter",
"PackageName": "postgresql",
"Port": "$.Parameters.Port",
"Role": "Server"
"Role": "Server",
"DataDirectory": "$.Parameters.DataDirectory"
}
},
{
Expand All @@ -154,4 +158,4 @@
}
}
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"Parameters": {
"DatabaseName": "sbtest",
"DiskFilter": "osdisk:false&sizegreaterthan:256g",
"DataDirectory": "",
"Port": "5432",
"SharedMemoryBuffer": "{calculate({SystemMemoryMegabytes} * 85 / 100)}",
"DatabaseScenario": "Balanced",
Expand Down Expand Up @@ -155,15 +156,17 @@
"Type": "FormatDisks",
"Parameters": {
"Scenario": "FormatDisks",
"Role": "Server"
"Role": "Server",
"DiskFilter": "$.Parameters.DiskFilter"
}
},
{
"Type": "MountDisks",
"Parameters": {
"Scenario": "CreateMountPoints",
"MountLocation": "Root",
"Role": "Server"
"Role": "Server",
"DiskFilter": "$.Parameters.DiskFilter"
}
},
{
Expand Down Expand Up @@ -249,7 +252,8 @@
"DiskFilter": "$.Parameters.DiskFilter",
"PackageName": "postgresql",
"Port": "$.Parameters.Port",
"Role": "Server"
"Role": "Server",
"DataDirectory": "$.Parameters.DataDirectory"
}
},
{
Expand All @@ -272,4 +276,4 @@
}
}
]
}
}
Loading
Loading