diff --git a/.gitlab/e2e_install_packages/windows.yml b/.gitlab/e2e_install_packages/windows.yml index c686c38145a92a..2bba14c507f0a5 100644 --- a/.gitlab/e2e_install_packages/windows.yml +++ b/.gitlab/e2e_install_packages/windows.yml @@ -249,3 +249,5 @@ new-e2e-installer-windows: - EXTRA_PARAMS: --run "TestAgentMSIInstallsDotnetLibrary/TestMSISkipRollbackIfInstalled$" - EXTRA_PARAMS: --run "TestAgentMSIInstallsDotnetLibrary/TestUninstallKeepsLibrary$" - EXTRA_PARAMS: --run "TestAgentMSIInstallsDotnetLibrary/TestUninstallScript$" + - EXTRA_PARAMS: --run "TestAgentScriptInstallsDotnetLibrary/TestInstallFromScript$" + - EXTRA_PARAMS: --run "TestAgentScriptInstallsDotnetLibrary/TestScriptThenRemoteUpgrade$" diff --git a/pkg/fleet/installer/setup/defaultscript/default_script.go b/pkg/fleet/installer/setup/defaultscript/default_script.go index 7e4853f5706570..e38694768df6a0 100644 --- a/pkg/fleet/installer/setup/defaultscript/default_script.go +++ b/pkg/fleet/installer/setup/defaultscript/default_script.go @@ -10,6 +10,7 @@ import ( "fmt" "os" "regexp" + "runtime" "strings" "github.com/DataDog/datadog-agent/pkg/fleet/installer/env" @@ -200,7 +201,11 @@ func installAPMPackages(s *common.Setup) { // Injector install _, apmInstrumentationEnabled := os.LookupEnv("DD_APM_INSTRUMENTATION_ENABLED") if apmInstrumentationEnabled { - s.Packages.Install(common.DatadogAPMInjectPackage, defaultInjectorVersion) + if runtime.GOOS != "windows" { + s.Packages.Install(common.DatadogAPMInjectPackage, defaultInjectorVersion) + } + // the "host" options will be added to windows + // this will then install the IIS agent package } // Libraries install diff --git a/test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/base_suite.go b/test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/base_suite.go index 03e3055e70c4ed..78ea612a8ce5d1 100644 --- a/test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/base_suite.go +++ b/test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/base_suite.go @@ -10,6 +10,7 @@ import ( "strings" installerwindows "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows" + "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows/consts" "github.com/DataDog/datadog-agent/test/new-e2e/tests/windows" ) @@ -90,3 +91,65 @@ func (s *baseIISSuite) getLibraryPathFromInstrumentedIIS() string { s.Require().NoErrorf(err, "failed to get content from site: %s", output) return strings.TrimSpace(output) } + +func (s *baseIISSuite) setAgentConfig() { + err := s.Env().RemoteHost.MkdirAll("C:\\ProgramData\\Datadog") + s.Require().NoError(err) + _, err = s.Env().RemoteHost.WriteFile(consts.ConfigPath, []byte(` +api_key: aaaaaaaaa +remote_updates: true +`)) + s.Require().NoError(err) +} + +func (s *baseIISSuite) cleanupAgentConfig() { + err := s.Env().RemoteHost.Remove(consts.ConfigPath) + s.Require().NoError(err) +} + +func (s *baseIISSuite) assertSuccessfulStartExperiment(version string) { + s.Require().Host(s.Env().RemoteHost).HasDatadogInstaller().Status(). + HasPackage("datadog-apm-library-dotnet"). + WithExperimentVersionMatchPredicate(func(actual string) { + s.Require().Contains(actual, version) + }) +} + +func (s *baseIISSuite) assertSuccessfulPromoteExperiment(version string) { + s.Require().Host(s.Env().RemoteHost).HasDatadogInstaller().Status(). + HasPackage("datadog-apm-library-dotnet"). + WithStableVersionMatchPredicate(func(actual string) { + s.Require().Contains(actual, version) + }). + WithExperimentVersionEqual("") +} + +func (s *baseIISSuite) startExperimentCurrentDotnetLibrary(version installerwindows.PackageVersion) (string, error) { + return s.startExperimentWithCustomPackage(installerwindows.WithName("datadog-apm-library-dotnet"), + installerwindows.WithAlias("apm-library-dotnet-package"), + // TODO remove override once image is published in prod + installerwindows.WithVersion(version.PackageVersion()), + installerwindows.WithRegistry("install.datad0g.com.internal.dda-testing.com"), + installerwindows.WithDevEnvOverrides("CURRENT_DOTNET_LIBRARY"), + ) +} + +func (s *baseIISSuite) startExperimentWithCustomPackage(opts ...installerwindows.PackageOption) (string, error) { + packageConfig, err := installerwindows.NewPackageConfig(opts...) + s.Require().NoError(err) + packageConfig, err = installerwindows.CreatePackageSourceIfLocal(s.Env().RemoteHost, packageConfig) + s.Require().NoError(err) + + // Set catalog so daemon can find the package + _, err = s.Installer().SetCatalog(installerwindows.Catalog{ + Packages: []installerwindows.PackageEntry{ + { + Package: packageConfig.Name, + Version: packageConfig.Version, + URL: packageConfig.URL(), + }, + }, + }) + s.Require().NoError(err) + return s.Installer().StartExperiment("datadog-apm-library-dotnet", packageConfig.Version) +} diff --git a/test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/install_script_test.go b/test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/install_script_test.go new file mode 100644 index 00000000000000..a1db6f20867ce9 --- /dev/null +++ b/test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/install_script_test.go @@ -0,0 +1,140 @@ +// Unless explicitly stated otherwise all files in this repository are licensed +// under the Apache License Version 2.0. +// This product includes software developed at Datadog (https://www.datadoghq.com/). +// Copyright 2016-present Datadog, Inc. + +package dotnettests + +import ( + "fmt" + "os" + + "github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e" + winawshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/provisioners/aws/host/windows" + installerwindows "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows" + + "testing" +) + +type testAgentScriptInstallsDotnetLibrary struct { + baseIISSuite + previousDotnetLibraryVersion installerwindows.PackageVersion + currentDotnetLibraryVersion installerwindows.PackageVersion +} + +// TestDotnetInstalls tests the usage of the Datadog installer and the MSI to install the apm-library-dotnet-package package. +func TestAgentScriptInstallsDotnetLibrary(t *testing.T) { + e2e.Run(t, &testAgentScriptInstallsDotnetLibrary{}, + e2e.WithProvisioner( + winawshost.ProvisionerNoAgentNoFakeIntake())) +} + +func (s *testAgentScriptInstallsDotnetLibrary) SetupSuite() { + s.baseIISSuite.SetupSuite() + + s.previousDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion(os.Getenv("PREVIOUS_DOTNET_VERSION_PACKAGE")) + if s.previousDotnetLibraryVersion.PackageVersion() == "" { + s.previousDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion("3.19.0-pipeline.67299728.beta.sha-c05ddfb1-1") + } + s.currentDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion(os.Getenv("CURRENT_DOTNET_VERSION_PACKAGE")) + if s.currentDotnetLibraryVersion.PackageVersion() == "" { + s.currentDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion("3.19.0-pipeline.67351320.beta.sha-c05ddfb1-1") + } +} + +func (s *testAgentScriptInstallsDotnetLibrary) AfterTest(suiteName, testName string) { + s.Installer().Purge() + s.baseIISSuite.AfterTest(suiteName, testName) +} + +// TestInstallFromScript tests the Agent script can install the dotnet library OCI package +func (s *testAgentScriptInstallsDotnetLibrary) TestInstallFromScript() { + // Arrange + version := s.currentDotnetLibraryVersion + + // Act + s.installCurrentAgentVersion( + installerwindows.WithExtraEnvVars(map[string]string{ + "DD_APM_INSTRUMENTATION_ENABLED": "iis", + // TODO: remove override once image is published in prod + "DD_INSTALLER_REGISTRY_URL": "install.datad0g.com.internal.dda-testing.com", + "DD_APM_INSTRUMENTATION_LIBRARIES": fmt.Sprintf("dotnet:%s", version.Version()), + }), + ) + // Start the IIS app to load the library + defer s.stopIISApp() + s.startIISApp(webConfigFile, aspxFile) + + // Assert + s.assertSuccessfulPromoteExperiment(version.Version()) + // Check that the expected version of the library is loaded + oldLibraryPath := s.getLibraryPathFromInstrumentedIIS() + s.Require().Contains(oldLibraryPath, version.Version()) +} + +// TestScriptThenRemoteUpgrade tests the dotnet library can be remotely upgraded from an Agent script installed version +func (s *testAgentScriptInstallsDotnetLibrary) TestScriptThenRemoteUpgrade() { + defer s.cleanupAgentConfig() + s.setAgentConfig() + + oldVersion := s.previousDotnetLibraryVersion + newVersion := s.currentDotnetLibraryVersion + + // Install first version + s.installCurrentAgentVersion( + installerwindows.WithExtraEnvVars(map[string]string{ + "DD_APM_INSTRUMENTATION_ENABLED": "iis", + // TODO: remove override once image is published in prod + "DD_INSTALLER_REGISTRY_URL": "install.datad0g.com.internal.dda-testing.com", + "DD_APM_INSTRUMENTATION_LIBRARIES": fmt.Sprintf("dotnet:%s", oldVersion.Version()), + }), + ) + + // Start the IIS app to load the library + defer s.stopIISApp() + s.startIISApp(webConfigFile, aspxFile) + + // Check that the expected version of the library is loaded + s.assertSuccessfulPromoteExperiment(oldVersion.Version()) + oldLibraryPath := s.getLibraryPathFromInstrumentedIIS() + s.Require().Contains(oldLibraryPath, oldVersion.Version()) + + // Start remote upgrade experiment + _, err := s.startExperimentCurrentDotnetLibrary(newVersion) + s.Require().NoError(err) + s.assertSuccessfulStartExperiment(newVersion.Version()) + + // Check that the old version of the library is still loaded since we have not restarted yet + oldLibraryPathAgain := s.getLibraryPathFromInstrumentedIIS() + s.Require().Contains(oldLibraryPathAgain, oldVersion.Version()) + s.Require().Equal(oldLibraryPath, oldLibraryPathAgain) + + // Restart the IIS application + s.startIISApp(webConfigFile, aspxFile) + + // Check that the new version of the library is loaded + newLibraryPath := s.getLibraryPathFromInstrumentedIIS() + s.Require().Contains(newLibraryPath, newVersion.Version()) + s.Require().NotEqual(oldLibraryPath, newLibraryPath) + + // Promote the experiment + _, err = s.Installer().PromoteExperiment("datadog-apm-library-dotnet") + s.Require().NoError(err) + s.assertSuccessfulPromoteExperiment(newVersion.Version()) +} + +// installCurrentAgentVersion installs the current agent version with script +func (s *testAgentScriptInstallsDotnetLibrary) installCurrentAgentVersion(opts ...installerwindows.Option) { + output, err := s.InstallScript().Run(opts...) + if s.NoError(err) { + fmt.Printf("%s\n", output) + } + s.Require().NoErrorf(err, "failed to install the Datadog Agent package: %s", output) + s.Require().NoError(s.WaitForInstallerService("Running")) + s.Require().Host(s.Env().RemoteHost). + HasARunningDatadogInstallerService(). + HasARunningDatadogAgentService(). + WithVersionMatchPredicate(func(version string) { + s.Require().Contains(version, s.CurrentAgentVersion().Version()) + }) +} diff --git a/test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/msi_install_test.go b/test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/msi_install_test.go index 39f171d9f11baa..bb013d0017e24c 100644 --- a/test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/msi_install_test.go +++ b/test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/msi_install_test.go @@ -103,7 +103,7 @@ func (s *testAgentMSIInstallsDotnetLibrary) TestMSIThenRemoteUpgrade() { s.Require().Contains(oldLibraryPath, oldVersion.Version()) // Start remote upgrade experiment - _, err := s.startExperimentCurrentVersion() + _, err := s.startExperimentCurrentDotnetLibrary(newVersion) s.Require().NoError(err) s.assertSuccessfulStartExperiment(newVersion.Version()) @@ -297,68 +297,6 @@ func (s *testAgentMSIInstallsDotnetLibrary) TestUninstallScript() { s.Require().Empty(newLibraryPath) } -func (s *testAgentMSIInstallsDotnetLibrary) setAgentConfig() { - err := s.Env().RemoteHost.MkdirAll("C:\\ProgramData\\Datadog") - s.Require().NoError(err) - _, err = s.Env().RemoteHost.WriteFile(consts.ConfigPath, []byte(` -api_key: aaaaaaaaa -remote_updates: true -`)) - s.Require().NoError(err) -} - -func (s *testAgentMSIInstallsDotnetLibrary) cleanupAgentConfig() { - err := s.Env().RemoteHost.Remove(consts.ConfigPath) - s.Require().NoError(err) -} - -func (s *testAgentMSIInstallsDotnetLibrary) assertSuccessfulStartExperiment(version string) { - s.Require().Host(s.Env().RemoteHost).HasDatadogInstaller().Status(). - HasPackage("datadog-apm-library-dotnet"). - WithExperimentVersionMatchPredicate(func(actual string) { - s.Require().Contains(actual, version) - }) -} - -func (s *testAgentMSIInstallsDotnetLibrary) assertSuccessfulPromoteExperiment(version string) { - s.Require().Host(s.Env().RemoteHost).HasDatadogInstaller().Status(). - HasPackage("datadog-apm-library-dotnet"). - WithStableVersionMatchPredicate(func(actual string) { - s.Require().Contains(actual, version) - }). - WithExperimentVersionEqual("") -} - -func (s *testAgentMSIInstallsDotnetLibrary) startExperimentCurrentVersion() (string, error) { - return s.startExperimentWithCustomPackage(installerwindows.WithName("datadog-apm-library-dotnet"), - installerwindows.WithAlias("apm-library-dotnet-package"), - // TODO remove override once image is published in prod - installerwindows.WithVersion(s.currentDotnetLibraryVersion.PackageVersion()), - installerwindows.WithRegistry("install.datad0g.com.internal.dda-testing.com"), - installerwindows.WithDevEnvOverrides("CURRENT_DOTNET_LIBRARY"), - ) -} - -func (s *testAgentMSIInstallsDotnetLibrary) startExperimentWithCustomPackage(opts ...installerwindows.PackageOption) (string, error) { - packageConfig, err := installerwindows.NewPackageConfig(opts...) - s.Require().NoError(err) - packageConfig, err = installerwindows.CreatePackageSourceIfLocal(s.Env().RemoteHost, packageConfig) - s.Require().NoError(err) - - // Set catalog so daemon can find the package - _, err = s.Installer().SetCatalog(installerwindows.Catalog{ - Packages: []installerwindows.PackageEntry{ - { - Package: packageConfig.Name, - Version: packageConfig.Version, - URL: packageConfig.URL(), - }, - }, - }) - s.Require().NoError(err) - return s.Installer().StartExperiment("datadog-apm-library-dotnet", packageConfig.Version) -} - func (s *testAgentMSIInstallsDotnetLibrary) installPreviousAgentVersion(opts ...installerwindows.MsiOption) { agentVersion := s.StableAgentVersion().Version() options := []installerwindows.MsiOption{