Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/1.25.x' into 1.27.x
Browse files Browse the repository at this point in the history
  • Loading branch information
gaetanmaisse committed Apr 27, 2023
2 parents 96d9993 + 66ceb5a commit d695482
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 3 deletions.
73 changes: 73 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,76 @@
## [1.25.6](https://github.com/gravitee-io/gravitee-node/compare/1.25.5...1.25.6) (2023-04-27)


### Bug Fixes

* add 'With' methods to HttpServerConfiguration ([a0bb68f](https://github.com/gravitee-io/gravitee-node/commit/a0bb68f5b2a57bbef1709292c583c18602ce6ce7))
* **api:** load the right property source for /configuration ([563b0f8](https://github.com/gravitee-io/gravitee-node/commit/563b0f8f62f278a52f9a355c9b7dd90b1e290465))
* **api:** send head before writing response for /monitor ([3700dd0](https://github.com/gravitee-io/gravitee-node/commit/3700dd0cf91db2b9b182e3e940831cf22dc61bca))
* **prometheus:** Stream scraping output instead of using a single String instance ([6e4271b](https://github.com/gravitee-io/gravitee-node/commit/6e4271bf66faa109bd21b078629fc1f7ed895f51))

## [1.24.7](https://github.com/gravitee-io/gravitee-node/compare/1.24.6...1.24.7) (2023-04-24)


### Bug Fixes

* **prometheus:** Stream scraping output instead of using a single String instance ([6e4271b](https://github.com/gravitee-io/gravitee-node/commit/6e4271bf66faa109bd21b078629fc1f7ed895f51))

## [1.24.6](https://github.com/gravitee-io/gravitee-node/compare/1.24.5...1.24.6) (2023-03-31)


### Bug Fixes

* add 'With' methods to HttpServerConfiguration ([a0bb68f](https://github.com/gravitee-io/gravitee-node/commit/a0bb68f5b2a57bbef1709292c583c18602ce6ce7))

## [1.24.5](https://github.com/gravitee-io/gravitee-node/compare/1.24.4...1.24.5) (2023-02-16)


### Bug Fixes

* **api:** load the right property source for /configuration ([563b0f8](https://github.com/gravitee-io/gravitee-node/commit/563b0f8f62f278a52f9a355c9b7dd90b1e290465))

## [1.24.4](https://github.com/gravitee-io/gravitee-node/compare/1.24.3...1.24.4) (2023-02-10)


### Bug Fixes

* **api:** send head before writing response for /monitor ([3700dd0](https://github.com/gravitee-io/gravitee-node/commit/3700dd0cf91db2b9b182e3e940831cf22dc61bca))

## [1.25.5](https://github.com/gravitee-io/gravitee-node/compare/1.25.4...1.25.5) (2023-04-06)


### Bug Fixes

* bump kubernetes client ([137eaf0](https://github.com/gravitee-io/gravitee-node/commit/137eaf0e48c306882cb37438a16968ece6684b24))

## [1.25.4](https://github.com/gravitee-io/gravitee-node/compare/1.25.3...1.25.4) (2023-03-31)


### Bug Fixes

* add 'With' methods to HttpServerConfiguration ([1051060](https://github.com/gravitee-io/gravitee-node/commit/1051060a81435c7b67c69ee972e5447b6386d716))

## [1.25.3](https://github.com/gravitee-io/gravitee-node/compare/1.25.2...1.25.3) (2023-03-07)


### Bug Fixes

* avoid spring loading issue with vertx and k8s client ([fe829f9](https://github.com/gravitee-io/gravitee-node/commit/fe829f9fcf9b80f2525925316553aa1db54737b7))

## [1.25.2](https://github.com/gravitee-io/gravitee-node/compare/1.25.1...1.25.2) (2023-02-16)


### Bug Fixes

* **api:** load the right property source for /configuration ([f9580e2](https://github.com/gravitee-io/gravitee-node/commit/f9580e26395fc4b92d72b81d7eb5c6f10e3fc784))

## [1.25.1](https://github.com/gravitee-io/gravitee-node/compare/1.25.0...1.25.1) (2023-02-10)


### Bug Fixes

* **api:** send head before writing response for /monitor ([08d02ea](https://github.com/gravitee-io/gravitee-node/commit/08d02ead134ee9a318ccbd58d8465d40378dbf76))

## [1.27.7](https://github.com/gravitee-io/gravitee-node/compare/1.27.6...1.27.7) (2023-03-13)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,29 @@
*/
package io.gravitee.node.management.http.metrics.prometheus;

import static io.prometheus.client.exporter.common.TextFormat.*;
import static io.vertx.core.http.HttpHeaders.*;

import io.gravitee.common.http.HttpMethod;
import io.gravitee.node.management.http.endpoint.ManagementEndpoint;
import io.micrometer.prometheus.PrometheusMeterRegistry;
import io.vertx.core.buffer.Buffer;
import io.vertx.core.http.HttpServerResponse;
import io.vertx.ext.web.RoutingContext;
import io.vertx.micrometer.backends.BackendRegistries;
import java.io.IOException;
import java.io.Writer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
* @author David BRASSELY (david.brassely at graviteesource.com)
* @author GraviteeSource Team
*/
public class PrometheusEndpoint implements ManagementEndpoint {

private static final Logger LOGGER = LoggerFactory.getLogger(PrometheusEndpoint.class);

@Override
public HttpMethod method() {
return HttpMethod.GET;
Expand All @@ -39,7 +50,72 @@ public String path() {

@Override
public void handle(RoutingContext routingContext) {
String response = ((PrometheusMeterRegistry) BackendRegistries.getDefaultNow()).scrape();
routingContext.response().end(response);
PrometheusMeterRegistry registry = (PrometheusMeterRegistry) BackendRegistries.getDefaultNow();
HttpServerResponse response = routingContext.response();

response.putHeader(CONTENT_TYPE, CONTENT_TYPE_004);
response.setChunked(true);

try (BufferWriter writer = new BufferWriter(response)) {
registry.scrape(writer);
} catch (IOException ioe) {
LOGGER.error("Unexpected error while scraping the Prometheus endpoint", ioe);
response.close();
}
}

private static class BufferWriter extends Writer {

private final HttpServerResponse response;

private BufferWriter(HttpServerResponse response) {
this.response = response;
}

@Override
public void write(char[] cbuf, int off, int len) throws IOException {
push(Buffer.buffer(charArrayToByteArray(cbuf)));
}

@Override
public void write(int c) throws IOException {
push(Buffer.buffer(1).appendByte((byte) (c & 0xFF)));
}

@Override
public void write(char[] cbuf) throws IOException {
push(Buffer.buffer(new String(cbuf)));
}

@Override
public void write(String str) throws IOException {
push(Buffer.buffer(str));
}

@Override
public void write(String str, int off, int len) throws IOException {
push(Buffer.buffer(str));
}

private void push(Buffer buffer) {
response.write(buffer);
}

@Override
public void flush() {}

@Override
public void close() throws IOException {
response.end();
}
}

private static byte[] charArrayToByteArray(char[] charBuf) {
if (charBuf == null) return null;
int iLen = charBuf.length;
byte[] buf = new byte[iLen];
for (int p = 0; p < iLen; p++) buf[p] = (byte) (charBuf[p]);

return buf;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import io.vertx.core.tracing.TracingPolicy;
import java.util.ArrayList;
import java.util.List;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.With;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.env.Environment;
Expand All @@ -31,6 +34,8 @@
* @author David BRASSELY (david.brassely at graviteesource.com)
* @author GraviteeSource Team
*/
@With
@AllArgsConstructor(access = AccessLevel.PRIVATE)
public class HttpServerConfiguration {

private static final Logger logger = LoggerFactory.getLogger(HttpServerConfiguration.class);
Expand Down
10 changes: 9 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
<scope>provided</scope>
</dependency>
</dependencies>

<properties>
Expand All @@ -253,7 +260,7 @@
<gravitee-expression-language.version>1.9.2</gravitee-expression-language.version>
<gravitee-reporter-api.version>1.22.0</gravitee-reporter-api.version>
<gravitee-tracing-api.version>1.0.0</gravitee-tracing-api.version>
<gravitee-kubernetes.version>0.4.0</gravitee-kubernetes.version>
<gravitee-kubernetes.version>0.4.1</gravitee-kubernetes.version>
<snakeyaml.version>1.30</snakeyaml.version>
<hazelcast.version>4.1.9</hazelcast.version>
<gravitee-alert-api.version>1.8.0</gravitee-alert-api.version>
Expand All @@ -264,6 +271,7 @@
<bouncycastle.version>1.70</bouncycastle.version>
<guava.version>31.1-jre</guava.version>
<license3j.version>3.2.0</license3j.version>
<lombok.version>1.18.24</lombok.version>
</properties>
<build>
<plugins>
Expand Down

0 comments on commit d695482

Please sign in to comment.