Skip to content

Commit

Permalink
Fix unworking tests
Browse files Browse the repository at this point in the history
  • Loading branch information
faderskd committed Aug 29, 2023
1 parent 7b3179a commit 29665be
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package pl.allegro.tech.hermes.management.infrastructure.prometheus
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.junit.WireMockRule
import jakarta.ws.rs.core.MediaType
import org.glassfish.jersey.uri.UriComponent
import org.junit.Rule
import org.springframework.web.client.RestTemplate
import pl.allegro.tech.hermes.management.infrastructure.metrics.MonitoringMetricsContainer
Expand All @@ -17,14 +18,14 @@ import static pl.allegro.tech.hermes.api.MetricDecimalValue.of
class RestTemplatePrometheusClientTest extends Specification {

private static final int PROMETHEUS_HTTP_PORT = Ports.nextAvailable()
private static final String query = "sumby(__name__,group,topic,subscription,status_code)" +
private static final String query = "sum by (__name__,group,topic,subscription,status_code)" +
"(irate{__name__=~'hermes_consumers_subscription_delivered_total" +
"|hermes_consumers_subscription_timeouts_total" +
"|hermes_consumers_subscription_throughput_bytes_total" +
"|hermes_consumers_subscription_other_errors_total" +
"|hermes_consumers_subscription_batches_total" +
"|hermes_consumers_subscription_http_status_codes_total'," +
"group='pl.allegro.tech.hermes',topic='hermesTopic',subscription='hermesSubscription'}[1m])keep_metric_names)"
"group='pl.allegro.tech.hermes',topic='hermesTopic',subscription='hermesSubscription'}[1m]) keep_metric_names)"

@Rule
WireMockRule wireMockRule = new WireMockRule(
Expand Down Expand Up @@ -75,6 +76,7 @@ class RestTemplatePrometheusClientTest extends Specification {

private void mockPrometheus(String query, String responseFile) {
String encodedQuery = URLEncoder.encode(query, defaultCharset())
encodedQuery = UriComponent.contextualEncode(encodedQuery, UriComponent.Type.QUERY_PARAM);
WireMock.stubFor(WireMock.get(urlEqualTo(String.format("/api/v1/query?query=%s", encodedQuery)))
.willReturn(WireMock.aResponse()
.withStatus(200)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.fasterxml.jackson.jakarta.rs.json.JacksonXmlBindJsonProvider;
import jakarta.ws.rs.client.ClientRequestContext;
import java.util.function.Function;
import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.client.ClientProperties;
import org.glassfish.jersey.client.proxy.WebResourceFactory;
Expand Down Expand Up @@ -75,6 +77,21 @@ private static ClientBuilder getClientBuilder(ClientConfig clientConfig) {
);
}

public Hermes withPassword(String password) {
this.filters.add(new PasswordAuthenticationFeature(password));
return this;
}

public Hermes withAuthToken(String authToken) {
this.filters.add(new OAuth2AuthenticationFeature(clientRequestContext -> authToken));
return this;
}

public Hermes withAuthToken(Function<ClientRequestContext, String> authTokenSupplier) {
this.filters.add(new OAuth2AuthenticationFeature(authTokenSupplier));
return this;
}

public Hermes withManagementConfig(ClientConfig config) {
this.managementConfig = config;
return this;
Expand Down

0 comments on commit 29665be

Please sign in to comment.