Skip to content

Commit

Permalink
Unhelathy topic/subscriptions tests rewritten to prometheus
Browse files Browse the repository at this point in the history
  • Loading branch information
faderskd committed Aug 25, 2023
1 parent 82f712e commit ae06e6c
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import com.googlecode.catchexception.CatchException;
import jakarta.ws.rs.BadRequestException;
import java.util.Collections;

Check warning on line 5 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L5 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

'java.util.Collections' should be separated from previous import group by one line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:5:1: warning: 'java.util.Collections' should be separated from previous import group by one line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import java.util.List;
import org.testng.annotations.BeforeMethod;

Check warning on line 7 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L7 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'org.testng.annotations.BeforeMethod' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:7:1: warning: Import statement for 'org.testng.annotations.BeforeMethod' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import org.testng.annotations.Test;

Check warning on line 8 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L8 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'org.testng.annotations.Test' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:8:1: warning: Import statement for 'org.testng.annotations.Test' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import pl.allegro.tech.hermes.api.MessageFilterSpecification;

Check warning on line 9 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L9 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.api.MessageFilterSpecification' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:9:1: warning: Import statement for 'pl.allegro.tech.hermes.api.MessageFilterSpecification' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
Expand All @@ -14,6 +16,9 @@
import pl.allegro.tech.hermes.frontend.config.GraphiteProperties;

Check warning on line 16 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L16 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.frontend.config.GraphiteProperties' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:16:1: warning: Import statement for 'pl.allegro.tech.hermes.frontend.config.GraphiteProperties' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import pl.allegro.tech.hermes.integration.env.SharedServices;

Check warning on line 17 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L17 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.integration.env.SharedServices' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:17:1: warning: Import statement for 'pl.allegro.tech.hermes.integration.env.SharedServices' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint;

Check warning on line 18 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L18 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:18:1: warning: Import statement for 'pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusSubscriptionResponse;

Check warning on line 19 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L19 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusSubscriptionResponse' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:19:1: warning: Import statement for 'pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusSubscriptionResponse' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusSubscriptionResponseBuilder;

Check warning on line 20 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L20 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusSubscriptionResponseBuilder' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:20:1: warning: Import statement for 'pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusSubscriptionResponseBuilder' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusTopicResponse;

Check warning on line 21 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L21 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusTopicResponse' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:21:1: warning: Import statement for 'pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusTopicResponse' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import pl.allegro.tech.hermes.integration.helper.graphite.GraphiteMockServer;

Check warning on line 22 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L22 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.integration.helper.graphite.GraphiteMockServer' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:22:1: warning: Import statement for 'pl.allegro.tech.hermes.integration.helper.graphite.GraphiteMockServer' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import pl.allegro.tech.hermes.integration.shame.Unreliable;

Check warning on line 23 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L23 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.integration.shame.Unreliable' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:23:1: warning: Import statement for 'pl.allegro.tech.hermes.integration.shame.Unreliable' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import pl.allegro.tech.hermes.test.helper.endpoint.RemoteServiceEndpoint;

Check warning on line 24 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L24 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.test.helper.endpoint.RemoteServiceEndpoint' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:24:1: warning: Import statement for 'pl.allegro.tech.hermes.test.helper.endpoint.RemoteServiceEndpoint' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
Expand All @@ -27,6 +32,7 @@
import static java.lang.Integer.MAX_VALUE;
import static org.assertj.core.api.Assertions.assertThat;
import static pl.allegro.tech.hermes.api.BatchSubscriptionPolicy.Builder.batchSubscriptionPolicy;
import static pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusSubscriptionResponseBuilder.*;

Check warning on line 35 in integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java#L35 <com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck>

