-
-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🐛 Fix Cannot change the uri of the metrics service
- Loading branch information
Showing
6 changed files
with
37 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,9 +20,14 @@ | |
*/ | ||
package org.restheart.metrics; | ||
|
||
import java.io.IOException; | ||
import java.io.StringWriter; | ||
import java.util.Map; | ||
|
||
import org.restheart.exchange.StringRequest; | ||
import org.restheart.exchange.StringResponse; | ||
import org.restheart.plugins.Inject; | ||
import org.restheart.plugins.OnInit; | ||
import org.restheart.plugins.RegisterPlugin; | ||
import org.restheart.plugins.StringService; | ||
import static org.restheart.utils.BsonUtils.array; | ||
|
@@ -38,21 +43,30 @@ | |
* | ||
* @author Andrea Di Cesare {@literal <[email protected]>} | ||
*/ | ||
@RegisterPlugin(name = "metrics", description = "returns requests metrics", secure = true) | ||
@RegisterPlugin(name = "metrics", description = "returns requests metrics", secure = true, defaultURI="/metrics") | ||
public class MetricsService implements StringService { | ||
/** | ||
* | ||
* prefix for registry names used by retheart-metrics plugins | ||
*/ | ||
public static String METRICS_REGISTRIES_PREFIX = "METRICS-"; | ||
|
||
@Inject("config") | ||
private Map<String, Object> config; | ||
private String serviceUri = "/metrics"; | ||
|
||
@OnInit | ||
public void onInit() { | ||
this.serviceUri = argOrDefault(config, "uri", "/metrics"); | ||
} | ||
|
||
/** | ||
* | ||
* @param exchange | ||
* @throws Exception | ||
* @param request | ||
* @param response | ||
* @throws java.io.IOException | ||
*/ | ||
@Override | ||
public void handle(StringRequest request, StringResponse response) throws Exception { | ||
public void handle(StringRequest request, StringResponse response) throws IOException { | ||
if (request.isOptions()) { | ||
handleOptions(request); | ||
return; | ||
|
@@ -61,7 +75,7 @@ public void handle(StringRequest request, StringResponse response) throws Except | |
return; | ||
} | ||
|
||
var params = request.getPathParams("/{servicename}/{*}"); | ||
var params = request.getPathParams(serviceUri.concat("/{*}")); | ||
|
||
if (!params.containsKey("*")) { | ||
var content = array(); | ||
|
@@ -82,7 +96,6 @@ public void handle(StringRequest request, StringResponse response) throws Except | |
response.setContent(writer.toString()); | ||
} else { | ||
response.setInError(HttpStatus.SC_NOT_FOUND, "metric not found"); | ||
return; | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters