-
Notifications
You must be signed in to change notification settings - Fork 798
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bearerToken builder to pushgateway exporter (#968)
* feat: add bearerToken builder to pushgateway exporter Signed-off-by: Martin Chodur <[email protected]> * feat: add tests and docs Signed-off-by: Martin Chodur <[email protected]> * fix: drop integration tests for bearer token Signed-off-by: Martin Chodur <[email protected]> --------- Signed-off-by: Martin Chodur <[email protected]>
- Loading branch information
Showing
4 changed files
with
76 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,4 +128,4 @@ private static void makeMetrics() { | |
.register(); | ||
duration.set(0.5); | ||
} | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
.../src/test/java/io/prometheus/metrics/exporter/pushgateway/BearerTokenPushGatewayTest.java
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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.prometheus.metrics.exporter.pushgateway; | ||
|
||
import io.prometheus.metrics.core.metrics.Gauge; | ||
import io.prometheus.metrics.model.registry.PrometheusRegistry; | ||
import org.junit.Before; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.mockserver.client.MockServerClient; | ||
import org.mockserver.junit.MockServerRule; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.mockserver.model.HttpRequest.request; | ||
import static org.mockserver.model.HttpResponse.response; | ||
|
||
public class BearerTokenPushGatewayTest { | ||
|
||
@Rule | ||
public MockServerRule mockServerRule = new MockServerRule(this); | ||
private MockServerClient mockServerClient; | ||
|
||
PrometheusRegistry registry; | ||
Gauge gauge; | ||
PushGateway pushGateway; | ||
|
||
@Before | ||
public void setUp() { | ||
registry = new PrometheusRegistry(); | ||
gauge = Gauge.builder().name("g").help("help").build(); | ||
pushGateway = PushGateway.builder() | ||
.address("localhost:" + mockServerRule.getPort()) | ||
.bearerToken("xxx") | ||
.registry(registry) | ||
.job("j") | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void testAuthorizedPush() throws IOException { | ||
mockServerClient.when( | ||
request() | ||
.withMethod("PUT") | ||
.withHeader("Authorization", "Bearer xxx") | ||
.withPath("/metrics/job/j") | ||
).respond(response().withStatusCode(202)); | ||
pushGateway.push(); | ||
} | ||
} |