Skip to content

Commit

Permalink
Merge pull request #60 from snicoll/gh-57
Browse files Browse the repository at this point in the history
Disable account negotiation if metric exports is disabled
  • Loading branch information
snicoll committed Jun 4, 2020
2 parents 38dd0ef + ce2c2dc commit 3a9014f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public AccountManagementClient accountManagementClient(RestTemplateBuilder restT
WavefrontController wavefrontController(WavefrontProperties properties,
AccountManagementClient accountManagementClient, WavefrontConfig wavefrontConfig,
ApplicationTags applicationTags) {
if (properties.isFreemiumAccount()) {
if (Boolean.TRUE.equals(properties.getFreemiumAccount())) {
return new WavefrontController(new OneTimeDashboardUrlSupplier(
accountManagementClient, wavefrontConfig, applicationTags));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@
class AccountManagementEnvironmentPostProcessor
implements EnvironmentPostProcessor, ApplicationListener<SpringApplicationEvent> {

private static final String ENABLED_PROPERTY = "management.metrics.export.wavefront.enabled";

private static final String API_TOKEN_PROPERTY = "management.metrics.export.wavefront.api-token";

private static final String URI_PROPERTY = "management.metrics.export.wavefront.uri";
Expand Down Expand Up @@ -81,11 +83,11 @@ private boolean shouldRun(ConfigurableEnvironment environment) {
// Do not run in the bootstrap phase as the user configuration is not available yet
return false;
}
if (!environment.getProperty(FREEMIUM_ACCOUNT_PROPERTY, Boolean.class, true)) {
// freemium account explicit disabled
return false;
Boolean freemiumAccount = environment.getProperty(FREEMIUM_ACCOUNT_PROPERTY, Boolean.class);
if (freemiumAccount != null) {
return freemiumAccount;
}
return true;
return environment.getProperty(ENABLED_PROPERTY, Boolean.class, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
public class WavefrontProperties {

/**
* Whether a freemium account has to be configured.
* Whether the configured account is a freemium account. Can be enabled explicitly for
* user-configured freemium accounts that do not have a user yet. Can be disabled
* explicitly to prevent the account negotiation to kick-in.
*/
private boolean freemiumAccount;
private Boolean freemiumAccount;

private final Application application = new Application();

private final Tracing tracing = new Tracing();

public boolean isFreemiumAccount() {
public Boolean getFreemiumAccount() {
return this.freemiumAccount;
}

public void setFreemiumAccount(boolean freemiumAccount) {
public void setFreemiumAccount(Boolean freemiumAccount) {
this.freemiumAccount = freemiumAccount;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
@ExtendWith(OutputCaptureExtension.class)
class AccountManagementEnvironmentPostProcessorTests {

private static final String ENABLED_PROPERTY = "management.metrics.export.wavefront.enabled";

private static final String API_TOKEN_PROPERTY = "management.metrics.export.wavefront.api-token";

private static final String URI_PROPERTY = "management.metrics.export.wavefront.uri";
Expand All @@ -66,6 +68,15 @@ void accountProvisioningIsNotNeededWhenApiTokenIsNotNecessary() {
assertThat(environment.getProperty(FREEMIUM_ACCOUNT_PROPERTY)).isNull();
}

@Test
void accountProvisioningIsNotTriggeredWhenMetricsExportIsDisabled() {
MockEnvironment environment = new MockEnvironment().withProperty(ENABLED_PROPERTY, "false");
new AccountManagementEnvironmentPostProcessor().postProcessEnvironment(environment, this.application);
assertThat(environment.getProperty(API_TOKEN_PROPERTY)).isNull();
assertThat(environment.getProperty(URI_PROPERTY)).isNull();
assertThat(environment.getProperty(FREEMIUM_ACCOUNT_PROPERTY)).isNull();
}

@Test
void accountProvisioningIsNotTriggeredWhenFreemiumAccountFlagIsDisabled() {
MockEnvironment environment = new MockEnvironment().withProperty(FREEMIUM_ACCOUNT_PROPERTY, "false");
Expand All @@ -75,6 +86,18 @@ void accountProvisioningIsNotTriggeredWhenFreemiumAccountFlagIsDisabled() {
assertThat(environment.getProperty(FREEMIUM_ACCOUNT_PROPERTY)).isEqualTo("false");
}

@Test
void accountProvisioningApplyIfMetricsExportIsDisabledAndFreemiumAccountFlagIsEnabled() throws IOException {
Resource apiTokenResource = mockApiTokenResource("abc-def");
MockEnvironment environment = new MockEnvironment().withProperty(ENABLED_PROPERTY, "false").withProperty(FREEMIUM_ACCOUNT_PROPERTY, "true");
TestAccountManagementEnvironmentPostProcessor postProcessor = TestAccountManagementEnvironmentPostProcessor
.forExistingAccount(apiTokenResource, () -> new AccountInfo("abc-def", "https://wavefront.surf/us/test1"));
postProcessor.postProcessEnvironment(environment, this.application);
assertThat(environment.getProperty(API_TOKEN_PROPERTY)).isEqualTo("abc-def");
assertThat(environment.getProperty(URI_PROPERTY)).isEqualTo("https://wavefront.surf");
assertThat(environment.getProperty(FREEMIUM_ACCOUNT_PROPERTY)).isEqualTo("true");
}

@Test
void configurationOfRegularAccountDoesNotRetrieveOneTimeLoginUrl(CapturedOutput output) {
MockEnvironment environment = new MockEnvironment().withProperty(API_TOKEN_PROPERTY, "test");
Expand Down

0 comments on commit 3a9014f

Please sign in to comment.