Skip to content

Commit

Permalink
Merge branch 'gm/gitops-example-fixes' of github.com:flipt-io/flipt-d…
Browse files Browse the repository at this point in the history
…ocs into gm/gitops-example-fixes
  • Loading branch information
GeorgeMac committed Dec 13, 2023
2 parents fd2f45a + 9084dfa commit c125ffb
Showing 1 changed file with 83 additions and 79 deletions.
162 changes: 83 additions & 79 deletions guides/get-going-with-gitops.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -93,27 +93,29 @@ We provide this evaluation call with a request containing the flags key, an enti
return
}

- bubbleSort(words)
+ flag, err := s.flipt.Evaluation().Boolean(r.Context(), &evaluation.EvaluationRequest{
+ FlagKey: "use-quicksort-algorithm",
+ EntityId: getUser(r.Context()),
+ Context: map[string]string{
+ "organization": getOrganization(r.Context()),
+ },
+ })
+
+ if flag.Enabled {
+ quicksort(words)
+ } else {
+ bubblesort(words)
+ }

if err := json.NewEncoder(w).Encode(words); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}
```
- bubbleSort(words)

* flag, err := s.flipt.Evaluation().Boolean(r.Context(), &evaluation.EvaluationRequest{
* FlagKey: "use-quicksort-algorithm",
* EntityId: getUser(r.Context()),
* Context: map[string]string{
* "organization": getOrganization(r.Context()),
* },
* })
*
* if flag.Enabled {
* quicksort(words)
* } else {
* bubblesort(words)
* }

if err := json.NewEncoder(w).Encode(words); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
}

````

```go pkg/server/words.go
func (s *Server) ListWords(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -142,7 +144,8 @@ func (s *Server) ListWords(w http.ResponseWriter, r *http.Request) {
return
}
}
```
````

</CodeGroup>

The entity ID used here is going to be an identifier for the requests authenticated user. This is returned by the call to `getUser(r.Context())`.
Expand Down Expand Up @@ -195,10 +198,10 @@ This flag will be a _boolean_ type flag and be in a disabled (`enabled = false`)
version: "1.2"
namespace: default
flags:
- key: use-quicksort-algorithm
name: Use Quicksort Algorithm
type: BOOLEAN_FLAG_TYPE
enabled: false
- key: use-quicksort-algorithm
name: Use Quicksort Algorithm
type: BOOLEAN_FLAG_TYPE
enabled: false
```
### Running Flipt Locally
Expand Down Expand Up @@ -324,23 +327,23 @@ We open the `features.yml` file and update the definition with a new segment and
version: "1.2"
namespace: default
flags:
- key: use-quicksort-algorithm
name: Use Quicksort Algorithm
type: BOOLEAN_FLAG_TYPE
enabled: false
rollouts:
- segment:
key: internal-users
value: true
- key: use-quicksort-algorithm
name: Use Quicksort Algorithm
type: BOOLEAN_FLAG_TYPE
enabled: false
rollouts:
- segment:
key: internal-users
value: true
segments:
- key: internal-users
name: Internal Users
match_type: ANY_MATCH_TYPE
constraints:
- property: organization
operator: eq
value: internal
type: STRING_COMPARISON_TYPE
- key: internal-users
name: Internal Users
match_type: ANY_MATCH_TYPE
constraints:
- property: organization
operator: eq
value: internal
type: STRING_COMPARISON_TYPE
```
</CodeGroup>
Expand All @@ -352,14 +355,14 @@ Breaking this change down we've got:
```yaml features.yml
# ...
segments:
- key: internal-users
name: Internal Users
match_type: ANY_MATCH_TYPE
constraints:
- property: organization
operator: eq
value: internal
type: STRING_COMPARISON_TYPE
- key: internal-users
name: Internal Users
match_type: ANY_MATCH_TYPE
constraints:
- property: organization
operator: eq
value: internal
type: STRING_COMPARISON_TYPE
```

This [segment](/concepts#segments) definition matches any evaluation request where there exists a key `organization` on the context, with a value `internal`.
Expand All @@ -372,12 +375,12 @@ Now, when the user happens to be associated with the `internal` organization, it

```yaml features.yml
flags:
- key: use-quicksort-algorithm
# ...
rollouts:
- segment:
key: internal-users
value: true
- key: use-quicksort-algorithm
# ...
rollouts:
- segment:
key: internal-users
value: true
```

Finally, we add a [rollout rule](/concepts#rollouts) to our boolean flag.
Expand Down Expand Up @@ -474,27 +477,28 @@ Then we're going to edit `features.yml` and add a threshold percentage rule.
version: "1.2"
namespace: default
flags:
- key: use-quicksort-algorithm
name: Use Quicksort Algorithm
type: BOOLEAN_FLAG_TYPE
enabled: false
rollouts:
- segment:
key: internal-users
value: true
- threshold:
percentage: 20
value: true
- key: use-quicksort-algorithm
name: Use Quicksort Algorithm
type: BOOLEAN_FLAG_TYPE
enabled: false
rollouts:
- segment:
key: internal-users
value: true
- threshold:
percentage: 20
value: true
segments:
- key: internal-users
name: Internal Users
match_type: ANY_MATCH_TYPE
constraints:
- property: organization
operator: eq
value: internal
type: STRING_COMPARISON_TYPE
- key: internal-users
name: Internal Users
match_type: ANY_MATCH_TYPE
constraints:
- property: organization
operator: eq
value: internal
type: STRING_COMPARISON_TYPE
```

</CodeGroup>

Again, breaking this change down:
Expand Down Expand Up @@ -552,10 +556,10 @@ Once we get to the stage of enabling the flag for 100% of users, we can either s
version: "1.2"
namespace: default
flags:
- key: use-quicksort-algorithm
name: Use Quicksort Algorithm
type: BOOLEAN_FLAG_TYPE
enabled: true
- key: use-quicksort-algorithm
name: Use Quicksort Algorithm
type: BOOLEAN_FLAG_TYPE
enabled: true
```

Beyond this, we can further close the loop by removing the feature flag call from our application code and simply use the new `quicksort` function.
Expand Down

0 comments on commit c125ffb

Please sign in to comment.