Skip to content

Commit

Permalink
update 1.1.5
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramk committed May 15, 2020
1 parent a538298 commit 54e0907
Show file tree
Hide file tree
Showing 9 changed files with 280 additions and 155 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

</p>
<p class="note"><strong>Note:</strong> The cached version of this extension buildpack for both Dotnet Core and Dotnet Framework contains New Relic Dotnet Agents version <code>8.13.798.0</code></p>
<p class="note"><strong>Note:</strong> The cached version of this extension buildpack for both Dotnet Core and Dotnet Framework contains New Relic Dotnet Agents version <code>8.27.139.0</code></p>


<br/>
Expand All @@ -54,23 +54,23 @@ The following table provides version and version-support information about New R
<th>Details</th>
<tr>
<td>Tile version</td>
<td>1.1.0</td>
<td>1.1.5</td>
</tr>
<tr>
<td>Release date</td>
<td>February 20, 2019</td>
<td>May 14, 2020</td>
</tr>
<tr>
<td>Software component version</td>
<td>New Relic Dotnet Extension Buildpack v1.1.0 (General Access)</td>
<td>New Relic Dotnet Extension Buildpack v1.1.5 (General Access)</td>
</tr>
<tr>
<td>Compatible Ops Manager version(s)</td>
<td>v2.1.x, v2.2.x, v2.3.x, and v2.4.x</td>
<td>v2.6.x, v2.7.x, v2.8.x, and v2.9.x</td>
</tr>
<tr>
<td>Compatible Pivotal Application Service versions</td>
<td>v2.1.x, v2.2.x, v2.3.x, and v2.4.x</td>
<td>v2.6.x, v2.7.x, v2.8.x, and v2.9.x</td>
</tr>
<tr>
<td>IaaS support</td>
Expand Down
2 changes: 1 addition & 1 deletion core-extension/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.3
1.1.5
6 changes: 3 additions & 3 deletions core-extension/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion core-extension/newrelic.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<!-- Copyright (c) 2008-2017 New Relic, Inc. All rights reserved. -->
<!-- Copyright (c) 2008-2020 New Relic, Inc. All rights reserved. -->
<!-- For more information see: https://newrelic.com/docs/dotnet/dotnet-agent-configuration -->
<configuration xmlns="urn:newrelic-config" agentEnabled="true">
<service licenseKey="REPLACE_WITH_LICENSE_KEY" />
Expand Down
143 changes: 108 additions & 35 deletions core-extension/src/newrelic-dotnetcore-extension/supply/supply.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand All @@ -203,38 +238,50 @@ 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
}
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
}
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion hwc-extension/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.1.3
1.1.5
6 changes: 3 additions & 3 deletions hwc-extension/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion hwc-extension/newrelic.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0"?>
<!-- Copyright (c) 2008-2017 New Relic, Inc. All rights reserved. -->
<!-- Copyright (c) 2008-2020 New Relic, Inc. All rights reserved. -->
<!-- For more information see: https://newrelic.com/docs/dotnet/dotnet-agent-configuration -->
<configuration xmlns="urn:newrelic-config" agentEnabled="true">
<service licenseKey="REPLACE_WITH_LICENSE_KEY" />
Expand Down
Loading

0 comments on commit 54e0907

Please sign in to comment.