Skip to content

Commit

Permalink
Revert "Still failing. Debugging why"
Browse files Browse the repository at this point in the history
This reverts commit 1302336.
  • Loading branch information
sburmanoctopus committed Dec 14, 2023
1 parent 1302336 commit ef2570a
Show file tree
Hide file tree
Showing 8 changed files with 12 additions and 125 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class ClientAndTentacle: IAsyncDisposable
public TentacleClient TentacleClient { get; }
public TemporaryDirectory TemporaryDirectory { get; }
public RpcRetrySettings RpcRetrySettings { get; }
public string HomeDirectory { get; }

public LegacyTentacleClientBuilder LegacyTentacleClientBuilder()
{
Expand All @@ -35,10 +34,9 @@ public ClientAndTentacle(IHalibutRuntime halibutRuntime,
PortForwarder? portForwarder,
RunningTentacle runningTentacle,
TentacleClient tentacleClient,
TemporaryDirectory temporaryDirectory,
TemporaryDirectory temporaryDirectory,
RpcRetrySettings rpcRetrySettings,
ILogger logger,
string homeDirectory)
ILogger logger)
{
this.halibutRuntime = halibutRuntime;
Server = server;
Expand All @@ -47,7 +45,6 @@ public ClientAndTentacle(IHalibutRuntime halibutRuntime,
TentacleClient = tentacleClient;
TemporaryDirectory = temporaryDirectory;
RpcRetrySettings = rpcRetrySettings;
HomeDirectory = homeDirectory;
this.ServiceEndPoint = serviceEndPoint;
this.logger = logger.ForContext<ClientAndTentacle>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ public async Task<ClientAndTentacle> Build(CancellationToken cancellationToken)

var temporaryDirectory = new TemporaryDirectory();
var tentacleExe = tentacleVersion == null ? TentacleExeFinder.FindTentacleExe(this.tentacleRuntime) : await TentacleFetcher.GetTentacleVersion(temporaryDirectory.DirectoryPath, tentacleVersion, tentacleRuntime, logger, cancellationToken);
string homeDirectory;

logger.Information($"Tentacle.exe location: {tentacleExe}");

Expand All @@ -207,7 +206,6 @@ public async Task<ClientAndTentacle> Build(CancellationToken cancellationToken)
pollingTentacleBuilder.InstallAsAService();
}

homeDirectory = pollingTentacleBuilder.HomeDirectory.DirectoryPath;
runningTentacle = await pollingTentacleBuilder.Build(logger, cancellationToken);

tentacleEndPoint = new ServiceEndPoint(runningTentacle.ServiceUri, runningTentacle.Thumbprint, serverHalibutRuntime.TimeoutsAndLimits);
Expand All @@ -224,7 +222,6 @@ public async Task<ClientAndTentacle> Build(CancellationToken cancellationToken)
listeningTentacleBuilder.InstallAsAService();
}

homeDirectory = listeningTentacleBuilder.HomeDirectory.DirectoryPath;
runningTentacle = await listeningTentacleBuilder.Build(logger, cancellationToken);

portForwarder = BuildPortForwarder(runningTentacle.ServiceUri.Port, null);
Expand Down Expand Up @@ -261,7 +258,7 @@ public async Task<ClientAndTentacle> Build(CancellationToken cancellationToken)
clientOptions,
tentacleServiceDecorator);

