Skip to content

Commit 33e6c78

Browse files
dd-octo-sts[bot]jack0x2avonengel
authored
[Backport 7.72.x] Fix Windows Fleet Setup Script (#42193)
Backport 8497514 from #42085. ___ ### What does this PR do? Fixes a bug in the windows installer to not try and install the non exsistient datadog-inject package and fail install when IIS options are set. ### Motivation https://datadoghq.atlassian.net/browse/WINA-1930 https://datadoghq.atlassian.net/browse/WINA-1356 ### Describe how you validated your changes Adds e2e test that uses install script to install agent with APM IIS SSI options. ### Additional Notes When host option added for IIS we should better split this logic to install correct package. Co-authored-by: jack0x2 <jack.phillips@datadoghq.com> Co-authored-by: axel.vonengel <axel.vonengel@datadoghq.com>
1 parent 58bf5fd commit 33e6c78

5 files changed

Lines changed: 212 additions & 64 deletions

File tree

.gitlab/e2e_install_packages/windows.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,3 +247,5 @@ new-e2e-installer-windows:
247247
- EXTRA_PARAMS: --run "TestAgentMSIInstallsDotnetLibrary/TestMSISkipRollbackIfInstalled$"
248248
- EXTRA_PARAMS: --run "TestAgentMSIInstallsDotnetLibrary/TestUninstallKeepsLibrary$"
249249
- EXTRA_PARAMS: --run "TestAgentMSIInstallsDotnetLibrary/TestUninstallScript$"
250+
- EXTRA_PARAMS: --run "TestAgentScriptInstallsDotnetLibrary/TestInstallFromScript$"
251+
- EXTRA_PARAMS: --run "TestAgentScriptInstallsDotnetLibrary/TestScriptThenRemoteUpgrade$"

pkg/fleet/installer/setup/defaultscript/default_script.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"os"
1212
"regexp"
13+
"runtime"
1314
"strings"
1415

1516
"github.com/DataDog/datadog-agent/pkg/fleet/installer/env"
@@ -200,7 +201,11 @@ func installAPMPackages(s *common.Setup) {
200201
// Injector install
201202
_, apmInstrumentationEnabled := os.LookupEnv("DD_APM_INSTRUMENTATION_ENABLED")
202203
if apmInstrumentationEnabled {
203-
s.Packages.Install(common.DatadogAPMInjectPackage, defaultInjectorVersion)
204+
if runtime.GOOS != "windows" {
205+
s.Packages.Install(common.DatadogAPMInjectPackage, defaultInjectorVersion)
206+
}
207+
// the "host" options will be added to windows
208+
// this will then install the IIS agent package
204209
}
205210

206211
// Libraries install

test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/base_suite.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"strings"
1111

1212
installerwindows "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows"
13+
"github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows/consts"
1314
"github.com/DataDog/datadog-agent/test/new-e2e/tests/windows"
1415
)
1516

@@ -90,3 +91,65 @@ func (s *baseIISSuite) getLibraryPathFromInstrumentedIIS() string {
9091
s.Require().NoErrorf(err, "failed to get content from site: %s", output)
9192
return strings.TrimSpace(output)
9293
}
94+
95+
func (s *baseIISSuite) setAgentConfig() {
96+
err := s.Env().RemoteHost.MkdirAll("C:\\ProgramData\\Datadog")
97+
s.Require().NoError(err)
98+
_, err = s.Env().RemoteHost.WriteFile(consts.ConfigPath, []byte(`
99+
api_key: aaaaaaaaa
100+
remote_updates: true
101+
`))
102+
s.Require().NoError(err)
103+
}
104+
105+
func (s *baseIISSuite) cleanupAgentConfig() {
106+
err := s.Env().RemoteHost.Remove(consts.ConfigPath)
107+
s.Require().NoError(err)
108+
}
109+
110+
func (s *baseIISSuite) assertSuccessfulStartExperiment(version string) {
111+
s.Require().Host(s.Env().RemoteHost).HasDatadogInstaller().Status().
112+
HasPackage("datadog-apm-library-dotnet").
113+
WithExperimentVersionMatchPredicate(func(actual string) {
114+
s.Require().Contains(actual, version)
115+
})
116+
}
117+
118+
func (s *baseIISSuite) assertSuccessfulPromoteExperiment(version string) {
119+
s.Require().Host(s.Env().RemoteHost).HasDatadogInstaller().Status().
120+
HasPackage("datadog-apm-library-dotnet").
121+
WithStableVersionMatchPredicate(func(actual string) {
122+
s.Require().Contains(actual, version)
123+
}).
124+
WithExperimentVersionEqual("")
125+
}
126+
127+
func (s *baseIISSuite) startExperimentCurrentDotnetLibrary(version installerwindows.PackageVersion) (string, error) {
128+
return s.startExperimentWithCustomPackage(installerwindows.WithName("datadog-apm-library-dotnet"),
129+
installerwindows.WithAlias("apm-library-dotnet-package"),
130+
// TODO remove override once image is published in prod
131+
installerwindows.WithVersion(version.PackageVersion()),
132+
installerwindows.WithRegistry("install.datad0g.com.internal.dda-testing.com"),
133+
installerwindows.WithDevEnvOverrides("CURRENT_DOTNET_LIBRARY"),
134+
)
135+
}
136+
137+
func (s *baseIISSuite) startExperimentWithCustomPackage(opts ...installerwindows.PackageOption) (string, error) {
138+
packageConfig, err := installerwindows.NewPackageConfig(opts...)
139+
s.Require().NoError(err)
140+
packageConfig, err = installerwindows.CreatePackageSourceIfLocal(s.Env().RemoteHost, packageConfig)
141+
s.Require().NoError(err)
142+
143+
// Set catalog so daemon can find the package
144+
_, err = s.Installer().SetCatalog(installerwindows.Catalog{
145+
Packages: []installerwindows.PackageEntry{
146+
{
147+
Package: packageConfig.Name,
148+
Version: packageConfig.Version,
149+
URL: packageConfig.URL(),
150+
},
151+
},
152+
})
153+
s.Require().NoError(err)
154+
return s.Installer().StartExperiment("datadog-apm-library-dotnet", packageConfig.Version)
155+
}
Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
// Unless explicitly stated otherwise all files in this repository are licensed
2+
// under the Apache License Version 2.0.
3+
// This product includes software developed at Datadog (https://www.datadoghq.com/).
4+
// Copyright 2016-present Datadog, Inc.
5+
6+
package dotnettests
7+
8+
import (
9+
"fmt"
10+
"os"
11+
12+
"github.com/DataDog/datadog-agent/test/new-e2e/pkg/e2e"
13+
winawshost "github.com/DataDog/datadog-agent/test/new-e2e/pkg/provisioners/aws/host/windows"
14+
installerwindows "github.com/DataDog/datadog-agent/test/new-e2e/tests/installer/windows"
15+
16+
"testing"
17+
)
18+
19+
type testAgentScriptInstallsDotnetLibrary struct {
20+
baseIISSuite
21+
previousDotnetLibraryVersion installerwindows.PackageVersion
22+
currentDotnetLibraryVersion installerwindows.PackageVersion
23+
}
24+
25+
// TestDotnetInstalls tests the usage of the Datadog installer and the MSI to install the apm-library-dotnet-package package.
26+
func TestAgentScriptInstallsDotnetLibrary(t *testing.T) {
27+
e2e.Run(t, &testAgentScriptInstallsDotnetLibrary{},
28+
e2e.WithProvisioner(
29+
winawshost.ProvisionerNoAgentNoFakeIntake()))
30+
}
31+
32+
func (s *testAgentScriptInstallsDotnetLibrary) SetupSuite() {
33+
s.baseIISSuite.SetupSuite()
34+
35+
s.previousDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion(os.Getenv("PREVIOUS_DOTNET_VERSION_PACKAGE"))
36+
if s.previousDotnetLibraryVersion.PackageVersion() == "" {
37+
s.previousDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion("3.19.0-pipeline.67299728.beta.sha-c05ddfb1-1")
38+
}
39+
s.currentDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion(os.Getenv("CURRENT_DOTNET_VERSION_PACKAGE"))
40+
if s.currentDotnetLibraryVersion.PackageVersion() == "" {
41+
s.currentDotnetLibraryVersion = installerwindows.NewVersionFromPackageVersion("3.19.0-pipeline.67351320.beta.sha-c05ddfb1-1")
42+
}
43+
}
44+
45+
func (s *testAgentScriptInstallsDotnetLibrary) AfterTest(suiteName, testName string) {
46+
s.Installer().Purge()
47+
s.baseIISSuite.AfterTest(suiteName, testName)
48+
}
49+
50+
// TestInstallFromScript tests the Agent script can install the dotnet library OCI package
51+
func (s *testAgentScriptInstallsDotnetLibrary) TestInstallFromScript() {
52+
// Arrange
53+
version := s.currentDotnetLibraryVersion
54+
55+
// Act
56+
s.installCurrentAgentVersion(
57+
installerwindows.WithExtraEnvVars(map[string]string{
58+
"DD_APM_INSTRUMENTATION_ENABLED": "iis",
59+
// TODO: remove override once image is published in prod
60+
"DD_INSTALLER_REGISTRY_URL": "install.datad0g.com.internal.dda-testing.com",
61+
"DD_APM_INSTRUMENTATION_LIBRARIES": fmt.Sprintf("dotnet:%s", version.Version()),
62+
}),
63+
)
64+
// Start the IIS app to load the library
65+
defer s.stopIISApp()
66+
s.startIISApp(webConfigFile, aspxFile)
67+
68+
// Assert
69+
s.assertSuccessfulPromoteExperiment(version.Version())
70+
// Check that the expected version of the library is loaded
71+
oldLibraryPath := s.getLibraryPathFromInstrumentedIIS()
72+
s.Require().Contains(oldLibraryPath, version.Version())
73+
}
74+
75+
// TestScriptThenRemoteUpgrade tests the dotnet library can be remotely upgraded from an Agent script installed version
76+
func (s *testAgentScriptInstallsDotnetLibrary) TestScriptThenRemoteUpgrade() {
77+
defer s.cleanupAgentConfig()
78+
s.setAgentConfig()
79+
80+
oldVersion := s.previousDotnetLibraryVersion
81+
newVersion := s.currentDotnetLibraryVersion
82+
83+
// Install first version
84+
s.installCurrentAgentVersion(
85+
installerwindows.WithExtraEnvVars(map[string]string{
86+
"DD_APM_INSTRUMENTATION_ENABLED": "iis",
87+
// TODO: remove override once image is published in prod
88+
"DD_INSTALLER_REGISTRY_URL": "install.datad0g.com.internal.dda-testing.com",
89+
"DD_APM_INSTRUMENTATION_LIBRARIES": fmt.Sprintf("dotnet:%s", oldVersion.Version()),
90+
}),
91+
)
92+
93+
// Start the IIS app to load the library
94+
defer s.stopIISApp()
95+
s.startIISApp(webConfigFile, aspxFile)
96+
97+
// Check that the expected version of the library is loaded
98+
s.assertSuccessfulPromoteExperiment(oldVersion.Version())
99+
oldLibraryPath := s.getLibraryPathFromInstrumentedIIS()
100+
s.Require().Contains(oldLibraryPath, oldVersion.Version())
101+
102+
// Start remote upgrade experiment
103+
_, err := s.startExperimentCurrentDotnetLibrary(newVersion)
104+
s.Require().NoError(err)
105+
s.assertSuccessfulStartExperiment(newVersion.Version())
106+
107+
// Check that the old version of the library is still loaded since we have not restarted yet
108+
oldLibraryPathAgain := s.getLibraryPathFromInstrumentedIIS()
109+
s.Require().Contains(oldLibraryPathAgain, oldVersion.Version())
110+
s.Require().Equal(oldLibraryPath, oldLibraryPathAgain)
111+
112+
// Restart the IIS application
113+
s.startIISApp(webConfigFile, aspxFile)
114+
115+
// Check that the new version of the library is loaded
116+
newLibraryPath := s.getLibraryPathFromInstrumentedIIS()
117+
s.Require().Contains(newLibraryPath, newVersion.Version())
118+
s.Require().NotEqual(oldLibraryPath, newLibraryPath)
119+
120+
// Promote the experiment
121+
_, err = s.Installer().PromoteExperiment("datadog-apm-library-dotnet")
122+
s.Require().NoError(err)
123+
s.assertSuccessfulPromoteExperiment(newVersion.Version())
124+
}
125+
126+
// installCurrentAgentVersion installs the current agent version with script
127+
func (s *testAgentScriptInstallsDotnetLibrary) installCurrentAgentVersion(opts ...installerwindows.Option) {
128+
output, err := s.InstallScript().Run(opts...)
129+
if s.NoError(err) {
130+
fmt.Printf("%s\n", output)
131+
}
132+
s.Require().NoErrorf(err, "failed to install the Datadog Agent package: %s", output)
133+
s.Require().NoError(s.WaitForInstallerService("Running"))
134+
s.Require().Host(s.Env().RemoteHost).
135+
HasARunningDatadogInstallerService().
136+
HasARunningDatadogAgentService().
137+
WithVersionMatchPredicate(func(version string) {
138+
s.Require().Contains(version, s.CurrentAgentVersion().Version())
139+
})
140+
}

test/new-e2e/tests/installer/windows/suites/apm-library-dotnet-package/msi_install_test.go

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (s *testAgentMSIInstallsDotnetLibrary) TestMSIThenRemoteUpgrade() {
104104
s.Require().Contains(oldLibraryPath, oldVersion.Version())
105105

106106
// Start remote upgrade experiment
107-
_, err := s.startExperimentCurrentVersion()
107+
_, err := s.startExperimentCurrentDotnetLibrary(newVersion)
108108
s.Require().NoError(err)
109109
s.assertSuccessfulStartExperiment(newVersion.Version())
110110

@@ -298,68 +298,6 @@ func (s *testAgentMSIInstallsDotnetLibrary) TestUninstallScript() {
298298
s.Require().Empty(newLibraryPath)
299299
}
300300

301-
func (s *testAgentMSIInstallsDotnetLibrary) setAgentConfig() {
302-
err := s.Env().RemoteHost.MkdirAll("C:\\ProgramData\\Datadog")
303-
s.Require().NoError(err)
304-
_, err = s.Env().RemoteHost.WriteFile(consts.ConfigPath, []byte(`
305-
api_key: aaaaaaaaa
306-
remote_updates: true
307-
`))
308-
s.Require().NoError(err)
309-
}
310-
311-
func (s *testAgentMSIInstallsDotnetLibrary) cleanupAgentConfig() {
312-
err := s.Env().RemoteHost.Remove(consts.ConfigPath)
313-
s.Require().NoError(err)
314-
}
315-
316-
func (s *testAgentMSIInstallsDotnetLibrary) assertSuccessfulStartExperiment(version string) {
317-
s.Require().Host(s.Env().RemoteHost).HasDatadogInstaller().Status().
318-
HasPackage("datadog-apm-library-dotnet").
319-
WithExperimentVersionMatchPredicate(func(actual string) {
320-
s.Require().Contains(actual, version)
321-
})
322-
}
323-
324-
func (s *testAgentMSIInstallsDotnetLibrary) assertSuccessfulPromoteExperiment(version string) {
325-
s.Require().Host(s.Env().RemoteHost).HasDatadogInstaller().Status().
326-
HasPackage("datadog-apm-library-dotnet").
327-
WithStableVersionMatchPredicate(func(actual string) {
328-
s.Require().Contains(actual, version)
329-
}).
330-
WithExperimentVersionEqual("")
331-
}
332-
333-
func (s *testAgentMSIInstallsDotnetLibrary) startExperimentCurrentVersion() (string, error) {
334-
return s.startExperimentWithCustomPackage(installerwindows.WithName("datadog-apm-library-dotnet"),
335-
installerwindows.WithAlias("apm-library-dotnet-package"),
336-
// TODO remove override once image is published in prod
337-
installerwindows.WithVersion(s.currentDotnetLibraryVersion.PackageVersion()),
338-
installerwindows.WithRegistry("install.datad0g.com.internal.dda-testing.com"),
339-
installerwindows.WithDevEnvOverrides("CURRENT_DOTNET_LIBRARY"),
340-
)
341-
}
342-
343-
func (s *testAgentMSIInstallsDotnetLibrary) startExperimentWithCustomPackage(opts ...installerwindows.PackageOption) (string, error) {
344-
packageConfig, err := installerwindows.NewPackageConfig(opts...)
345-
s.Require().NoError(err)
346-
packageConfig, err = installerwindows.CreatePackageSourceIfLocal(s.Env().RemoteHost, packageConfig)
347-
s.Require().NoError(err)
348-
349-
// Set catalog so daemon can find the package
350-
_, err = s.Installer().SetCatalog(installerwindows.Catalog{
351-
Packages: []installerwindows.PackageEntry{
352-
{
353-
Package: packageConfig.Name,
354-
Version: packageConfig.Version,
355-
URL: packageConfig.URL(),
356-
},
357-
},
358-
})
359-
s.Require().NoError(err)
360-
return s.Installer().StartExperiment("datadog-apm-library-dotnet", packageConfig.Version)
361-
}
362-
363301
func (s *testAgentMSIInstallsDotnetLibrary) installPreviousAgentVersion(opts ...installerwindows.MsiOption) {
364302
agentVersion := s.StableAgentVersion().Version()
365303
options := []installerwindows.MsiOption{

0 commit comments

Comments
 (0)