Skip to content

Commit

Permalink
#5 - Deprecate InsightClient.create() in favour of InsightClient.buil…
Browse files Browse the repository at this point in the history
…der()
  • Loading branch information
rbygrave committed Feb 8, 2023
1 parent 7b1d8fa commit b84217f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
33 changes: 32 additions & 1 deletion client/src/main/java/io/ebean/insight/InsightClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,16 @@
/**
* Client that collects Ebean metrics and Avaje metrics for
* sending to the monitoring service.
*
* <pre>{@code
*
* final InsightClient client = InsightClient.builder()
* .appName("myapp")
* .environment("dev")
* .key("YeahNah")
* .build();
*
* }</pre>
*/
public class InsightClient {

Expand Down Expand Up @@ -51,10 +61,31 @@ public class InsightClient {
private long collectMicros;
private long reportMicros;

public static InsightClient.Builder create() {
/**
* Create a new builder for InsightClient.
*
* <pre>{@code
*
* final InsightClient client = InsightClient.builder()
* .appName("myapp")
* .environment("dev")
* .key("YeahNah")
* .build();
*
* }</pre>
*/
public static InsightClient.Builder builder() {
return new InsightClient.Builder();
}

/**
* Deprecated - migrate to {@link #builder()}
*/
@Deprecated
public static InsightClient.Builder create() {
return builder();
}

private InsightClient(Builder builder) {
this.enabled = builder.enabled();
this.ingestUri = URI.create(builder.url + "/api/ingest/metrics");
Expand Down
28 changes: 14 additions & 14 deletions client/src/test/java/io/ebean/insight/InsightClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ void create() throws InterruptedException {
.registerJvmMetrics()
.registerLogbackMetrics();

final InsightClient client = InsightClient.create()
final InsightClient client = InsightClient.builder()
//.url("http://localhost:8090")
.periodSecs(5)
.appName("test")
Expand All @@ -44,7 +44,7 @@ void pingFailed_expect_notStarted() throws InterruptedException {
MetricManager.jvmMetrics()
.registerJvmMetrics();

final InsightClient client = InsightClient.create()
final InsightClient client = InsightClient.builder()
.url("http://doesNotExist:8090")
.periodSecs(1)
.appName("test")
Expand All @@ -65,36 +65,36 @@ void pingFailed_expect_notStarted() throws InterruptedException {
void notEnabled_when_keyNotValid() {

// not valid keys
assertThat(InsightClient.create().key(null).enabled()).isFalse();
assertThat(InsightClient.create().key("").enabled()).isFalse();
assertThat(InsightClient.create().key(" ").enabled()).isFalse();
assertThat(InsightClient.create().key("none").enabled()).isFalse();
assertThat(InsightClient.builder().key(null).enabled()).isFalse();
assertThat(InsightClient.builder().key("").enabled()).isFalse();
assertThat(InsightClient.builder().key(" ").enabled()).isFalse();
assertThat(InsightClient.builder().key("none").enabled()).isFalse();

// valid
assertThat(InsightClient.create().key("foo").enabled()).isTrue();
assertThat(InsightClient.builder().key("foo").enabled()).isTrue();
}

@Test
void notEnabled_when_systemPropertySet() {
assertThat(InsightClient.create().key("foo").enabled()).isTrue();
assertThat(InsightClient.builder().key("foo").enabled()).isTrue();

Config.setProperty("ebean.insight.enabled", "false");
assertThat(InsightClient.create().key("foo").enabled()).isFalse();
assertThat(InsightClient.builder().key("foo").enabled()).isFalse();

Config.setProperty("ebean.insight.enabled", "true");
assertThat(InsightClient.create().key("foo").enabled()).isTrue();
assertThat(InsightClient.builder().key("foo").enabled()).isTrue();
}

@Test
void enabled() {
assertThat(InsightClient.create().key("foo").enabled(true).enabled()).isTrue();
assertThat(InsightClient.create().key("foo").enabled(false).enabled()).isFalse();
assertThat(InsightClient.create().key("foo").enabled()).isTrue();
assertThat(InsightClient.builder().key("foo").enabled(true).enabled()).isTrue();
assertThat(InsightClient.builder().key("foo").enabled(false).enabled()).isFalse();
assertThat(InsightClient.builder().key("foo").enabled()).isTrue();
}

@Test
void buildJsonContent() {
InsightClient client = InsightClient.create()
InsightClient client = InsightClient.builder()
.collectEbeanMetrics(false)
.collectAvajeMetrics(false)
.build();
Expand Down

0 comments on commit b84217f

Please sign in to comment.