grafana / grafana/pyroscope-java
BUG Memory leak when use agent
- Dominant language
- Java
- Stars
- 126
- Forks
- 48
- Avg merge
- 4d 14h
- Merged PRs (30d)
- 5
Description
I use 0.12.0 agent upload JFR data to my backend.
```
io.pyroscope
agent
0.12.0
```
Upload code:
```
Config profileConfig = new Config.Builder()
.setFormat(Format.JFR)
.setLogLevel(Logger.Level.INFO)
.setProfilingEvent(EventType.ITIMER)
.setProfilingAlloc("0")
.setProfilingInterval(Duration.ofMillis(10))
.setUploadInterval(Duration.ofSeconds(5))
.build();
GalileoProfileExporter exporter = new GalileoProfileExporter(resource, DEFAULT_RETRY);
PyroscopeAgent.start(new PyroscopeAgent.Options.Builder(profileConfig).setExporter(exporter).build());
```
My exporter:
```
public class GalileoProfileExporter implements Exporter {
private static final Duration TIMEOUT = Duration.ofSeconds(10);
private static final String ENDPOINT = "https://xxxxxxxxxxxxx";
final Ocp.Resource resource;
final int ingestMaxTries;
final Logger logger = new DefaultLogger(Logger.Level.INFO, System.err);
final OkHttpClient client = new OkHttpClient.Builder()
.connectTimeout(TIMEOUT)
.readTimeout(TIMEOUT)
.callTimeout(TIMEOUT)
.build();
public GalileoProfileExporter(Ocp.Resource resource, int ingestMaxTries) {
this.resource = resource;
this.ingestMaxTries = ingestMaxTries;
}
@Override
public void export(Snapshot snapshot) {
final HttpUrl url = HttpUrl.parse(ENDPOINT);
logger.log(Logger.Level.INFO, "Upload profile. %s %s JFR: %s",
snapshot.started.toString(), snapshot.ended.toString(), snapshot.data.length);
byte[] reqBody = constructReqBody(snapshot);
byte[] compressedData = new byte[0];
try {
compressedData = Snappy.compress(reqBody);
} catch (IOException e) {
logger.log(Logger.Level.ERROR, "Error compress snapshot.");
}
MediaType type = MediaType.parse("application/octet-stream");
RequestBody jfrBody = RequestBody.create(compressedData, type);
Request.Builder request = new Request.Builder()
.post(jfrBody)
.url(url);
request.header("language", "java");
try (Response response = client.newCall(request.build()).execute()) {
int status = response.code();
if (status >= 400) {
ResponseBody body = response.body();
final String responseBody;
if (body == null) {
responseBody = "";
} else {
responseBody = body.string();
}
logger.log(Logger.Level.ERROR, "Error uploading snapshot: %s %s", status, responseBody);
}
if (status == 200) {
logger.log(Logger.Level.INFO, "Success upload jfr");
}
} catch (final IOException e) {
logger.log(Logger.Level.ERROR, "Error uploading snapshot: %s", e.getMessage());
}
}
private byte[] constructReqBody(Snapshot snapshot) {
Otp.Profile.Builder profile = Otp.Profile.newBuilder()
.setName("jfr")
.setType("cpu")
.setData(ByteString.copyFrom(snapshot.data));
Otp.ProfilesBatch profilesBatch = Otp.ProfilesBatch.newBuilder()
.setSequence(1)
.setStart(snapshot.started.toEpochMilli() / 1000)
.setEnd(snapshot.ended.toEpochMilli() / 1000)
.setResource(this.resource)
.addProfiles(profile)
.build();
return profilesBatch.toByteArray();
}
}
```
When I opened the agent report, I found that the memory was constantly rising, and I suspected there was a memory leak situation

Is there anyone who has encountered similar problems with me, or is there a problem with where I wrote it? Thanks
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.