Skip to content

Commit

Permalink
Fix breaking scrape API change #892 (#898)
Browse files Browse the repository at this point in the history
Signed-off-by: Fabian Stäber <fabian@fstab.de>
  • Loading branch information
fstab authored Nov 12, 2023
1 parent e8b3f87 commit dd31ee6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ public Enumeration<String> getHeaders(String name) {
public String getMethod() {
return httpExchange.getRequestMethod();
}

@Override
public String getRequestPath() {
URI requestURI = httpExchange.getRequestURI();
String uri = requestURI.toString();
int qx = uri.indexOf('?');
if (qx != -1) {
uri = uri.substring(0, qx);
}
return uri;
}
}

public class HttpResponse implements PrometheusHttpResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import java.io.IOException;
import java.io.OutputStream;
import java.net.URI;
import java.util.Enumeration;

public class HttpExchangeAdapter implements PrometheusHttpExchange {
Expand Down Expand Up @@ -67,6 +68,24 @@ public Enumeration<String> getHeaders(String name) {
public String getMethod() {
return request.getMethod();
}

@Override
public String getRequestPath() {
StringBuilder uri = new StringBuilder();
String contextPath = request.getContextPath();
if (contextPath.startsWith("/")) {
uri.append(contextPath);
}
String servletPath = request.getServletPath();
if (servletPath.startsWith("/")) {
uri.append(servletPath);
}
String pathInfo = request.getPathInfo();
if (pathInfo != null) {
uri.append(pathInfo);
}
return uri.toString();
}
}

public static class Response implements PrometheusHttpResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

/**
* Infos extracted from the request received by the endpoint
*
*/
public interface PrometheusScrapeRequest {

String[] getParameterValues(String name);

/**
* Absolute path of the HTTP request.
*/
String getRequestPath();

/**
* See {@code jakarta.servlet.ServletRequest.getParameterValues(String name)}
*/
String[] getParameterValues(String name);
}

0 comments on commit dd31ee6

Please sign in to comment.