-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #106 from paketo-buildpacks/flight_recorder
Added support for Java Flight Recorder features
- Loading branch information
Showing
14 changed files
with
259 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* Copyright 2018-2020 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package helper | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/paketo-buildpacks/libpak/sherpa" | ||
|
||
"github.com/paketo-buildpacks/libpak/bard" | ||
) | ||
|
||
type JFR struct { | ||
Logger bard.Logger | ||
} | ||
|
||
func (j JFR) Execute() (map[string]string, error) { | ||
if val, ok := os.LookupEnv("BPL_JFR_ENABLED"); !ok || val != "true" { | ||
return nil, nil | ||
} | ||
|
||
var argList string | ||
if argList = sherpa.GetEnvWithDefault("BPL_JFR_ARGS", ""); argList == "" { | ||
argList = fmt.Sprintf("dumponexit=true,filename=%s", filepath.Join(os.TempDir(), "recording.jfr")) | ||
} | ||
j.Logger.Infof("Enabling Java Flight Recorder with args: %s", argList) | ||
|
||
// minimum flag to enable JFR, with default config args | ||
jfrConfig := fmt.Sprintf("-XX:StartFlightRecording=%s", argList) | ||
|
||
opts := sherpa.AppendToEnvVar("JAVA_TOOL_OPTIONS", " ", jfrConfig) | ||
|
||
return map[string]string{"JAVA_TOOL_OPTIONS": opts}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2018-2020 the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package helper_test | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
"testing" | ||
|
||
. "github.com/onsi/gomega" | ||
"github.com/paketo-buildpacks/libjvm/helper" | ||
"github.com/sclevine/spec" | ||
) | ||
|
||
func testJFR(t *testing.T, context spec.G, it spec.S) { | ||
var ( | ||
Expect = NewWithT(t).Expect | ||
|
||
jfr = helper.JFR{} | ||
) | ||
|
||
it("returns if $BPL_JFR_ENABLED is not set", func() { | ||
Expect(jfr.Execute()).To(BeNil()) | ||
}) | ||
context("$BPL_JFR_ENABLED", func() { | ||
it.Before(func() { | ||
Expect(os.Setenv("BPL_JFR_ENABLED", "true")).To(Succeed()) | ||
}) | ||
|
||
it.After(func() { | ||
Expect(os.Unsetenv("BPL_JFR_ENABLED")).To(Succeed()) | ||
}) | ||
|
||
it("contributes base JFR configuration", func() { | ||
Expect(jfr.Execute()).To(Equal(map[string]string{ | ||
"JAVA_TOOL_OPTIONS": fmt.Sprintf("-XX:StartFlightRecording=dumponexit=true,filename=%s", filepath.Join(os.TempDir(), "recording.jfr")), | ||
})) | ||
}) | ||
|
||
context("$BPL_JFR_ARGS is set", func() { | ||
it("contributes all arguments to JFR configuration", func() { | ||
Expect(os.Setenv("BPL_JFR_ARGS", "filename=/tmp/test.jfr,name=file,delay=60s,dumponexit=true,duration=10s,maxage=1d,maxsize=1024m,path-to-gc-roots=true,settings=true")).To(Succeed()) | ||
Expect(jfr.Execute()).To(Equal(map[string]string{ | ||
"JAVA_TOOL_OPTIONS": "-XX:StartFlightRecording=filename=/tmp/test.jfr,name=file,delay=60s,dumponexit=true,duration=10s,maxage=1d,maxsize=1024m,path-to-gc-roots=true,settings=true"})) | ||
}) | ||
}) | ||
|
||
context("$JAVA_TOOL_OPTIONS", func() { | ||
it.Before(func() { | ||
Expect(os.Setenv("JAVA_TOOL_OPTIONS", "test-java-tool-options")).To(Succeed()) | ||
}) | ||
|
||
it.After(func() { | ||
Expect(os.Unsetenv("JAVA_TOOL_OPTIONS")).To(Succeed()) | ||
}) | ||
|
||
it("contributes configuration appended to existing $JAVA_TOOL_OPTIONS", func() { | ||
Expect(os.Setenv("BPL_JFR_ARGS", "filename=/tmp/test.jfr,name=file")).To(Succeed()) | ||
Expect(jfr.Execute()).To(Equal(map[string]string{ | ||
"JAVA_TOOL_OPTIONS": "test-java-tool-options -XX:StartFlightRecording=filename=/tmp/test.jfr,name=file", | ||
})) | ||
}) | ||
}) | ||
|
||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters