Skip to content

Commit

Permalink
merge: #9274
Browse files Browse the repository at this point in the history
9274: [Backport stable/8.0] feat(broker): add feature flag template r=pihme a=github-actions[bot]

# Description
Backport of #9257 to `stable/8.0`.

relates to #9254

Co-authored-by: pihme <pihme@users.noreply.github.com>
  • Loading branch information
zeebe-bors-camunda[bot] and pihme committed May 3, 2022
2 parents d91a276 + 1aba23c commit f7d5b0a
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 0 deletions.
4 changes: 4 additions & 0 deletions broker/pom.xml
Expand Up @@ -227,6 +227,10 @@
<groupId>uk.co.real-logic</groupId>
<artifactId>sbe-tool</artifactId>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>io.camunda</groupId>
<artifactId>zeebe-util</artifactId>
Expand Down
Expand Up @@ -30,6 +30,8 @@ public class ExperimentalCfg implements ConfigurationEntry {
private QueryApiCfg queryApi = new QueryApiCfg();
private ConsistencyCheckCfg consistencyChecks = new ConsistencyCheckCfg();

private FeatureFlagsCfg features = new FeatureFlagsCfg();

@Override
public void init(final BrokerCfg globalConfig, final String brokerBase) {
rocksdb.init(globalConfig, brokerBase);
Expand Down Expand Up @@ -104,6 +106,14 @@ public void setConsistencyChecks(final ConsistencyCheckCfg consistencyChecks) {
this.consistencyChecks = consistencyChecks;
}

public FeatureFlagsCfg getFeatures() {
return features;
}

public void setFeatures(final FeatureFlagsCfg features) {
this.features = features;
}

@Override
public String toString() {
return "ExperimentalCfg{"
Expand All @@ -121,6 +131,8 @@ public String toString() {
+ queryApi
+ ", consistencyChecks="
+ consistencyChecks
+ ", features="
+ features
+ '}';
}
}
@@ -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);
}
}
5 changes: 5 additions & 0 deletions util/pom.xml
Expand Up @@ -81,6 +81,11 @@
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
44 changes: 44 additions & 0 deletions util/src/main/java/io/camunda/zeebe/util/FeatureFlags.java
@@ -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 util/src/test/java/io/camunda/zeebe/util/FeatureFlagsTest.java
@@ -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();
}
}

0 comments on commit f7d5b0a

Please sign in to comment.