Skip to content

Commit

Permalink
Quickpulse Post Request Json Bug Fix (#42144)
Browse files Browse the repository at this point in the history
* fix

* changelog

* removing unnecessary imports
  • Loading branch information
harsimar authored Sep 30, 2024
1 parent 7da661f commit bb3d2ce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
### Breaking Changes

### Bugs Fixed
- Fix a bug where post requests to Live Metrics returned http 400 due to malformed json.

### Other Changes

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.azure.core.http.HttpRequest;
import com.azure.core.util.logging.ClientLogger;
import com.azure.monitor.opentelemetry.exporter.implementation.quickpulse.model.QuickPulseEnvelope;
import com.azure.monitor.opentelemetry.exporter.implementation.quickpulse.model.QuickPulseMonitoringDataPoints;
import com.azure.monitor.opentelemetry.exporter.implementation.quickpulse.model.QuickPulseMetrics;
import com.azure.monitor.opentelemetry.exporter.implementation.utils.Strings;
import org.slf4j.MDC;
Expand Down Expand Up @@ -123,9 +124,9 @@ private String buildPostEntity(QuickPulseDataCollector.FinalCounters counters) t
postEnvelope.setTimeStamp("/Date(" + System.currentTimeMillis() + ")/");
postEnvelope.setMetrics(addMetricsToQuickPulseEnvelope(counters));
envelopes.add(postEnvelope);

QuickPulseMonitoringDataPoints points = new QuickPulseMonitoringDataPoints(envelopes);
// By default '/' is not escaped in JSON, so we need to escape it manually as the backend requires it.
return postEnvelope.toJsonString().replace("/", "\\/");
return points.toJsonString().replace("/", "\\/");
}

private static List<QuickPulseMetrics>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.azure.monitor.opentelemetry.exporter.implementation.quickpulse.model;

import com.azure.json.JsonSerializable;
import com.azure.json.JsonWriter;

import java.io.IOException;
import java.util.List;

public class QuickPulseMonitoringDataPoints implements JsonSerializable<QuickPulseEnvelope> {
private List<QuickPulseEnvelope> monitoringDataPoints;

public QuickPulseMonitoringDataPoints(List<QuickPulseEnvelope> monitoringDataPoints) {
this.monitoringDataPoints = monitoringDataPoints;
}

@Override
public JsonWriter toJson(JsonWriter jsonWriter) throws IOException {
return jsonWriter.writeArray(monitoringDataPoints, JsonWriter::writeJson, false);
}
}

0 comments on commit bb3d2ce

Please sign in to comment.