-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathwindows.go
More file actions
99 lines (78 loc) · 3.46 KB
/
windows.go
File metadata and controls
99 lines (78 loc) · 3.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package dynatrace
import (
"fmt"
"os"
"path/filepath"
"slices"
"strings"
"github.com/cloudfoundry/libbuildpack"
)
func (h *Hook) runInstallerWindows(installerFilePath, installDir string, creds *credentials, stager *libbuildpack.Stager) error {
h.Log.BeginStep("Starting Dynatrace OneAgent installation")
h.Log.Info("Unzipping archive '%s' to '%s'", installerFilePath, filepath.Join(stager.BuildDir(), installDir))
err := libbuildpack.ExtractZip(installerFilePath, filepath.Join(stager.BuildDir(), installDir))
if err != nil {
h.Log.Error("Error during unzipping paas archive")
return err
}
h.Log.Info("Dynatrace OneAgent installed.")
// Post-installation setup...
h.Log.BeginStep("Setting up Dynatrace OneAgent injection...")
if slices.Contains(h.IncludeTechnologies, "dotnet") {
err = h.setUpDotNetCorProfilerInjection(creds, installDir, stager)
} else {
h.Log.Warning("No injection method available for technology stack")
return nil
}
if err != nil {
return err
}
return nil
}
func (h *Hook) setUpDotNetCorProfilerInjection(creds *credentials, installDir string, stager *libbuildpack.Stager) error {
agentPath, err := h.findAbsoluteAgentPath(stager, installDir)
if err != nil {
return fmt.Errorf("cannot find oneagentdotnet.dll: %s", err)
}
scriptContent := "set COR_ENABLE_PROFILING=1\n"
scriptContent += "set COR_PROFILER={B7038F67-52FC-4DA2-AB02-969B3C1EDA03}\n"
scriptContent += "set DT_AGENTACTIVE=true\n"
scriptContent += "set DT_BLOCKLIST=powershell*\n"
scriptContent += fmt.Sprintf("set COR_PROFILER_PATH_64=%s\n", agentPath)
if creds.NetworkZone != "" {
h.Log.Debug("Setting DT_NETWORK_ZONE...")
scriptContent += "set DT_NETWORK_ZONE=" + creds.NetworkZone + "\n"
}
ver, err := stager.BuildpackVersion()
if err != nil {
h.Log.Warning("Failed to get buildpack version: %v", err)
ver = "unknown"
}
h.Log.Debug("Preparing custom properties...")
scriptContent += fmt.Sprintf("set DT_CUSTOM_PROP=\"%%DT_CUSTOM_PROP%% CloudFoundryBuildpackLanguage=%s CloudFoundryBuildpackVersion=%s\"\n", stager.BuildpackLanguage(), ver)
stager.WriteProfileD("dynatrace-env.cmd", scriptContent)
return nil
}
func (h *Hook) findAbsoluteAgentPath(stager *libbuildpack.Stager, installDir string) (string, error) {
// look for dotnet agent DLL file relative to the root of the downloaded zip archive
// and get the path from the manifest e.g. agent/bin/windows-x86-64/oneagentdotnet .dll
agentDllPath, err := h.findAgentPath(filepath.Join(stager.BuildDir(), installDir), "dotnet", "primary", "oneagentdotnet.dll", "windows-x86-64")
if err != nil {
h.Log.Error("Manifest handling failed!")
return "", err
}
// windows path separator is "\" instead of "/"
agentDllPath = strings.ReplaceAll(agentDllPath, "/", "\\")
// build the agent DLL path relative to the app directory
// e.g. dynatrace/oneagent/agent/bin/windows-x86-64/oneagentdotnet.dll
agentDllPathInAppDir := filepath.Join(installDir, agentDllPath)
// check that the agent dll is present in the build dir
// e.g. at \tmp\app\dynatrace\oneagent\agent\bin\1.303.0.20240930-081133\windows-x86-32\oneagentdotnet.dll
agentDllPathInBuildDir := filepath.Join(stager.BuildDir(), agentDllPathInAppDir)
if _, err = os.Stat(agentDllPathInBuildDir); os.IsNotExist(err) {
h.Log.Error("Agent library (%s) not found!", agentDllPathInBuildDir)
return "", err
}
// build the absolute path of the agent DLL as it will be available at runtime
return filepath.Join("C:\\users\\vcap\\app", agentDllPathInAppDir), nil
}