Skip to content

Commit 892c080

Browse files
committed
Profiler output dir is only used by the keep files setting
1 parent 4e2314e commit 892c080

3 files changed

Lines changed: 21 additions & 45 deletions

File tree

profiler/src/main/java/com/splunk/opentelemetry/profiler/JfrActivator.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,15 @@ public void afterAgent(AutoConfiguredOpenTelemetrySdk autoConfiguredOpenTelemetr
6464
}
6565

6666
configurationLogger.log(config);
67-
logger.info("JFR profiler is active.");
67+
logger.info("Profiler is active.");
6868
executor.submit(
6969
logUncaught(
7070
() -> activateJfrAndRunForever(config, autoConfiguredOpenTelemetrySdk.getResource())));
7171
}
7272

7373
private boolean notClearForTakeoff(ConfigProperties config) {
7474
if (!config.getBoolean(CONFIG_KEY_ENABLE_PROFILER, false)) {
75-
logger.fine("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
76-
logger.fine("xxxxxxxxx JFR PROFILER DISABLED! xxxxxxxxx");
77-
logger.fine("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
75+
logger.fine("Profiler is not enabled.");
7876
return true;
7977
}
8078
if (!JFR.instance.isAvailable()) {
@@ -83,35 +81,42 @@ private boolean notClearForTakeoff(ConfigProperties config) {
8381
return true;
8482
}
8583

86-
Path outputDir = Paths.get(config.getString(CONFIG_KEY_PROFILER_DIRECTORY));
84+
return false;
85+
}
86+
87+
private boolean checkOutputDir(Path outputDir) {
8788
if (!Files.exists(outputDir)) {
8889
// Try creating the directory for the user...
8990
try {
9091
Files.createDirectories(outputDir);
9192
} catch (IOException e) {
92-
return outdirWarn(outputDir, "does not exist and could not be created");
93+
outdirWarn(outputDir, "does not exist and could not be created");
94+
return false;
9395
}
9496
}
9597
if (!Files.isDirectory(outputDir)) {
96-
return outdirWarn(outputDir, "exists but is not a directory");
98+
outdirWarn(outputDir, "exists but is not a directory");
99+
return false;
97100
}
98101

99102
if (!Files.isWritable(outputDir)) {
100-
return outdirWarn(outputDir, "exists but is not writable.");
103+
outdirWarn(outputDir, "exists but is not writable.");
104+
return false;
101105
}
102-
return false;
103-
}
104106

105-
private boolean outdirWarn(Path dir, String suffix) {
106-
logger.log(
107-
WARNING,
108-
"PROFILER WILL NOT BE STARTED: The configured output directory {0} {1}.",
109-
new Object[] {dir, suffix});
110107
return true;
111108
}
112109

110+
private void outdirWarn(Path dir, String suffix) {
111+
logger.log(WARNING, "The configured output directory {0} {1}.", new Object[] {dir, suffix});
112+
}
113+
113114
private void activateJfrAndRunForever(ConfigProperties config, Resource resource) {
115+
boolean keepFiles = keepFiles(config);
114116
Path outputDir = Paths.get(config.getString(CONFIG_KEY_PROFILER_DIRECTORY));
117+
if (keepFiles && !checkOutputDir(outputDir)) {
118+
keepFiles = false;
119+
}
115120
RecordingFileNamingConvention namingConvention = new RecordingFileNamingConvention(outputDir);
116121

117122
int stackDepth = Configuration.getStackDepth(config);
@@ -167,7 +172,7 @@ private void activateJfrAndRunForever(ConfigProperties config, Resource resource
167172
.jfr(JFR.instance)
168173
.onNewRecording(jfrRecordingHandler)
169174
.namingConvention(namingConvention)
170-
.keepRecordingFiles(keepFiles(config))
175+
.keepRecordingFiles(keepFiles)
171176
.build();
172177

173178
RecordingSequencer sequencer =

profiler/src/main/java/com/splunk/opentelemetry/profiler/RecordingFileNamingConvention.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,4 @@ Path newOutputPath(LocalDateTime dateTime) throws IOException {
4747
return Files.createTempFile(
4848
outputDir, PREFIX + "-" + timestamp.replace(':', '_') + "-", ".jfr");
4949
}
50-
51-
/** Determines if the path represents a file that we would have recorded to. */
52-
boolean matches(Path path) {
53-
return outputDir.equals(path.getParent()) && filenameMatches(path);
54-
}
55-
56-
private boolean filenameMatches(Path path) {
57-
String filename = path.getFileName().toString();
58-
return filenamePattern.matcher(filename).matches();
59-
}
60-
61-
Path getOutputPath() {
62-
return outputDir;
63-
}
6450
}

profiler/src/test/java/com/splunk/opentelemetry/profiler/RecordingFileNamingConventionTest.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,9 @@
1717
package com.splunk.opentelemetry.profiler;
1818

1919
import static org.assertj.core.api.Assertions.assertThat;
20-
import static org.junit.jupiter.api.Assertions.assertFalse;
21-
import static org.junit.jupiter.api.Assertions.assertTrue;
2220

2321
import java.io.IOException;
2422
import java.nio.file.Path;
25-
import java.nio.file.Paths;
2623
import java.time.LocalDateTime;
2724
import java.time.Month;
2825
import org.junit.jupiter.api.Test;
@@ -42,16 +39,4 @@ void testNewPath() throws IOException {
4239

4340
assertThat(path.toString()).startsWith(expected.toString()).endsWith(".jfr");
4441
}
45-
46-
@Test
47-
void testMatches() {
48-
RecordingFileNamingConvention convention = new RecordingFileNamingConvention(outputDir);
49-
Path doesMatch = outputDir.resolve("otel-profiler-1999-02-12T17_03_21-123.jfr");
50-
Path differentDir = Paths.get("/no/way/out/otel-profiler-1999-02-12T17_03_21-123.jfr");
51-
Path badFilename = outputDir.resolve("tugboat-1999-02-12T17_03_21-123.jfr");
52-
53-
assertTrue(convention.matches(doesMatch));
54-
assertFalse(convention.matches(differentDir));
55-
assertFalse(convention.matches(badFilename));
56-
}
5742
}

0 commit comments

Comments
 (0)