Skip to content

Commit

Permalink
feat!: package refactor
Browse files Browse the repository at this point in the history
Signed-off-by: James Milligan <james@omnant.co.uk>
  • Loading branch information
james-milligan committed Mar 30, 2023
2 parents 3faddd7 + 019be18 commit b765684
Show file tree
Hide file tree
Showing 53 changed files with 1,012 additions and 432 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ jobs:
severity: "CRITICAL,HIGH"

- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@67a35a08586135a9573f4327e904ecbf517a882d # v2
uses: github/codeql-action/upload-sarif@04df1262e6247151b5ac09cd2c303ac36ad3f62b # v2
with:
sarif_file: "trivy-results.sarif"

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dev-benches-page.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- name: Setup Pages
uses: actions/configure-pages@7110e9e03ffb4a421945e5d0607007b8e9f1f52b # v3
- name: Upload artifact
uses: actions/upload-pages-artifact@253fd476ed429e83b7aae64a92a75b4ceb1a17cf # v1
uses: actions/upload-pages-artifact@64bcae551a7b18bcb9a09042ddf1960979799187 # v1
with:
path: './dev/bench'
- name: Deploy to GitHub Pages
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/publish-benchmark.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ jobs:
with:
go-version: ${{ env.GO_VERSION }}

- name: Workspace init
run: make workspace-init

- name: Run benchmark
run: set -o pipefail; go test -bench=Bench -short -benchtime=5s -benchmem ./core/... | tee output.txt

Expand All @@ -32,3 +35,7 @@ jobs:
output-file-path: output.txt
github-token: ${{ secrets.GITHUB_TOKEN }}
auto-push: true
# Show alert with commit comment on detecting possible performance regression
alert-threshold: "130%"
comment-on-alert: true
fail-on-alert: false
16 changes: 8 additions & 8 deletions .github/workflows/release-please.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ on:

env:
# Stringified list of items that should be published
PUBLISHABLE_ITEMS: '["flagd","kube-flagd-proxy"]'
PUBLISHABLE_ITEMS: '["flagd","flagd-proxy"]'
REGISTRY: ghcr.io
REPO_OWNER: ${{ github.repository_owner }}
DEFAULT_GO_VERSION: 1.19
Expand All @@ -19,7 +19,7 @@ jobs:
runs-on: ubuntu-latest
# Release-please creates a PR that tracks all changes
steps:
- uses: google-github-actions/release-please-action@e0b9d1885d92e9a93d5ce8656de60e3b806e542c # v3
- uses: google-github-actions/release-please-action@ee9822ec2c397e8a364d634464339ac43a06e042 # v3
id: release
with:
command: manifest
Expand Down Expand Up @@ -53,8 +53,8 @@ jobs:
items_to_publish: ${{ steps.items-to-publish.outputs.result }}
flagd_version: ${{ steps.release.outputs.flagd--version }}
flagd_tag_name: ${{ steps.release.outputs.flagd--tag_name }}
kube-flagd-proxy_version: ${{ steps.release.outputs.kube-flagd-proxy--version }}
kube-flagd-proxy_tag_name: ${{ steps.release.outputs.kube-flagd-proxy--tag_name }}
flagd-proxy_version: ${{ steps.release.outputs.flagd-proxy--version }}
flagd-proxy_tag_name: ${{ steps.release.outputs.flagd-proxy--tag_name }}

container-release:
name: Build and push containers to GHCR
Expand Down Expand Up @@ -118,7 +118,7 @@ jobs:
COMMIT=${{ github.sha }}
DATE=${{ steps.date.outputs.date }}
- name: Install Cosign
uses: sigstore/cosign-installer@00bf1366a3f8c043c1f6f802441642bced142f5c
uses: sigstore/cosign-installer@8348525c79cd67509c593a9352954618bdc3a862