return new ClientAndTentacle(server.ServerHalibutRuntime, tentacleEndPoint, server, portForwarder, runningTentacle, tentacleClient, temporaryDirectory, retrySettings, logger, homeDirectory);
return new ClientAndTentacle(server.ServerHalibutRuntime, tentacleEndPoint, server, portForwarder, runningTentacle, tentacleClient, temporaryDirectory, retrySettings, logger);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ public RunningTentacle(
public string HomeDirectory { get; }
public string ApplicationDirectory { get; }
public FileInfo TentacleExe { get; }
public string LogFileDirectory => Path.Combine(HomeDirectory, "Logs");
public string LogFilePath => Path.Combine(LogFileDirectory, "OctopusTentacle.txt");
public string LogFilePath => Path.Combine(HomeDirectory, "Logs", "OctopusTentacle.txt");

public async Task Start(CancellationToken cancellationToken)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public abstract class TentacleBuilder<T> : ITentacleBuilder

TemporaryDirectory? homeDirectory;

public TemporaryDirectory HomeDirectory
protected TemporaryDirectory HomeDirectory
{
get
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NUnit.Framework;
using Octopus.Tentacle.Configuration;
using Octopus.Tentacle.Configuration.Instances;
using Octopus.Tentacle.Diagnostics;
using Octopus.Tentacle.Tests.Integration.Support;
using Octopus.Tentacle.Tests.Integration.Support.TestAttributes;
using Octopus.Tentacle.Util;
Expand Down Expand Up @@ -404,51 +401,19 @@ public async Task ListInstancesCommandJson(TentacleConfigurationTestCase tc)
stderr.Should().BeNullOrEmpty();
}

class Instance
{
public Instance(string name, string configurationFilePath)
{
Name = name;
ConfigurationFilePath = configurationFilePath;
}

public string Name { get; }
public string ConfigurationFilePath { get; set; }
}

[Test]
[TentacleConfigurations(scriptServiceToTest: ScriptServiceVersionToTest.None)]
// Run these tests in serial to avoid conflicts
[NonParallelizable]
public async Task ShouldLogStartupDiagnosticsToInstanceLogFileOnly(TentacleConfigurationTestCase tc)
{
Logger.Error($"*** Env Home: {Environment.GetEnvironmentVariable(HomeConfiguration.OctopusHomeSettingName)}, {Environment.GetEnvironmentVariable(ApplicationConfigurationContributionFlag.ContributeSettingsFlag)}");
await using var clientAndTentacle = await tc.CreateBuilder().Build(CancellationToken);
Logger.Error($"*** Env Home2: {Environment.GetEnvironmentVariable(HomeConfiguration.OctopusHomeSettingName)}, {Environment.GetEnvironmentVariable(ApplicationConfigurationContributionFlag.ContributeSettingsFlag)}");


Logger.Information("######### CONFIG FILE OG #########");
var configFilePath = Path.Combine(clientAndTentacle.HomeDirectory, $"{clientAndTentacle.RunningTentacle.InstanceName}.cfg");
var configFile = File.ReadAllText(configFilePath);
Logger.Information(Environment.NewLine + configFile);
Logger.Information("######### CONFIG FILE OG #########");


await clientAndTentacle.RunningTentacle.Stop(CancellationToken);

Logger.Error($"*** Env Home3: {Environment.GetEnvironmentVariable(HomeConfiguration.OctopusHomeSettingName)}, {Environment.GetEnvironmentVariable(ApplicationConfigurationContributionFlag.ContributeSettingsFlag)}");

var startingLogText = clientAndTentacle.RunningTentacle.ReadAllLogFileText();
string wholeLog = string.Empty;
////TODO: REMOVE
//await Task.Delay(5000);
//var startingLogText2 = clientAndTentacle.RunningTentacle.ReadAllLogFileText();

//startingLogText2.Should().Be(startingLogText);

var (exitCode, stdout, stderr) = await RunCommandAndAssertExitsWithSuccessExitCode(tc, "show-thumbprint", $"--instance={clientAndTentacle.RunningTentacle.InstanceName}");

Logger.Error($"*** Env Home4: {Environment.GetEnvironmentVariable(HomeConfiguration.OctopusHomeSettingName)}, {Environment.GetEnvironmentVariable(ApplicationConfigurationContributionFlag.ContributeSettingsFlag)}");

try
{
var logFileText = Policy
Expand All @@ -460,8 +425,7 @@ public async Task ShouldLogStartupDiagnosticsToInstanceLogFileOnly(TentacleConfi
.Execute(
() =>
{

wholeLog = clientAndTentacle.RunningTentacle.ReadAllLogFileText();
var wholeLog = clientAndTentacle.RunningTentacle.ReadAllLogFileText();
var newLog = wholeLog.Replace(startingLogText, string.Empty);
if (string.IsNullOrWhiteSpace(newLog) || !newLog.Contains("CommandLine:"))
{
Expand Down Expand Up @@ -493,65 +457,16 @@ public async Task ShouldLogStartupDiagnosticsToInstanceLogFileOnly(TentacleConfi
logFileText.Should().ContainEquivalentOf("HostProcessName: ", "the HostProcessName should be in our diagnostics");
stdout.Should().NotContainEquivalentOf($"{RuntimeInformation.OSDescription}", "the OSVersion should not be written to stdout");
await Task.CompletedTask;


//TODO: REMOVE
Logger.Error($"Process exit code {exitCode}");
Logger.Error($"Starting log text: {Environment.NewLine}{startingLogText}");
Logger.Error($"Current log text: {Environment.NewLine}{clientAndTentacle.RunningTentacle.ReadAllLogFileText()}");
Logger.Error($"Command StdOut: {Environment.NewLine}{stdout}");
Logger.Error($"Command StdErr: {Environment.NewLine}{stderr}");

//TODO: REMOVE?
var logFiles = Directory.EnumerateFiles(clientAndTentacle.RunningTentacle.LogFileDirectory);
foreach (var logFile in logFiles)
{
Logger.Error($"Found Log file: {logFile}");

if (logFile.Contains("Debug"))
{
Logger.Error($"Debug Contents:{File.ReadAllText(logFile)}");
}
}
}
catch (NotLoggedYetException)
{
Logger.Error("Failed to get new log content");
Logger.Error($"Process exit code {exitCode}");
Logger.Error($"**** Starting log text: {Environment.NewLine}{startingLogText}");
Logger.Error($"**** Whole log text: {Environment.NewLine}{wholeLog}");
Logger.Error($"**** Current log text: {Environment.NewLine}{clientAndTentacle.RunningTentacle.ReadAllLogFileText()}");
Logger.Error($"Starting log text: {Environment.NewLine}{startingLogText}");
Logger.Error($"Current log text: {Environment.NewLine}{clientAndTentacle.RunningTentacle.ReadAllLogFileText()}");
Logger.Error($"Command StdOut: {Environment.NewLine}{stdout}");
Logger.Error($"Command StdErr: {Environment.NewLine}{stderr}");

//TODO: REMOVE?
var logFiles = Directory.EnumerateFiles(clientAndTentacle.RunningTentacle.LogFileDirectory);
foreach (var logFile in logFiles)
{
Logger.Error($"Found Log file: {logFile}");

if (logFile.Contains("Debug"))
{
Logger.Error($"Debug Contents:{File.ReadAllText(logFile)}");
}
}

Logger.Information("######### CONFIG FILE 2 #########");
configFile = File.ReadAllText(configFilePath);
Logger.Information(Environment.NewLine + configFile);
Logger.Information("######### CONFIG FILE 2 #########");


var defaultLogDir = Path.Combine(OctopusLogsDirectoryRenderer.DefaultLogsDirectory, "OctopusTentacle.txt");
var tentacleLog = File.ReadAllText(defaultLogDir);
Logger.Information("############################################");
Logger.Information("######### DEFAULT LOG #########");
Logger.Information("############################################");
Logger.Information(Environment.NewLine + tentacleLog);
Logger.Information("############################################");
Logger.Information("######### DEFAULT LOG #########");
Logger.Information("############################################");

throw;
}
}
Expand Down Expand Up @@ -745,7 +660,6 @@ FileVersionInfo GetVersionInfo(TentacleConfigurationTestCase tentacleConfigurati
async Task<(int ExitCode, string StdOut, string StdError)> RunCommand(TentacleConfigurationTestCase tentacleConfigurationTestCase, params string[] arguments)
{
var tentacleExe = TentacleExeFinder.FindTentacleExe(tentacleConfigurationTestCase.TentacleRuntime);
Logger.Error($"** Tentacle Exe Path: {tentacleExe}");
var output = new StringBuilder();
var errorOut = new StringBuilder();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@ public bool CanLoadCurrentInstance()
LoadCurrentInstance();
return true;
}
catch (Exception ex)
catch
{
log.Error(ex, "*** Could not load instance....");
return false;
}
}
Expand All @@ -67,7 +66,7 @@ ApplicationInstanceConfiguration LoadInstance()
var appInstance = LocateApplicationPrimaryConfiguration();
EnsureConfigurationExists(appInstance.instanceName, appInstance.configurationpath);

log.Verbose($"Loading configuration from::: {appInstance.configurationpath}");
log.Verbose($"Loading configuration from {appInstance.configurationpath}");
var writableConfig = new XmlFileKeyValueStore(fileSystem, appInstance.configurationpath);

var aggregatedKeyValueStore = ContributeAdditionalConfiguration(writableConfig);
Expand Down
10 changes: 1 addition & 9 deletions source/Octopus.Tentacle/Configuration/LogInitializer.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System;
using System.IO;
using Octopus.Diagnostics;
using Octopus.Tentacle.Diagnostics;
using Octopus.Tentacle.Startup;

Expand All @@ -10,15 +9,11 @@ class LogInitializer
{
readonly ILoggingConfiguration configuration;
readonly ILogFileOnlyLogger logFileOnlyLogger;
readonly IHomeConfiguration homeConfiguration;
readonly ISystemLog log;

public LogInitializer(ILoggingConfiguration configuration, ILogFileOnlyLogger logFileOnlyLogger, IHomeConfiguration homeConfiguration, ISystemLog log)
public LogInitializer(ILoggingConfiguration configuration, ILogFileOnlyLogger logFileOnlyLogger)
{
this.configuration = configuration;
this.logFileOnlyLogger = logFileOnlyLogger;
this.homeConfiguration = homeConfiguration;
this.log = log;
}

public void Start()
Expand All @@ -32,9 +27,6 @@ void InitializeLogs()
var logDirectory = configuration.LogsDirectory;
if (logDirectory == null) return;

logFileOnlyLogger.Info($"** Log file is {logDirectory}, default is {OctopusLogsDirectoryRenderer.DefaultLogsDirectory}, home is {homeConfiguration.HomeDirectory}");
log.Info($"** (sys) Log file is {logDirectory}, default is {OctopusLogsDirectoryRenderer.DefaultLogsDirectory}, home is {homeConfiguration.HomeDirectory}");

var previousLogDirectory = OctopusLogsDirectoryRenderer.LogsDirectory;
if (previousLogDirectory != logDirectory)
{
Expand Down
11 changes: 0 additions & 11 deletions source/Octopus.Tentacle/Startup/AbstractCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Octopus.Tentacle.Diagnostics;
using Octopus.Tentacle.Internals.Options;

namespace Octopus.Tentacle.Startup
Expand Down Expand Up @@ -77,16 +76,6 @@ public virtual void Start(string[] commandLineArguments, ICommandRuntime command
LogFileOnlyLogger.Info($"==== {GetType().Name} ====");
LogFileOnlyLogger.Info($"CommandLine: {string.Join(" ", Environment.GetCommandLineArgs())}");

var logDir = OctopusLogsDirectoryRenderer.LogsDirectory;
var instance = Guid.NewGuid().ToString();
var debugFile = Path.Combine(logDir, $"Debug-{instance}.txt");
File.WriteAllLines(debugFile, new []
{
string.Join(" ", Environment.GetCommandLineArgs()),

});


Start();
Completed();
}
Expand Down

0 comments on commit ef2570a

Please sign in to comment.