Skip to content

Commit

Permalink
docs: Update README to reflect how appName can be used for metrics (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonctoms authored Apr 12, 2024
1 parent 5e96dd0 commit 54fe483
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ build
*.ipr
*.iws
bin/

# Ignore local gradle properties
local.properties
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,13 @@ You should use a singleton pattern to avoid file contention on cache directory.
#### Step 3a: Unleash Context

The important properties to configure on the context are
* Appname - In case you use strategies that depend on which app
* UserId - GradualRolloutStrategies often use this to decide stickiness when assigning which group of users the user end up in
* SessionId - GradualRolloutStrategies often use this to decide stickiness

```kotlin
import io.getunleash.UnleashContext

val context = UnleashContext.newBuilder()
.appName("Your AppName")
.userId("However you resolve your userid")
.sessionId("However you resolve your session id")
.build()
Expand All @@ -67,6 +65,7 @@ val context = UnleashContext.newBuilder()
#### Step 3b: Unleash Config
To create a client, use the UnleashConfig.newBuilder method. When building a configuration, you'll need to provide it with:

- `appName`: the name of the application to be used in strategies and metrics
- `proxyUrl`: the URL the Unleash front-end API is available at **OR** the URL your proxy is available at
- `clientKey`: the API token or proxy client key you wish to use (this method was known as clientSecret prior to version 0.4.0)
- `pollMode`: how you want to load the toggle status
Expand All @@ -87,6 +86,7 @@ Configuring a client with a 60 seconds poll interval:

```kotlin
val config = UnleashConfig.newBuilder()
.appName("Your AppName")
.proxyUrl("URL to your front-end API or proxy")
.clientKey("your front-end API token or proxy client key")
.pollingMode(PollingModes.autoPoll(60) { // poll interval in seconds
Expand All @@ -107,6 +107,7 @@ val toggles = File("/tmp/proxyresponse.json")
val pollingMode = PollingModes.fileMode(toggles)

val config = UnleashConfig.newBuilder()
.appName("Your AppName")
.proxyUrl("Doesn't matter since we don't use it when sent a file")
.clientKey("Doesn't matter since we don't use it when sent a file")
.pollMode(pollingMode)
Expand Down Expand Up @@ -136,11 +137,11 @@ The listener is a no-argument lambda that gets called by the RefreshPolicy for e
Example usage is equal to the `Example setup` above
```kotlin
val context = UnleashContext.newBuilder()
.appName("Your AppName")
.userId("However you resolve your userid")
.sessionId("However you resolve your session id")
.build()
val config = UnleashConfig.newBuilder()
.appName("Your AppName")
.proxyUrl("URL to your front-end API or proxy")
.clientKey("your front-end API token or proxy client key")
.pollingMode(PollingModes.autoPoll(60) { // poll interval in seconds
Expand All @@ -159,11 +160,11 @@ The following example shows how to use it, provided the file to use is located a
val toggles = File("/tmp/proxyresponse.json")
val pollingMode = PollingModes.fileMode(toggles)
val context = UnleashContext.newBuilder()
.appName("Your AppName")
.userId("However you resolve your userid")
.sessionId("However you resolve your session id")
.build()
val config = UnleashConfig.newBuilder()
.appName("Your AppName")
.proxyUrl("URL to your front-end API or proxy") // These two don't matter for FilePolling,
.clientKey("front-end API token / proxy client key") // since the client never speaks to the proxy
.pollingMode(pollingMode)
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/io/getunleash/UnleashConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ data class ReportMetrics(
* Represents configuration for Unleash.
* @property proxyUrl HTTP(s) URL to the Unleash Proxy (Required).
* @property clientKey the key added as the Authorization header sent to the unleash-proxy (Required)
* @property appName: name of the underlying application. Will be used as default in the [io.getunleash.UnleashContext] call (Required).
* @property appName: name of the underlying application. Will be used as default in the [io.getunleash.UnleashContext] call (Optional - Defaults to 'unknown').
* @property environment which environment is the application running in. Will be used as default argument for the [io.getunleash.UnleashContext]. (Optional - Defaults to 'default')
* @property instanceId instance id of your client
* @property pollingMode How to poll for features. Defaults to [io.getunleash.polling.AutoPollingMode] with poll interval set to 60 seconds.
Expand Down
6 changes: 2 additions & 4 deletions src/main/kotlin/io/getunleash/UnleashContext.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ package io.getunleash
* @property remoteAddress the Ip address of the client. If your feature uses the remoteAddress strategy
* you'll need to set this
* @property properties - Other properties for custom strategies.
* @property appName - The name of your app - mostly used for metrics server side, but someone might use this to
* evaluate a strategy as well
* @property environment - Which environment are you running in? Not currently supported server side
* (per Unleash-server v4.0.0), but support is coming, and can be used for custom strategies
* @property appName - The name of your app, used for evaluating strategies - defaults to the one set in the [io.getunleash.UnleashConfig]
* @property environment - Which environment are you running in - defaults to the one set in the [io.getunleash.UnleashConfig]
*/
data class UnleashContext(
val userId: String? = null,
Expand Down

0 comments on commit 54fe483

Please sign in to comment.