Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v.1.0.1: Metrics configuration #2

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Add dependency to your project
<dependency>
<groupId>com.rasklaad</groupId>
<artifactId>wiremock-metrics</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
</dependency>
```
Add `MetricsEndpointExtension` and `PrometheusMetricsExtension` to your wiremock configuration, for example:
Expand All @@ -40,7 +40,37 @@ public class Main {
}
}
```
### Configuration
By default all requests will be registered using path with query params. For example two requests `/hello?name=John` and `/hello?name=Jane` requests will be registered as two different requests.
There are various configuration parameters for changing this behaviour:
```
// /hello?name=John and /hello?name=Jane requests will be registered as one request
MetricsConfiguration metricsConfiguration = PrometheusMetricsExtension.options()
.useRequestsUrl()
.ignoreQueryParams();

WireMockServer server = new WireMockServer(
WireMockConfiguration.options()
.port(8080)
.extensions(new PrometheusMetricsExtension(), new MetricsEndpointExtension(metricsConfiguration))
);
server.start();
```

```
/*
* wiremock stub url pattern: WireMock.urlMatching("/some-test.+")
* request: GET /some-test?queryParam=true&anotherParam=123
* metric will be registered as:
* wiremock_request_totalTime_ms_count{method=GET,path="/some-test.+",status=200,} 1.0
*/
MetricsConfiguration metricsConfiguration = PrometheusMetricsExtension.options()
.useMappingUrlPattern();
```
There are more examples in `MetricsConfigurationTest` class.

### Standalone process
```java
If you are running wiremock as [standalone](https://wiremock.org/docs/running-standalone/) process, you still can use this extension:
1. Download metrics extension standalone jar from [releases](https://github.com/rasklaad/wiremock-metrics/releases/)
2. Place it near your wiremock standalone jar
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.rasklaad</groupId>
<artifactId>wiremock-metrics</artifactId>
<version>1.0.0</version>
<version>1.0.1</version>
<name>wiremock-metrics</name>
<description>Metrics extension for standalone wiremock</description>
<url>https://github.com/rasklaad/wiremock-metrics</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,9 @@
public class MetricsEndpointExtension implements AdminApiExtension {
public static final String EXTENSION_NAME = "metrics-endpoint-extension";

private final AdminTask adminTask;

public MetricsEndpointExtension() {
adminTask = new PrometheusEndpointAdminTask();
}
@Override
public void contributeAdminApiRoutes(Router router) {
router.add(RequestMethod.GET, "/prometheus-metrics", adminTask);
router.add(RequestMethod.GET, "/prometheus-metrics", new PrometheusEndpointAdminTask());
}

@Override
Expand Down