Skip to content

Commit

Permalink
test: add rolling upgrade test
Browse files Browse the repository at this point in the history
  • Loading branch information
gfyrag committed Nov 8, 2024
1 parent 5314238 commit 45a4b37
Show file tree
Hide file tree
Showing 55 changed files with 2,261 additions and 121 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
token: ${{ secrets.NUMARY_GITHUB_TOKEN }}
- run: >
earthly
--no-output
--allow-privileged
--secret SPEAKEASY_API_KEY=$SPEAKEASY_API_KEY
${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }}
Expand All @@ -77,6 +78,46 @@ jobs:
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

TestsDeployments:
runs-on: "formance-runner"
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-deployments-tests
cancel-in-progress: false
steps:
- uses: 'actions/checkout@v4'
with:
fetch-depth: 0
- name: Setup Env
uses: ./.github/actions/env
with:
token: ${{ secrets.NUMARY_GITHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: "NumaryBot"
password: ${{ secrets.NUMARY_GITHUB_TOKEN }}
- run: >
earthly
--allow-privileged
--no-output
--push
--secret GITHUB_TOKEN=$GITHUB_TOKEN
--secret KUBE_APISERVER=$KUBE_APISERVER
--secret KUBE_TOKEN=$KUBE_TOKEN
--secret PULUMI_ACCESS_TOKEN=$PULUMI_ACCESS_TOKEN
${{ contains(github.event.pull_request.labels.*.name, 'no-cache') && '--no-cache' || '' }}
./test/rolling-upgrades+run
--CLUSTER_NAME ledger-${{ github.event.number }}
--NO_CLEANUP=${{ contains(github.event.pull_request.labels.*.name, 'no-cleanup') && 'true' || 'false' }}
--NO_CLEANUP_ON_FAILURE=true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
KUBE_APISERVER: ${{ secrets.FORMANCE_DEV_KUBE_API_SERVER_ADDRESS }}
KUBE_TOKEN: ${{ secrets.FORMANCE_DEV_KUBE_TOKEN }}
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
GoReleaser:
runs-on: "formance-runner"
if: contains(github.event.pull_request.labels.*.name, 'build-images') || github.ref == 'refs/heads/main' || github.event_name == 'merge_group'
Expand Down
10 changes: 6 additions & 4 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,10 +382,12 @@ That's because, if we would do that, we would have frequent serialization errors

Tests are split in different scopes :
* Unit tests: as any go app, you will find unit test along the source code in _test.go files over the app.
* [e2e](./test/e2e) : End to end test. Those tests are mainly api tests, and app lifecycle tests. It checks than the ledger endpoint works as expected.
* [migrations](./test/migrations) : Migrations tests. Tests inside this package allow to import an existing database to apply current code migrations on it.
* [performance](./test/performance) : Performance tests. Tests inside this package test performance of the ledger.
* [stress](./test/stress) : Stress tests. Tests inside this package ensure than ledger state stay consistent under high concurrency.
* Integration tests: tests that involve the ledger and external services, like the database.
* [e2e](./test/e2e) : End to end test. Those tests are mainly api tests, and app lifecycle tests. It checks than the ledger endpoint works as expected.
* [migrations](./test/migrations) : Migrations tests. Tests inside this package allow to import an existing database to apply current code migrations on it.
* [performance](./test/performance) : Performance tests. Tests inside this package test performance of the ledger.
* [stress](./test/stress) : Stress tests. Tests inside this package ensure than ledger state stay consistent under high concurrency.
* [rolling-upgrades](./test/rolling-upgrades) : Rolling upgrade test under K8S

## API changes

Expand Down
33 changes: 26 additions & 7 deletions Earthfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
VERSION 0.8
VERSION --wildcard-builds 0.8
PROJECT FormanceHQ/ledger

IMPORT github.com/formancehq/earthly:tags/v0.17.1 AS core
Expand All @@ -22,7 +22,7 @@ sources:
WORKDIR /src
COPY go.mod go.sum ./
RUN go mod download
COPY --dir internal pkg cmd tools .
COPY --dir internal pkg cmd .
COPY main.go .
SAVE ARTIFACT /src

Expand Down Expand Up @@ -68,7 +68,6 @@ tests:
COPY --dir --pass-args (+generate/*) .

ARG includeIntegrationTests="true"
ARG includeEnd2EndTests="true"
ARG coverage=""
ARG debug=false

Expand Down Expand Up @@ -128,7 +127,6 @@ lint:
SAVE ARTIFACT internal AS LOCAL internal
SAVE ARTIFACT pkg AS LOCAL pkg
SAVE ARTIFACT test AS LOCAL test
SAVE ARTIFACT tools AS LOCAL tools
SAVE ARTIFACT main.go AS LOCAL main.go

pre-commit:
Expand All @@ -142,6 +140,10 @@ pre-commit:
BUILD +generate-client
BUILD +export-docs-events

# todo: currently not working with earthly
#BUILD ./test/rolling-upgrades+pre-commit
#BUILD ./tools/*+pre-commit

openapi:
FROM node:20-alpine
RUN apk update && apk add yq
Expand All @@ -167,6 +169,9 @@ tidy:
COPY --dir test .
RUN go mod tidy

SAVE ARTIFACT go.mod AS LOCAL go.mod
SAVE ARTIFACT go.sum AS LOCAL go.sum

release:
FROM core+builder-image
ARG mode=local
Expand All @@ -189,9 +194,23 @@ generate-client:
export-database-schema:
FROM +sources
RUN go install github.com/roerohan/wait-for-it@latest
COPY --dir scripts scripts
WITH DOCKER --load=postgres:15-alpine=+postgres --pull schemaspy/schemaspy:6.2.4
RUN ./scripts/export-database-schema.sh
RUN bash -c '
echo "Creating PG server...";
postgresContainerID=$(docker run -d --rm -e POSTGRES_USER=root -e POSTGRES_PASSWORD=root -e POSTGRES_DB=formance --net=host postgres:15-alpine);
wait-for-it -w 127.0.0.1:5432;
echo "Creating bucket...";
go run main.go buckets upgrade _default --postgres-uri "postgres://root:root@127.0.0.1:5432/formance?sslmode=disable";
echo "Exporting schemas...";
docker run --rm -u root \
-v ./docs/database:/output \
--net=host \
schemaspy/schemaspy:6.2.4 -u root -db formance -t pgsql11 -host 127.0.0.1 -port 5432 -p root -schemas _system,_default;
docker kill "$postgresContainerID";
'
END
SAVE ARTIFACT docs/database/_system/diagrams AS LOCAL docs/database/_system/diagrams
SAVE ARTIFACT docs/database/_default/diagrams AS LOCAL docs/database/_default/diagrams
Expand All @@ -201,6 +220,6 @@ export-docs-events:
CACHE --id go-mod-cache /go/pkg/mod
CACHE --id go-cache /root/.cache/go-build

RUN go run tools/docs/events/main.go --write-dir docs/events
RUN go run . docs events --write-dir docs/events

SAVE ARTIFACT docs/events AS LOCAL docs/events
13 changes: 13 additions & 0 deletions cmd/docs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package cmd

import "github.com/spf13/cobra"

func NewDocsCommand() *cobra.Command {
ret := &cobra.Command{
Use: "docs",
}
ret.AddCommand(NewDocFlagsCommand())
ret.AddCommand(NewDocEventsCommand())

return ret
}
11 changes: 3 additions & 8 deletions tools/docs/events/main.go → cmd/docs_events.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package main
package cmd

import (
"encoding/json"
Expand All @@ -11,11 +11,12 @@ import (
"reflect"
)

func newDocEventsCommand() *cobra.Command {
func NewDocEventsCommand() *cobra.Command {
const (
writeDirFlag = "write-dir"
)
cmd := &cobra.Command{
Use: "events",
RunE: func(cmd *cobra.Command, _ []string) error {

writeDir, err := cmd.Flags().GetString(writeDirFlag)
Expand Down Expand Up @@ -52,9 +53,3 @@ func newDocEventsCommand() *cobra.Command {

return cmd
}

func main() {
if err := newDocEventsCommand().Execute(); err != nil {
os.Exit(1)
}
}
14 changes: 3 additions & 11 deletions tools/docs/flags/main.go → cmd/docs_flags.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package main
package cmd

import (
"fmt"
ledgercmd "github.com/formancehq/ledger/cmd"
"os"
"sort"
"strings"
"text/tabwriter"
Expand All @@ -12,7 +10,7 @@ import (
"github.com/spf13/pflag"
)

func newDocFlagsCommand() *cobra.Command {
func NewDocFlagsCommand() *cobra.Command {
return &cobra.Command{
Use: "flags",
RunE: func(cmd *cobra.Command, _ []string) error {
Expand All @@ -21,7 +19,7 @@ func newDocFlagsCommand() *cobra.Command {

allKeys := make([]string, 0)

serveCommand := ledgercmd.NewServeCommand()
serveCommand := NewServeCommand()
serveCommand.Flags().VisitAll(func(f *pflag.Flag) {
allKeys = append(allKeys, f.Name)
})
Expand Down Expand Up @@ -51,9 +49,3 @@ func newDocFlagsCommand() *cobra.Command {
},
}
}

func main() {
if err := newDocFlagsCommand().Execute(); err != nil {
os.Exit(1)
}
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func NewRootCommand() *cobra.Command {
// todo: use provided db ...
return upgradeAll(cmd)
}))
root.AddCommand(NewDocsCommand())

return root
}
Expand Down
File renamed without changes.
File renamed without changes.
23 changes: 23 additions & 0 deletions deployments/helm/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*.orig
*~
# Various IDEs
.project
.idea/
*.tmproj
.vscode/
24 changes: 24 additions & 0 deletions deployments/helm/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
apiVersion: v2
name: ledger
description: A Helm chart for Kubernetes

# A chart can be either an 'application' or a 'library' chart.
#
# Application charts are a collection of templates that can be packaged into versioned archives
# to be deployed.
#
# Library charts provide useful utilities or functions for the chart developer. They're included as
# a dependency of application charts to inject those utilities and functions into the rendering
# pipeline. Library charts do not define any templates and therefore cannot be deployed.
type: application

# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.1.0

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
# follow Semantic Versioning. They should reflect the version the application is using.
# It is recommended to use it with quotes.
appVersion: "latest"
12 changes: 12 additions & 0 deletions deployments/helm/Earthfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
VERSION 0.8
PROJECT FormanceHQ/ledger

IMPORT github.com/formancehq/earthly:tags/v0.17.1 AS core

FROM core+base-image

sources:
WORKDIR /src
COPY *.yaml .
COPY --dir templates .
SAVE ARTIFACT /src
5 changes: 5 additions & 0 deletions deployments/helm/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Helm

> [!WARNING]
> This chart is used for testing only. It is not intended for production use.
> It can be broken or removed at any time.
22 changes: 22 additions & 0 deletions deployments/helm/templates/NOTES.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
1. Get the application URL by running these commands:
{{- if .Values.ingress.enabled }}
{{- range $host := .Values.ingress.hosts }}
{{- range .paths }}
http{{ if $.Values.ingress.tls }}s{{ end }}://{{ $host.host }}{{ .path }}
{{- end }}
{{- end }}
{{- else if contains "NodePort" .Values.service.type }}
export NODE_PORT=$(kubectl get --namespace {{ .Release.Namespace }} -o jsonpath="{.spec.ports[0].nodePort}" services {{ include "chart.fullname" . }})
export NODE_IP=$(kubectl get nodes --namespace {{ .Release.Namespace }} -o jsonpath="{.items[0].status.addresses[0].address}")
echo http://$NODE_IP:$NODE_PORT
{{- else if contains "LoadBalancer" .Values.service.type }}
NOTE: It may take a few minutes for the LoadBalancer IP to be available.
You can watch the status of by running 'kubectl get --namespace {{ .Release.Namespace }} svc -w {{ include "chart.fullname" . }}'
export SERVICE_IP=$(kubectl get svc --namespace {{ .Release.Namespace }} {{ include "chart.fullname" . }} --template "{{"{{ range (index .status.loadBalancer.ingress 0) }}{{.}}{{ end }}"}}")
echo http://$SERVICE_IP:{{ .Values.service.port }}
{{- else if contains "ClusterIP" .Values.service.type }}
export POD_NAME=$(kubectl get pods --namespace {{ .Release.Namespace }} -l "app.kubernetes.io/name={{ include "chart.name" . }},app.kubernetes.io/instance={{ .Release.Name }}" -o jsonpath="{.items[0].metadata.name}")
export CONTAINER_PORT=$(kubectl get pod --namespace {{ .Release.Namespace }} $POD_NAME -o jsonpath="{.spec.containers[0].ports[0].containerPort}")
echo "Visit http://127.0.0.1:8080 to use your application"
kubectl --namespace {{ .Release.Namespace }} port-forward $POD_NAME 8080:$CONTAINER_PORT
{{- end }}
Loading

0 comments on commit 45a4b37

Please sign in to comment.