Skip to content

[fleet installer] Split the install command in two #6766

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 1 commit into from
Mar 14, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ RUN mkdir /logs; \
mkdir /monitoring-home; \
cd /install; \
Expand-Archive 'c:\install\windows-tracer-home.zip' -DestinationPath 'c:\monitoring-home\'; \
c:\install\installer\Datadog.FleetInstaller.exe install --home-path c:\monitoring-home; \
c:\install\installer\Datadog.FleetInstaller.exe install-version --home-path c:\monitoring-home; \
c:\install\installer\Datadog.FleetInstaller.exe enable-iis-instrumentation --home-path c:\monitoring-home; \
cd /app;

# Set the additional env vars
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="InstallCommand.cs" company="Datadog">
// <copyright file="EnableIisInstrumentationCommand.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>
Expand All @@ -12,23 +12,21 @@
namespace Datadog.FleetInstaller.Commands;

/// <summary>
/// Install a new version of the .NET Tracer. Could be the first version, or simply a new version
/// Enables instrumentation of IIS for an already installed version of the .NET tracer
/// </summary>
internal class InstallCommand : CommandBase
internal class EnableIisInstrumentationCommand : CommandBase
{
private const string Command = "enable-iis-instrumentation";
private const string CommandDescription = "Enables instrumentation with the .NET library on IIS, for an already installed version of the .NET library";

private readonly Option<string> _versionedPathOption = new("--home-path", () => null!)
{
Description = "Path to the tracer-home-directory",
IsRequired = true,
};

public InstallCommand()
: this("install")
{
}

protected InstallCommand(string command)
: base(command)
public EnableIisInstrumentationCommand()
: base(Command, CommandDescription)
{
AddOption(_versionedPathOption);
AddValidator(Validate);
Expand All @@ -54,7 +52,7 @@ internal static ReturnCode Execute(
string tracerLogDirectory,
string registryKeyName)
{
log.WriteInfo("Installing .NET tracer");
log.WriteInfo("Enabling IIS instrumentation for .NET tracer");

bool tryIisRollback;

Expand Down Expand Up @@ -87,17 +85,6 @@ internal static ReturnCode Execute(
return ReturnCode.ErrorReadingIisConfiguration;
}

if (!FileHelper.CreateLogDirectory(log, tracerLogDirectory))
{
// This probably isn't a reason to bail out
}

if (!GacInstaller.TryGacInstall(log, tracerValues))
{
// definitely bail out
return ReturnCode.ErrorDuringGacInstallation;
}

if (!AppHostHelper.SetAllEnvironmentVariables(log, tracerValues))
{
// hard to be sure exactly of the state at this point
Expand All @@ -112,12 +99,6 @@ internal static ReturnCode Execute(
return ReturnCode.ErrorSettingAppPoolVariables;
}

if (!RegistryHelper.AddCrashTrackingKey(log, tracerValues, registryKeyName))
{
// Don't need to bail out of installation just because we failed to add crash tracking
// The tracer itself can manage this at runtime if required
}

return ReturnCode.Success;
}

Expand All @@ -128,6 +109,7 @@ private void Validate(CommandResult commandResult)
return;
}

// We can't enable iis instrumentation if IIS is not available or is to low a version
if (!HasValidIIsVersion(Log.Instance, out var errorMessage))
{
commandResult.ErrorMessage = errorMessage;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// <copyright file="InstallVersionCommand.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>

using System.CommandLine;
using System.CommandLine.Invocation;
using System.CommandLine.Parsing;
using System.Threading.Tasks;

namespace Datadog.FleetInstaller.Commands;

/// <summary>
/// Installs a new version of the .NET Tracer. Could be the first version, or simply a new version
/// </summary>
internal class InstallVersionCommand : CommandBase
{
private const string Command = "install-version";
private const string CommandDescription = "Prepares a new version of the .NET tracer, without enabling instrumentation";

private readonly Option<string> _versionedPathOption = new("--home-path", () => null!)
{
Description = "Path to the tracer-home-directory",
IsRequired = true,
};

public InstallVersionCommand()
: base(Command, CommandDescription)
{
AddOption(_versionedPathOption);
AddValidator(Validate);
this.SetHandler(ExecuteAsync);
}

public Task ExecuteAsync(InvocationContext context)
{
var versionedPath = context.ParseResult.GetValueForOption(_versionedPathOption)!;
var tracerValues = new TracerValues(versionedPath);
var log = Log.Instance;

var result = Execute(log, tracerValues, Defaults.TracerLogDirectory, Defaults.CrashTrackingRegistryKey);

context.ExitCode = (int)result;
return Task.CompletedTask;
}

// Internal for testing
internal static ReturnCode Execute(
ILogger log,
TracerValues tracerValues,
string tracerLogDirectory,
string registryKeyName)
{
log.WriteInfo("Installing .NET tracer");

if (!FileHelper.CreateLogDirectory(log, tracerLogDirectory))
{
// This probably isn't a reason to bail out
}

if (!GacInstaller.TryGacInstall(log, tracerValues))
{
// definitely bail out
return ReturnCode.ErrorDuringGacInstallation;
}

if (!RegistryHelper.AddCrashTrackingKey(log, tracerValues, registryKeyName))
{
// Don't need to bail out of installation just because we failed to add crash tracking
// The tracer itself can manage this at runtime if required
}

return ReturnCode.Success;
}

private void Validate(CommandResult commandResult)
{
if (!IsValidEnvironment(commandResult))
{
return;
}

var path = commandResult.GetValueForOption(_versionedPathOption);
if (path is not null && !FileHelper.TryVerifyFilesExist(Log.Instance, new TracerValues(path), out var err))
{
commandResult.ErrorMessage = err;
}
}
}
15 changes: 0 additions & 15 deletions tracer/src/Datadog.FleetInstaller/Commands/ReinstallCommand.cs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// <copyright file="UninstallProductCommand.cs" company="Datadog">
// <copyright file="RemoveIisInstrumentation.cs" company="Datadog">
// Unless explicitly stated otherwise all files in this repository are licensed under the Apache 2 License.
// This product includes software developed at Datadog (https://www.datadoghq.com/). Copyright 2017 Datadog, Inc.
// </copyright>
Expand All @@ -11,12 +11,15 @@
namespace Datadog.FleetInstaller.Commands;

/// <summary>
/// Perform the final uninstall for the product
/// Remove IIS instrumentation completely
/// </summary>
internal class UninstallProductCommand : CommandBase
internal class RemoveIisInstrumentation : CommandBase
{
public UninstallProductCommand()
: base("uninstall-product")
private const string Command = "remove-iis-instrumentation";
private const string CommandDescription = "Removes instrumentation with the .NET library from IIS";

public RemoveIisInstrumentation()
: base(Command, CommandDescription)
{
AddValidator(Validate);
this.SetHandler(ExecuteAsync);
Expand All @@ -35,11 +38,11 @@ public Task ExecuteAsync(InvocationContext context)
// Internal for testing
internal ReturnCode Execute(ILogger log)
{
log.WriteInfo("Uninstalling .NET tracer product");
log.WriteInfo("Removing IIS instrumentation for .NET tracer");

if (!HasValidIIsVersion(log, out var errorMessage))
{
// IIS isn't available, weird because it means they removed it _after_ installing the product
// IIS isn't available, weird because it means they removed it _after_ successfully installing the product
// but whatever, there's no variables there if that's the case!
Log.Instance.WriteInfo(errorMessage);
Log.Instance.WriteInfo("Unable to uninstall from IIS, skipping IIS removal and continuing");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,17 @@ namespace Datadog.FleetInstaller.Commands;
/// </summary>
internal class UninstallVersionCommand : CommandBase
{
private const string Command = "uninstall-version";
private const string CommandDescription = "Uninstalls a single of the .NET library";

private readonly Option<string> _versionedPathOption = new("--home-path", () => null!)
{
Description = "Path to the tracer-home-directory",
IsRequired = true
};

public UninstallVersionCommand()
: base("uninstall-version")
: base(Command, CommandDescription)
{
AddOption(_versionedPathOption);
AddValidator(Validate);
Expand Down
14 changes: 7 additions & 7 deletions tracer/src/Datadog.FleetInstaller/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,21 @@
.CancelOnProcessTermination();

rootCommand.AddExample("""
install --home-path "C:\datadog\versions\3.9.0"
install-version --home-path "C:\datadog\versions\3.9.0"
""");
rootCommand.AddExample("""
reinstall --home-path "C:\datadog\versions\3.9.0"
uninstall-version --home-path "C:\datadog\versions\3.9.0"
""");
rootCommand.AddExample("""
uninstall-version --home-path "C:\datadog\versions\3.9.0"
enable-iis-instrumentation --home-path "C:\datadog\versions\3.9.0"
""");
rootCommand.AddExample("""
uninstall-product"
remove-iis-instrumentation"
""");

rootCommand.AddCommand(new InstallCommand());
rootCommand.AddCommand(new ReinstallCommand());
rootCommand.AddCommand(new InstallVersionCommand());
rootCommand.AddCommand(new UninstallVersionCommand());
rootCommand.AddCommand(new UninstallProductCommand());
rootCommand.AddCommand(new EnableIisInstrumentationCommand());
rootCommand.AddCommand(new RemoveIisInstrumentation());

return builder.Build().Invoke(args);
Loading