Skip to content

Commit ed3b327

Browse files
Merge pull request #6 from sideshowcoder/sideshowcoder/document-usage-and-access-to-feature-provider
docs: add docs for usage and access to FeatureProvider
2 parents c6d86cc + 9cccdc8 commit ed3b327

File tree

1 file changed

+101
-20
lines changed

1 file changed

+101
-20
lines changed

README.md

Lines changed: 101 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,67 @@
11
# Dropwizard Openfeature
22

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
44
flags, provided by supported openfeature providers via a managed `OpenFeatureAPI` instance.
55

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
97

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
1123

1224
```
1325
git clone https://github.com/sideshowcoder/dropwizard-openfeature
1426
cd dropwizard-openfeature
1527
./mvn install
1628
```
1729

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`
1931

2032
```xml
2133
<dependency>
2234
<groupId>io.github.sideshowcoder</groupId>
2335
<artifactId>dropwizard-openfeature</artifactId>
24-
<version>$VERSION</version>
36+
<version>0.0.3-SNAPSHOT</version>
2537
</dependency>
2638
```
2739

40+
41+
2842
## Included in the bundle
2943

3044
### Supported providers
3145

3246
The bundle currently supports both the SDK included `InMemoryProvider` as well as `flagd`, the provider can be selected
3347
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].
3549

3650
### OpenFeatureAPI management
3751

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`.
3954

4055
### Healthcheck
4156

4257
By default the bundle registers a healthcheck on the state of the provider configured, this healthcheck can be further
4358
configured via the `OpenFeatureHealthCheckConfiguration`.
4459

45-
## Activating the bundle: Configuration
60+
## Activating the bundle
4661

47-
Your Dropwizard application configuration class must implement `OpenFeatureBundleConfiguration`:
62+
Your Dropwizard application configuration class must implement `OpenFeatureBundleConfiguration`
4863

49-
## Configuring dropwizard-openfeature in the dropwizard config file
64+
### Configuring dropwizard-openfeature in the dropwizard config file
5065

5166
For a full overview see `OpenFeatureConfiguration`, `OpenFeatureHealthCheckConfiguration`, and `FlagdConfiguration` a
5267
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
6378
`OpenFeatureBundleConfiguration`.
6479

6580
```java
66-
import io.github.sideshowcoder.dropwizard_openfeature.OpenFeatureConfiguration;
67-
68-
public class ApplicationConfiguration implements OpenFeatureBundleConfiguration {
81+
public class Config extends Configuration implements OpenFeatureBundleConfiguration {
6982
7083
@Valid
7184
@NotNull
@@ -79,18 +92,86 @@ public class ApplicationConfiguration implements OpenFeatureBundleConfiguration
7992
}
8093
```
8194

82-
## Activating the bundle: Initialization
95+
### Initialization
8396

8497
In your application's `initialize` method, call `bootstrap.addBundle(new OpenFeatureBundle())`:
8598

8699
```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+
}
88106
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+
}
92167
}
93168
```
94169

95170
# Contributors
96171
* [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

Comments
 (0)