- name: Sign the image
run: |
Expand Down Expand Up @@ -173,7 +173,7 @@ jobs:
with:
version: v1
- name: setup for builds
# TODO: The README should also be moved ready for bundling once both kube-flagd-proxy and flagd have package specific READMEs
# TODO: The README should also be moved ready for bundling once both flagd-proxy and flagd have package specific READMEs
run: |
make workspace-init
mv ./${{ matrix.path }}/CHANGELOG.md CHANGELOG.md
Expand Down Expand Up @@ -218,7 +218,7 @@ jobs:
needs: release-please
runs-on: ubuntu-latest
# Only run on non-forked flagd releases
if: ${{ github.repository_owner == 'openfeature' && needs.release-please.outputs.flagd_tag_name }}
if: ${{ github.repository_owner == 'open-feature' && needs.release-please.outputs.flagd_tag_name }}
steps:
- uses: mislav/bump-homebrew-formula-action@v2
with:
Expand All @@ -229,4 +229,4 @@ jobs:
{{formulaName}} {{version}}
Created by https://github.com/mislav/bump-homebrew-formula-action
env:
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
COMMITTER_TOKEN: ${{ secrets.COMMITTER_TOKEN }}
2 changes: 1 addition & 1 deletion .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"flagd": "0.4.5",
"kube-flagd-proxy": "0.1.2",
"flagd-proxy": "0.1.2",
"core": "0.4.5"
}
5 changes: 4 additions & 1 deletion CODEOWNERS
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
# These owners will be the default owners for everything in
# the repo. Unless a later match takes precedence
* @AlexsJones @james-milligan @toddbaert @kavindu-dodan
#
# Managed by Peribolos: https://github.com/open-feature/community/blob/main/config/open-feature/cloud-native/workgroup.yaml
#
* @open-feature/cloud-native-maintainers
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@ PHONY: .docker-build .build .run .mockgen
PREFIX=/usr/local
ALL_GO_MOD_DIRS := $(shell find . -type f -name 'go.mod' -exec dirname {} \; | sort)

workspace-init:
workspace-init: workspace-clean
go work init
$(foreach module, $(ALL_GO_MOD_DIRS), go work use $(module);)

workspace-update:
$(foreach module, $(ALL_GO_MOD_DIRS), go work use $(module);)

workspace-clean:
rm -rf go.work

guard-%:
@ if [ "${${*}}" = "" ]; then \
echo "Environment variable $* not set"; \
Expand All @@ -23,7 +26,7 @@ docker-build-flagd:
docker buildx build --build-arg=VERSION="$$(git describe --tags --abbrev=0)" --build-arg=COMMIT="$$(git rev-parse --short HEAD)" --build-arg DATE="$$(date +%FT%TZ)" --platform="linux/arm64" -t ${IMG} -f flagd/build.Dockerfile .
docker-push-flagd:
docker buildx build --push --build-arg=VERSION="$$(git describe --tags --abbrev=0)" --build-arg=COMMIT="$$(git rev-parse --short HEAD)" --build-arg DATE="$$(date +%FT%TZ)" --platform="linux/ppc64le,linux/s390x,linux/amd64,linux/arm64" -t ${IMG} -f flagd/build.Dockerfile .
build: # default to flagd
build: workspace-init # default to flagd
make build-flagd
build-flagd:
go build -ldflags "-X main.version=dev -X main.commit=$$(git rev-parse --short HEAD) -X main.date=$$(date +%FT%TZ)" -o ./bin/flagd ./flagd
Expand Down Expand Up @@ -60,6 +63,7 @@ mockgen: install-mockgen
cd core; mockgen -source=pkg/sync/grpc/grpc_sync.go -destination=pkg/sync/grpc/mock/grpc.go -package=grpcmock
cd core; mockgen -source=pkg/sync/grpc/credentials/builder.go -destination=pkg/sync/grpc/credentials/mock/builder.go -package=credendialsmock
cd core; mockgen -source=pkg/eval/ievaluator.go -destination=pkg/eval/mock/ievaluator.go -package=evalmock
cd core; mockgen -source=pkg/service/middleware/interface.go -destination=pkg/service/middleware/mock/interface.go -package=middlewaremock
generate-docs:
cd flagd; go run ./cmd/doc/main.go

Expand Down
126 changes: 108 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<img src="images/flagD.png" width="350px;" >
</h1>

<h2 align="center">A feature flag daemon with a Unix philosophy.</h4>
<h2 align="center">A feature flag daemon with a Unix philosophy.</h2>

<p align="center">
<a href="https://github.com/open-feature/flagd/actions">
Expand All @@ -12,32 +12,122 @@
<a href="https://goreportcard.com/report/github.com/open-feature/flagd">
<img src="https://goreportcard.com/badge/github.com/open-feature/flagd">
</a>
</a>
<a href="https://killercoda.com/open-feature/scenario/flagd-demo">
<img src="https://img.shields.io/badge/Killercoda-Interactive%20Demo-blue">
</a>
</p>

<!-- markdownlint-enable MD033 -->

