Skip to content

Commit 98d643e

Browse files
committed
Merge release branch 4.18 to main
* 4.18: Fixed spelling and added missing states to response (apache#8248) Let Prometheus exporter plugin support utf8 characters (apache#8228)
2 parents eaa4123 + 1b56a8e commit 98d643e

File tree

4 files changed

+18
-7
lines changed

4 files changed

+18
-7
lines changed

api/src/main/java/org/apache/cloudstack/api/response/AcquireIPAddressResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public class AcquireIPAddressResponse extends BaseResponse implements Controlle
124124
private String networkId;
125125

126126
@SerializedName(ApiConstants.STATE)
127-
@Param(description = "State of the ip address. Can be: Allocatin, Allocated and Releasing")
127+
@Param(description = "State of the ip address. Can be: Allocating, Allocated and Releasing")
128128
private String state;
129129

130130
@SerializedName(ApiConstants.PHYSICAL_NETWORK_ID)

api/src/main/java/org/apache/cloudstack/api/response/IPAddressResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public class IPAddressResponse extends BaseResponseWithAnnotations implements Co
128128
private String networkId;
129129

130130
@SerializedName(ApiConstants.STATE)
131-
@Param(description = "State of the ip address. Can be: Allocatin, Allocated and Releasing")
131+
@Param(description = "State of the ip address. Can be: Allocating, Allocated, Releasing, Reserved and Free")
132132
private String state;
133133

134134
@SerializedName(ApiConstants.PHYSICAL_NETWORK_ID)

api/src/main/java/org/apache/cloudstack/api/response/PortableIpResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public class PortableIpResponse extends BaseResponse {
6868
private Date allocated;
6969

7070
@SerializedName(ApiConstants.STATE)
71-
@Param(description = "State of the ip address. Can be: Allocatin, Allocated and Releasing")
71+
@Param(description = "State of the ip address. Can be: Allocating, Allocated, Releasing and Free")
7272
private String state;
7373

7474
public void setRegionId(Integer regionId) {

plugins/integrations/prometheus/src/main/java/org/apache/cloudstack/metrics/PrometheusExporterServerImpl.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.IOException;
2929
import java.io.OutputStream;
3030
import java.net.InetSocketAddress;
31+
import java.nio.charset.StandardCharsets;
3132
import java.util.Arrays;
3233

3334
public class PrometheusExporterServerImpl extends ManagerBase implements PrometheusExporterServer, Configurable {
@@ -57,11 +58,21 @@ public void handle(final HttpExchange httpExchange) throws IOException {
5758
response = prometheusExporter.getMetrics();
5859
responseCode = 200;
5960
}
60-
httpExchange.getResponseHeaders().set("content-type", "text/plain");
61-
httpExchange.sendResponseHeaders(responseCode, response.length());
61+
byte[] bytesToOutput = response.getBytes(StandardCharsets.UTF_8);
62+
httpExchange.getResponseHeaders().set("content-type", "text/plain; charset=UTF-8");
63+
httpExchange.sendResponseHeaders(responseCode, bytesToOutput.length);
6264
final OutputStream os = httpExchange.getResponseBody();
63-
os.write(response.getBytes());
64-
os.close();
65+
try {
66+
os.write(bytesToOutput);
67+
} catch (IOException e) {
68+
LOG.error(String.format("could not export Prometheus data due to %s", e.getLocalizedMessage()));
69+
if (LOG.isDebugEnabled()) {
70+
LOG.debug("Error during Prometheus export: ", e);
71+
}
72+
os.write("The system could not export Prometheus due to an internal error. Contact your operator to learn about the reason.".getBytes());
73+
} finally {
74+
os.close();
75+
}
6576
}
6677
}
6778

0 commit comments

Comments
 (0)