Using the '.*' form of import should be avoided - pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusSubscriptionResponseBuilder.*.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/MetricsTest.java:35:113: warning: Using the '.*' form of import should be avoided - pl.allegro.tech.hermes.integration.helper.PrometheusEndpoint.PrometheusSubscriptionResponseBuilder.*. (com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck)
import static pl.allegro.tech.hermes.test.helper.builder.SubscriptionBuilder.subscription;
import static pl.allegro.tech.hermes.test.helper.builder.TopicBuilder.randomTopic;

Expand Down Expand Up @@ -54,7 +60,8 @@ public void shouldIncreaseTopicMetricsAfterMessageHasBeenPublished() {
// given
Topic topic = operations.buildTopic(randomTopic("group", "topic_metrics").build());
operations.createSubscription(topic, "subscription", remoteService.getUrl());
prometheusEndpoint.returnTopicMetrics(topic.getName().getGroupName(), topic.getName().getName(), 10, 15);
prometheusEndpoint.returnTopicMetrics(topic.getName().getGroupName(), topic.getName().getName(),
new PrometheusTopicResponse(10, 15, 0));

remoteService.expectMessages(TestMessage.simple().body());
assertThat(publisher.publish(topic.getQualifiedName(), TestMessage.simple().body()).getStatus())
Expand All @@ -79,7 +86,7 @@ public void shouldIncreaseSubscriptionDeliveredMetricsAfterMessageDelivered() {
// given
Topic topic = operations.buildTopic(randomTopic("pl.group", "topic").build());
operations.createSubscription(topic, "subscription", remoteService.getUrl());
prometheusEndpoint.returnSubscriptionMetrics(topic, "subscription", 15);
prometheusEndpoint.returnSubscriptionMetrics(topic, "subscription", builder().withRate(15).build());

remoteService.expectMessages(TestMessage.simple().body());
assertThat(publisher.publish(topic.getQualifiedName(), TestMessage.simple().body()).getStatus())
Expand Down Expand Up @@ -122,7 +129,7 @@ public void shouldReadSubscriptionDeliveryRate() {
Topic topic = operations.buildTopic("pl.allegro.tech.hermes", "topic");
String subscriptionName = "pl.allegro.tech.hermes.subscription";
operations.createSubscription(topic, subscriptionName, remoteService.getUrl());
prometheusEndpoint.returnSubscriptionMetrics(topic, subscriptionName, 15);
prometheusEndpoint.returnSubscriptionMetrics(topic, subscriptionName, builder().withRate(15).build());

wait.until(() -> {
// when
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package pl.allegro.tech.hermes.integration.helper;

import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.github.tomakehurst.wiremock.WireMockServer;
import com.github.tomakehurst.wiremock.client.WireMock;
import java.util.List;
import java.util.ArrayList;

Check warning on line 9 in integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java#L9 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

'java.util.ArrayList' should be separated from previous import group by one line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java:9:1: warning: 'java.util.ArrayList' should be separated from previous import group by one line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import pl.allegro.tech.hermes.api.Topic;

Check warning on line 10 in integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java#L10 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.api.Topic' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java:10:1: warning: Import statement for 'pl.allegro.tech.hermes.api.Topic' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)
import pl.allegro.tech.hermes.integration.env.EnvironmentAware;

Check warning on line 11 in integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java#L11 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Import statement for 'pl.allegro.tech.hermes.integration.env.EnvironmentAware' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java:11:1: warning: Import statement for 'pl.allegro.tech.hermes.integration.env.EnvironmentAware' is in the wrong order. Should be in the 'THIRD_PARTY_PACKAGE' group, expecting group 'STATIC' on this line. (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)

import java.util.List;

Check warning on line 13 in integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java#L13 <com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck>

Extra separation in import group before 'java.util.List'
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java:13:1: warning: Extra separation in import group before 'java.util.List' (com.puppycrawl.tools.checkstyle.checks.imports.CustomImportOrderCheck)

import static com.github.tomakehurst.wiremock.client.WireMock.aResponse;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.urlMatching;
Expand Down Expand Up @@ -37,7 +40,7 @@ public class PrometheusEndpoint implements EnvironmentAware {
".*hermes_consumers_subscription_throughput_bytes_total" +

Check warning on line 40 in integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java#L40 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java:40:70: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
".*hermes_consumers_subscription_other_errors_total" +

Check warning on line 41 in integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java#L41 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java:41:66: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
".*hermes_consumers_subscription_batches_total" +

Check warning on line 42 in integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java

View workflow job for this annotation

GitHub Actions / checkstyle-integration

[checkstyle-integration] integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java#L42 <com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck>

'+' should be on a new line.
Raw output
/home/runner/work/hermes/hermes/integration/src/integration/java/pl/allegro/tech/hermes/integration/helper/PrometheusEndpoint.java:42:61: warning: '+' should be on a new line. (com.puppycrawl.tools.checkstyle.checks.whitespace.OperatorWrapCheck)
".*hermes_consumers_subscription_http_status_codes_total.*";
".*hermes_consumers_subscription_http_status_codes_total.*GROUP.*TOPIC.*SUBSCRIPTION.*";

private final ObjectMapper objectMapper;
private final WireMock prometheusListener;
Expand All @@ -47,8 +50,8 @@ public PrometheusEndpoint(WireMockServer prometheus) {
this.objectMapper = new ObjectMapper();
}

public void returnTopicMetrics(String group, String topic, int rate, int deliveryRate) {
String response = generateTopicsMetricsResponse(rate, deliveryRate);
public void returnTopicMetrics(String group, String topic, PrometheusTopicResponse topicStub) {
String response = generateTopicsMetricsResponse(topicStub.topicRate, topicStub.deliveredRate, topicStub.throughput);
String query = TOPIC_QUERY_PATTERN
.replaceAll("GROUP", group)
.replaceAll("TOPIC", topic);
Expand All @@ -59,8 +62,8 @@ public void returnTopicMetrics(String group, String topic, int rate, int deliver
.withBody(response)));
}

public void returnSubscriptionMetrics(Topic topic, String subscription, int rate) {
String response = generateSubscriptionResponse(rate);
public void returnSubscriptionMetrics(Topic topic, String subscription, PrometheusSubscriptionResponse stub) {
String response = generateSubscriptionResponse(stub);
String query = SUBSCRIPTION_QUERY_PATTERN
.replaceAll("GROUP", topic.getName().getGroupName())
.replaceAll("TOPIC", topic.getName().getName())
Expand All @@ -72,128 +75,66 @@ public void returnSubscriptionMetrics(Topic topic, String subscription, int rate
.withBody(response)));
}

private String generateTopicsMetricsResponse(int rate, int deliveryRate) {
public void returnSubscriptionMetricsWithDelay(Topic topic, String subscription, PrometheusSubscriptionResponse stub,
int prometheusDelay) {
String response = generateSubscriptionResponse(stub);
String query = SUBSCRIPTION_QUERY_PATTERN
.replaceAll("GROUP", topic.getName().getGroupName())
.replaceAll("TOPIC", topic.getName().getName())
.replaceAll("SUBSCRIPTION", subscription);
prometheusListener.register(get(urlMatching(query))
.willReturn(aResponse()
.withStatus(200)
.withFixedDelay(prometheusDelay)
.withHeader("Content-Type", "application/json")
.withBody(response)));
}

public void returnServerErrorForAllTopics() {
String query = TOPIC_QUERY_PATTERN
.replaceAll("GROUP", "")
.replaceAll("TOPIC", "");
prometheusListener.register(get(urlMatching(query))
.willReturn(aResponse()
.withStatus(500)
.withHeader("Content-Type", "application/json")));
}

private String generateTopicsMetricsResponse(int rate, int deliveryRate, int throughput) {
return writeToString(
new PrometheusResponse(
"success",
new PrometheusResponse.Data(
"vector",
List.of(
new PrometheusResponse.Result(
new PrometheusResponse.MetricName(TOPIC_REQUESTS_TOTAL),
new PrometheusResponse.MetricName(TOPIC_REQUESTS_TOTAL, null),
List.of(TIMESTAMP, String.valueOf(rate))),
new PrometheusResponse.Result(
new PrometheusResponse.MetricName(TOPIC_DELIVERED_TOTAL),
List.of(TIMESTAMP, String.valueOf(deliveryRate))))
new PrometheusResponse.MetricName(TOPIC_DELIVERED_TOTAL, null),
List.of(TIMESTAMP, String.valueOf(deliveryRate))),
new PrometheusResponse.Result(
new PrometheusResponse.MetricName(TOPIC_THROUGHPUT_TOTAL, null),
List.of(TIMESTAMP, String.valueOf(throughput))))
)));
}

private String generateSubscriptionResponse(int rate) {
return writeToString(
new PrometheusResponse(
"success",
new PrometheusResponse.Data(
"vector",
List.of(
new PrometheusResponse.Result(
new PrometheusResponse.MetricName(SUBSCRIPTION_DELIVERED),
List.of(TIMESTAMP, String.valueOf(rate)))
))));
private String generateSubscriptionResponse(PrometheusSubscriptionResponse stub) {
List<PrometheusResponse.Result> results = new ArrayList<>();
results.add(
new PrometheusResponse.Result(
new PrometheusResponse.MetricName(SUBSCRIPTION_DELIVERED, null),
List.of(TIMESTAMP, String.valueOf(stub.rate)))
);
stub.statusCodes().forEach(s -> results.add(
new PrometheusResponse.Result(
new PrometheusResponse.MetricName(SUBSCRIPTION_STATUS_CODES, s.code()),
List.of(TIMESTAMP, String.valueOf(s.rate)))));
PrometheusResponse response = new PrometheusResponse(
"success", new PrometheusResponse.Data("vector", results));
return writeToString(response);
}


// public void returnServerErrorForAllTopics() {
// graphiteListener.register(get(urlMatching(TOPIC_URL_PATTERN))
// .willReturn(aResponse()
// .withStatus(500)
// .withHeader("Content-Type", "application/json")
// )
// );
// }
//
// public void returnMetric(SubscriptionMetricsStubDefinition metricsStubDefinition) {
// graphiteListener.register(get(urlMatching(metricsStubDefinition.toUrlPattern()))
// .willReturn(aResponse()
// .withStatus(200)
// .withHeader("Content-Type", "application/json")
// .withBody(metricsStubDefinition.toBody())));
// }
//
// public void returnMetricWithDelay(SubscriptionMetricsStubDefinition metricsStubDefinition, int responseDelayInMs) {
// graphiteListener.register(get(urlMatching(metricsStubDefinition.toUrlPattern()))
// .willReturn(aResponse()
// .withFixedDelay(responseDelayInMs)
// .withStatus(200)
// .withHeader("Content-Type", "application/json")
// .withBody(metricsStubDefinition.toBody())));
// }
//
// private static class SubscriptionMetricsStubDefinition {
// private final String subscription;
// private final List<GraphiteStubResponse> responseBody;
//
// private SubscriptionMetricsStubDefinition(String subscription, List<GraphiteStubResponse> responseBody) {
// this.subscription = subscription;
// this.responseBody = responseBody;
// }
//
// private String toUrlPattern() {
// return "/.*sumSeries%28stats.tech.hermes\\.consumer\\.%2A\\.meter\\." + subscription + "\\.m1_rate%29.*";
// }
//
// private String toBody() {
// try {
// return new ObjectMapper().writeValueAsString(responseBody);
// } catch (JsonProcessingException e) {
// throw new RuntimeException(e);
// }
// }
// }
//
// public static class SubscriptionMetricsStubDefinitionBuilder {
// private final String subscription;
// private final List<GraphiteStubResponse> response = new ArrayList<>();
//
// private SubscriptionMetricsStubDefinitionBuilder(String subscription) {
// this.subscription = subscription;
// }
//
// public SubscriptionMetricsStubDefinitionBuilder withRate(int rate) {
// String target = "sumSeries(stats.tech.hermes.consumer.*.meter." + subscription + ".m1_rate)";
// response.add(new GraphiteStubResponse(target, dataPointOf(rate)));
// return this;
// }
//
// public SubscriptionMetricsStubDefinitionBuilder withThroughput(int rate) {
// String target = "sumSeries(stats.tech.hermes.consumer.*.throughput." + subscription + ".m1_rate)";
// response.add(new GraphiteStubResponse(target, dataPointOf(rate)));
// return this;
// }
//
// public SubscriptionMetricsStubDefinitionBuilder withStatusRate(int httpStatus, int rate) {
// String statusFamily = httpStatusFamily(httpStatus);
// String target = "sumSeries(stats.tech.hermes.consumer.*.status." + subscription + "." + statusFamily + ".m1_rate)";
// response.add(new GraphiteStubResponse(target, dataPointOf(rate)));
// return this;
// }
//
// public SubscriptionMetricsStubDefinition build() {
// return new SubscriptionMetricsStubDefinition(subscription, response);
// }
//
// private String httpStatusFamily(int statusCode) {
// return format("%dxx", statusCode / 100);
// }
//
// private static List<List<Object>> dataPointOf(int rate) {
// return singletonList(asList(rate, TIMESTAMP));
// }
// }
//
// public static SubscriptionMetricsStubDefinitionBuilder subscriptionMetricsStub(String subscription) {
// return new SubscriptionMetricsStubDefinitionBuilder(subscription);
// }

String writeToString(Object o) {
try {
return objectMapper.writeValueAsString(o);
Expand All @@ -202,27 +143,58 @@ String writeToString(Object o) {
}
}

record PrometheusResponse(@JsonProperty("status") String status,
@JsonProperty("data") Data data) {
public record PrometheusTopicResponse(int topicRate, int deliveredRate, int throughput) {
}

public record PrometheusSubscriptionResponse(int rate, List<SubscriptionStatusCode> statusCodes) {
}

public record SubscriptionStatusCode(String code, int rate) {
}

public static class PrometheusSubscriptionResponseBuilder {
private int rate = 0;
private final List<SubscriptionStatusCode> statusCodes = new ArrayList<>();

boolean isSuccess() {
return status.equals("success") && data.isVector();
private PrometheusSubscriptionResponseBuilder() {
}

public static PrometheusSubscriptionResponseBuilder builder() {
return new PrometheusSubscriptionResponseBuilder();
}

public PrometheusSubscriptionResponseBuilder withRate(int rate) {
this.rate = rate;
return this;
}

public PrometheusSubscriptionResponseBuilder withRatedStatusCode(String statusCode, int rate) {
this.statusCodes.add(new SubscriptionStatusCode(statusCode, rate));
return this;
}

public PrometheusSubscriptionResponse build() {
return new PrometheusSubscriptionResponse(rate, statusCodes);
}
}

record PrometheusResponse(@JsonProperty("status") String status,
@JsonProperty("data") Data data) {

record Data(@JsonProperty("resultType") String resultType,
@JsonProperty("result") List<Result> results) {
boolean isVector() {
return resultType.equals("vector");
}
}

record Result(
@JsonProperty("metric") MetricName metricName,
@JsonProperty("value") List<String> values) {
}

@JsonInclude(JsonInclude.Include.NON_NULL)
record MetricName(
@JsonProperty(value = "__name__") String name) {
@JsonProperty(value = "__name__") String name,
@JsonProperty(value = "status_code") String statusCode
) {
}
}
}
Loading

0 comments on commit ae06e6c

Please sign in to comment.