## What's flagd?

Flagd is a feature flag daemon with a Unix philosophy. Think of it as a ready-made, open source, OpenFeature compliant feature flag backend system.

## Features

- OpenFeature compliant with providers available in many languages
- Multiple flag configuration sources including `files`, `http`, and `Kubernetes`
- Accessible over gRPC and HTTP
- Supports subscriptions to real-time flag change events
- Flexible targeting rules based on [JSON Logic](https://jsonlogic.com/)
- Lightweight daemon, with an emphasis on performance
- Native support for metrics using Prometheus
- 🌐 OpenFeature compliant and [speaks your language](docs/usage/flagd_providers.md).
- 🆕 Easy to [extend to new languages](docs/other_resources/creating_providers.md).
- 🔄 Supports multiple data sources simultaneously.
- 🕒 Feature Flag updates occur in near real-time.
- 💪 Contains a [powerful and flexible rule targeting engine](docs/configuration/reusable_targeting_rules.md) and [deterministic percentage-based rollouts](docs/configuration/fractional_evaluation.md).
- 🔦 Flag evaluation statistics and metrics are exposed and compatible with Prometheus.

## ▶️ Quick Start

Experiment with flagd in your browser using [the Killercoda tutorial](https://killercoda.com/open-feature/scenario/flagd-demo) or follow the instructions below to run on your own infrastructure.

1. flagd can be run as a standalone-binary or container. [Download and install flagd or run it as a container](docs/usage/installation_options.md)

Kubernetes-native? flagd can also be run [as part of the Kubernetes Operator](https://github.com/open-feature/open-feature-operator).

2. Start flagd:

```sh
flagd start \
--port 8013 \
--uri https://raw.githubusercontent.com/open-feature/flagd/main/samples/example_flags.flagd.json
```

Or use docker:

```sh
docker run \
--rm -it \
--name flagd \
-p 8013:8013 \
ghcr.io/open-feature/flagd:latest start \
--uri https://raw.githubusercontent.com/open-feature/flagd/main/samples/example_flags.flagd.json
```

If you wish, download the file locally to make changes:

```sh
wget https://raw.githubusercontent.com/open-feature/flagd/main/samples/example_flags.flagd.json
```

In local mode, run flagd like this:

```sh
flagd start \
--port 8013 \
--uri file:./example_flags.flagd.json
```

Or use docker:

```sh
docker run \
--rm -it \
--name flagd \
-p 8013:8013 \
-v $(pwd):/etc/flagd \
ghcr.io/open-feature/flagd:latest start \
--uri file:./etc/flagd/example_flags.flagd.json
```

`--uri` can be a local file or any remote endpoint. Use `file:` prefix for local files. eg. `--uri file:/path/to/example_flags.flagd.json`. `gRPC` and `http` have their own requirements. More information can be found [here](docs/configuration/configuration.md#uri-patterns).

Multiple `--uri` parameters can be specified. In other words, flagd can retrieve flags from multiple sources simultaneously.

3. Flagd is now ready to perform flag evaluations over either `HTTP(s)` or `gRPC`. This example utilizes `HTTP` via `cURL`.

Retrieve a `String` value:

```sh
curl -X POST "http://localhost:8013/schema.v1.Service/ResolveString" \
-d '{"flagKey":"myStringFlag","context":{}}' -H "Content-Type: application/json"
```

Result:

```json
{
"value": "val1",
"reason": "DEFAULT",
"variant":"key1"
}
```

Updates to the underlying flag store (e.g. JSON file) are reflected by flagd in realtime. No restarts required.

flagd also supports boolean, integer, float and object flag types. Read more on the [evaluation examples page](docs/usage/evaluation_examples.md)

4. Now that flagd is running, it is time to integrate into your application. Do this by using [an OpenFeature provider in a language of your choice](https://github.com/open-feature/flagd/blob/main/docs/usage/flagd_providers.md).

## 📐 High-level Architecture

![logical architecture of flagd](docs/images/flagd-logical-architecture.jpg "High level, logical architecture of flagd")

## Get started
## 📝 Further Documentation

Flagd is a simple command line tool for fetching and evaluating feature flags for services.
It is designed to conform with the OpenFeature specification.
To get started, follow the installation instructions in the [docs](https://github.com/open-feature/flagd/blob/main/docs/README.md).
Further documentation including flagd configuration options, fractional evaluation, targeting rules and flag configuration merging strategies can be found [on this page](docs/README.md).

## Contributing
## 🫶 Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to the OpenFeature project.
Interested in contributing? Great, we'd love your help! To get started, take a look at the [CONTRIBUTING](CONTRIBUTING.md) guide.
Our community meetings are held regularly and open to everyone.
Check the [OpenFeature community calendar](https://calendar.google.com/calendar/u/0?cid=MHVhN2kxaGl2NWRoMThiMjd0b2FoNjM2NDRAZ3JvdXAuY2FsZW5kYXIuZ29vZ2xlLmNvbQ) for specific dates and for the Zoom meeting links.
We also hold regular community meetings that are open to everyone.
Check the [OpenFeature community page](https://docs.openfeature.dev/community/) for all the ways to get involved.
Thanks so much to our contributors.
Expand All @@ -51,4 +141,4 @@ Made with [contrib.rocks](https://contrib.rocks).
## License
Apache License 2.0
[Apache License 2.0](LICENSE)
2 changes: 1 addition & 1 deletion config/deployments/kube-flagd-proxy/crb.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ subjects:
namespace: system
- kind: ServiceAccount
name: default
namespace: kube-proxy
namespace: flagd-proxy
16 changes: 8 additions & 8 deletions config/deployments/kube-flagd-proxy/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,29 @@ apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
namespace: kube-proxy
namespace: flagd-proxy
labels:
app: kube-proxy
name: kube-proxy
app: flagd-proxy
name: flagd-proxy
annotations:
openfeature.dev/allowkubernetessync: "true"
spec:
replicas: 1
selector:
matchLabels:
app: kube-proxy
app: flagd-proxy
template:
metadata:
creationTimestamp: null
labels:
app.kubernetes.io/name: kube-proxy
app: kube-proxy
app.kubernetes.io/name: flagd-proxy
app: flagd-proxy
annotations:
openfeature.dev/allowkubernetessync: "true"
spec:
containers:
- image: ghcr.io/open-feature/kube-flagd-proxy:latest
name: kube-flagd-proxy
- image: ghcr.io/open-feature/flagd-proxy:latest
name: flagd-proxy
ports:
- containerPort: 8015
args:
Expand Down
6 changes: 3 additions & 3 deletions config/deployments/kube-flagd-proxy/service.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
apiVersion: v1
kind: Service
metadata:
name: kube-proxy-svc
namespace: kube-proxy
name: flagd-proxy-svc
namespace: flagd-proxy
spec:
selector:
app.kubernetes.io/name: kube-proxy
app.kubernetes.io/name: flagd-proxy
ports:
- port: 8015
targetPort: 8015
2 changes: 1 addition & 1 deletion core/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
gopkg.in/yaml.v3 v3.0.1
k8s.io/apimachinery v0.26.3
k8s.io/client-go v0.26.3
sigs.k8s.io/controller-runtime v0.14.5
sigs.k8s.io/controller-runtime v0.14.6
)

require (
Expand Down
2 changes: 2 additions & 0 deletions core/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1313,6 +1313,8 @@ rsc.io/quote/v3 v3.1.0/go.mod h1:yEA65RcK8LyAZtP9Kv3t0HmxON59tX3rD+tICJqUlj0=
rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
sigs.k8s.io/controller-runtime v0.14.5 h1:6xaWFqzT5KuAQ9ufgUaj1G/+C4Y1GRkhrxl+BJ9i+5s=
sigs.k8s.io/controller-runtime v0.14.5/go.mod h1:WqIdsAY6JBsjfc/CqO0CORmNtoCtE4S6qbPc9s68h+0=
sigs.k8s.io/controller-runtime v0.14.6 h1:oxstGVvXGNnMvY7TAESYk+lzr6S3V5VFxQ6d92KcwQA=
sigs.k8s.io/controller-runtime v0.14.6/go.mod h1:WqIdsAY6JBsjfc/CqO0CORmNtoCtE4S6qbPc9s68h+0=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd h1:EDPBXCAspyGV4jQlpZSudPeMmr1bNJefnuqLsRAsHZo=
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd/go.mod h1:B8JuhiUyNFVKdsE8h686QcCxMaH6HrOAZj4vswFpcB0=
sigs.k8s.io/structured-merge-diff/v4 v4.2.3 h1:PRbqxJClWWYMNV1dhaG4NsibJbArud9kFxnAMREiWFE=
Expand Down
Loading

0 comments on commit b765684

Please sign in to comment.