forked from RedHatInsights/notifications-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RHCLOUD-31503 Log Unleash toggles changes in all apps
- Loading branch information
Showing
9 changed files
with
148 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
common-unleash/src/main/java/com/redhat/cloud/notifications/unleash/ToggleRegistry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.redhat.cloud.notifications.unleash; | ||
|
||
import io.quarkus.logging.Log; | ||
import io.quarkus.runtime.ApplicationConfig; | ||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
@ApplicationScoped | ||
public class ToggleRegistry { | ||
|
||
private static final String DEFAULT_APP_NAME = "notifications-default-app-name"; | ||
|
||
@Inject | ||
ApplicationConfig applicationConfig; | ||
|
||
private final Set<String> loggedToggles = new HashSet<>(); | ||
|
||
public String register(String feature, boolean logChanges) { | ||
|
||
if (applicationConfig == null) { | ||
throw new IllegalStateException("This method must be called after CDI is done initializing"); | ||
} | ||
|
||
String appName = applicationConfig.name.orElseGet(() -> { | ||
// This should only happen when tests are executed. | ||
Log.warnf("Application name not found in the Quarkus config, defaulting to %s", DEFAULT_APP_NAME); | ||
return DEFAULT_APP_NAME; | ||
}); | ||
|
||
String toggleName = String.format("%s.%s.enabled", appName, feature); | ||
|
||
if (logChanges) { | ||
loggedToggles.add(toggleName); | ||
} | ||
|
||
return toggleName; | ||
} | ||
|
||
public Set<String> getLoggedToggles() { | ||
return loggedToggles; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.