Skip to content

Commit

Permalink
Redis cache impl (#954)
Browse files Browse the repository at this point in the history
* Redis impl

* small changes

* Fix linter false positives

* rm sleuth/nancy from scan workflow

* Update server/middleware.go

Co-authored-by: Thomas Sickert <thomas.sickert@gmail.com>

* remove double comment

* add some more test coverage for cache config

* Add test coverage for evaluation middleware

Co-authored-by: Thomas Sickert <thomas.sickert@gmail.com>
  • Loading branch information
markphelps and tsickert committed Jul 25, 2022
1 parent d507232 commit 61d898b
Show file tree
Hide file tree
Showing 62 changed files with 2,932 additions and 2,116 deletions.
2 changes: 1 addition & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
*.out
*.test

.devcontainer/
.github/
.vscode/
.licenses/
.task/
Dockerfile
LICENSE
Expand Down
10 changes: 7 additions & 3 deletions .github/actions/integration-test/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@
name: "Flipt IT Tests"
description: "Container for running Flipt ITs"
inputs:
args: # id of input
description: args to pass to container'
script: # id of input
description: "script to run in the container"
required: true
config: # id of input
description: "optional config file"
required: false
runs:
using: "docker"
image: "docker://ghcr.io/flipt-io/flipt-integration-test"
args:
- ${{ inputs.args }}
- ${{ inputs.script }}
- ${{ inputs.config }}
139 changes: 121 additions & 18 deletions .github/workflows/integration-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ on:
workflow_dispatch:

jobs:
test:
name: Test
build:
name: Build
runs-on: ubuntu-latest

timeout-minutes: 20
Expand All @@ -32,7 +32,16 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: "1.17.x"
go-version: "1.17"
check-latest: true
cache: true

- uses: actions/cache@v3
with:
path: _tools/
key: ${{ runner.os }}-go-tools${{ hashFiles('_tools/go.sum') }}
restore-keys: |
${{ runner.os }}-go-tools-
- uses: actions/setup-node@v3
with:
Expand All @@ -42,30 +51,124 @@ jobs:

- uses: arduino/setup-task@v1

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Build the binary
run: |
task
- name: Test API
- name: Upload the binary
uses: actions/upload-artifact@v3
with:
name: flipt
path: bin/flipt
if-no-files-found: error
retention-days: 1

api:
needs: build
name: Test API
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
id: download
with:
name: flipt
path: bin/

- run: chmod +x flipt
working-directory: bin/

- name: Run API tests
uses: ./.github/actions/integration-test
with:
script: ./test/api.sh

- name: Upload the log
uses: actions/upload-artifact@v3
with:
name: api.log
path: out.log
retention-days: 5

redis:
needs: build
name: Test Redis
runs-on: ubuntu-latest

services:
redis:
image: redis
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
id: download
with:
name: flipt
path: bin/

- run: chmod +x flipt
working-directory: bin/

- name: Run API tests
uses: ./.github/actions/integration-test
with:
args: ./test/api.sh
script: ./test/api.sh
config: "redis.yml"

- name: Test CLI
- name: Upload the log
uses: actions/upload-artifact@v3
with:
name: redis.log
path: out.log
retention-days: 5

cli:
needs: build
name: Test CLI
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
name: flipt
path: bin/

- run: chmod +x flipt
working-directory: bin/

- name: Run CLI tests
uses: ./.github/actions/integration-test
with:
args: ./test/cli.bats
script: ./test/cli.bats

ui:
needs: build
name: Test UI
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/download-artifact@v3
with:
name: flipt
path: bin/

- run: chmod +x flipt
working-directory: bin/

- name: Test UI
- name: Run UI tests
uses: ./.github/actions/integration-test
with:
args: ./test/ui.sh
script: ./test/ui.sh
18 changes: 0 additions & 18 deletions .github/workflows/scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,6 @@ on:
workflow_dispatch:

jobs:
sleuth:
name: Nancy
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- uses: actions/setup-go@v3
with:
go-version: "1.17.x"

- run: go list -json -m all > go.list

- name: Nancy
uses: sonatype-nexus-community/nancy-github-action@main

gitleaks:
name: Gitleaks
runs-on: ubuntu-latest
Expand Down
26 changes: 6 additions & 20 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,45 +29,31 @@ jobs:

- uses: actions/setup-go@v3
with:
go-version: "1.17.x"
go-version: "1.17"
check-latest: true
cache: true

- name: golangci-lint
uses: golangci/golangci-lint-action@v3.2.0
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.44

# Optional: working directory, useful for monorepos
# working-directory: somedir

# Optional: golangci-lint command line arguments.
# args: --issues-exit-code=0

# Optional: show only new issues if it's a pull request. The default value is `false`.
# only-new-issues: true

test:
name: Test
runs-on: ubuntu-latest
strategy:
matrix:
go: ["1.17.x", "1.18.x"]
go: ["1.17", "1.18"]

steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}

- uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
check-latest: true
cache: true

- name: Unit Test (SQLite)
run: go test -race -covermode=atomic -coverprofile=coverage.txt -count=1 ./...
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ _test
!**/**/testdata/**/*.pem

bin
pkg
benchmark
coverage.txt
dist
Expand All @@ -36,4 +37,4 @@ __debug_bin

Brewfile.lock.json
*.key
.task/
.task/
20 changes: 9 additions & 11 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ linters:
- unparam
- varcheck
disable:
- contextcheck
- exhaustive
- rowserrcheck
enable-all: false
Expand All @@ -61,21 +62,18 @@ issues:
# excluded by default patterns execute `golangci-lint run --help`
exclude:
- "composite literal uses unkeyed fields"
exclude-rules:
# Exclude some staticcheck messages
- linters:
- staticcheck
text: "SA1019: package github.com/golang/protobuf"
- linters:
- staticcheck
text: "SA1019: ptypes."
- linters:
- staticcheck
text: "SA1019: proto."

linters-settings:
depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/pkg/errors
staticcheck:
checks:
- all
- "-SA1019" # exclude staticcheck messages from github.com/golang/protobuf
gosec:
excludes: # exclude gosec messages about weak crypto
- "G501"
- "G401"
7 changes: 2 additions & 5 deletions Brewfile
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
tap 'filosottile/musl-cross'
tap 'goreleaser/tap'
tap 'go-task/tap'
tap 'anchore/syft'

brew 'cmake'
brew 'cosign'
brew 'go'
brew 'goreleaser'
brew 'go-task'
brew 'hadolint'
brew 'minikube'
brew 'musl-cross'
brew 'pkg-config'
brew 'protobuf'
brew 'sqlite'
brew 'syft'
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

### Added

- Redis cache support :tada: [https://github.com/markphelps/flipt/issues/633](https://github.com/markphelps/flipt/issues/633)
- Support for pretty printing JSON responses from API (via ?pretty=true or setting `Accept: application/json+pretty` header)
- Configuration warnings/deprecations are displayed in console at startup

### Changed

- Ping database on startup to check if it's alive
- Default cache TTL is 1m. Previously there was no TTL for the in memory cache.

### Deprecated

- `cache.memory.enabled` config value is deprecated. See [Deprecations](DEPRECATIONS.md) for more info
- `cache.memory.expiration` config value is deprecated. See [Deprecations](DEPRECATIONS.md) for more info

### Fixed

- Build date was incorrect and always showed current date/time
Expand Down
Loading

0 comments on commit 61d898b

Please sign in to comment.