diff --git a/README.md b/README.md
index 9337ce9..9c78557 100644
--- a/README.md
+++ b/README.md
@@ -39,7 +39,7 @@ The 3rd and 4th buildpacks are HWC extensions for Windows 2012 R2 and Windows 20
All 4 buildpacks use the multi-buildpack approach of Cloud Foundry and require either the standard Dotnet Core buildpack or HWC buildpack to be specified in the buildpack chain, either in application's manifest or in the CF CLI command line.
-Note: The cached version of this extension buildpack for both Dotnet Core and Dotnet Framework contains New Relic Dotnet Agents version 8.13.798.0
+Note: The cached version of this extension buildpack for both Dotnet Core and Dotnet Framework contains New Relic Dotnet Agents version 8.27.139.0
@@ -54,23 +54,23 @@ The following table provides version and version-support information about New R
Details |
Tile version |
- 1.1.0 |
+ 1.1.5 |
Release date |
- February 20, 2019 |
+ May 14, 2020 |
Software component version |
- New Relic Dotnet Extension Buildpack v1.1.0 (General Access) |
+ New Relic Dotnet Extension Buildpack v1.1.5 (General Access) |
Compatible Ops Manager version(s) |
- v2.1.x, v2.2.x, v2.3.x, and v2.4.x |
+ v2.6.x, v2.7.x, v2.8.x, and v2.9.x |
Compatible Pivotal Application Service versions |
- v2.1.x, v2.2.x, v2.3.x, and v2.4.x |
+ v2.6.x, v2.7.x, v2.8.x, and v2.9.x |
IaaS support |
diff --git a/core-extension/VERSION b/core-extension/VERSION
index 781dcb0..e25d8d9 100644
--- a/core-extension/VERSION
+++ b/core-extension/VERSION
@@ -1 +1 @@
-1.1.3
+1.1.5
diff --git a/core-extension/manifest.yml b/core-extension/manifest.yml
index 72aac20..75f2c4c 100644
--- a/core-extension/manifest.yml
+++ b/core-extension/manifest.yml
@@ -5,9 +5,9 @@ dependency_deprecation_dates:
dependencies:
- name: newrelic
version: latest
- # version: 8.21.34.0
- uri: http://download.newrelic.com/dot_net_agent/previous_releases/8.21.34.0/newrelic-netcore20-agent_8.21.34.0_amd64.tar.gz
- sha256: 9a6bdc9d0fcc1a9cc18af2bf508b877e68b930e282327115d1b8c2ffbd633b1c
+ # version: 8.27.139.0
+ uri: http://download.newrelic.com/dot_net_agent/previous_releases/8.27.139.0/newrelic-netcore20-agent_8.27.139.0_amd64.tar.gz
+ sha256: ad116ae4112729243afd28cace336715f848c5c647a0cf6b41051f26b77e0322
cf_stacks:
- cflinuxfs2
- cflinuxfs3
diff --git a/core-extension/newrelic.config b/core-extension/newrelic.config
index 8d4bb7f..e85e603 100644
--- a/core-extension/newrelic.config
+++ b/core-extension/newrelic.config
@@ -1,5 +1,5 @@
-
+
diff --git a/core-extension/src/newrelic-dotnetcore-extension/supply/supply.go b/core-extension/src/newrelic-dotnetcore-extension/supply/supply.go
index 0695f08..dcce87a 100644
--- a/core-extension/src/newrelic-dotnetcore-extension/supply/supply.go
+++ b/core-extension/src/newrelic-dotnetcore-extension/supply/supply.go
@@ -81,7 +81,7 @@ type Supplier struct {
const bucketXMLUrl = "https://nr-downloads-main.s3.amazonaws.com/?delimiter=/&prefix=dot_net_agent/latest_release/"
// previous_releases contains all releases including latest
-const latestNrDownloadUrl = "http://download.newrelic.com/dot_net_agent/previous_releases/9.9.9.9/newrelic-netcore20-agent_9.9.9.9_amd64.tar.gz"
+const nrAgentDownloadUrl = "http://download.newrelic.com/dot_net_agent/previous_releases/9.9.9.9/newrelic-netcore20-agent_9.9.9.9_amd64.tar.gz"
const latestNrDownloadSha256Url = "http://download.newrelic.com/dot_net_agent/previous_releases/9.9.9.9/SHA256/newrelic-netcore20-agent_9.9.9.9_amd64.tar.gz.sha256"
const nrVersionPattern = "((\\d{1,3}\\.){3}\\d{1,3})" // regexp pattern to find agent version from urls
@@ -135,34 +135,75 @@ func (s *Supplier) Run() error {
}
s.Log.Debug("buildpackDir: %v", buildpackDir)
- nrDownloadURL := latestNrDownloadUrl
+ s.Log.BeginStep("Creating cache directory " + s.Stager.CacheDir())
+ if err := os.MkdirAll(s.Stager.CacheDir(), 0755); err != nil {
+ s.Log.Error("Failed to create cache directory "+s.Stager.CacheDir(), err)
+ return err
+ }
+
+ // set temp directory for downloads
+ s.Log.Debug("Creating tmp folder for downloading agent")
+ tmpDir, err := ioutil.TempDir(s.Stager.DepDir(), "downloads")
+ if err != nil {
+ return err
+ }
+ nrDownloadLocalFilename := filepath.Join(tmpDir, "agent.tar.gz")
+
+ // // nrAgentPath := filepath.Join(s.Stager.DepDir(), newrelicAgentFolder)
+ // nrAgentPath := filepath.Join(s.Stager.BuildDir(), newrelicAgentFolder)
+ // s.Log.Debug("New Relic Agent Path: " + nrAgentPath)
+
+
+ nrDownloadURL := nrAgentDownloadUrl
nrDownloadFile := ""
nrVersion := "latest"
nrSha256Sum := ""
+
+ // #################################################################
+ // determine the method to obtain the agent ########################
+ nrav, isAgenVersionEnvSet := os.LookupEnv("NEW_RELIC_AGENT_VERSION")
+ downloadURL, isAgentUrlEnvSet := os.LookupEnv("NEW_RELIC_DOWNLOAD_URL")
+ cachedBuildpack := false
+ if (isAgenVersionEnvSet && isAgentUrlEnvSet) {
+ s.Log.Warning("\nboth NEW_RELIC_AGENT_VERSION and NEW_RELIC_DOWNLOAD_URL are specified. Ignoring NEW_RELIC_AGENT_VERSION and using NEW_RELIC_DOWNLOAD_URL")
+ nrav = ""
+ }
+ //////////////////////////////////////////////////////////////////////
for _, entry := range s.Manifest.(*libbuildpack.Manifest).ManifestEntries {
if entry.Dependency.Name == "newrelic" {
nrDownloadURL = entry.URI
nrVersion = entry.Dependency.Version
nrDownloadFile = entry.File
nrSha256Sum = entry.SHA256
+ if nrDownloadFile != "" {
+ cachedBuildpack = true
+ }
+ break;
}
}
- s.Log.BeginStep("Creating cache directory " + s.Stager.CacheDir())
- if err := os.MkdirAll(s.Stager.CacheDir(), 0755); err != nil {
- s.Log.Error("Failed to create cache directory "+s.Stager.CacheDir(), err)
- return err
+ if isAgenVersionEnvSet {
+ if cachedBuildpack {
+ s.Log.Warning("\nNEW_RELIC_AGENT_VERSION env variable cannot be used with cached extension buildpack. Ignoring NEW_RELIC_AGENT_VERSION")
+ } else {
+ nrVersion = nrav
+ s.Log.Debug("NEW_RELIC_AGENT_VERSION specified by environment variable: <%s>", nrVersion)
+ // nrDownloadURL = ""
+ }
}
+ //////////////////////////////////////////////////////////////////////
//Begin: Download and Install
- //Approach 1: Recommended by Pivotal, but only works for fixed dependency version and URL specified in the manifest and checks shasum//
+ //Approach 1: Recommended by Pivotal, but only works for fixed dependency version and URL specified in the manifest and checks shasum256//
/*
// this approach is dependent on dependencies from manifest.yml file
// we use different approaches to obtain the agent
- // 1 - NEW_RELIC_DOWNLOAD_URL env var
- // 2 - cached dependencies (use manifest dependency entries for caching)
- // 3 - version "latest" from manifest dependencies (figures out the latest and composes the URL)
+ // 1 - using NEW_RELIC_DOWNLOAD_URL env var
+ // 2 - cached dependencies (use manifest dependency entries to copy the file from cache)
+ // 3 - if dependency is from buildoack's manifest, use Pivotal's standard InstallDependency()
+ // version "latest" from manifest dependencies (figures out the latest and composes the URL)
+
newrelicDependency := libbuildpack.Dependency{Name: "newrelic", Version: "7.1.229.0"}
if err := s.Manifest.InstallDependency(newrelicDependency, s.Stager.DepDir()); err != nil {
s.Log.Error("Error Installing NewRelic Agent", err)
@@ -175,25 +216,19 @@ func (s *Supplier) Run() error {
s.Log.Debug("Installing NewRelic Agent -- Install (dep) directory: " + s.Stager.DepDir())
- // set temp directory for downloads
- s.Log.Debug("Creating tmp folder for downloading agent")
- tmpDir, err := ioutil.TempDir(s.Stager.DepDir(), "downloads")
- if err != nil {
- return err
- }
- nrDownloadLocalFilename := filepath.Join(tmpDir, "agent.tar.gz")
-
// get agent version
- needToDownloadNrAgentFile := false
- if downloadURL, exists := os.LookupEnv("NEW_RELIC_DOWNLOAD_URL"); exists == true {
+ needToDownloadNrAgentFile := true
+ if isAgentUrlEnvSet {
+
+ s.Log.Info("Using NEW_RELIC_DOWNLOAD_URL environment variable...")
nrDownloadURL = strings.TrimSpace(downloadURL)
if sha256, exists := os.LookupEnv("NEW_RELIC_DOWNLOAD_SHA256"); exists == true {
nrSha256Sum = sha256 // set by env var
} else {
nrSha256Sum = "" // ignore sha256 sum if not set by env var
}
- needToDownloadNrAgentFile = true
- } else if nrDownloadFile != "" { // this file is cached by the buildpack
+
+ } else if cachedBuildpack { // this file is cached by the buildpack
s.Log.Info("Using cached dependencies...")
source := nrDownloadFile
if !filepath.IsAbs(source) {
@@ -203,26 +238,37 @@ func (s *Supplier) Run() error {
if err := libbuildpack.CopyFile(source, nrDownloadLocalFilename); err != nil {
return err
}
+
+ needToDownloadNrAgentFile = false
+
} else {
- if (nrDownloadURL == "" || in_array(strings.ToLower(nrVersion), []string{"", "0.0.0.0", "latest", "current"})) {
- s.Log.Info("Obtaining latest agent version ")
- nrVersion, err = getLatestAgentVersion(s)
- if err != nil {
- s.Log.Error("Unable to obtain latest agent version from the metadata bucket", err)
- return err
+
+ if (nrDownloadURL == "" || isAgenVersionEnvSet || in_array(strings.ToLower(nrVersion), []string{"", "0.0.0.0", "latest", "current"})) {
+ nrAgentVersion := nrVersion
+ if isAgenVersionEnvSet {
+ s.Log.Info("Obtaining requested agent version ")
+ } else {
+ s.Log.Info("Obtaining latest agent version ")
+ nrAgentVersion, err = getLatestAgentVersion(s)
+ if err != nil {
+ s.Log.Error("Unable to obtain latest agent version from the metadata bucket", err)
+ return err
+ }
}
- s.Log.Debug("Latest agent version is " + nrVersion)
+
+ s.Log.Debug("Using agent version: " + nrAgentVersion)
// substitute agent version in the url
- updatedUrl, err := substituteUrlVersion(s, latestNrDownloadUrl, nrVersion)
+ updatedUrl, err := substituteUrlVersion(s, nrAgentDownloadUrl, nrAgentVersion)
if err != nil {
s.Log.Error("filed to substitute agent version in url")
return err
}
nrDownloadURL = updatedUrl
- // read sha256 sum of the agent from NR download site
- latestNrAgentSha256Sum, err := getLatestNrAgentSha256Sum(s, tmpDir, nrVersion)
+ // if agent is being downloaded read sha256 sum of the agent from NR download site
+
+ latestNrAgentSha256Sum, err := getLatestNrAgentSha256Sum(s, tmpDir, nrAgentVersion)
if err != nil {
s.Log.Error("Can't get SHA256 checksum for latest New Relic Agent download", err)
return err
@@ -230,11 +276,12 @@ func (s *Supplier) Run() error {
nrSha256Sum = latestNrAgentSha256Sum
}
- needToDownloadNrAgentFile = true
}
+ // Start: downloading AgentFile ##############################################################################
if needToDownloadNrAgentFile {
s.Log.BeginStep("Downloading New Relic agent...")
+ s.Log.Debug("downloading the agent using downloadDependency() ...")
if err := downloadDependency(s, nrDownloadURL, nrDownloadLocalFilename); err != nil {
return err
}
@@ -243,18 +290,24 @@ func (s *Supplier) Run() error {
// compare sha256 sum of the downloaded file against expected sum
if nrSha256Sum != "" {
if err := checkSha256(nrDownloadLocalFilename, nrSha256Sum); err != nil {
- s.Log.Error("SHA256 checksum failed", err)
+ s.Log.Error("New Relic agent SHA256 checksum failed: ", err)
return err
}
}
+ // End: downloading AgentFile ################################################################################
+
+ // Start: extracting AgentFile ###############################################################################
// when dotnet core agent is extracted, it creates folder called "newrelic-netcore20-agent"
s.Log.BeginStep("Extracting NewRelic .Net Core Agent to %s", nrDownloadLocalFilename)
if err := libbuildpack.ExtractTarGz(nrDownloadLocalFilename, s.Stager.DepDir()); err != nil {
s.Log.Error("Error Extracting NewRelic .Net Core Agent", err)
return err
}
- // End: Download and Install
+ // End: extracting AgentFile #################################################################################
+
+
+
// decide which newrelic.config file to use (appdir, buildpackdir, agentdir)
if err := getNewRelicConfigFile(s, newrelicAgentFolder, buildpackDir); err != nil {
@@ -670,6 +723,26 @@ func parseUserProvidedServices(s *Supplier, vcapServices map[string]interface{},
return newrelicAppName, newrelicLicenseKey, newrelicDistributedTracing
}
+func writeToFile(source io.Reader, destFile string, mode os.FileMode) error {
+ err := os.MkdirAll(filepath.Dir(destFile), 0755)
+ if err != nil {
+ return err
+ }
+
+ fh, err := os.OpenFile(destFile, os.O_RDWR|os.O_CREATE|os.O_TRUNC, mode)
+ if err != nil {
+ return err
+ }
+ defer fh.Close()
+
+ _, err = io.Copy(fh, source)
+ if err != nil {
+ return err
+ }
+
+ return nil
+}
+
func getLatestAgentVersion(s *Supplier) (string, error) {
latestAgentVersion := ""
resp, err := http.Get(bucketXMLUrl)
diff --git a/hwc-extension/VERSION b/hwc-extension/VERSION
index 781dcb0..e25d8d9 100644
--- a/hwc-extension/VERSION
+++ b/hwc-extension/VERSION
@@ -1 +1 @@
-1.1.3
+1.1.5
diff --git a/hwc-extension/manifest.yml b/hwc-extension/manifest.yml
index eada464..5297c3c 100644
--- a/hwc-extension/manifest.yml
+++ b/hwc-extension/manifest.yml
@@ -5,9 +5,9 @@ dependency_deprecation_dates:
dependencies:
- name: newrelic
version: latest
- # version: 8.21.34.0
- uri: http://download.newrelic.com/dot_net_agent/previous_releases/8.21.34.0/newrelic-agent-win-x64-8.21.34.0.zip
- sha256: b774dbe481599541288283f55ae3132ae598a9c6ef4a39a1922eb308ff13f6bf
+ # version: 8.27.139.0
+ uri: http://download.newrelic.com/dot_net_agent/previous_releases/8.27.139.0/newrelic-agent-win-x64-8.27.139.0.zip
+ sha256: a2a744c2a220488f9751b7c90c9a1fcf249e3baba72c5d5d9d8d9245a8647fd9
cf_stacks:
- windows2012R2
- windows2016
diff --git a/hwc-extension/newrelic.config b/hwc-extension/newrelic.config
index f922703..4d4f600 100644
--- a/hwc-extension/newrelic.config
+++ b/hwc-extension/newrelic.config
@@ -1,5 +1,5 @@
-
+
diff --git a/hwc-extension/src/newrelic-hwc-extension/supply/supply.go b/hwc-extension/src/newrelic-hwc-extension/supply/supply.go
index f7b8ef2..c61fbe5 100644
--- a/hwc-extension/src/newrelic-hwc-extension/supply/supply.go
+++ b/hwc-extension/src/newrelic-hwc-extension/supply/supply.go
@@ -82,7 +82,7 @@ type Supplier struct {
const bucketXMLUrl = "https://nr-downloads-main.s3.amazonaws.com/?delimiter=/&prefix=dot_net_agent/latest_release/"
// previous_releases contains all releases including latest
-const latestNrDownloadUrl = "http://download.newrelic.com/dot_net_agent/previous_releases/9.9.9.9/newrelic-agent-win-x64-9.9.9.9.zip"
+const nrAgentDownloadUrl = "http://download.newrelic.com/dot_net_agent/previous_releases/9.9.9.9/newrelic-agent-win-x64-9.9.9.9.zip"
const latestNrDownloadSha256Url = "http://download.newrelic.com/dot_net_agent/previous_releases/9.9.9.9/SHA256/newrelic-agent-win-x64-9.9.9.9.zip.sha256"
const nrVersionPattern = "((\\d{1,3}\\.){3}\\d{1,3})" // regexp pattern to find agent version from urls
@@ -136,41 +136,12 @@ func (s *Supplier) Run() error {
}
s.Log.Debug("buildpackDir: %v", buildpackDir)
- nrDownloadURL := latestNrDownloadUrl
- nrDownloadFile := ""
- nrVersion := "latest"
- nrSha256Sum := ""
- v := os.Getenv("NEW_RELIC_AGENT_VERSION")
- s.Log.Debug("NEW_RELIC_AGENT_VERSION specified by environment variable: <%s>", v)
- if v == "" {
- for _, entry := range s.Manifest.(*libbuildpack.Manifest).ManifestEntries {
- if entry.Dependency.Name == "newrelic" {
- nrDownloadURL = entry.URI
- nrVersion = entry.Dependency.Version
- nrDownloadFile = entry.File
- nrSha256Sum = entry.SHA256
- s.Log.Debug("newrelic agent: \n\tdownload Url: %s\n\tversion: %s\n\tcached file: %s\n\tchecksum: %s", nrDownloadURL, nrVersion, nrDownloadFile, nrSha256Sum)
- break;
- }
- }
- } else { // agent version specified by environment variable
- nrVersion = v
- // nrDownloadURL = ""
- }
-
s.Log.BeginStep("Creating cache directory " + s.Stager.CacheDir())
if err := os.MkdirAll(s.Stager.CacheDir(), 0755); err != nil {
s.Log.Error("Failed to create cache directory "+s.Stager.CacheDir(), err)
return err
}
-
- //Begin: Download and Install
- // 1: download the agent using the provided NEW_RELIC_DOWNLOAD_URL
- // 2: use cached dependency -- no download required - just copy the file from cache
- // 3: if dependency is from buildoack's manifest, use Pivotal's standar InstallDependency()
-
-
// set temp directory for downloads
s.Log.Debug("Creating tmp folder for downloading agent")
tmpDir, err := ioutil.TempDir(s.Stager.DepDir(), "downloads")
@@ -183,10 +154,62 @@ func (s *Supplier) Run() error {
nrAgentPath := filepath.Join(s.Stager.BuildDir(), newrelicAgentFolder)
s.Log.Debug("New Relic Agent Path: " + nrAgentPath)
+
+ nrDownloadURL := nrAgentDownloadUrl
+ nrDownloadFile := ""
+ nrVersion := "latest"
+ nrSha256Sum := ""
+
+ // #################################################################
+ // determine the method to obtain the agent ########################
+ nrav, isAgenVersionEnvSet := os.LookupEnv("NEW_RELIC_AGENT_VERSION")
+ downloadURL, isAgentUrlEnvSet := os.LookupEnv("NEW_RELIC_DOWNLOAD_URL")
+ cachedBuildpack := false
+ if (isAgenVersionEnvSet && isAgentUrlEnvSet) {
+ s.Log.Warning("\nboth NEW_RELIC_AGENT_VERSION and NEW_RELIC_DOWNLOAD_URL are specified. Ignoring NEW_RELIC_AGENT_VERSION and using NEW_RELIC_DOWNLOAD_URL")
+ nrav = ""
+ }
+ //////////////////////////////////////////////////////////////////////
+ for _, entry := range s.Manifest.(*libbuildpack.Manifest).ManifestEntries {
+ if entry.Dependency.Name == "newrelic" {
+ nrDownloadURL = entry.URI
+ nrVersion = entry.Dependency.Version
+ nrDownloadFile = entry.File
+ nrSha256Sum = entry.SHA256
+ if nrDownloadFile != "" {
+ cachedBuildpack = true
+ }
+ break;
+ break;
+ }
+ }
+
+ if isAgenVersionEnvSet {
+ if cachedBuildpack {
+ s.Log.Warning("\nNEW_RELIC_AGENT_VERSION env variable cannot be used with cached extension buildpack. Ignoring NEW_RELIC_AGENT_VERSION")
+ } else {
+ nrVersion = nrav
+ s.Log.Debug("NEW_RELIC_AGENT_VERSION specified by environment variable: <%s>", nrVersion)
+ // nrDownloadURL = ""
+ }
+ }
+ //////////////////////////////////////////////////////////////////////
+
+
+ //Begin: Download and Install
+ /*
+ // this approach is dependent on dependencies from manifest.yml file
+ // we use different approaches to obtain the agent
+ // 1 - using NEW_RELIC_DOWNLOAD_URL env var
+ // 2 - cached dependencies (use manifest dependency entries to copy the file from cache)
+ // 3 - if dependency is from buildoack's manifest, use Pivotal's standard InstallDependency()
+ // version "latest" from manifest dependencies (figures out the latest and composes the URL)
+ */
+
+
// get agent version
- downloadAgentFile := true
- extractAgentFile := true
- if downloadURL, exists := os.LookupEnv("NEW_RELIC_DOWNLOAD_URL"); exists == true {
+ needToDownloadNrAgentFile := true
+ if isAgentUrlEnvSet {
s.Log.Info("Using NEW_RELIC_DOWNLOAD_URL environment variable...")
nrDownloadURL = strings.TrimSpace(downloadURL)
@@ -195,10 +218,8 @@ func (s *Supplier) Run() error {
} else {
nrSha256Sum = "" // ignore sha256 sum if not set by env var
}
- downloadAgentFile = true
- extractAgentFile = true
- } else if nrDownloadFile != "" { // this file is cached by the buildpack
+ } else if cachedBuildpack { // this file is cached by the buildpack
s.Log.Info("Using cached dependencies...")
source := nrDownloadFile
@@ -210,78 +231,81 @@ func (s *Supplier) Run() error {
return err
}
- extractAgentFile = true
+ needToDownloadNrAgentFile = false
} else {
- if (nrDownloadURL == "" || in_array(strings.ToLower(nrVersion), []string{"", "0.0.0.0", "latest", "current"})) {
- s.Log.Info("Obtaining latest agent version ")
- latestNrVersion := nrVersion
- latestNrVersion, err = getLatestAgentVersion(s)
- if err != nil {
- s.Log.Error("Unable to obtain latest agent version from the metadata bucket", err)
- return err
+ if (nrDownloadURL == "" || isAgenVersionEnvSet || in_array(strings.ToLower(nrVersion), []string{"", "0.0.0.0", "latest", "current"})) {
+ nrAgentVersion := nrVersion
+ if isAgenVersionEnvSet {
+ s.Log.Info("Obtaining requested agent version ")
+ } else {
+ s.Log.Info("Obtaining latest agent version ")
+ nrAgentVersion, err = getLatestAgentVersion(s)
+ if err != nil {
+ s.Log.Error("Unable to obtain latest agent version from the metadata bucket", err)
+ return err
+ }
}
- s.Log.Debug("Latest agent version is " + latestNrVersion)
+
+ s.Log.Debug("Using agent version: " + nrAgentVersion)
// substitute agent version in the url
- updatedUrl, err := substituteUrlVersion(s, latestNrDownloadUrl, latestNrVersion)
+ updatedUrl, err := substituteUrlVersion(s, nrAgentDownloadUrl, nrAgentVersion)
if err != nil {
s.Log.Error("filed to substitute agent version in url")
return err
}
nrDownloadURL = updatedUrl
- // ### THIS ROUTINE IS NOT NEEDED if using s.Installer.InstallDependency()
- // // read sha256 sum of the agent from NR download site
- //
- // latestNrAgentSha256Sum, err := getLatestNrAgentSha256Sum(s, tmpDir, latestNrVersion)
- // if err != nil {
- // s.Log.Error("Can't get SHA256 checksum for latest New Relic Agent download", err)
- // return err
- // }
- // nrSha256Sum = latestNrAgentSha256Sum
+ // if agent is being downloaded read sha256 sum of the agent from NR download site
+
+ latestNrAgentSha256Sum, err := getLatestNrAgentSha256Sum(s, tmpDir, nrAgentVersion)
+ if err != nil {
+ s.Log.Error("Can't get SHA256 checksum for latest New Relic Agent download", err)
+ return err
+ }
+ nrSha256Sum = latestNrAgentSha256Sum
}
- downloadAgentFile = true
}
- if downloadAgentFile { // either dependency specified in manifest.yml or NEW_RELIC_DOWNLOAD_URL specified
+ // Start: downloading AgentFile ##############################################################################
+ if needToDownloadNrAgentFile { // either dependency specified in manifest.yml or NEW_RELIC_DOWNLOAD_URL specified
s.Log.BeginStep("Downloading New Relic agent...")
- if extractAgentFile { // NEW_RELIC_DOWNLOAD_URL specified
- s.Log.Debug("downloading the agent using downloadDependency() ...")
- if err := downloadDependency(s, nrDownloadURL, nrDownloadLocalFilename); err != nil {
- return err
- }
-
- // compare sha256 sum of the downloaded file against expected sum
- if nrSha256Sum != "" {
- if err := checkSha256(nrDownloadLocalFilename, nrSha256Sum); err != nil {
- s.Log.Error("SHA256 checksum failed", err)
- return err
- }
- }
- } else { // dependency from manifest
- newrelicDependency := libbuildpack.Dependency{Name: "newrelic", Version: nrVersion}
- s.Log.Debug("downloading the agent using s.Installer.InstallDependency() ...")
- if err := s.Installer.InstallDependency(newrelicDependency, nrAgentPath); err != nil {
- s.Log.Error("Error Installing NewRelic Agent", err)
- return err
- }
-
+ s.Log.Debug("downloading the agent using downloadDependency() ...")
+ if err := downloadDependency(s, nrDownloadURL, nrDownloadLocalFilename); err != nil {
+ return err
}
- } // End: downloadAgentFile
-
- if extractAgentFile { // only if NEW_RELIC_DOWNLOAD_URL was used or cached agent was copied
- // when dotnet framework agent is extracted, it doesn't create it's folder.
- // need to set agent dir to s.Stager.BuildDir()/newrelic or s.Stager.DepDir()/newrelic
- s.Log.BeginStep("Extracting NewRelic .Net Framework Agent to %s", nrAgentPath) // nrDownloadLocalFilename)
- if err := libbuildpack.ExtractZip(nrDownloadLocalFilename, nrAgentPath); err != nil {
- s.Log.Error("Error Extracting NewRelic .Net Framework Agent", err)
+ }
+
+ // compare sha256 sum of the downloaded file against expected sum
+ if nrSha256Sum != "" {
+ if err := checkSha256(nrDownloadLocalFilename, nrSha256Sum); err != nil {
+ s.Log.Error("New Relic agent SHA256 checksum failed: ", err)
return err
}
}
- // End: extractAgentFile
+
+ // // dependency from manifest -- use s.Installer.InstallDependency()
+ // newrelicDependency := libbuildpack.Dependency{Name: "newrelic", Version: nrVersion}
+ // s.Log.Debug("downloading the agent using s.Installer.InstallDependency() ...")
+ // if err := s.Installer.InstallDependency(newrelicDependency, nrAgentPath); err != nil {
+ // s.Log.Error("Error Installing NewRelic Agent", err)
+ // return err
+ // }
+ // End: downloading AgentFile ################################################################################
+
+
+ // Start: extracting AgentFile ###############################################################################
+ // when dotnet framework agent is extracted, it doesn't create it's folder.
+ // need to set agent dir to s.Stager.BuildDir()/newrelic or s.Stager.DepDir()/newrelic
+ s.Log.BeginStep("Extracting NewRelic .Net Framework Agent to %s", nrAgentPath) // nrDownloadLocalFilename)
+ if err := libbuildpack.ExtractZip(nrDownloadLocalFilename, nrAgentPath); err != nil {
+ s.Log.Error("Error Extracting NewRelic .Net Framework Agent", err)
+ return err
+ }
+ // End: extracting AgentFile #################################################################################
@@ -291,6 +315,11 @@ func (s *Supplier) Run() error {
return err
}
+ // if there is newrelic_instrumentation.xml file in app folder, copy it to agent's "extensions" directory
+ if err := getNewRelicXmlInstrumentationFile(s, nrAgentPath); err != nil {
+ return err
+ }
+
// get Procfile - first check in app folder, if doesn't exisit check in buildpack dir
// only use Procfile if building "run.cmd"
// once hwc buildpack fully supports profile.d folder, this can be removed
@@ -386,26 +415,26 @@ func substituteUrlVersion(s *Supplier, url string, nrVersion string) (string, er
return strings.Replace(url, uriVersion, nrVersion, -1), nil
}
-// func getLatestNrAgentSha256Sum(s *Supplier, tmpDownloadDir string, latestNrVersion string) (string, error) {
-// s.Log.Info("Obtaining Agent sha256 Sum from New Relic")
-// shaUrl, err := substituteUrlVersion(s, latestNrDownloadSha256Url, latestNrVersion)
-// if err != nil {
-// s.Log.Error("filed to substitute agent version in sha256 url")
-// return "", err
-// }
+func getLatestNrAgentSha256Sum(s *Supplier, tmpDownloadDir string, latestNrVersion string) (string, error) {
+ s.Log.Info("Obtaining Agent sha256 Sum from New Relic")
+ shaUrl, err := substituteUrlVersion(s, latestNrDownloadSha256Url, latestNrVersion)
+ if err != nil {
+ s.Log.Error("filed to substitute agent version in sha256 url")
+ return "", err
+ }
-// sha256File := filepath.Join(tmpDownloadDir, "nragent.sha256")
-// if err := downloadDependency(s, shaUrl, sha256File); err != nil {
-// return "", err
-// }
+ sha256File := filepath.Join(tmpDownloadDir, "nragent.sha256")
+ if err := downloadDependency(s, shaUrl, sha256File); err != nil {
+ return "", err
+ }
-// sha256Sum, err := ioutil.ReadFile(sha256File)
-// if err != nil {
-// return "", err
-// }
+ sha256Sum, err := ioutil.ReadFile(sha256File)
+ if err != nil {
+ return "", err
+ }
-// return strings.Split(string(sha256Sum), " ")[0], nil
-// }
+ return strings.Split(string(sha256Sum), " ")[0], nil
+}
func downloadDependency(s *Supplier, url string, filepath string) (err error) {
s.Log.Debug("Downloading from [%s]", url)
@@ -497,6 +526,29 @@ func getNewRelicConfigFile(s *Supplier, nrAgentPath string, buildpackDir string)
return nil
}
+func getNewRelicXmlInstrumentationFile(s *Supplier, nrAgentPath string) error {
+ newrelicXmlInstrumentation := filepath.Join(s.Stager.BuildDir(), "newrelic_instrumentation.xml")
+ newrelicConfigDest := filepath.Join(s.Stager.DepDir(), nrAgentPath, "extensions", "newrelic_instrumentation.xml")
+
+ newrelicXmlInstrumentationExists, err := libbuildpack.FileExists(newrelicXmlInstrumentation)
+ if err != nil {
+ s.Log.Debug("No custom instrumentation file found in app folder", err)
+ newrelicXmlInstrumentationExists = false
+ }
+
+
+ if newrelicXmlInstrumentationExists {
+ // newrelic XML instrumentation file found in app folder
+ s.Log.Info("Using custom instrumentation file \"newrelic_instrumentation.xml\" provided in the app folder")
+ s.Log.Debug("Copying %s to %s", newrelicXmlInstrumentation, newrelicConfigDest)
+ if err := libbuildpack.CopyFile(newrelicXmlInstrumentation, newrelicConfigDest); err != nil {
+ s.Log.Error("Error Copying newrelic_instrumentation.xml provided within the app folder", err)
+ return err
+ }
+ }
+ return nil
+}
+
func getProcfile(s *Supplier, buildpackDir string) error {
procFileBundledWithApp := filepath.Join(s.Stager.BuildDir(), "Procfile")
procFileBundledWithAppExists, err := libbuildpack.FileExists(procFileBundledWithApp)