Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added Dynatrace hook #149

Merged
merged 2 commits into from
Feb 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module github.com/cloudfoundry/python-buildpack

require (
github.com/Dynatrace/libbuildpack-dynatrace v1.2.1
github.com/blang/semver v3.5.1+incompatible
github.com/cloudfoundry/libbuildpack v0.0.0-20190805205250-e22ed19132ff
github.com/golang/mock v1.3.1
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Dynatrace/libbuildpack-dynatrace v1.2.1 h1:XJ+mmQSAOoaeVip6kAIV/tWd2gQQWUeowU/bEGFil2c=
github.com/Dynatrace/libbuildpack-dynatrace v1.2.1/go.mod h1:TojYXsxk1r+TaVOTUOWKyX2hAOzbvb+BsQGxUZ8Cb2s=
github.com/Masterminds/semver v1.4.2 h1:WBLTQ37jOCzSLtXNdoo8bNM8876KhNqOKvrlGITgsTc=
github.com/Masterminds/semver v1.4.2/go.mod h1:MB6lktGJrhw8PrUyiEoblNEGEQ+RzHPF078ddwwvV3Y=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
Expand Down
10 changes: 10 additions & 0 deletions src/python/hooks/dynatrace.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package hooks

import (
"github.com/Dynatrace/libbuildpack-dynatrace"
"github.com/cloudfoundry/libbuildpack"
)

func init() {
libbuildpack.AddHook(dynatrace.NewHook("sdk", "process"))
}
227 changes: 227 additions & 0 deletions src/python/integration/deploy_python_app_with_dynatrace_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,227 @@
package integration_test

import (
"os/exec"
"path/filepath"

"github.com/cloudfoundry/libbuildpack/cutlass"

. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)

var _ = Describe("CF Python Buildpack", func() {
var app *cutlass.App
var createdServices []string

BeforeEach(func() {
//app = cutlass.New(Fixtures("flask"))
app = cutlass.New(filepath.Join(bpDir, "fixtures", "flask"))
app.SetEnv("BP_DEBUG", "true")
PushAppAndConfirm(app)

createdServices = make([]string, 0)
})

AfterEach(func() {
if app != nil {
app.Destroy()
}
app = nil

for _, service := range createdServices {
command := exec.Command("cf", "delete-service", "-f", service)
_, err := command.Output()
Expect(err).To(BeNil())
}
})

Context("deploying a Python app with Dynatrace agent with single credentials service", func() {
It("checks if Dynatrace injection was successful", func() {
serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
command := exec.Command("cf", "cups", serviceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas/manifest\",\"environmentid\":\"envid\"}'")
_, err := command.CombinedOutput()
Expect(err).To(BeNil())
createdServices = append(createdServices, serviceName)

command = exec.Command("cf", "bind-service", app.Name, serviceName)
_, err = command.CombinedOutput()
Expect(err).To(BeNil())
command = exec.Command("cf", "restage", app.Name)
_, err = command.Output()
Expect(err).To(BeNil())

Expect(app.ConfirmBuildpack(buildpackVersion)).To(Succeed())
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace PaaS agent."))
Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace PaaS agent installer"))
Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh"))
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent installed."))
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent injection is set up."))
})
})

Context("deploying a Python app with Dynatrace agent with two credentials services", func() {
It("checks if detection of second service with credentials works", func() {
CredentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
command := exec.Command("cf", "cups", CredentialsServiceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas/manifest\",\"environmentid\":\"envid\"}'")
_, err := command.CombinedOutput()
Expect(err).To(BeNil())
createdServices = append(createdServices, CredentialsServiceName)

duplicateCredentialsServiceName := "dynatrace-dupe-" + cutlass.RandStringRunes(20) + "-service"
command = exec.Command("cf", "cups", duplicateCredentialsServiceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas/manifest\",\"environmentid\":\"envid\"}'")
_, err = command.CombinedOutput()
Expect(err).To(BeNil())
createdServices = append(createdServices, duplicateCredentialsServiceName)

command = exec.Command("cf", "bind-service", app.Name, CredentialsServiceName)
_, err = command.CombinedOutput()
Expect(err).To(BeNil())
command = exec.Command("cf", "bind-service", app.Name, duplicateCredentialsServiceName)
_, err = command.CombinedOutput()
Expect(err).To(BeNil())

command = exec.Command("cf", "restage", app.Name)
_, err = command.Output()
Expect(err).To(BeNil())

Expect(app.Stdout.String()).To(ContainSubstring("More than one matching service found!"))
})
})

Context("deploying a Python app with Dynatrace agent with failing agent download and ignoring errors", func() {
It("checks if skipping download errors works", func() {
CredentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
command := exec.Command("cf", "cups", CredentialsServiceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paasFAILING/manifest\",\"environmentid\":\"envid\",\"skiperrors\":\"true\"}'")
_, err := command.CombinedOutput()
Expect(err).To(BeNil())
createdServices = append(createdServices, CredentialsServiceName)

command = exec.Command("cf", "bind-service", app.Name, CredentialsServiceName)
_, err = command.CombinedOutput()
Expect(err).To(BeNil())

command = exec.Command("cf", "restage", app.Name)
_, err = command.Output()
Expect(err).To(BeNil())

Expect(app.Stdout.String()).To(ContainSubstring("Download returned with status 404"))
Expect(app.Stdout.String()).To(ContainSubstring("Error during installer download, skipping installation"))
})
})

Context("deploying a Python app with Dynatrace agent with two dynatrace services", func() {
It("check if service detection isn't disturbed by a service with tags", func() {
CredentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
command := exec.Command("cf", "cups", CredentialsServiceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas/manifest\",\"environmentid\":\"envid\"}'")
_, err := command.CombinedOutput()
Expect(err).To(BeNil())
createdServices = append(createdServices, CredentialsServiceName)

tagsServiceName := "dynatrace-tags-" + cutlass.RandStringRunes(20) + "-service"
command = exec.Command("cf", "cups", tagsServiceName, "-p", "'{\"tag:dttest\":\"dynatrace_test\"}'")
_, err = command.CombinedOutput()
Expect(err).To(BeNil())
createdServices = append(createdServices, tagsServiceName)

command = exec.Command("cf", "bind-service", app.Name, CredentialsServiceName)
_, err = command.CombinedOutput()
Expect(err).To(BeNil())
command = exec.Command("cf", "bind-service", app.Name, tagsServiceName)
_, err = command.CombinedOutput()
Expect(err).To(BeNil())

command = exec.Command("cf", "restage", app.Name)
_, err = command.Output()
Expect(err).To(BeNil())

Expect(app.ConfirmBuildpack(buildpackVersion)).To(Succeed())
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace PaaS agent."))
Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace PaaS agent installer"))
Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh"))
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent installed."))
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent injection is set up."))
})
})

Context("deploying a Python app with Dynatrace agent with single credentials service and without manifest.json", func() {
It("checks if Dynatrace injection was successful", func() {
serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
command := exec.Command("cf", "cups", serviceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas\",\"environmentid\":\"envid\"}'")
_, err := command.CombinedOutput()
Expect(err).To(BeNil())
createdServices = append(createdServices, serviceName)

command = exec.Command("cf", "bind-service", app.Name, serviceName)
_, err = command.CombinedOutput()
Expect(err).To(BeNil())
command = exec.Command("cf", "restage", app.Name)
_, err = command.Output()
Expect(err).To(BeNil())

Expect(app.ConfirmBuildpack(buildpackVersion)).To(Succeed())
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace PaaS agent."))
Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace PaaS agent installer"))
Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh"))
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent installed."))
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent injection is set up."))
})
})

Context("deploying a Python app with Dynatrace agent with failing agent download and checking retry", func() {
It("checks if retrying downloads works", func() {
CredentialsServiceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
command := exec.Command("cf", "cups", CredentialsServiceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paasFAILING/manifest\",\"environmentid\":\"envid\"}'")
_, err := command.CombinedOutput()
Expect(err).To(BeNil())
createdServices = append(createdServices, CredentialsServiceName)

command = exec.Command("cf", "bind-service", app.Name, CredentialsServiceName)
_, err = command.CombinedOutput()
Expect(err).To(BeNil())

command = exec.Command("cf", "restage", app.Name)
_, err = command.CombinedOutput()

Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 4s"))
Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 5s"))
Eventually(app.Stdout.String).Should(ContainSubstring("Error during installer download, retrying in 7s"))
Eventually(app.Stdout.String).Should(ContainSubstring("Download returned with status 404"))

Eventually(app.Stdout.String).Should(ContainSubstring("Failed to compile droplet"))
})
})

Context("deploying a Python app with Dynatrace agent with single credentials service and a redis service", func() {
It("checks if Dynatrace injection was successful", func() {
serviceName := "dynatrace-" + cutlass.RandStringRunes(20) + "-service"
command := exec.Command("cf", "cups", serviceName, "-p", "'{\"apitoken\":\"secretpaastoken\",\"apiurl\":\"https://s3.amazonaws.com/dt-paas/manifest\",\"environmentid\":\"envid\"}'")
_, err := command.CombinedOutput()
Expect(err).To(BeNil())
createdServices = append(createdServices, serviceName)
command = exec.Command("cf", "bind-service", app.Name, serviceName)
_, err = command.CombinedOutput()
Expect(err).To(BeNil())

redisServiceName := "redis-" + cutlass.RandStringRunes(20) + "-service"
command = exec.Command("cf", "cups", redisServiceName, "-p", "'{\"name\":\"redis\", \"credentials\":{\"db_type\":\"redis\", \"instance_administration_api\":{\"deployment_id\":\"12345asdf\", \"instance_id\":\"12345asdf\", \"root\":\"https://doesnotexi.st\"}}}'")
_, err = command.CombinedOutput()
Expect(err).To(BeNil())
createdServices = append(createdServices, redisServiceName)
command = exec.Command("cf", "bind-service", app.Name, redisServiceName)
_, err = command.CombinedOutput()
Expect(err).To(BeNil())

command = exec.Command("cf", "restage", app.Name)
_, err = command.Output()
Expect(err).To(BeNil())

Expect(app.ConfirmBuildpack(buildpackVersion)).To(Succeed())
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace service credentials found. Setting up Dynatrace PaaS agent."))
Expect(app.Stdout.String()).To(ContainSubstring("Starting Dynatrace PaaS agent installer"))
Expect(app.Stdout.String()).To(ContainSubstring("Copy dynatrace-env.sh"))
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent installed."))
Expect(app.Stdout.String()).To(ContainSubstring("Dynatrace PaaS agent injection is set up."))
})
})
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading