Skip to content

Commit

Permalink
Add boolean meta flag for response only nodes
Browse files Browse the repository at this point in the history
* fixes #21
  • Loading branch information
olle committed May 15, 2020
1 parent a9479b5 commit 87180dd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.LinkedList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicLong;
import java.util.function.Supplier;
import java.util.stream.Collectors;
Expand All @@ -45,6 +46,7 @@ class Statistics implements Logging {
private static final String META_NAME = "name";
private static final String META_UPTIME = "uptime";
private static final String META_HOSTNAME = "host";
private static final String META_RESPONSES = "only_responses";

private static final String STAT_COUNT_QUERIES = "count_queries";
private static final String STAT_COUNT_CONSUMED_RESPONSES = "count_consumed_responses";
Expand All @@ -68,6 +70,8 @@ class Statistics implements Logging {
private AtomicLong lastPublishedQueriesCount = new AtomicLong(0);
private AtomicLong lastPublishedResponsesCount = new AtomicLong(0);

protected final AtomicBoolean onlyResponses = new AtomicBoolean(true);

protected Supplier<String> pidSupplier = () -> getPidOrDefault("-");
protected Supplier<String> nameSupplier = () -> getApplicationNameOrDefault("application");
protected Supplier<String> hostSupplier = () -> getHostnameOrDefault("unknown");
Expand Down Expand Up @@ -102,6 +106,7 @@ protected Collection<Stat> getStats() {
getMeta(META_HOSTNAME, hostSupplier.get()), // NOSONAR
getMeta(META_PID, pidSupplier.get()), // NOSONAR
getMeta(META_UPTIME, uptimeSupplier.get()), // NOSONAR
getMeta(META_RESPONSES, onlyResponses.get()), // NOSONAR
getMaxLatencyStat(), // NOSONAR
getMinLatencyStat(), // NOSONAR
getAvgLatencyStat(), // NOSONAR
Expand Down Expand Up @@ -244,6 +249,7 @@ protected String getApplicationNameOrDefault(String defaults) {

public void incrementPublishedQueriesCounter() {

onlyResponses.compareAndExchange(true, false);
this.publishedQueriesCount.incrementAndGet();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,29 @@ void ensureBuildsResponseOnApplicationReady() throws InterruptedException {
}


@Test
void ensureMetaWithPublishingOnlyStatus() throws Exception {

ResponseRegistry.instance = () -> registry;

var env = new MockEnvironment();
var sut = new Statistics(env, ctx);

var key = "only_responses";
Stat s1 = sut.getStats().stream().filter(s -> key.equals(s.key)).findFirst().get();

assertThat(s1.value).isEqualTo(true);
assertThat(s1.uuid).isEqualTo(sut.uuid);

sut.onlyResponses.set(false);

Stat s2 = sut.getStats().stream().filter(s -> key.equals(s.key)).findFirst().get();
assertThat(s2.value).isEqualTo(false);

ResponseRegistry.instance = () -> null;
}


@Test
void ensureMetaWithPidPartOfStats() throws Exception {

Expand Down

0 comments on commit 87180dd

Please sign in to comment.