-
Notifications
You must be signed in to change notification settings - Fork 555
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
9257: feat(broker): add feature flag template r=pihme a=pihme ## Description Adds template to add feature flags. The template consists of two parts: * `FeatureFlags` to hold the flags and default values. Visible in most of the code base * `FeatureFlagsCfg` to make feature flags configurable. Instances of this class can be used to obtain a `FeatureFlags` object ## Review Hints * I did try to implement reflection based tests to check that e.g. the cfg object and the feature flags object have the same getters, and that values are passed in correctly. However, this spiraled out of control into a big chunk of over-engineered tests. So I dropped these completely * Secondly there are often config tests like `ExperimentalCfgTest` not sure if these add value. Let me know if you miss them as part of the template * Overall, this is a minimal implementation. Please let me know if you want to change any names or such things. ## Related issues closes #9254 Co-authored-by: pihme <pihme@users.noreply.github.com>
- Loading branch information
Showing
6 changed files
with
128 additions
and
0 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
41 changes: 41 additions & 0 deletions
41
broker/src/main/java/io/camunda/zeebe/broker/system/configuration/FeatureFlagsCfg.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,41 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under | ||
* one or more contributor license agreements. See the NOTICE file distributed | ||
* with this work for additional information regarding copyright ownership. | ||
* Licensed under the Zeebe Community License 1.1. You may not use this file | ||
* except in compliance with the Zeebe Community License 1.1. | ||
*/ | ||
package io.camunda.zeebe.broker.system.configuration; | ||
|
||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import io.camunda.zeebe.util.FeatureFlags; | ||
import org.apache.commons.lang3.builder.ToStringBuilder; | ||
import org.apache.commons.lang3.builder.ToStringStyle; | ||
|
||
@JsonSerialize // this annotation seems to implicitly disable | ||
// SerializationFeature.FAIL_ON_EMPTY_BEANS | ||
public final class FeatureFlagsCfg { | ||
|
||
// To add a new feature flag, read the comments in FeatureFlags | ||
|
||
private static final FeatureFlags DEFAULT_SETTINGS = FeatureFlags.createDefault(); | ||
// | ||
// private boolean enableFoo = DEFAULT_SETTINGS.foo(); | ||
// | ||
// public boolean isEnableFoo() { | ||
// return enableFoo; | ||
// } | ||
// | ||
// public void setEnableFoo(final boolean enableFoo) { | ||
// this.enableFoo = enableFoo; | ||
// } | ||
|
||
FeatureFlags toFeatureFlags() { | ||
return new FeatureFlags(/*enableFoo*/ ); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); | ||
} | ||
} |
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
44 changes: 44 additions & 0 deletions
44
util/src/main/java/io/camunda/zeebe/util/FeatureFlags.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,44 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under | ||
* one or more contributor license agreements. See the NOTICE file distributed | ||
* with this work for additional information regarding copyright ownership. | ||
* Licensed under the Zeebe Community License 1.1. You may not use this file | ||
* except in compliance with the Zeebe Community License 1.1. | ||
*/ | ||
package io.camunda.zeebe.util; | ||
|
||
import org.apache.commons.lang3.builder.ToStringBuilder; | ||
import org.apache.commons.lang3.builder.ToStringStyle; | ||
|
||
public record FeatureFlags(/*boolean foo*/ ) { | ||
|
||
/* To add a new feature toggle, please follow these steps: | ||
* | ||
* - add a record property to this class, and extend the test for this class | ||
* | ||
* - define the default value. When introducing a new feature flag the default | ||
* value should be 'false'. This way the feature is disabled by default | ||
* for all customers who do not change their configuration. | ||
* As we gain more confidence in the efficacy of the feature flag, the | ||
* default value can be set to 'true' | ||
* | ||
* - add a field, getter and setter to FeatureFlagsCfg | ||
* | ||
* - add a description of the feature flag to | ||
* - dist/src/main/config/broker.standalone.yaml.template | ||
* - dist/src/main/config/broker.yaml.template | ||
* | ||
* Be careful with parameter order in constructor calls! | ||
*/ | ||
|
||
// protected static final boolean FOO_DEFAULT = false; | ||
// | ||
public static FeatureFlags createDefault() { | ||
return new FeatureFlags(/*FOO_DEFAULT*/ ); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
util/src/test/java/io/camunda/zeebe/util/FeatureFlagsTest.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,22 @@ | ||
/* | ||
* Copyright Camunda Services GmbH and/or licensed to Camunda Services GmbH under | ||
* one or more contributor license agreements. See the NOTICE file distributed | ||
* with this work for additional information regarding copyright ownership. | ||
* Licensed under the Zeebe Community License 1.1. You may not use this file | ||
* except in compliance with the Zeebe Community License 1.1. | ||
*/ | ||
package io.camunda.zeebe.util; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class FeatureFlagsTest { | ||
|
||
@Test | ||
void testDefaultValues() { | ||
// given | ||
final var sut = FeatureFlags.createDefault(); | ||
|
||
// then | ||
// assertThat(sut.foo()).isFalse(); | ||
} | ||
} |