1
1
# Dropwizard Openfeature
2
2
3
- This plugin integrates [ openfeature] ( https://openfeature.dev/ ) with dropwizard and allows you to use openfeature feature
3
+ This plugin integrates [ openfeature] [ 1 ] with dropwizard and allows you to use openfeature feature
4
4
flags, provided by supported openfeature providers via a managed ` OpenFeatureAPI ` instance.
5
5
6
- Currently only [ flagd] ( https://flagd.dev/ ) and the SDKs
7
- [ InMemoryProvider] ( https://github.com/open-feature/java-sdk/blob/main/src/main/java/dev/openfeature/sdk/providers/memory/InMemoryProvider.java )
8
- providers are supported
6
+ Currently only [ flagd] [ 2 ] and the SDKs [ InMemoryProvider] [ 3 ] providers are supported
9
7
10
- ## Installing the bundle from source code
8
+ ## Installing the bundle
9
+
10
+ ### Releases from maven central
11
+
12
+ [ io.github.sideshowcoder/dropwizard-openfeature] [ 4 ]
13
+
14
+ ``` xml
15
+ <dependency >
16
+ <groupId >io.github.sideshowcoder</groupId >
17
+ <artifactId >dropwizard-openfeature</artifactId >
18
+ <version >0.0.2</version >
19
+ </dependency >
20
+ ```
21
+
22
+ ### Snapshots form source
11
23
12
24
```
13
25
git clone https://github.com/sideshowcoder/dropwizard-openfeature
14
26
cd dropwizard-openfeature
15
27
./mvn install
16
28
```
17
29
18
- After installing the plugin locally you can include it in your pom.xml
30
+ After installing the plugin locally you can include it in your ` pom.xml `
19
31
20
32
``` xml
21
33
<dependency >
22
34
<groupId >io.github.sideshowcoder</groupId >
23
35
<artifactId >dropwizard-openfeature</artifactId >
24
- <version >$VERSION </version >
36
+ <version >0.0.3-SNAPSHOT </version >
25
37
</dependency >
26
38
```
27
39
40
+
41
+
28
42
## Included in the bundle
29
43
30
44
### Supported providers
31
45
32
46
The bundle currently supports both the SDK included ` InMemoryProvider ` as well as ` flagd ` , the provider can be selected
33
47
via the configuration. For details on the configuration options see ` FlagdConfiguration ` as well the
34
- [ flagd documentation] ( https://flagd.dev/providers/java/ ) .
48
+ [ flagd documentation] [ 5 ] .
35
49
36
50
### OpenFeatureAPI management
37
51
38
- The initialized ` OpenFeatureAPI ` is managed via the dropwizard lifecycle.
52
+ The initialized ` OpenFeatureAPI ` is managed via the dropwizard lifecycle and will be shutdown gracefully upon
53
+ application shutdown, see ` OpenFeatureAPIManager ` .
39
54
40
55
### Healthcheck
41
56
42
57
By default the bundle registers a healthcheck on the state of the provider configured, this healthcheck can be further
43
58
configured via the ` OpenFeatureHealthCheckConfiguration ` .
44
59
45
- ## Activating the bundle: Configuration
60
+ ## Activating the bundle
46
61
47
- Your Dropwizard application configuration class must implement ` OpenFeatureBundleConfiguration ` :
62
+ Your Dropwizard application configuration class must implement ` OpenFeatureBundleConfiguration `
48
63
49
- ## Configuring dropwizard-openfeature in the dropwizard config file
64
+ ### Configuring dropwizard-openfeature in the dropwizard config file
50
65
51
66
For a full overview see ` OpenFeatureConfiguration ` , ` OpenFeatureHealthCheckConfiguration ` , and ` FlagdConfiguration ` a
52
67
minimal configuration for flagd runnining locally on the port 8013 would look as follows.
@@ -63,9 +78,7 @@ For the bundle to have access to the configuration, your application configurati
63
78
` OpenFeatureBundleConfiguration`.
64
79
65
80
` ` ` java
66
- import io.github.sideshowcoder.dropwizard_openfeature.OpenFeatureConfiguration;
67
-
68
- public class ApplicationConfiguration implements OpenFeatureBundleConfiguration {
81
+ public class Config extends Configuration implements OpenFeatureBundleConfiguration {
69
82
70
83
@Valid
71
84
@NotNull
@@ -79,18 +92,86 @@ public class ApplicationConfiguration implements OpenFeatureBundleConfiguration
79
92
}
80
93
` ` `
81
94
82
- # # Activating the bundle: Initialization
95
+ # ## Initialization
83
96
84
97
In your application's `initialize` method, call `bootstrap.addBundle(new OpenFeatureBundle())` :
85
98
86
99
` ` ` java
87
- import io.github.sideshowcoder.dropwizard_openfeature.OpenFeatureBundle;
100
+ public class App extends Application<Config> {
101
+
102
+ @Override
103
+ public void initialize(Bootstrap<MyConfiguration> bootstrap) {
104
+ bootstrap.addBundle(new OpenFeatureBundle());
105
+ }
88
106
89
- @Override
90
- public void initialize(Bootstrap<MyConfiguration> bootstrap) {
91
- bootstrap.addBundle(new OpenFeatureBundle());
107
+ @Override
108
+ public void run(Config config, Environment environment) throws Exception {
109
+ /* ... */
110
+ }
111
+ }
112
+ ` ` `
113
+
114
+ # ## Using the client
115
+
116
+ OpenFeature configures a global `OpenFeatureAPI` which grants access to a client, which can be injected as needed, it is
117
+ common practise to provide a domain as an identifier, this is however not required, unless multiple clients are to be
118
+ created.
119
+
120
+ ` ` ` java
121
+ public class App extends Application<Config> {
122
+
123
+ @Override
124
+ public void initialize(Bootstrap<MyConfiguration> bootstrap) {
125
+ bootstrap.addBundle(new OpenFeatureBundle());
126
+ }
127
+
128
+ @Override
129
+ public void run(Config config, Environment environment) throws Exception {
130
+ /* ... */
131
+ var client = OpenFeatureAPI.getInstance().getClient("my-application-domain");
132
+
133
+ var myResource = new MyResource(client);
134
+ environment.jersey().register(myResource);
135
+
136
+ var myOtherResource = new MyOtherResource(client);
137
+ environment.jersey().register(myResource);
138
+ /* ... */
139
+ }
140
+ }
141
+ ` ` `
142
+
143
+ # ## Accessing the underlying feature provider
144
+
145
+ The bundle exposes access to the underlying feature provider. Useful for runtime configuration and introspection of the
146
+ provider. For example when using the `InMemoryProvider` flags can be updated at runtime for example for testing.
147
+
148
+ ` ` ` java
149
+ public class App extends Application<Config> {
150
+
151
+ private OpenFeatureBundle bundle;
152
+ private InMemoryProvider provider;
153
+
154
+ @Override
155
+ public void initialize(Bootstrap<MyConfiguration> bootstrap) {
156
+ bundle = new OpenFeatureBundle();
157
+ bootstrap.addBundle(bundle);
158
+ }
159
+
160
+ @Override
161
+ public void run(Config config, Environment environment) throws Exception {
162
+ // ...
163
+ provider = (InMemoryProvider) bundle.getFeatureProvider();
164
+ provider.updateFlags(Map.of(/* ... */));
165
+ // ...
166
+ }
92
167
}
93
168
` ` `
94
169
95
170
# Contributors
96
171
* [Philipp Fehre](https://github.com/sideshowcoder)
172
+
173
+ [1] : https://openfeature.dev/
174
+ [2] : https://flagd.dev/
175
+ [3] : https://github.com/open-feature/java-sdk/blob/main/src/main/java/dev/openfeature/sdk/providers/memory/InMemoryProvider.java
176
+ [4] : https://central.sonatype.com/artifact/io.github.sideshowcoder/dropwizard-openfeature
177
+ [5] : https://flagd.dev/providers/java/
0 commit comments