Skip to content

Commit

Permalink
Fixed OOM for json metrics output (#92)
Browse files Browse the repository at this point in the history
* Fixed OOM for json metrics output

* Reworked code a bit to match current code style
  • Loading branch information
qvad authored Apr 28, 2023
1 parent 569b7a1 commit 889aa99
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.yugabyte</groupId>
<artifactId>yb-sample-apps</artifactId>
<version>1.3.10-SNAPSHOT</version>
<version>1.3.11-SNAPSHOT</version>
<name>YB Sample Apps</name>
<description>
Sample applications for benchmarking YugaByte DB functionality on various workload types.
Expand Down
12 changes: 8 additions & 4 deletions src/main/java/com/yugabyte/sample/common/metrics/Metric.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,21 @@
import com.google.gson.JsonObject;

public class Metric {
private ReadableStatsMetric readableStatsMetric;
private JsonStatsMetric jsonStatsMetric;
private final boolean outputJsonMetrics;

private final ReadableStatsMetric readableStatsMetric;
private final JsonStatsMetric jsonStatsMetric;

public Metric(String name, boolean outputJsonMetrics) {
this.outputJsonMetrics = outputJsonMetrics;

public Metric(String name) {
readableStatsMetric = new ReadableStatsMetric(name);
jsonStatsMetric = new JsonStatsMetric(name);
}

public synchronized void observe(Observation o) {
readableStatsMetric.accumulate(o.getCount(), o.getLatencyNanos());
jsonStatsMetric.observe(o);
if (outputJsonMetrics) jsonStatsMetric.observe(o);
}

public String getReadableMetricsAndReset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public void registerStatusMessageAppender(StatusMessageAppender appender) {

public synchronized void createMetric(MetricName metricName) {
if (!metrics.containsKey(metricName)) {
metrics.put(metricName, new Metric(metricName.name()));
metrics.put(metricName, new Metric(metricName.name(), outputJsonMetrics));
}
}

Expand Down

0 comments on commit 889aa99

Please sign in to comment.