Skip to content

Commit

Permalink
Merge pull request #52 from Ecwid/prometheus-1.2
Browse files Browse the repository at this point in the history
Prometheus 1.3
  • Loading branch information
turchenkoalex authored Jun 5, 2024
2 parents 0295c2c + 31c78a7 commit 6c79236
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 17 deletions.
8 changes: 4 additions & 4 deletions core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@


<artifactId>rest4j-core</artifactId>
<version>1.2-ecwid-27</version>
<version>1.2-ecwid-28</version>
<url>https://code.google.com/p/rest4j/</url>
<scm>
<connection>
Expand Down Expand Up @@ -59,7 +59,7 @@
<parent>
<artifactId>rest4j</artifactId>
<groupId>com.rest4j</groupId>
<version>1.2-ecwid-27</version>
<version>1.2-ecwid-28</version>
</parent>
<build>
<plugins>
Expand Down Expand Up @@ -181,8 +181,8 @@
</dependency>
<dependency>
<groupId>io.prometheus</groupId>
<artifactId>simpleclient</artifactId>
<version>0.16.0</version>
<artifactId>prometheus-metrics-core</artifactId>
<version>1.3.1</version>
</dependency>

<!-- optional dependencies for Spring users -->
Expand Down
21 changes: 10 additions & 11 deletions core/src/main/java/com/rest4j/impl/APIImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@
import com.rest4j.type.ApiType;
import com.rest4j.type.ArrayApiType;
import com.rest4j.type.SimpleApiType;
import io.prometheus.client.Summary;
import io.prometheus.metrics.core.datapoints.DistributionDataPoint;
import io.prometheus.metrics.core.datapoints.Timer;
import io.prometheus.metrics.core.metrics.Summary;
import io.prometheus.metrics.model.snapshots.Unit;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;

Expand All @@ -45,11 +48,10 @@
* @author Joseph Kapizza <[email protected]>
*/
public class APIImpl implements API {
static final Summary requestDuration = Summary.build()
.namespace("rest4j")
.subsystem("http")
.name("request_duration_seconds")
static final Summary requestDuration = Summary.builder()
.name("rest4j_http_request_duration_seconds")
.help("Requests duration in seconds.")
.unit(Unit.SECONDS)
.labelNames("http_method", "service_name", "method_name")
.quantile(0.5, 0.01)
.quantile(0.95, 0.01)
Expand Down Expand Up @@ -236,20 +238,17 @@ interface ArgHandler {
}

class InstrumentedEndpointMapping extends EndpointMapping {
private final Summary.Child duration;
private final DistributionDataPoint duration;

InstrumentedEndpointMapping(Endpoint ep, ServiceProvider serviceProvider, PermissionChecker permissionChecker) throws ConfigurationException {
super(ep, serviceProvider, permissionChecker);
this.duration = requestDuration.labels(httpMethod, endpoint.getService().getName(), method.getName());
this.duration = requestDuration.labelValues(httpMethod, endpoint.getService().getName(), method.getName());
}

@Override
Object invokeRaw(ApiRequest request, Object getResult) throws IOException, ApiException {
Summary.Timer requestTimer = duration.startTimer();
try {
try(Timer timer = duration.startTimer()) {
return super.invokeRaw(request, getResult);
} finally {
requestTimer.observeDuration();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion generator/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<artifactId>rest4j</artifactId>
<groupId>com.rest4j</groupId>
<version>1.2-ecwid-27</version>
<version>1.2-ecwid-28</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.rest4j</groupId>
<artifactId>rest4j</artifactId>
<packaging>pom</packaging>
<version>1.2-ecwid-27</version>
<version>1.2-ecwid-28</version>
<url>https://code.google.com/p/rest4j/</url>
<scm>
<connection>
Expand Down

0 comments on commit 6c79236

Please sign in to comment.