Skip to content

Commit

Permalink
merge: #9257
Browse files Browse the repository at this point in the history
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
zeebe-bors-camunda[bot] and pihme committed May 2, 2022
2 parents 5c029be + a1a5c65 commit 706e7f9
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
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
<dependency>
<groupId>io.camunda</groupId>
<artifactId>zeebe-util</artifactId>
Expand Down
Original file line number Diff line number Diff line change
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
+ '}';
}
}
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);
}
}
5 changes: 5 additions & 0 deletions util/pom.xml
Original file line number Diff line number Diff line change
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
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 util/src/test/java/io/camunda/zeebe/util/FeatureFlagsTest.java
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();
}
}

0 comments on commit 706e7f9

Please sign in to comment.